blob: 0de768755f91297d4dadbc521f29d2b2d39e91d1 [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, Tomasc2d79b42008-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, Tomasc2d79b42008-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, Tomasc2d79b42008-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, Tomasc2d79b42008-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
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001388static void iwl3945_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07001389{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001390 struct iwl_priv *priv =
1391 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07001392 struct sk_buff *beacon;
1393
1394 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02001395 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07001396
1397 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001398 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07001399 return;
1400 }
1401
1402 mutex_lock(&priv->mutex);
1403 /* new beacon skb is allocated every time; dispose previous.*/
1404 if (priv->ibss_beacon)
1405 dev_kfree_skb(priv->ibss_beacon);
1406
1407 priv->ibss_beacon = beacon;
1408 mutex_unlock(&priv->mutex);
1409
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001410 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001411}
1412
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001413static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001414 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001415{
Samuel Ortizd08853a2009-01-23 13:45:17 -08001416#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001417 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001418 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
Zhu Yib481de92007-09-25 17:54:57 -07001419 u8 rate = beacon->beacon_notify_hdr.rate;
1420
Tomas Winklere1623442009-01-27 14:27:56 -08001421 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
Zhu Yib481de92007-09-25 17:54:57 -07001422 "tsf %d %d rate %d\n",
1423 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
1424 beacon->beacon_notify_hdr.failure_frame,
1425 le32_to_cpu(beacon->ibss_mgr_status),
1426 le32_to_cpu(beacon->high_tsf),
1427 le32_to_cpu(beacon->low_tsf), rate);
1428#endif
1429
Johannes Berg05c914f2008-09-11 00:01:58 +02001430 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -07001431 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1432 queue_work(priv->workqueue, &priv->beacon_update);
1433}
1434
Zhu Yib481de92007-09-25 17:54:57 -07001435/* Handle notification from uCode that card's power state is changing
1436 * due to software, hardware, or critical temperature RFKILL */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001437static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001438 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001439{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001440 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001441 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1442 unsigned long status = priv->status;
1443
Tomas Winklere1623442009-01-27 14:27:56 -08001444 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n",
Zhu Yib481de92007-09-25 17:54:57 -07001445 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1446 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1447
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001448 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001449 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1450
1451 if (flags & HW_CARD_DISABLED)
1452 set_bit(STATUS_RF_KILL_HW, &priv->status);
1453 else
1454 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1455
1456
1457 if (flags & SW_CARD_DISABLED)
1458 set_bit(STATUS_RF_KILL_SW, &priv->status);
1459 else
1460 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1461
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08001462 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001463
1464 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1465 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1466 (test_bit(STATUS_RF_KILL_SW, &status) !=
1467 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1468 queue_work(priv->workqueue, &priv->rf_kill);
1469 else
1470 wake_up_interruptible(&priv->wait_command_queue);
1471}
1472
1473/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001474 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07001475 *
1476 * Setup the RX handlers for each of the reply types sent from the uCode
1477 * to the host.
1478 *
1479 * This function chains into the hardware specific files for them to setup
1480 * any hardware specific handlers as well.
1481 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001482static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001483{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001484 priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
1485 priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
Abhijeet Kolekar261b9c32009-02-18 15:54:29 -08001486 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001487 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -08001488 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001489 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -08001490 iwl_rx_pm_debug_statistics_notif;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001491 priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001492
Ben Cahill9fbab512007-11-29 11:09:47 +08001493 /*
1494 * The same handler is used for both the REPLY to a discrete
1495 * statistics request from the host as well as for the periodic
1496 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07001497 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001498 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
1499 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
Zhu Yib481de92007-09-25 17:54:57 -07001500
Abhijeet Kolekar261b9c32009-02-18 15:54:29 -08001501 iwl_setup_spectrum_handlers(priv);
Abhijeet Kolekarcade0eb2009-02-18 15:54:26 -08001502 iwl_setup_rx_scan_handlers(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001503 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001504
Ben Cahill9fbab512007-11-29 11:09:47 +08001505 /* Set up hardware specific Rx handlers */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001506 iwl3945_hw_rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001507}
1508
1509/**
Tomas Winkler91c066f2008-03-06 17:36:55 -08001510 * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries
1511 * When FW advances 'R' index, all entries between old and new 'R' index
1512 * need to be reclaimed.
1513 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001514static void iwl3945_cmd_queue_reclaim(struct iwl_priv *priv,
Tomas Winkler91c066f2008-03-06 17:36:55 -08001515 int txq_id, int index)
1516{
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001517 struct iwl_tx_queue *txq = &priv->txq[txq_id];
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001518 struct iwl_queue *q = &txq->q;
Tomas Winkler91c066f2008-03-06 17:36:55 -08001519 int nfreed = 0;
1520
Winkler, Tomas625a3812009-01-08 10:19:55 -08001521 if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001522 IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, "
Tomas Winkler91c066f2008-03-06 17:36:55 -08001523 "is out of range [0-%d] %d %d.\n", txq_id,
1524 index, q->n_bd, q->write_ptr, q->read_ptr);
1525 return;
1526 }
1527
1528 for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
1529 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
1530 if (nfreed > 1) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001531 IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", index,
Tomas Winkler91c066f2008-03-06 17:36:55 -08001532 q->write_ptr, q->read_ptr);
1533 queue_work(priv->workqueue, &priv->restart);
1534 break;
1535 }
1536 nfreed++;
1537 }
1538}
1539
1540
1541/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001542 * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
Zhu Yib481de92007-09-25 17:54:57 -07001543 * @rxb: Rx buffer to reclaim
1544 *
1545 * If an Rx buffer has an async callback associated with it the callback
1546 * will be executed. The attached skb (if present) will only be freed
1547 * if the callback returns 1
1548 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001549static void iwl3945_tx_cmd_complete(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001550 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001551{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001552 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001553 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
1554 int txq_id = SEQ_TO_QUEUE(sequence);
1555 int index = SEQ_TO_INDEX(sequence);
Tomas Winkler600c0e12008-12-19 10:37:04 +08001556 int huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
Zhu Yib481de92007-09-25 17:54:57 -07001557 int cmd_index;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08001558 struct iwl_cmd *cmd;
Zhu Yib481de92007-09-25 17:54:57 -07001559
Chatre, Reinette638d0eb2009-01-19 15:30:24 -08001560 if (WARN(txq_id != IWL_CMD_QUEUE_NUM,
1561 "wrong command queue %d, sequence 0x%X readp=%d writep=%d\n",
1562 txq_id, sequence,
1563 priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr,
1564 priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) {
1565 iwl_print_hex_dump(priv, IWL_DL_INFO , rxb, 32);
1566 return;
1567 }
Zhu Yib481de92007-09-25 17:54:57 -07001568
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001569 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
1570 cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
Zhu Yib481de92007-09-25 17:54:57 -07001571
1572 /* Input error checking is done when commands are added to queue. */
1573 if (cmd->meta.flags & CMD_WANT_SKB) {
1574 cmd->meta.source->u.skb = rxb->skb;
1575 rxb->skb = NULL;
1576 } else if (cmd->meta.u.callback &&
1577 !cmd->meta.u.callback(priv, cmd, rxb->skb))
1578 rxb->skb = NULL;
1579
Tomas Winkler91c066f2008-03-06 17:36:55 -08001580 iwl3945_cmd_queue_reclaim(priv, txq_id, index);
Zhu Yib481de92007-09-25 17:54:57 -07001581
1582 if (!(cmd->meta.flags & CMD_ASYNC)) {
1583 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1584 wake_up_interruptible(&priv->wait_command_queue);
1585 }
1586}
1587
1588/************************** RX-FUNCTIONS ****************************/
1589/*
1590 * Rx theory of operation
1591 *
1592 * The host allocates 32 DMA target addresses and passes the host address
1593 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
1594 * 0 to 31
1595 *
1596 * Rx Queue Indexes
1597 * The host/firmware share two index registers for managing the Rx buffers.
1598 *
1599 * The READ index maps to the first position that the firmware may be writing
1600 * to -- the driver can read up to (but not including) this position and get
1601 * good data.
1602 * The READ index is managed by the firmware once the card is enabled.
1603 *
1604 * The WRITE index maps to the last position the driver has read from -- the
1605 * position preceding WRITE is the last slot the firmware can place a packet.
1606 *
1607 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
1608 * WRITE = READ.
1609 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001610 * During initialization, the host sets up the READ queue position to the first
Zhu Yib481de92007-09-25 17:54:57 -07001611 * INDEX position, and WRITE to the last (READ - 1 wrapped)
1612 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001613 * When the firmware places a packet in a buffer, it will advance the READ index
Zhu Yib481de92007-09-25 17:54:57 -07001614 * and fire the RX interrupt. The driver can then query the READ index and
1615 * process as many packets as possible, moving the WRITE index forward as it
1616 * resets the Rx queue buffers with new memory.
1617 *
1618 * The management in the driver is as follows:
1619 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
1620 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Ian Schram01ebd062007-10-25 17:15:22 +08001621 * to replenish the iwl->rxq->rx_free.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001622 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
Zhu Yib481de92007-09-25 17:54:57 -07001623 * iwl->rxq is replenished and the READ INDEX is updated (updating the
1624 * 'processed' and 'read' driver indexes as well)
1625 * + A received packet is processed and handed to the kernel network stack,
1626 * detached from the iwl->rxq. The driver 'processed' index is updated.
1627 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
1628 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
1629 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
1630 * were enough free buffers and RX_STALLED is set it is cleared.
1631 *
1632 *
1633 * Driver sequence:
1634 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001635 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001636 * iwl3945_rx_queue_restock
Ben Cahill9fbab512007-11-29 11:09:47 +08001637 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
Zhu Yib481de92007-09-25 17:54:57 -07001638 * queue, updates firmware pointers, and updates
1639 * the WRITE index. If insufficient rx_free buffers
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001640 * are available, schedules iwl3945_rx_replenish
Zhu Yib481de92007-09-25 17:54:57 -07001641 *
1642 * -- enable interrupts --
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001643 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
Zhu Yib481de92007-09-25 17:54:57 -07001644 * READ INDEX, detaching the SKB from the pool.
1645 * Moves the packet buffer from queue to rx_used.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001646 * Calls iwl3945_rx_queue_restock to refill any empty
Zhu Yib481de92007-09-25 17:54:57 -07001647 * slots.
1648 * ...
1649 *
1650 */
1651
1652/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001653 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
Zhu Yib481de92007-09-25 17:54:57 -07001654 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001655static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001656 dma_addr_t dma_addr)
1657{
1658 return cpu_to_le32((u32)dma_addr);
1659}
1660
1661/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001662 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
Zhu Yib481de92007-09-25 17:54:57 -07001663 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001664 * If there are slots in the RX queue that need to be restocked,
Zhu Yib481de92007-09-25 17:54:57 -07001665 * and we have free pre-allocated buffers, fill the ranks as much
Ben Cahill9fbab512007-11-29 11:09:47 +08001666 * as we can, pulling from rx_free.
Zhu Yib481de92007-09-25 17:54:57 -07001667 *
1668 * This moves the 'write' index forward to catch up with 'processed', and
1669 * also updates the memory address in the firmware to reference the new
1670 * target buffer.
1671 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001672static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001673{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001674 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001675 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001676 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001677 unsigned long flags;
1678 int write, rc;
1679
1680 spin_lock_irqsave(&rxq->lock, flags);
1681 write = rxq->write & ~0x7;
Winkler, Tomas37d68312009-01-08 10:19:54 -08001682 while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001683 /* Get next free Rx buffer, remove from free list */
Zhu Yib481de92007-09-25 17:54:57 -07001684 element = rxq->rx_free.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001685 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Zhu Yib481de92007-09-25 17:54:57 -07001686 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001687
1688 /* Point to Rx buffer via next RBD in circular buffer */
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001689 rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
Zhu Yib481de92007-09-25 17:54:57 -07001690 rxq->queue[rxq->write] = rxb;
1691 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
1692 rxq->free_count--;
1693 }
1694 spin_unlock_irqrestore(&rxq->lock, flags);
1695 /* If the pre-allocated buffer pool is dropping low, schedule to
1696 * refill it */
1697 if (rxq->free_count <= RX_LOW_WATERMARK)
1698 queue_work(priv->workqueue, &priv->rx_replenish);
1699
1700
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001701 /* If we've added more space for the firmware to place data, tell it.
1702 * Increment device's write pointer in multiples of 8. */
Zhu Yib481de92007-09-25 17:54:57 -07001703 if ((write != (rxq->write & ~0x7))
1704 || (abs(rxq->write - rxq->read) > 7)) {
1705 spin_lock_irqsave(&rxq->lock, flags);
1706 rxq->need_update = 1;
1707 spin_unlock_irqrestore(&rxq->lock, flags);
Winkler, Tomas141c43a2009-01-08 10:19:53 -08001708 rc = iwl_rx_queue_update_write_ptr(priv, rxq);
Zhu Yib481de92007-09-25 17:54:57 -07001709 if (rc)
1710 return rc;
1711 }
1712
1713 return 0;
1714}
1715
1716/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001717 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
Zhu Yib481de92007-09-25 17:54:57 -07001718 *
1719 * When moving to rx_free an SKB is allocated for the slot.
1720 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001721 * Also restock the Rx queue via iwl3945_rx_queue_restock.
Ian Schram01ebd062007-10-25 17:15:22 +08001722 * This is called as a scheduled work item (except for during initialization)
Zhu Yib481de92007-09-25 17:54:57 -07001723 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001724static void iwl3945_rx_allocate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001725{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001726 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001727 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001728 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001729 unsigned long flags;
1730 spin_lock_irqsave(&rxq->lock, flags);
1731 while (!list_empty(&rxq->rx_used)) {
1732 element = rxq->rx_used.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001733 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001734
1735 /* Alloc a new receive buffer */
Zhu Yib481de92007-09-25 17:54:57 -07001736 rxb->skb =
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001737 alloc_skb(priv->hw_params.rx_buf_size,
1738 __GFP_NOWARN | GFP_ATOMIC);
Zhu Yib481de92007-09-25 17:54:57 -07001739 if (!rxb->skb) {
1740 if (net_ratelimit())
Tomas Winkler978785a2008-12-19 10:37:31 +08001741 IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
Zhu Yib481de92007-09-25 17:54:57 -07001742 /* We don't reschedule replenish work here -- we will
1743 * call the restock method and if it still needs
1744 * more buffers it will schedule replenish */
1745 break;
1746 }
Zhu Yi12342c42007-12-20 11:27:32 +08001747
1748 /* If radiotap head is required, reserve some headroom here.
1749 * The physical head count is a variable rx_stats->phy_count.
1750 * We reserve 4 bytes here. Plus these extra bytes, the
1751 * headroom of the physical head should be enough for the
1752 * radiotap head that iwl3945 supported. See iwl3945_rt.
1753 */
1754 skb_reserve(rxb->skb, 4);
1755
Zhu Yib481de92007-09-25 17:54:57 -07001756 priv->alloc_rxb_skb++;
1757 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001758
1759 /* Get physical address of RB/SKB */
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001760 rxb->real_dma_addr = pci_map_single(priv->pci_dev,
1761 rxb->skb->data,
1762 priv->hw_params.rx_buf_size,
1763 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001764 list_add_tail(&rxb->list, &rxq->rx_free);
1765 rxq->free_count++;
1766 }
1767 spin_unlock_irqrestore(&rxq->lock, flags);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001768}
1769
1770/*
1771 * this should be called while priv->lock is locked
1772 */
Tomas Winkler4fd1f842007-12-05 20:59:58 +02001773static void __iwl3945_rx_replenish(void *data)
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001774{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001775 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001776
1777 iwl3945_rx_allocate(priv);
1778 iwl3945_rx_queue_restock(priv);
1779}
1780
1781
1782void iwl3945_rx_replenish(void *data)
1783{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001784 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001785 unsigned long flags;
1786
1787 iwl3945_rx_allocate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001788
1789 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001790 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001791 spin_unlock_irqrestore(&priv->lock, flags);
1792}
1793
Zhu Yib481de92007-09-25 17:54:57 -07001794/* Convert linear signal-to-noise ratio into dB */
1795static u8 ratio2dB[100] = {
1796/* 0 1 2 3 4 5 6 7 8 9 */
1797 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
1798 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
1799 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
1800 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
1801 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
1802 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
1803 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
1804 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
1805 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
1806 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
1807};
1808
1809/* Calculates a relative dB value from a ratio of linear
1810 * (i.e. not dB) signal levels.
1811 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001812int iwl3945_calc_db_from_ratio(int sig_ratio)
Zhu Yib481de92007-09-25 17:54:57 -07001813{
Adrian Bunk221c80c2008-02-02 23:19:01 +02001814 /* 1000:1 or higher just report as 60 dB */
1815 if (sig_ratio >= 1000)
Zhu Yib481de92007-09-25 17:54:57 -07001816 return 60;
1817
Adrian Bunk221c80c2008-02-02 23:19:01 +02001818 /* 100:1 or higher, divide by 10 and use table,
Zhu Yib481de92007-09-25 17:54:57 -07001819 * add 20 dB to make up for divide by 10 */
Adrian Bunk221c80c2008-02-02 23:19:01 +02001820 if (sig_ratio >= 100)
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001821 return 20 + (int)ratio2dB[sig_ratio/10];
Zhu Yib481de92007-09-25 17:54:57 -07001822
1823 /* We shouldn't see this */
1824 if (sig_ratio < 1)
1825 return 0;
1826
1827 /* Use table for ratios 1:1 - 99:1 */
1828 return (int)ratio2dB[sig_ratio];
1829}
1830
1831#define PERFECT_RSSI (-20) /* dBm */
1832#define WORST_RSSI (-95) /* dBm */
1833#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
1834
1835/* Calculate an indication of rx signal quality (a percentage, not dBm!).
1836 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
1837 * about formulas used below. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001838int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
Zhu Yib481de92007-09-25 17:54:57 -07001839{
1840 int sig_qual;
1841 int degradation = PERFECT_RSSI - rssi_dbm;
1842
1843 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
1844 * as indicator; formula is (signal dbm - noise dbm).
1845 * SNR at or above 40 is a great signal (100%).
1846 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
1847 * Weakest usable signal is usually 10 - 15 dB SNR. */
1848 if (noise_dbm) {
1849 if (rssi_dbm - noise_dbm >= 40)
1850 return 100;
1851 else if (rssi_dbm < noise_dbm)
1852 return 0;
1853 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
1854
1855 /* Else use just the signal level.
1856 * This formula is a least squares fit of data points collected and
1857 * compared with a reference system that had a percentage (%) display
1858 * for signal quality. */
1859 } else
1860 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
1861 (15 * RSSI_RANGE + 62 * degradation)) /
1862 (RSSI_RANGE * RSSI_RANGE);
1863
1864 if (sig_qual > 100)
1865 sig_qual = 100;
1866 else if (sig_qual < 1)
1867 sig_qual = 0;
1868
1869 return sig_qual;
1870}
1871
1872/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001873 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001874 *
1875 * Uses the priv->rx_handlers callback function array to invoke
1876 * the appropriate handlers, including command responses,
1877 * frame-received notifications, and other notifications.
1878 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001879static void iwl3945_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001880{
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001881 struct iwl_rx_mem_buffer *rxb;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001882 struct iwl_rx_packet *pkt;
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001883 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001884 u32 r, i;
1885 int reclaim;
1886 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001887 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001888 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07001889
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001890 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1891 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8cd812b2008-12-19 10:37:43 +08001892 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07001893 i = rxq->read;
1894
Winkler, Tomas37d68312009-01-08 10:19:54 -08001895 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001896 fill_rx = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001897 /* Rx interrupt, but nothing sent from uCode */
1898 if (i == r)
Tomas Winklere1623442009-01-27 14:27:56 -08001899 IWL_DEBUG(priv, IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001900
1901 while (i != r) {
1902 rxb = rxq->queue[i];
1903
Ben Cahill9fbab512007-11-29 11:09:47 +08001904 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001905 * then a bug has been introduced in the queue refilling
1906 * routines -- catch it here */
1907 BUG_ON(rxb == NULL);
1908
1909 rxq->queue[i] = NULL;
1910
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001911 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001912 priv->hw_params.rx_buf_size,
Zhu Yib481de92007-09-25 17:54:57 -07001913 PCI_DMA_FROMDEVICE);
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001914 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001915
1916 /* Reclaim a command buffer only if this packet is a response
1917 * to a (driver-originated) command.
1918 * If the packet (e.g. Rx frame) originated from uCode,
1919 * there is no command buffer to reclaim.
1920 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1921 * but apparently a few don't get set; catch them here. */
1922 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1923 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1924 (pkt->hdr.cmd != REPLY_TX);
1925
1926 /* Based on type of command response or notification,
1927 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001928 * rx_handlers table. See iwl3945_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001929 if (priv->rx_handlers[pkt->hdr.cmd]) {
Tomas Winklere1623442009-01-27 14:27:56 -08001930 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07001931 "r = %d, i = %d, %s, 0x%02x\n", r, i,
1932 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
1933 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1934 } else {
1935 /* No handling needed */
Tomas Winklere1623442009-01-27 14:27:56 -08001936 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07001937 "r %d i %d No handler needed for %s, 0x%02x\n",
1938 r, i, get_cmd_string(pkt->hdr.cmd),
1939 pkt->hdr.cmd);
1940 }
1941
1942 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001943 /* Invoke any callbacks, transfer the skb to caller, and
Samuel Ortiz518099a2009-01-19 15:30:27 -08001944 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001945 * as we reclaim the driver command queue */
1946 if (rxb && rxb->skb)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001947 iwl3945_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001948 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001949 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07001950 }
1951
1952 /* For now we just don't re-use anything. We can tweak this
1953 * later to try and re-use notification packets and SKBs that
1954 * fail to Rx correctly */
1955 if (rxb->skb != NULL) {
1956 priv->alloc_rxb_skb--;
1957 dev_kfree_skb_any(rxb->skb);
1958 rxb->skb = NULL;
1959 }
1960
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001961 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001962 priv->hw_params.rx_buf_size,
1963 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001964 spin_lock_irqsave(&rxq->lock, flags);
1965 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1966 spin_unlock_irqrestore(&rxq->lock, flags);
1967 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001968 /* If there are a lot of unused frames,
1969 * restock the Rx queue so ucode won't assert. */
1970 if (fill_rx) {
1971 count++;
1972 if (count >= 8) {
1973 priv->rxq.read = i;
1974 __iwl3945_rx_replenish(priv);
1975 count = 0;
1976 }
1977 }
Zhu Yib481de92007-09-25 17:54:57 -07001978 }
1979
1980 /* Backtrack one entry */
1981 priv->rxq.read = i;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001982 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001983}
1984
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001985/* call this function to flush any scheduled tasklet */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001986static inline void iwl_synchronize_irq(struct iwl_priv *priv)
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001987{
Tomas Winklera96a27f2008-10-23 23:48:56 -07001988 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001989 synchronize_irq(priv->pci_dev->irq);
1990 tasklet_kill(&priv->irq_tasklet);
1991}
1992
Zhu Yib481de92007-09-25 17:54:57 -07001993static const char *desc_lookup(int i)
1994{
1995 switch (i) {
1996 case 1:
1997 return "FAIL";
1998 case 2:
1999 return "BAD_PARAM";
2000 case 3:
2001 return "BAD_CHECKSUM";
2002 case 4:
2003 return "NMI_INTERRUPT";
2004 case 5:
2005 return "SYSASSERT";
2006 case 6:
2007 return "FATAL_ERROR";
2008 }
2009
2010 return "UNKNOWN";
2011}
2012
2013#define ERROR_START_OFFSET (1 * sizeof(u32))
2014#define ERROR_ELEM_SIZE (7 * sizeof(u32))
2015
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002016static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002017{
2018 u32 i;
2019 u32 desc, time, count, base, data1;
2020 u32 blink1, blink2, ilink1, ilink2;
2021 int rc;
2022
2023 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
2024
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002025 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002026 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07002027 return;
2028 }
2029
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002030 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002031 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002032 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002033 return;
2034 }
2035
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002036 count = iwl_read_targ_mem(priv, base);
Zhu Yib481de92007-09-25 17:54:57 -07002037
2038 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002039 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
2040 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
2041 priv->status, count);
Zhu Yib481de92007-09-25 17:54:57 -07002042 }
2043
Winkler, Tomas15b16872008-12-19 10:37:33 +08002044 IWL_ERR(priv, "Desc Time asrtPC blink2 "
Zhu Yib481de92007-09-25 17:54:57 -07002045 "ilink1 nmiPC Line\n");
2046 for (i = ERROR_START_OFFSET;
2047 i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
2048 i += ERROR_ELEM_SIZE) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002049 desc = iwl_read_targ_mem(priv, base + i);
Zhu Yib481de92007-09-25 17:54:57 -07002050 time =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002051 iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002052 blink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002053 iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002054 blink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002055 iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002056 ilink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002057 iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002058 ilink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002059 iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002060 data1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002061 iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002062
Winkler, Tomas15b16872008-12-19 10:37:33 +08002063 IWL_ERR(priv,
2064 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
2065 desc_lookup(desc), desc, time, blink1, blink2,
2066 ilink1, ilink2, data1);
Zhu Yib481de92007-09-25 17:54:57 -07002067 }
2068
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002069 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002070
2071}
2072
Ben Cahillf58177b2007-11-29 11:09:43 +08002073#define EVENT_START_OFFSET (6 * sizeof(u32))
Zhu Yib481de92007-09-25 17:54:57 -07002074
2075/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002076 * iwl3945_print_event_log - Dump error event log to syslog
Zhu Yib481de92007-09-25 17:54:57 -07002077 *
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002078 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
Zhu Yib481de92007-09-25 17:54:57 -07002079 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002080static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
Zhu Yib481de92007-09-25 17:54:57 -07002081 u32 num_events, u32 mode)
2082{
2083 u32 i;
2084 u32 base; /* SRAM byte address of event log header */
2085 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
2086 u32 ptr; /* SRAM byte address of log data */
2087 u32 ev, time, data; /* event log data */
2088
2089 if (num_events == 0)
2090 return;
2091
2092 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
2093
2094 if (mode == 0)
2095 event_size = 2 * sizeof(u32);
2096 else
2097 event_size = 3 * sizeof(u32);
2098
2099 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
2100
2101 /* "time" is actually "data" for mode 0 (no timestamp).
2102 * place event id # at far right for easier visual parsing. */
2103 for (i = 0; i < num_events; i++) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002104 ev = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002105 ptr += sizeof(u32);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002106 time = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002107 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002108 if (mode == 0) {
2109 /* data, ev */
2110 IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
2111 } else {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002112 data = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002113 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002114 IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
Zhu Yib481de92007-09-25 17:54:57 -07002115 }
2116 }
2117}
2118
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002119static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002120{
2121 int rc;
2122 u32 base; /* SRAM byte address of event log header */
2123 u32 capacity; /* event log capacity in # entries */
2124 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
2125 u32 num_wraps; /* # times uCode wrapped to top of log */
2126 u32 next_entry; /* index of next entry to be written by uCode */
2127 u32 size; /* # entries that we'll print */
2128
2129 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002130 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002131 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07002132 return;
2133 }
2134
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002135 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002136 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002137 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002138 return;
2139 }
2140
2141 /* event log header */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002142 capacity = iwl_read_targ_mem(priv, base);
2143 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
2144 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
2145 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
Zhu Yib481de92007-09-25 17:54:57 -07002146
2147 size = num_wraps ? capacity : next_entry;
2148
2149 /* bail out if nothing in log */
2150 if (size == 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002151 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002152 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002153 return;
2154 }
2155
Winkler, Tomas15b16872008-12-19 10:37:33 +08002156 IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07002157 size, num_wraps);
2158
2159 /* if uCode has wrapped back to top of log, start at the oldest entry,
2160 * i.e the next one that uCode would fill. */
2161 if (num_wraps)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002162 iwl3945_print_event_log(priv, next_entry,
Zhu Yib481de92007-09-25 17:54:57 -07002163 capacity - next_entry, mode);
2164
2165 /* (then/else) start at top of log */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002166 iwl3945_print_event_log(priv, 0, next_entry, mode);
Zhu Yib481de92007-09-25 17:54:57 -07002167
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002168 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002169}
2170
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002171static void iwl3945_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002172{
2173 unsigned long flags;
2174
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002175 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
2176 sizeof(priv->staging_rxon));
2177 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002178 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002179
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002180 iwl3945_add_station(priv, priv->bssid, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002181
2182 spin_lock_irqsave(&priv->lock, flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002183 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07002184 priv->error_recovering = 0;
2185 spin_unlock_irqrestore(&priv->lock, flags);
2186}
2187
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002188static void iwl3945_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002189{
2190 u32 inta, handled = 0;
2191 u32 inta_fh;
2192 unsigned long flags;
Samuel Ortizd08853a2009-01-23 13:45:17 -08002193#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07002194 u32 inta_mask;
2195#endif
2196
2197 spin_lock_irqsave(&priv->lock, flags);
2198
2199 /* Ack/clear/reset pending uCode interrupts.
2200 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
2201 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002202 inta = iwl_read32(priv, CSR_INT);
2203 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07002204
2205 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
2206 * Any new interrupts that happen after this, either while we're
2207 * in this tasklet, or later, will show up in next ISR/tasklet. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002208 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
2209 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07002210
Samuel Ortizd08853a2009-01-23 13:45:17 -08002211#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002212 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08002213 /* just for debug */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002214 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Tomas Winklere1623442009-01-27 14:27:56 -08002215 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002216 inta, inta_mask, inta_fh);
2217 }
2218#endif
2219
2220 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
2221 * atomic, make sure that inta covers all the interrupts that
2222 * we've discovered, even if FH interrupt came in just after
2223 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002224 if (inta_fh & CSR39_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002225 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002226 if (inta_fh & CSR39_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002227 inta |= CSR_INT_BIT_FH_TX;
2228
2229 /* Now service all interrupt bits discovered above. */
2230 if (inta & CSR_INT_BIT_HW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002231 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002232
2233 /* Tell the device to stop sending interrupts */
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002234 iwl_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002235
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002236 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002237
2238 handled |= CSR_INT_BIT_HW_ERR;
2239
2240 spin_unlock_irqrestore(&priv->lock, flags);
2241
2242 return;
2243 }
2244
Samuel Ortizd08853a2009-01-23 13:45:17 -08002245#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002246 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07002247 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002248 if (inta & CSR_INT_BIT_SCD)
Tomas Winklere1623442009-01-27 14:27:56 -08002249 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
Joonwoo Park25c03d82008-01-23 10:15:20 -08002250 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002251
2252 /* Alive notification via Rx interrupt will do the real work */
2253 if (inta & CSR_INT_BIT_ALIVE)
Tomas Winklere1623442009-01-27 14:27:56 -08002254 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002255 }
2256#endif
2257 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002258 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07002259
Zhu Yib481de92007-09-25 17:54:57 -07002260 /* Error detected by uCode */
2261 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002262 IWL_ERR(priv, "Microcode SW error detected. "
2263 "Restarting 0x%X.\n", inta);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002264 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002265 handled |= CSR_INT_BIT_SW_ERR;
2266 }
2267
2268 /* uCode wakes up after power-down sleep */
2269 if (inta & CSR_INT_BIT_WAKEUP) {
Tomas Winklere1623442009-01-27 14:27:56 -08002270 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
Winkler, Tomas141c43a2009-01-08 10:19:53 -08002271 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08002272 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
2273 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
2274 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
2275 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
2276 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
2277 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07002278
2279 handled |= CSR_INT_BIT_WAKEUP;
2280 }
2281
2282 /* All uCode command responses, including Tx command responses,
2283 * Rx "responses" (frame-received notification), and other
2284 * notifications from uCode come through here*/
2285 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002286 iwl3945_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002287 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
2288 }
2289
2290 if (inta & CSR_INT_BIT_FH_TX) {
Tomas Winklere1623442009-01-27 14:27:56 -08002291 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002292
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002293 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
2294 if (!iwl_grab_nic_access(priv)) {
2295 iwl_write_direct32(priv, FH39_TCSR_CREDIT
Tomas Winklerbddadf82008-12-19 10:37:01 +08002296 (FH39_SRVC_CHNL), 0x0);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002297 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002298 }
2299 handled |= CSR_INT_BIT_FH_TX;
2300 }
2301
2302 if (inta & ~handled)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002303 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Zhu Yib481de92007-09-25 17:54:57 -07002304
2305 if (inta & ~CSR_INI_SET_MASK) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002306 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Zhu Yib481de92007-09-25 17:54:57 -07002307 inta & ~CSR_INI_SET_MASK);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002308 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07002309 }
2310
2311 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002312 /* only Re-enable if disabled by irq */
2313 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002314 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002315
Samuel Ortizd08853a2009-01-23 13:45:17 -08002316#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002317 if (priv->debug_level & (IWL_DL_ISR)) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002318 inta = iwl_read32(priv, CSR_INT);
2319 inta_mask = iwl_read32(priv, CSR_INT_MASK);
2320 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Tomas Winklere1623442009-01-27 14:27:56 -08002321 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
Zhu Yib481de92007-09-25 17:54:57 -07002322 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
2323 }
2324#endif
2325 spin_unlock_irqrestore(&priv->lock, flags);
2326}
2327
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002328static irqreturn_t iwl3945_isr(int irq, void *data)
Zhu Yib481de92007-09-25 17:54:57 -07002329{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002330 struct iwl_priv *priv = data;
Zhu Yib481de92007-09-25 17:54:57 -07002331 u32 inta, inta_mask;
2332 u32 inta_fh;
2333 if (!priv)
2334 return IRQ_NONE;
2335
2336 spin_lock(&priv->lock);
2337
2338 /* Disable (but don't clear!) interrupts here to avoid
2339 * back-to-back ISRs and sporadic interrupts from our NIC.
2340 * If we have something to service, the tasklet will re-enable ints.
2341 * If we *don't* have something, we'll re-enable before leaving here. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002342 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
2343 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07002344
2345 /* Discover which interrupts are active/pending */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002346 inta = iwl_read32(priv, CSR_INT);
2347 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07002348
2349 /* Ignore interrupt if there's nothing in NIC to service.
2350 * This may be due to IRQ shared with another device,
2351 * or due to sporadic interrupts thrown from our NIC. */
2352 if (!inta && !inta_fh) {
Tomas Winklere1623442009-01-27 14:27:56 -08002353 IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0, inta_fh == 0\n");
Zhu Yib481de92007-09-25 17:54:57 -07002354 goto none;
2355 }
2356
2357 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
2358 /* Hardware disappeared */
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002359 IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
Oliver Neukumcb4da1a2007-11-13 21:10:32 -08002360 goto unplugged;
Zhu Yib481de92007-09-25 17:54:57 -07002361 }
2362
Tomas Winklere1623442009-01-27 14:27:56 -08002363 IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002364 inta, inta_mask, inta_fh);
2365
Joonwoo Park25c03d82008-01-23 10:15:20 -08002366 inta &= ~CSR_INT_BIT_SCD;
2367
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002368 /* iwl3945_irq_tasklet() will service interrupts and re-enable them */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002369 if (likely(inta || inta_fh))
2370 tasklet_schedule(&priv->irq_tasklet);
Oliver Neukumcb4da1a2007-11-13 21:10:32 -08002371unplugged:
Zhu Yib481de92007-09-25 17:54:57 -07002372 spin_unlock(&priv->lock);
2373
2374 return IRQ_HANDLED;
2375
2376 none:
2377 /* re-enable interrupts here since we don't have anything to service. */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002378 /* only Re-enable if disabled by irq */
2379 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002380 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002381 spin_unlock(&priv->lock);
2382 return IRQ_NONE;
2383}
2384
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002385static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01002386 enum ieee80211_band band,
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08002387 u8 is_active, u8 n_probes,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002388 struct iwl3945_scan_channel *scan_ch)
Zhu Yib481de92007-09-25 17:54:57 -07002389{
2390 const struct ieee80211_channel *channels = NULL;
Johannes Berg8318d782008-01-24 19:38:38 +01002391 const struct ieee80211_supported_band *sband;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08002392 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07002393 u16 passive_dwell = 0;
2394 u16 active_dwell = 0;
2395 int added, i;
2396
Kolekar, Abhijeetcbba18c2008-12-19 10:37:42 +08002397 sband = iwl_get_hw_mode(priv, band);
Johannes Berg8318d782008-01-24 19:38:38 +01002398 if (!sband)
Zhu Yib481de92007-09-25 17:54:57 -07002399 return 0;
2400
Johannes Berg8318d782008-01-24 19:38:38 +01002401 channels = sband->channels;
Zhu Yib481de92007-09-25 17:54:57 -07002402
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08002403 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
2404 passive_dwell = iwl_get_passive_dwell_time(priv, band);
Zhu Yib481de92007-09-25 17:54:57 -07002405
Abhijeet Kolekar8f4807a2008-09-03 11:26:31 +08002406 if (passive_dwell <= active_dwell)
2407 passive_dwell = active_dwell + 1;
2408
Johannes Berg8318d782008-01-24 19:38:38 +01002409 for (i = 0, added = 0; i < sband->n_channels; i++) {
Johannes Berg182e2e62008-04-04 10:41:56 +02002410 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
2411 continue;
2412
Johannes Berg8318d782008-01-24 19:38:38 +01002413 scan_ch->channel = channels[i].hw_value;
Zhu Yib481de92007-09-25 17:54:57 -07002414
Samuel Ortize6148912009-01-23 13:45:15 -08002415 ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
Zhu Yib481de92007-09-25 17:54:57 -07002416 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002417 IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
Zhu Yib481de92007-09-25 17:54:57 -07002418 scan_ch->channel);
2419 continue;
2420 }
2421
Zhu Yib481de92007-09-25 17:54:57 -07002422 scan_ch->active_dwell = cpu_to_le16(active_dwell);
2423 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002424 /* If passive , set up for auto-switch
2425 * and use long active_dwell time.
2426 */
2427 if (!is_active || is_channel_passive(ch_info) ||
2428 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
2429 scan_ch->type = 0; /* passive */
2430 if (IWL_UCODE_API(priv->ucode_ver) == 1)
2431 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
2432 } else {
2433 scan_ch->type = 1; /* active */
2434 }
2435
2436 /* Set direct probe bits. These may be used both for active
2437 * scan channels (probes gets sent right away),
2438 * or for passive channels (probes get se sent only after
2439 * hearing clear Rx packet).*/
2440 if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
2441 if (n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002442 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002443 } else {
2444 /* uCode v1 does not allow setting direct probe bits on
2445 * passive channel. */
2446 if ((scan_ch->type & 1) && n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002447 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002448 }
Zhu Yib481de92007-09-25 17:54:57 -07002449
Ben Cahill9fbab512007-11-29 11:09:47 +08002450 /* Set txpower levels to defaults */
Zhu Yib481de92007-09-25 17:54:57 -07002451 scan_ch->tpc.dsp_atten = 110;
2452 /* scan_pwr_info->tpc.dsp_atten; */
2453
2454 /*scan_pwr_info->tpc.tx_gain; */
Johannes Berg8318d782008-01-24 19:38:38 +01002455 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -07002456 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
2457 else {
2458 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
2459 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
Ben Cahill9fbab512007-11-29 11:09:47 +08002460 * power level:
Reinette Chatre8a1b0242008-01-14 17:46:25 -08002461 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
Zhu Yib481de92007-09-25 17:54:57 -07002462 */
2463 }
2464
Tomas Winklere1623442009-01-27 14:27:56 -08002465 IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n",
Zhu Yib481de92007-09-25 17:54:57 -07002466 scan_ch->channel,
2467 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
2468 (scan_ch->type & 1) ?
2469 active_dwell : passive_dwell);
2470
2471 scan_ch++;
2472 added++;
2473 }
2474
Tomas Winklere1623442009-01-27 14:27:56 -08002475 IWL_DEBUG_SCAN(priv, "total channels to scan %d \n", added);
Zhu Yib481de92007-09-25 17:54:57 -07002476 return added;
2477}
2478
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002479static void iwl3945_init_hw_rates(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002480 struct ieee80211_rate *rates)
2481{
2482 int i;
2483
2484 for (i = 0; i < IWL_RATE_COUNT; i++) {
Johannes Berg8318d782008-01-24 19:38:38 +01002485 rates[i].bitrate = iwl3945_rates[i].ieee * 5;
2486 rates[i].hw_value = i; /* Rate scaling will work on indexes */
2487 rates[i].hw_value_short = i;
2488 rates[i].flags = 0;
Samuel Ortizd9829a62008-12-19 10:37:12 +08002489 if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
Zhu Yib481de92007-09-25 17:54:57 -07002490 /*
Johannes Berg8318d782008-01-24 19:38:38 +01002491 * If CCK != 1M then set short preamble rate flag.
Zhu Yib481de92007-09-25 17:54:57 -07002492 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002493 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
Johannes Berg8318d782008-01-24 19:38:38 +01002494 0 : IEEE80211_RATE_SHORT_PREAMBLE;
Zhu Yib481de92007-09-25 17:54:57 -07002495 }
Zhu Yib481de92007-09-25 17:54:57 -07002496 }
2497}
2498
Zhu Yib481de92007-09-25 17:54:57 -07002499/******************************************************************************
2500 *
2501 * uCode download functions
2502 *
2503 ******************************************************************************/
2504
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002505static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002506{
Tomas Winkler98c92212008-01-14 17:46:20 -08002507 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
2508 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
2509 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
2510 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
2511 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
2512 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07002513}
2514
2515/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002516 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002517 * looking at all data.
2518 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002519static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002520{
2521 u32 val;
2522 u32 save_len = len;
2523 int rc = 0;
2524 u32 errcnt;
2525
Tomas Winklere1623442009-01-27 14:27:56 -08002526 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002527
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002528 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002529 if (rc)
2530 return rc;
2531
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002532 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002533 IWL39_RTC_INST_LOWER_BOUND);
Zhu Yib481de92007-09-25 17:54:57 -07002534
2535 errcnt = 0;
2536 for (; len > 0; len -= sizeof(u32), image++) {
2537 /* read data comes through single port, auto-incr addr */
2538 /* NOTE: Use the debugless read so we don't flood kernel log
2539 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002540 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002541 if (val != le32_to_cpu(*image)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002542 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002543 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2544 save_len - len, val, le32_to_cpu(*image));
2545 rc = -EIO;
2546 errcnt++;
2547 if (errcnt >= 20)
2548 break;
2549 }
2550 }
2551
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002552 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002553
2554 if (!errcnt)
Tomas Winklere1623442009-01-27 14:27:56 -08002555 IWL_DEBUG_INFO(priv,
2556 "ucode image in INSTRUCTION memory is good\n");
Zhu Yib481de92007-09-25 17:54:57 -07002557
2558 return rc;
2559}
2560
2561
2562/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002563 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002564 * using sample data 100 bytes apart. If these sample points are good,
2565 * it's a pretty good bet that everything between them is good, too.
2566 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002567static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002568{
2569 u32 val;
2570 int rc = 0;
2571 u32 errcnt = 0;
2572 u32 i;
2573
Tomas Winklere1623442009-01-27 14:27:56 -08002574 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002575
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002576 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002577 if (rc)
2578 return rc;
2579
2580 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
2581 /* read data comes through single port, auto-incr addr */
2582 /* NOTE: Use the debugless read so we don't flood kernel log
2583 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002584 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002585 i + IWL39_RTC_INST_LOWER_BOUND);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002586 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002587 if (val != le32_to_cpu(*image)) {
2588#if 0 /* Enable this if you want to see details */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002589 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002590 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2591 i, val, *image);
2592#endif
2593 rc = -EIO;
2594 errcnt++;
2595 if (errcnt >= 3)
2596 break;
2597 }
2598 }
2599
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002600 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002601
2602 return rc;
2603}
2604
2605
2606/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002607 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
Zhu Yib481de92007-09-25 17:54:57 -07002608 * and verify its contents
2609 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002610static int iwl3945_verify_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002611{
2612 __le32 *image;
2613 u32 len;
2614 int rc = 0;
2615
2616 /* Try bootstrap */
2617 image = (__le32 *)priv->ucode_boot.v_addr;
2618 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002619 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002620 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002621 IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002622 return 0;
2623 }
2624
2625 /* Try initialize */
2626 image = (__le32 *)priv->ucode_init.v_addr;
2627 len = priv->ucode_init.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002628 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002629 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002630 IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002631 return 0;
2632 }
2633
2634 /* Try runtime/protocol */
2635 image = (__le32 *)priv->ucode_code.v_addr;
2636 len = priv->ucode_code.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002637 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002638 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002639 IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002640 return 0;
2641 }
2642
Winkler, Tomas15b16872008-12-19 10:37:33 +08002643 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
Zhu Yib481de92007-09-25 17:54:57 -07002644
Ben Cahill9fbab512007-11-29 11:09:47 +08002645 /* Since nothing seems to match, show first several data entries in
2646 * instruction SRAM, so maybe visual inspection will give a clue.
2647 * Selection of bootstrap image (vs. other images) is arbitrary. */
Zhu Yib481de92007-09-25 17:54:57 -07002648 image = (__le32 *)priv->ucode_boot.v_addr;
2649 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002650 rc = iwl3945_verify_inst_full(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002651
2652 return rc;
2653}
2654
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002655static void iwl3945_nic_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002656{
2657 /* Remove all resets to allow NIC to operate */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002658 iwl_write32(priv, CSR_RESET, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002659}
2660
2661/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002662 * iwl3945_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07002663 *
2664 * Copy into buffers for card to fetch via bus-mastering
2665 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002666static int iwl3945_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002667{
Kolekar, Abhijeeta78fe752008-12-19 10:37:21 +08002668 struct iwl_ucode *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002669 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07002670 const struct firmware *ucode_raw;
2671 /* firmware file name contains uCode/driver compatibility version */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002672 const char *name_pre = priv->cfg->fw_name_pre;
2673 const unsigned int api_max = priv->cfg->ucode_api_max;
2674 const unsigned int api_min = priv->cfg->ucode_api_min;
2675 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07002676 u8 *src;
2677 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002678 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07002679
2680 /* Ask kernel firmware_class module to get the boot firmware off disk.
2681 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002682 for (index = api_max; index >= api_min; index--) {
2683 sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
2684 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
2685 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002686 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002687 buf, ret);
2688 if (ret == -ENOENT)
2689 continue;
2690 else
2691 goto error;
2692 } else {
2693 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002694 IWL_ERR(priv, "Loaded firmware %s, "
2695 "which is deprecated. "
2696 " Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002697 buf, api_max);
Tomas Winklere1623442009-01-27 14:27:56 -08002698 IWL_DEBUG_INFO(priv, "Got firmware '%s' file "
2699 "(%zd bytes) from disk\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002700 buf, ucode_raw->size);
2701 break;
2702 }
Zhu Yib481de92007-09-25 17:54:57 -07002703 }
2704
Reinette Chatrea0987a82008-12-02 12:14:06 -08002705 if (ret < 0)
2706 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07002707
2708 /* Make sure that we got at least our header! */
2709 if (ucode_raw->size < sizeof(*ucode)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002710 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002711 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002712 goto err_release;
2713 }
2714
2715 /* Data from ucode file: header followed by uCode images */
2716 ucode = (void *)ucode_raw->data;
2717
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08002718 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08002719 api_ver = IWL_UCODE_API(priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07002720 inst_size = le32_to_cpu(ucode->inst_size);
2721 data_size = le32_to_cpu(ucode->data_size);
2722 init_size = le32_to_cpu(ucode->init_size);
2723 init_data_size = le32_to_cpu(ucode->init_data_size);
2724 boot_size = le32_to_cpu(ucode->boot_size);
2725
Reinette Chatrea0987a82008-12-02 12:14:06 -08002726 /* api_ver should match the api version forming part of the
2727 * firmware filename ... but we don't check for that and only rely
2728 * on the API version read from firware header from here on forward */
2729
2730 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002731 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002732 "Driver supports v%u, firmware is v%u.\n",
2733 api_max, api_ver);
2734 priv->ucode_ver = 0;
2735 ret = -EINVAL;
2736 goto err_release;
2737 }
2738 if (api_ver != api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002739 IWL_ERR(priv, "Firmware has old API version. Expected %u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002740 "got %u. New firmware can be obtained "
2741 "from http://www.intellinuxwireless.org.\n",
2742 api_max, api_ver);
2743
Tomas Winkler978785a2008-12-19 10:37:31 +08002744 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
2745 IWL_UCODE_MAJOR(priv->ucode_ver),
2746 IWL_UCODE_MINOR(priv->ucode_ver),
2747 IWL_UCODE_API(priv->ucode_ver),
2748 IWL_UCODE_SERIAL(priv->ucode_ver));
2749
Tomas Winklere1623442009-01-27 14:27:56 -08002750 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002751 priv->ucode_ver);
Tomas Winklere1623442009-01-27 14:27:56 -08002752 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
2753 inst_size);
2754 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
2755 data_size);
2756 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
2757 init_size);
2758 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
2759 init_data_size);
2760 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
2761 boot_size);
Zhu Yib481de92007-09-25 17:54:57 -07002762
Reinette Chatrea0987a82008-12-02 12:14:06 -08002763
Zhu Yib481de92007-09-25 17:54:57 -07002764 /* Verify size of file vs. image size info in file's header */
2765 if (ucode_raw->size < sizeof(*ucode) +
2766 inst_size + data_size + init_size +
2767 init_data_size + boot_size) {
2768
Tomas Winklere1623442009-01-27 14:27:56 -08002769 IWL_DEBUG_INFO(priv, "uCode file size %zd too small\n",
2770 ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002771 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002772 goto err_release;
2773 }
2774
2775 /* Verify that uCode images will fit in card's SRAM */
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002776 if (inst_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002777 IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002778 inst_size);
2779 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002780 goto err_release;
2781 }
2782
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002783 if (data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002784 IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002785 data_size);
2786 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002787 goto err_release;
2788 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002789 if (init_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002790 IWL_DEBUG_INFO(priv,
2791 "uCode init instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002792 init_size);
2793 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002794 goto err_release;
2795 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002796 if (init_data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002797 IWL_DEBUG_INFO(priv,
2798 "uCode init data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002799 init_data_size);
2800 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002801 goto err_release;
2802 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002803 if (boot_size > IWL39_MAX_BSM_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002804 IWL_DEBUG_INFO(priv,
2805 "uCode boot instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002806 boot_size);
2807 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002808 goto err_release;
2809 }
2810
2811 /* Allocate ucode buffers for card's bus-master loading ... */
2812
2813 /* Runtime instructions and 2 copies of data:
2814 * 1) unmodified from disk
2815 * 2) backup cache for save/restore during power-downs */
2816 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002817 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07002818
2819 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002820 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07002821
2822 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002823 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07002824
2825 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
Tomas Winkler90e759d2007-11-29 11:09:41 +08002826 !priv->ucode_data_backup.v_addr)
Zhu Yib481de92007-09-25 17:54:57 -07002827 goto err_pci_alloc;
2828
Tomas Winkler90e759d2007-11-29 11:09:41 +08002829 /* Initialization instructions and data */
2830 if (init_size && init_data_size) {
2831 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002832 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002833
2834 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002835 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002836
2837 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
2838 goto err_pci_alloc;
2839 }
2840
2841 /* Bootstrap (instructions only, no data) */
2842 if (boot_size) {
2843 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002844 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002845
2846 if (!priv->ucode_boot.v_addr)
2847 goto err_pci_alloc;
2848 }
2849
Zhu Yib481de92007-09-25 17:54:57 -07002850 /* Copy images into buffers for card's bus-master reads ... */
2851
2852 /* Runtime instructions (first block of data in file) */
2853 src = &ucode->data[0];
2854 len = priv->ucode_code.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002855 IWL_DEBUG_INFO(priv,
2856 "Copying (but not loading) uCode instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002857 memcpy(priv->ucode_code.v_addr, src, len);
Tomas Winklere1623442009-01-27 14:27:56 -08002858 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002859 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
2860
2861 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002862 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
Zhu Yib481de92007-09-25 17:54:57 -07002863 src = &ucode->data[inst_size];
2864 len = priv->ucode_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002865 IWL_DEBUG_INFO(priv,
2866 "Copying (but not loading) uCode data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002867 memcpy(priv->ucode_data.v_addr, src, len);
2868 memcpy(priv->ucode_data_backup.v_addr, src, len);
2869
2870 /* Initialization instructions (3rd block) */
2871 if (init_size) {
2872 src = &ucode->data[inst_size + data_size];
2873 len = priv->ucode_init.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002874 IWL_DEBUG_INFO(priv,
2875 "Copying (but not loading) init instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002876 memcpy(priv->ucode_init.v_addr, src, len);
2877 }
2878
2879 /* Initialization data (4th block) */
2880 if (init_data_size) {
2881 src = &ucode->data[inst_size + data_size + init_size];
2882 len = priv->ucode_init_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002883 IWL_DEBUG_INFO(priv,
2884 "Copying (but not loading) init data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002885 memcpy(priv->ucode_init_data.v_addr, src, len);
2886 }
2887
2888 /* Bootstrap instructions (5th block) */
2889 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
2890 len = priv->ucode_boot.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002891 IWL_DEBUG_INFO(priv,
2892 "Copying (but not loading) boot instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002893 memcpy(priv->ucode_boot.v_addr, src, len);
2894
2895 /* We have our copies now, allow OS release its copies */
2896 release_firmware(ucode_raw);
2897 return 0;
2898
2899 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08002900 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002901 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002902 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002903
2904 err_release:
2905 release_firmware(ucode_raw);
2906
2907 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08002908 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002909}
2910
2911
2912/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002913 * iwl3945_set_ucode_ptrs - Set uCode address location
Zhu Yib481de92007-09-25 17:54:57 -07002914 *
2915 * Tell initialization uCode where to find runtime uCode.
2916 *
2917 * BSM registers initially contain pointers to initialization uCode.
2918 * We need to replace them to load runtime uCode inst and data,
2919 * and to save runtime data when powering down.
2920 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002921static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002922{
2923 dma_addr_t pinst;
2924 dma_addr_t pdata;
2925 int rc = 0;
2926 unsigned long flags;
2927
2928 /* bits 31:0 for 3945 */
2929 pinst = priv->ucode_code.p_addr;
2930 pdata = priv->ucode_data_backup.p_addr;
2931
2932 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002933 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002934 if (rc) {
2935 spin_unlock_irqrestore(&priv->lock, flags);
2936 return rc;
2937 }
2938
2939 /* Tell bootstrap uCode where to find image to load */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002940 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
2941 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
2942 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002943 priv->ucode_data.len);
2944
Tomas Winklera96a27f2008-10-23 23:48:56 -07002945 /* Inst byte count must be last to set up, bit 31 signals uCode
Zhu Yib481de92007-09-25 17:54:57 -07002946 * that all new ptr/size info is in place */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002947 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002948 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
2949
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002950 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002951
2952 spin_unlock_irqrestore(&priv->lock, flags);
2953
Tomas Winklere1623442009-01-27 14:27:56 -08002954 IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002955
2956 return rc;
2957}
2958
2959/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002960 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002961 *
2962 * Called after REPLY_ALIVE notification received from "initialize" uCode.
2963 *
Zhu Yib481de92007-09-25 17:54:57 -07002964 * Tell "initialize" uCode to go ahead and load the runtime uCode.
Ben Cahill9fbab512007-11-29 11:09:47 +08002965 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002966static void iwl3945_init_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002967{
2968 /* Check alive response for "valid" sign from uCode */
2969 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
2970 /* We had an error bringing up the hardware, so take it
2971 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002972 IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002973 goto restart;
2974 }
2975
2976 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
2977 * This is a paranoid check, because we would not have gotten the
2978 * "initialize" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002979 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002980 /* Runtime instruction load was bad;
2981 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002982 IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002983 goto restart;
2984 }
2985
2986 /* Send pointers to protocol/runtime uCode image ... init code will
2987 * load and launch runtime uCode, which will send us another "Alive"
2988 * notification. */
Tomas Winklere1623442009-01-27 14:27:56 -08002989 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002990 if (iwl3945_set_ucode_ptrs(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002991 /* Runtime instruction load won't happen;
2992 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002993 IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002994 goto restart;
2995 }
2996 return;
2997
2998 restart:
2999 queue_work(priv->workqueue, &priv->restart);
3000}
3001
3002
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003003/* temporary */
3004static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw,
3005 struct sk_buff *skb);
3006
Zhu Yib481de92007-09-25 17:54:57 -07003007/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003008 * iwl3945_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07003009 * from protocol/runtime uCode (initialization uCode's
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003010 * Alive gets handled by iwl3945_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07003011 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003012static void iwl3945_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003013{
3014 int rc = 0;
3015 int thermal_spin = 0;
3016 u32 rfkill;
3017
Tomas Winklere1623442009-01-27 14:27:56 -08003018 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003019
3020 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
3021 /* We had an error bringing up the hardware, so take it
3022 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08003023 IWL_DEBUG_INFO(priv, "Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003024 goto restart;
3025 }
3026
3027 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
3028 * This is a paranoid check, because we would not have gotten the
3029 * "runtime" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003030 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003031 /* Runtime instruction load was bad;
3032 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08003033 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003034 goto restart;
3035 }
3036
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003037 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003038
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003039 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003040 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003041 IWL_WARN(priv, "Can not read RFKILL status from adapter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003042 return;
3043 }
3044
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003045 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
Tomas Winklere1623442009-01-27 14:27:56 -08003046 IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003047 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003048
3049 if (rfkill & 0x1) {
3050 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winklera96a27f2008-10-23 23:48:56 -07003051 /* if RFKILL is not on, then wait for thermal
Zhu Yib481de92007-09-25 17:54:57 -07003052 * sensor in adapter to kick in */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003053 while (iwl3945_hw_get_temperature(priv) == 0) {
Zhu Yib481de92007-09-25 17:54:57 -07003054 thermal_spin++;
3055 udelay(10);
3056 }
3057
3058 if (thermal_spin)
Tomas Winklere1623442009-01-27 14:27:56 -08003059 IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n",
Zhu Yib481de92007-09-25 17:54:57 -07003060 thermal_spin * 10);
3061 } else
3062 set_bit(STATUS_RF_KILL_HW, &priv->status);
3063
Ben Cahill9fbab512007-11-29 11:09:47 +08003064 /* After the ALIVE response, we can send commands to 3945 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07003065 set_bit(STATUS_ALIVE, &priv->status);
3066
3067 /* Clear out the uCode error bit if it is set */
3068 clear_bit(STATUS_FW_ERROR, &priv->status);
3069
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003070 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003071 return;
3072
Johannes Berg36d68252008-05-15 12:55:26 +02003073 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07003074
3075 priv->active_rate = priv->rates_mask;
3076 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
3077
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08003078 iwl_power_update_mode(priv, false);
Zhu Yib481de92007-09-25 17:54:57 -07003079
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003080 if (iwl_is_associated(priv)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003081 struct iwl3945_rxon_cmd *active_rxon =
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003082 (struct iwl3945_rxon_cmd *)(&priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07003083
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003084 memcpy(&priv->staging_rxon, &priv->active_rxon,
3085 sizeof(priv->staging_rxon));
Zhu Yib481de92007-09-25 17:54:57 -07003086 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3087 } else {
3088 /* Initialize our rx_config data */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003089 iwl_connection_init_rx_config(priv, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003090 }
3091
Ben Cahill9fbab512007-11-29 11:09:47 +08003092 /* Configure Bluetooth device coexistence support */
Samuel Ortiz17f841c2009-01-23 13:45:20 -08003093 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003094
3095 /* Configure the adapter for unassociated operation */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003096 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003097
Zhu Yib481de92007-09-25 17:54:57 -07003098 iwl3945_reg_txpower_periodic(priv);
3099
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07003100 iwl3945_led_register(priv);
3101
Tomas Winklere1623442009-01-27 14:27:56 -08003102 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07003103 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a669262008-01-14 17:46:18 -08003104 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07003105
3106 if (priv->error_recovering)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003107 iwl3945_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003108
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003109 /* reassociate for ADHOC mode */
3110 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
3111 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
3112 priv->vif);
3113 if (beacon)
3114 iwl3945_mac_beacon_update(priv->hw, beacon);
3115 }
3116
Zhu Yib481de92007-09-25 17:54:57 -07003117 return;
3118
3119 restart:
3120 queue_work(priv->workqueue, &priv->restart);
3121}
3122
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003123static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07003124
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003125static void __iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003126{
3127 unsigned long flags;
3128 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
3129 struct ieee80211_conf *conf = NULL;
3130
Tomas Winklere1623442009-01-27 14:27:56 -08003131 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07003132
3133 conf = ieee80211_get_hw_conf(priv->hw);
3134
3135 if (!exit_pending)
3136 set_bit(STATUS_EXIT_PENDING, &priv->status);
3137
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07003138 iwl3945_led_unregister(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003139 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003140
3141 /* Unblock any waiting calls */
3142 wake_up_interruptible_all(&priv->wait_command_queue);
3143
Zhu Yib481de92007-09-25 17:54:57 -07003144 /* Wipe out the EXIT_PENDING status bit if we are not actually
3145 * exiting the module */
3146 if (!exit_pending)
3147 clear_bit(STATUS_EXIT_PENDING, &priv->status);
3148
3149 /* stop and reset the on-board processor */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003150 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07003151
3152 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003153 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08003154 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003155 spin_unlock_irqrestore(&priv->lock, flags);
3156 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003157
3158 if (priv->mac80211_registered)
3159 ieee80211_stop_queues(priv->hw);
3160
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003161 /* If we have not previously called iwl3945_init() then
Zhu Yib481de92007-09-25 17:54:57 -07003162 * clear all bits but the RF Kill and SUSPEND bits and return */
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003163 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003164 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3165 STATUS_RF_KILL_HW |
3166 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3167 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08003168 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3169 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07003170 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003171 STATUS_IN_SUSPEND |
3172 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3173 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07003174 goto exit;
3175 }
3176
3177 /* ...otherwise clear out all the status bits but the RF Kill and
3178 * SUSPEND bits and continue taking the NIC down. */
3179 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3180 STATUS_RF_KILL_HW |
3181 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3182 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08003183 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3184 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07003185 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
3186 STATUS_IN_SUSPEND |
3187 test_bit(STATUS_FW_ERROR, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003188 STATUS_FW_ERROR |
3189 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3190 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07003191
Abbas, Mohamede9414b62009-01-20 21:33:55 -08003192 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003193 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003194 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07003195 spin_unlock_irqrestore(&priv->lock, flags);
3196
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003197 iwl3945_hw_txq_ctx_stop(priv);
3198 iwl3945_hw_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003199
3200 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003201 if (!iwl_grab_nic_access(priv)) {
3202 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07003203 APMG_CLK_VAL_DMA_CLK_RQT);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003204 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003205 }
3206 spin_unlock_irqrestore(&priv->lock, flags);
3207
3208 udelay(5);
3209
Abbas, Mohamede9414b62009-01-20 21:33:55 -08003210 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
3211 priv->cfg->ops->lib->apm_ops.stop(priv);
3212 else
3213 priv->cfg->ops->lib->apm_ops.reset(priv);
3214
Zhu Yib481de92007-09-25 17:54:57 -07003215 exit:
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08003216 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07003217
3218 if (priv->ibss_beacon)
3219 dev_kfree_skb(priv->ibss_beacon);
3220 priv->ibss_beacon = NULL;
3221
3222 /* clear out any free frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003223 iwl3945_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003224}
3225
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003226static void iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003227{
3228 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003229 __iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003230 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08003231
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003232 iwl3945_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003233}
3234
3235#define MAX_HW_RESTARTS 5
3236
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003237static int __iwl3945_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003238{
3239 int rc, i;
3240
3241 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003242 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003243 return -EIO;
3244 }
3245
3246 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003247 IWL_WARN(priv, "Radio disabled by SW RF kill (module "
Zhu Yib481de92007-09-25 17:54:57 -07003248 "parameter)\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003249 return -ENODEV;
3250 }
3251
Reinette Chatree903fbd2008-01-30 22:05:15 -08003252 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003253 IWL_ERR(priv, "ucode not available for device bring up\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08003254 return -EIO;
3255 }
3256
Zhu Yie655b9f2008-01-24 02:19:38 -08003257 /* If platform's RF_KILL switch is NOT set to KILL */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003258 if (iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yie655b9f2008-01-24 02:19:38 -08003259 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3260 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3261 else {
3262 set_bit(STATUS_RF_KILL_HW, &priv->status);
3263 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003264 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003265 return -ENODEV;
3266 }
Zhu Yib481de92007-09-25 17:54:57 -07003267 }
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02003268
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003269 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07003270
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003271 rc = iwl3945_hw_nic_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003272 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003273 IWL_ERR(priv, "Unable to int nic\n");
Zhu Yib481de92007-09-25 17:54:57 -07003274 return rc;
3275 }
3276
3277 /* make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003278 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3279 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07003280 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
3281
3282 /* clear (again), then enable host interrupts */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003283 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08003284 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003285
3286 /* really make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003287 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3288 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07003289
3290 /* Copy original ucode data image from disk into backup cache.
3291 * This will be used to initialize the on-board processor's
3292 * data SRAM for a clean start when the runtime program first loads. */
3293 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a669262008-01-14 17:46:18 -08003294 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07003295
Zhu Yie655b9f2008-01-24 02:19:38 -08003296 /* We return success when we resume from suspend and rf_kill is on. */
3297 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
3298 return 0;
3299
Zhu Yib481de92007-09-25 17:54:57 -07003300 for (i = 0; i < MAX_HW_RESTARTS; i++) {
3301
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003302 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003303
3304 /* load bootstrap state machine,
3305 * load bootstrap program into processor's memory,
3306 * prepare to load the "initialize" uCode */
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08003307 priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003308
3309 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003310 IWL_ERR(priv,
3311 "Unable to set up bootstrap uCode: %d\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -07003312 continue;
3313 }
3314
3315 /* start card; "initialize" will load runtime ucode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003316 iwl3945_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003317
Tomas Winklere1623442009-01-27 14:27:56 -08003318 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003319
3320 return 0;
3321 }
3322
3323 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003324 __iwl3945_down(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003325 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003326
3327 /* tried to restart and config the device for as long as our
3328 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08003329 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07003330 return -EIO;
3331}
3332
3333
3334/*****************************************************************************
3335 *
3336 * Workqueue callbacks
3337 *
3338 *****************************************************************************/
3339
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003340static void iwl3945_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003341{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003342 struct iwl_priv *priv =
3343 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003344
3345 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3346 return;
3347
3348 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003349 iwl3945_init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003350 mutex_unlock(&priv->mutex);
3351}
3352
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003353static void iwl3945_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003354{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003355 struct iwl_priv *priv =
3356 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003357
3358 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3359 return;
3360
3361 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003362 iwl3945_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003363 mutex_unlock(&priv->mutex);
3364}
3365
Helmut Schaa26635162009-01-15 09:38:44 +01003366static void iwl3945_rfkill_poll(struct work_struct *data)
3367{
3368 struct iwl_priv *priv =
3369 container_of(data, struct iwl_priv, rfkill_poll.work);
3370 unsigned long status = priv->status;
3371
3372 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3373 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3374 else
3375 set_bit(STATUS_RF_KILL_HW, &priv->status);
3376
3377 if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status))
3378 queue_work(priv->workqueue, &priv->rf_kill);
3379
3380 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3381 round_jiffies_relative(2 * HZ));
3382
3383}
3384
Zhu Yib481de92007-09-25 17:54:57 -07003385#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003386static void iwl3945_bg_request_scan(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003387{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003388 struct iwl_priv *priv =
3389 container_of(data, struct iwl_priv, request_scan);
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08003390 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07003391 .id = REPLY_SCAN_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003392 .len = sizeof(struct iwl3945_scan_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07003393 .meta.flags = CMD_SIZE_HUGE,
3394 };
3395 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003396 struct iwl3945_scan_cmd *scan;
Zhu Yib481de92007-09-25 17:54:57 -07003397 struct ieee80211_conf *conf = NULL;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003398 u8 n_probes = 2;
Johannes Berg8318d782008-01-24 19:38:38 +01003399 enum ieee80211_band band;
John W. Linville9387b7c2008-09-30 20:59:05 -04003400 DECLARE_SSID_BUF(ssid);
Zhu Yib481de92007-09-25 17:54:57 -07003401
3402 conf = ieee80211_get_hw_conf(priv->hw);
3403
3404 mutex_lock(&priv->mutex);
3405
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003406 if (!iwl_is_ready(priv)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003407 IWL_WARN(priv, "request scan called when driver not ready.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003408 goto done;
3409 }
3410
Tomas Winklera96a27f2008-10-23 23:48:56 -07003411 /* Make sure the scan wasn't canceled before this queued work
Zhu Yib481de92007-09-25 17:54:57 -07003412 * was given the chance to run... */
3413 if (!test_bit(STATUS_SCANNING, &priv->status))
3414 goto done;
3415
3416 /* This should never be called or scheduled if there is currently
3417 * a scan active in the hardware. */
3418 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003419 IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests "
3420 "Ignoring second request.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003421 rc = -EIO;
3422 goto done;
3423 }
3424
3425 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003426 IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n");
Zhu Yib481de92007-09-25 17:54:57 -07003427 goto done;
3428 }
3429
3430 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003431 IWL_DEBUG_HC(priv,
3432 "Scan request while abort pending. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003433 goto done;
3434 }
3435
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003436 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003437 IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n");
Zhu Yib481de92007-09-25 17:54:57 -07003438 goto done;
3439 }
3440
3441 if (!test_bit(STATUS_READY, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003442 IWL_DEBUG_HC(priv,
3443 "Scan request while uninitialized. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003444 goto done;
3445 }
3446
3447 if (!priv->scan_bands) {
Tomas Winklere1623442009-01-27 14:27:56 -08003448 IWL_DEBUG_HC(priv, "Aborting scan due to no requested bands\n");
Zhu Yib481de92007-09-25 17:54:57 -07003449 goto done;
3450 }
3451
Winkler, Tomas805cee52009-01-19 15:30:28 -08003452 if (!priv->scan) {
3453 priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
Zhu Yib481de92007-09-25 17:54:57 -07003454 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
Winkler, Tomas805cee52009-01-19 15:30:28 -08003455 if (!priv->scan) {
Zhu Yib481de92007-09-25 17:54:57 -07003456 rc = -ENOMEM;
3457 goto done;
3458 }
3459 }
Winkler, Tomas805cee52009-01-19 15:30:28 -08003460 scan = priv->scan;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003461 memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07003462
3463 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
3464 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
3465
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003466 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003467 u16 interval = 0;
3468 u32 extra;
3469 u32 suspend_time = 100;
3470 u32 scan_suspend_time = 100;
3471 unsigned long flags;
3472
Tomas Winklere1623442009-01-27 14:27:56 -08003473 IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
Zhu Yib481de92007-09-25 17:54:57 -07003474
3475 spin_lock_irqsave(&priv->lock, flags);
3476 interval = priv->beacon_int;
3477 spin_unlock_irqrestore(&priv->lock, flags);
3478
3479 scan->suspend_time = 0;
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003480 scan->max_out_time = cpu_to_le32(200 * 1024);
Zhu Yib481de92007-09-25 17:54:57 -07003481 if (!interval)
3482 interval = suspend_time;
3483 /*
3484 * suspend time format:
3485 * 0-19: beacon interval in usec (time before exec.)
3486 * 20-23: 0
3487 * 24-31: number of beacons (suspend between channels)
3488 */
3489
3490 extra = (suspend_time / interval) << 24;
3491 scan_suspend_time = 0xFF0FFFFF &
3492 (extra | ((suspend_time % interval) * 1024));
3493
3494 scan->suspend_time = cpu_to_le32(scan_suspend_time);
Tomas Winklere1623442009-01-27 14:27:56 -08003495 IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003496 scan_suspend_time, interval);
3497 }
3498
3499 /* We should add the ability for user to lock to PASSIVE ONLY */
3500 if (priv->one_direct_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08003501 IWL_DEBUG_SCAN(priv, "Kicking off one direct scan for '%s'\n",
3502 print_ssid(ssid, priv->direct_ssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04003503 priv->direct_ssid_len));
Zhu Yib481de92007-09-25 17:54:57 -07003504 scan->direct_scan[0].id = WLAN_EID_SSID;
3505 scan->direct_scan[0].len = priv->direct_ssid_len;
3506 memcpy(scan->direct_scan[0].ssid,
3507 priv->direct_ssid, priv->direct_ssid_len);
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003508 n_probes++;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003509 } else
Tomas Winklere1623442009-01-27 14:27:56 -08003510 IWL_DEBUG_SCAN(priv, "Kicking off one indirect scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003511
3512 /* We don't build a direct scan probe request; the uCode will do
3513 * that based on the direct_mask added to each channel entry */
Zhu Yib481de92007-09-25 17:54:57 -07003514 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08003515 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07003516 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
3517
3518 /* flags + rate selection */
3519
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003520 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003521 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
3522 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
3523 scan->good_CRC_th = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01003524 band = IEEE80211_BAND_2GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003525 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003526 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
3527 scan->good_CRC_th = IWL_GOOD_CRC_TH;
Johannes Berg8318d782008-01-24 19:38:38 +01003528 band = IEEE80211_BAND_5GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003529 } else {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003530 IWL_WARN(priv, "Invalid scan band count\n");
Zhu Yib481de92007-09-25 17:54:57 -07003531 goto done;
3532 }
3533
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08003534 scan->tx_cmd.len = cpu_to_le16(
3535 iwl_fill_probe_req(priv, band,
3536 (struct ieee80211_mgmt *)scan->data,
3537 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
3538
Zhu Yib481de92007-09-25 17:54:57 -07003539 /* select Rx antennas */
3540 scan->flags |= iwl3945_get_antenna_flags(priv);
3541
Johannes Berg05c914f2008-09-11 00:01:58 +02003542 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
Zhu Yib481de92007-09-25 17:54:57 -07003543 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
3544
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003545 scan->channel_count =
3546 iwl3945_get_channels_for_scan(priv, band, 1, /* active */
3547 n_probes,
3548 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
Zhu Yib481de92007-09-25 17:54:57 -07003549
Reinette Chatre14b54332008-11-04 12:21:35 -08003550 if (scan->channel_count == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08003551 IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
Reinette Chatre14b54332008-11-04 12:21:35 -08003552 goto done;
3553 }
3554
Zhu Yib481de92007-09-25 17:54:57 -07003555 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003556 scan->channel_count * sizeof(struct iwl3945_scan_channel);
Zhu Yib481de92007-09-25 17:54:57 -07003557 cmd.data = scan;
3558 scan->len = cpu_to_le16(cmd.len);
3559
3560 set_bit(STATUS_SCAN_HW, &priv->status);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003561 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07003562 if (rc)
3563 goto done;
3564
3565 queue_delayed_work(priv->workqueue, &priv->scan_check,
3566 IWL_SCAN_CHECK_WATCHDOG);
3567
3568 mutex_unlock(&priv->mutex);
3569 return;
3570
3571 done:
Mohamed Abbas2420ebc2008-11-04 12:21:34 -08003572 /* can not perform scan make sure we clear scanning
3573 * bits from status so next scan request can be performed.
3574 * if we dont clear scanning status bit here all next scan
3575 * will fail
3576 */
3577 clear_bit(STATUS_SCAN_HW, &priv->status);
3578 clear_bit(STATUS_SCANNING, &priv->status);
3579
Ian Schram01ebd062007-10-25 17:15:22 +08003580 /* inform mac80211 scan aborted */
Zhu Yib481de92007-09-25 17:54:57 -07003581 queue_work(priv->workqueue, &priv->scan_completed);
3582 mutex_unlock(&priv->mutex);
3583}
3584
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003585static void iwl3945_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003586{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003587 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07003588
3589 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3590 return;
3591
3592 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003593 __iwl3945_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003594 mutex_unlock(&priv->mutex);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003595 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003596}
3597
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003598static void iwl3945_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003599{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003600 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07003601
3602 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3603 return;
3604
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003605 iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003606 queue_work(priv->workqueue, &priv->up);
3607}
3608
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003609static void iwl3945_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003610{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003611 struct iwl_priv *priv =
3612 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07003613
3614 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3615 return;
3616
3617 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003618 iwl3945_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003619 mutex_unlock(&priv->mutex);
3620}
3621
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003622#define IWL_DELAY_NEXT_SCAN (HZ*2)
3623
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003624static void iwl3945_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003625{
Zhu Yib481de92007-09-25 17:54:57 -07003626 int rc = 0;
3627 struct ieee80211_conf *conf = NULL;
3628
Johannes Berg05c914f2008-09-11 00:01:58 +02003629 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003630 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07003631 return;
3632 }
3633
3634
Tomas Winklere1623442009-01-27 14:27:56 -08003635 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003636 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07003637
3638 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3639 return;
3640
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003641 if (!priv->vif || !priv->is_open)
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003642 return;
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003643
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003644 iwl_scan_cancel_timeout(priv, 200);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003645
Zhu Yib481de92007-09-25 17:54:57 -07003646 conf = ieee80211_get_hw_conf(priv->hw);
3647
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003648 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003649 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003650
Tomas Winkler28afaf92008-12-19 10:37:06 +08003651 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003652 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003653 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07003654 sizeof(priv->rxon_timing), &priv->rxon_timing);
3655 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003656 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003657 "Attempting to continue.\n");
3658
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003659 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003660
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003661 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003662
Tomas Winklere1623442009-01-27 14:27:56 -08003663 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003664 priv->assoc_id, priv->beacon_int);
3665
3666 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003667 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003668 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003669 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003670
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003671 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003672 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003673 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003674 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003675 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003676
Johannes Berg05c914f2008-09-11 00:01:58 +02003677 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003678 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003679
3680 }
3681
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003682 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003683
3684 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02003685 case NL80211_IFTYPE_STATION:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003686 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07003687 break;
3688
Johannes Berg05c914f2008-09-11 00:01:58 +02003689 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07003690
Abhijeet Kolekarce546fd2008-11-19 15:32:22 -08003691 priv->assoc_id = 1;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003692 iwl3945_add_station(priv, priv->bssid, 0, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003693 iwl3945_sync_sta(priv, IWL_STA_ID,
Johannes Berg8318d782008-01-24 19:38:38 +01003694 (priv->band == IEEE80211_BAND_5GHZ) ?
Zhu Yib481de92007-09-25 17:54:57 -07003695 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
3696 CMD_ASYNC);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003697 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
3698 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003699
3700 break;
3701
3702 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08003703 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003704 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003705 break;
3706 }
3707
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003708 iwl3945_activate_qos(priv, 0);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08003709
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003710 /* we have just associated, don't start scan too early */
3711 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08003712}
3713
Johannes Berge8975582008-10-09 12:18:51 +02003714static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003715
Zhu Yib481de92007-09-25 17:54:57 -07003716/*****************************************************************************
3717 *
3718 * mac80211 entry point functions
3719 *
3720 *****************************************************************************/
3721
Zhu Yi5a669262008-01-14 17:46:18 -08003722#define UCODE_READY_TIMEOUT (2 * HZ)
3723
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003724static int iwl3945_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003725{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003726 struct iwl_priv *priv = hw->priv;
Zhu Yi5a669262008-01-14 17:46:18 -08003727 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003728
Tomas Winklere1623442009-01-27 14:27:56 -08003729 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003730
3731 /* we should be verifying the device is ready to be opened */
3732 mutex_lock(&priv->mutex);
3733
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003734 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
Zhu Yi5a669262008-01-14 17:46:18 -08003735 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
3736 * ucode filename and max sizes are card-specific. */
3737
3738 if (!priv->ucode_code.len) {
3739 ret = iwl3945_read_ucode(priv);
3740 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003741 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a669262008-01-14 17:46:18 -08003742 mutex_unlock(&priv->mutex);
3743 goto out_release_irq;
3744 }
3745 }
3746
Zhu Yie655b9f2008-01-24 02:19:38 -08003747 ret = __iwl3945_up(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08003748
Zhu Yib481de92007-09-25 17:54:57 -07003749 mutex_unlock(&priv->mutex);
Zhu Yi5a669262008-01-14 17:46:18 -08003750
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003751 iwl_rfkill_set_hw_state(priv);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02003752
Zhu Yie655b9f2008-01-24 02:19:38 -08003753 if (ret)
3754 goto out_release_irq;
3755
Tomas Winklere1623442009-01-27 14:27:56 -08003756 IWL_DEBUG_INFO(priv, "Start UP work.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003757
3758 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
3759 return 0;
3760
Zhu Yi5a669262008-01-14 17:46:18 -08003761 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
3762 * mac80211 will not be run successfully. */
3763 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
3764 test_bit(STATUS_READY, &priv->status),
3765 UCODE_READY_TIMEOUT);
3766 if (!ret) {
3767 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003768 IWL_ERR(priv,
3769 "Wait for START_ALIVE timeout after %dms.\n",
3770 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Zhu Yi5a669262008-01-14 17:46:18 -08003771 ret = -ETIMEDOUT;
3772 goto out_release_irq;
3773 }
3774 }
3775
Helmut Schaa26635162009-01-15 09:38:44 +01003776 /* ucode is running and will send rfkill notifications,
3777 * no need to poll the killswitch state anymore */
3778 cancel_delayed_work(&priv->rfkill_poll);
3779
Zhu Yie655b9f2008-01-24 02:19:38 -08003780 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08003781 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003782 return 0;
Zhu Yi5a669262008-01-14 17:46:18 -08003783
3784out_release_irq:
Zhu Yie655b9f2008-01-24 02:19:38 -08003785 priv->is_open = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08003786 IWL_DEBUG_MAC80211(priv, "leave - failed\n");
Zhu Yi5a669262008-01-14 17:46:18 -08003787 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003788}
3789
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003790static void iwl3945_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003791{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003792 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003793
Tomas Winklere1623442009-01-27 14:27:56 -08003794 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003795
Zhu Yie655b9f2008-01-24 02:19:38 -08003796 if (!priv->is_open) {
Tomas Winklere1623442009-01-27 14:27:56 -08003797 IWL_DEBUG_MAC80211(priv, "leave - skip\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003798 return;
3799 }
3800
Zhu Yib481de92007-09-25 17:54:57 -07003801 priv->is_open = 0;
Zhu Yi5a669262008-01-14 17:46:18 -08003802
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003803 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08003804 /* stop mac, cancel any scan request and clear
3805 * RXON_FILTER_ASSOC_MSK BIT
3806 */
Zhu Yi5a669262008-01-14 17:46:18 -08003807 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003808 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003809 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003810 }
3811
Zhu Yi5a669262008-01-14 17:46:18 -08003812 iwl3945_down(priv);
3813
3814 flush_workqueue(priv->workqueue);
Helmut Schaa26635162009-01-15 09:38:44 +01003815
3816 /* start polling the killswitch state again */
3817 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3818 round_jiffies_relative(2 * HZ));
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003819
Tomas Winklere1623442009-01-27 14:27:56 -08003820 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003821}
3822
Johannes Berge039fa42008-05-15 12:55:29 +02003823static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003824{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003825 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003826
Tomas Winklere1623442009-01-27 14:27:56 -08003827 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003828
Tomas Winklere1623442009-01-27 14:27:56 -08003829 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02003830 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07003831
Johannes Berge039fa42008-05-15 12:55:29 +02003832 if (iwl3945_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07003833 dev_kfree_skb_any(skb);
3834
Tomas Winklere1623442009-01-27 14:27:56 -08003835 IWL_DEBUG_MAC80211(priv, "leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08003836 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07003837}
3838
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003839static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003840 struct ieee80211_if_init_conf *conf)
3841{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003842 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003843 unsigned long flags;
3844
Tomas Winklere1623442009-01-27 14:27:56 -08003845 IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07003846
Johannes Berg32bfd352007-12-19 01:31:26 +01003847 if (priv->vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08003848 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
Tomas Winkler864792e2007-11-27 21:00:52 +02003849 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07003850 }
3851
3852 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01003853 priv->vif = conf->vif;
Zhu, Yi60294de2008-10-29 14:05:45 -07003854 priv->iw_mode = conf->type;
Zhu Yib481de92007-09-25 17:54:57 -07003855
3856 spin_unlock_irqrestore(&priv->lock, flags);
3857
3858 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02003859
3860 if (conf->mac_addr) {
Tomas Winklere1623442009-01-27 14:27:56 -08003861 IWL_DEBUG_MAC80211(priv, "Set: %pM\n", conf->mac_addr);
Tomas Winkler864792e2007-11-27 21:00:52 +02003862 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
3863 }
3864
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003865 if (iwl_is_ready(priv))
Zhu Yi5a669262008-01-14 17:46:18 -08003866 iwl3945_set_mode(priv, conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07003867
Zhu Yib481de92007-09-25 17:54:57 -07003868 mutex_unlock(&priv->mutex);
3869
Tomas Winklere1623442009-01-27 14:27:56 -08003870 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003871 return 0;
3872}
3873
3874/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003875 * iwl3945_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07003876 *
3877 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
3878 * be set inappropriately and the driver currently sets the hardware up to
3879 * use it whenever needed.
3880 */
Johannes Berge8975582008-10-09 12:18:51 +02003881static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed)
Zhu Yib481de92007-09-25 17:54:57 -07003882{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003883 struct iwl_priv *priv = hw->priv;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08003884 const struct iwl_channel_info *ch_info;
Johannes Berge8975582008-10-09 12:18:51 +02003885 struct ieee80211_conf *conf = &hw->conf;
Zhu Yib481de92007-09-25 17:54:57 -07003886 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08003887 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003888
3889 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08003890 IWL_DEBUG_MAC80211(priv, "enter to channel %d\n",
3891 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07003892
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003893 if (!iwl_is_ready(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003894 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08003895 ret = -EIO;
3896 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003897 }
3898
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08003899 if (unlikely(!iwl3945_mod_params.disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07003900 test_bit(STATUS_SCANNING, &priv->status))) {
Tomas Winklere1623442009-01-27 14:27:56 -08003901 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
Zhu Yia0646472007-12-20 14:10:01 +08003902 set_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003903 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08003904 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07003905 }
3906
3907 spin_lock_irqsave(&priv->lock, flags);
3908
Samuel Ortize6148912009-01-23 13:45:15 -08003909 ch_info = iwl_get_channel_info(priv, conf->channel->band,
3910 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07003911 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003912 IWL_DEBUG_SCAN(priv,
3913 "Channel %d [%d] is INVALID for this band.\n",
3914 conf->channel->hw_value, conf->channel->band);
3915 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
Zhu Yib481de92007-09-25 17:54:57 -07003916 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003917 ret = -EINVAL;
3918 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003919 }
3920
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003921 iwl_set_rxon_channel(priv, conf->channel);
Zhu Yib481de92007-09-25 17:54:57 -07003922
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003923 iwl_set_flags_for_band(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07003924
3925 /* The list of supported rates and rate mask can be different
3926 * for each phymode; since the phymode may have changed, reset
3927 * the rate mask to what mac80211 lists */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003928 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003929
3930 spin_unlock_irqrestore(&priv->lock, flags);
3931
3932#ifdef IEEE80211_CONF_CHANNEL_SWITCH
3933 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003934 iwl3945_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003935 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003936 }
3937#endif
3938
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003939 iwl3945_radio_kill_sw(priv, !conf->radio_enabled);
Zhu Yib481de92007-09-25 17:54:57 -07003940
3941 if (!conf->radio_enabled) {
Tomas Winklere1623442009-01-27 14:27:56 -08003942 IWL_DEBUG_MAC80211(priv, "leave - radio disabled\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08003943 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003944 }
3945
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003946 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003947 IWL_DEBUG_MAC80211(priv, "leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08003948 ret = -EIO;
3949 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003950 }
3951
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003952 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003953
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003954 if (memcmp(&priv->active_rxon,
3955 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003956 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003957 else
Tomas Winklere1623442009-01-27 14:27:56 -08003958 IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration\n");
Zhu Yib481de92007-09-25 17:54:57 -07003959
Tomas Winklere1623442009-01-27 14:27:56 -08003960 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003961
Zhu Yi76bb77e2007-11-22 10:53:22 +08003962out:
Zhu Yia0646472007-12-20 14:10:01 +08003963 clear_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003964 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003965 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003966}
3967
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003968static void iwl3945_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003969{
3970 int rc = 0;
3971
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08003972 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07003973 return;
3974
3975 /* The following should be done only at AP bring up */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003976 if (!(iwl_is_associated(priv))) {
Zhu Yib481de92007-09-25 17:54:57 -07003977
3978 /* RXON - unassoc (to set timing command) */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003979 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003980 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003981
3982 /* RXON Timing */
Tomas Winkler28afaf92008-12-19 10:37:06 +08003983 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003984 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003985 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
3986 sizeof(priv->rxon_timing),
3987 &priv->rxon_timing);
Zhu Yib481de92007-09-25 17:54:57 -07003988 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003989 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003990 "Attempting to continue.\n");
3991
3992 /* FIXME: what should be the assoc_id for AP? */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003993 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003994 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003995 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003996 RXON_FLG_SHORT_PREAMBLE_MSK;
3997 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003998 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003999 ~RXON_FLG_SHORT_PREAMBLE_MSK;
4000
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004001 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07004002 if (priv->assoc_capability &
4003 WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004004 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07004005 RXON_FLG_SHORT_SLOT_MSK;
4006 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004007 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07004008 ~RXON_FLG_SHORT_SLOT_MSK;
4009
Johannes Berg05c914f2008-09-11 00:01:58 +02004010 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004011 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07004012 ~RXON_FLG_SHORT_SLOT_MSK;
4013 }
4014 /* restore RXON assoc */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004015 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004016 iwl3945_commit_rxon(priv);
Kolekar, Abhijeetb5323d32008-12-19 10:37:22 +08004017 iwl3945_add_station(priv, iwl_bcast_addr, 0, 0);
Zhu Yi556f8db2007-09-27 11:27:33 +08004018 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004019 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004020
4021 /* FIXME - we need to add code here to detect a totally new
4022 * configuration, reset the AP, unassoc, rxon timing, assoc,
4023 * clear sta table, add BCAST sta... */
4024}
4025
Johannes Berg32bfd352007-12-19 01:31:26 +01004026static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
4027 struct ieee80211_vif *vif,
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004028 struct ieee80211_if_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07004029{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004030 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004031 int rc;
4032
4033 if (conf == NULL)
4034 return -EIO;
4035
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08004036 if (priv->vif != vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08004037 IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08004038 return 0;
4039 }
4040
Johannes Berg9d139c82008-07-09 14:40:37 +02004041 /* handle this temporarily here */
Johannes Berg05c914f2008-09-11 00:01:58 +02004042 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Johannes Berg9d139c82008-07-09 14:40:37 +02004043 conf->changed & IEEE80211_IFCC_BEACON) {
4044 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
4045 if (!beacon)
4046 return -ENOMEM;
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08004047 mutex_lock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02004048 rc = iwl3945_mac_beacon_update(hw, beacon);
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08004049 mutex_unlock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02004050 if (rc)
4051 return rc;
4052 }
4053
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004054 if (!iwl_is_alive(priv))
Zhu Yi5a669262008-01-14 17:46:18 -08004055 return -EAGAIN;
4056
Zhu Yib481de92007-09-25 17:54:57 -07004057 mutex_lock(&priv->mutex);
4058
Zhu Yib481de92007-09-25 17:54:57 -07004059 if (conf->bssid)
Tomas Winklere1623442009-01-27 14:27:56 -08004060 IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07004061
Johannes Berg4150c572007-09-17 01:29:23 -04004062/*
4063 * very dubious code was here; the probe filtering flag is never set:
4064 *
Zhu Yib481de92007-09-25 17:54:57 -07004065 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
4066 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04004067 */
Zhu Yib481de92007-09-25 17:54:57 -07004068
Johannes Berg05c914f2008-09-11 00:01:58 +02004069 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07004070 if (!conf->bssid) {
4071 conf->bssid = priv->mac_addr;
4072 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08004073 IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07004074 conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07004075 }
4076 if (priv->ibss_beacon)
4077 dev_kfree_skb(priv->ibss_beacon);
4078
Johannes Berg9d139c82008-07-09 14:40:37 +02004079 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
Zhu Yib481de92007-09-25 17:54:57 -07004080 }
4081
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004082 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08004083 goto done;
4084
Zhu Yib481de92007-09-25 17:54:57 -07004085 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
4086 !is_multicast_ether_addr(conf->bssid)) {
4087 /* If there is currently a HW scan going on in the background
4088 * then we need to cancel it else the RXON below will fail. */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004089 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004090 IWL_WARN(priv, "Aborted scan still in progress "
Zhu Yib481de92007-09-25 17:54:57 -07004091 "after 100ms\n");
Tomas Winklere1623442009-01-27 14:27:56 -08004092 IWL_DEBUG_MAC80211(priv, "leaving:scan abort failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07004093 mutex_unlock(&priv->mutex);
4094 return -EAGAIN;
4095 }
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004096 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07004097
4098 /* TODO: Audit driver for usage of these members and see
4099 * if mac80211 deprecates them (priv->bssid looks like it
4100 * shouldn't be there, but I haven't scanned the IBSS code
4101 * to verify) - jpk */
4102 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
4103
Johannes Berg05c914f2008-09-11 00:01:58 +02004104 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004105 iwl3945_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004106 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004107 rc = iwl3945_commit_rxon(priv);
Johannes Berg05c914f2008-09-11 00:01:58 +02004108 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004109 iwl3945_add_station(priv,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004110 priv->active_rxon.bssid_addr, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004111 }
4112
4113 } else {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004114 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004115 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004116 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004117 }
4118
Mohamed Abbasfde35712007-11-29 11:10:15 +08004119 done:
Tomas Winklere1623442009-01-27 14:27:56 -08004120 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004121 mutex_unlock(&priv->mutex);
4122
4123 return 0;
4124}
4125
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004126static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004127 struct ieee80211_if_init_conf *conf)
4128{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004129 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004130
Tomas Winklere1623442009-01-27 14:27:56 -08004131 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004132
4133 mutex_lock(&priv->mutex);
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004134
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004135 if (iwl_is_ready_rf(priv)) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004136 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004137 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Mohamed Abbasfde35712007-11-29 11:10:15 +08004138 iwl3945_commit_rxon(priv);
4139 }
Johannes Berg32bfd352007-12-19 01:31:26 +01004140 if (priv->vif == conf->vif) {
4141 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07004142 memset(priv->bssid, 0, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07004143 }
4144 mutex_unlock(&priv->mutex);
4145
Tomas Winklere1623442009-01-27 14:27:56 -08004146 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004147}
4148
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004149#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
4150
4151static void iwl3945_bss_info_changed(struct ieee80211_hw *hw,
4152 struct ieee80211_vif *vif,
4153 struct ieee80211_bss_conf *bss_conf,
4154 u32 changes)
4155{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004156 struct iwl_priv *priv = hw->priv;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004157
Tomas Winklere1623442009-01-27 14:27:56 -08004158 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004159
4160 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
Tomas Winklere1623442009-01-27 14:27:56 -08004161 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004162 bss_conf->use_short_preamble);
4163 if (bss_conf->use_short_preamble)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004164 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004165 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004166 priv->staging_rxon.flags &=
4167 ~RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004168 }
4169
4170 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
Tomas Winklere1623442009-01-27 14:27:56 -08004171 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n",
4172 bss_conf->use_cts_prot);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004173 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004174 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004175 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004176 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004177 }
4178
4179 if (changes & BSS_CHANGED_ASSOC) {
Tomas Winklere1623442009-01-27 14:27:56 -08004180 IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004181 /* This should never happen as this function should
4182 * never be called from interrupt context. */
4183 if (WARN_ON_ONCE(in_interrupt()))
4184 return;
4185 if (bss_conf->assoc) {
4186 priv->assoc_id = bss_conf->aid;
4187 priv->beacon_int = bss_conf->beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08004188 priv->timestamp = bss_conf->timestamp;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004189 priv->assoc_capability = bss_conf->assoc_capability;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08004190 priv->power_data.dtim_period = bss_conf->dtim_period;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004191 priv->next_scan_jiffies = jiffies +
4192 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
4193 mutex_lock(&priv->mutex);
4194 iwl3945_post_associate(priv);
4195 mutex_unlock(&priv->mutex);
4196 } else {
4197 priv->assoc_id = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08004198 IWL_DEBUG_MAC80211(priv,
4199 "DISASSOC %d\n", bss_conf->assoc);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004200 }
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004201 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
Tomas Winklere1623442009-01-27 14:27:56 -08004202 IWL_DEBUG_MAC80211(priv,
4203 "Associated Changes %d\n", changes);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004204 iwl3945_send_rxon_assoc(priv);
4205 }
4206
4207}
4208
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004209static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01004210 struct ieee80211_vif *vif,
4211 struct ieee80211_sta *sta,
4212 struct ieee80211_key_conf *key)
Zhu Yib481de92007-09-25 17:54:57 -07004213{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004214 struct iwl_priv *priv = hw->priv;
Johannes Bergdc822b52008-12-29 12:55:09 +01004215 const u8 *addr;
Winkler, Tomas42986792009-01-19 15:30:22 -08004216 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07004217 u8 sta_id;
4218
Tomas Winklere1623442009-01-27 14:27:56 -08004219 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004220
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004221 if (iwl3945_mod_params.sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08004222 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07004223 return -EOPNOTSUPP;
4224 }
4225
Winkler, Tomas42986792009-01-19 15:30:22 -08004226 addr = sta ? sta->addr : iwl_bcast_addr;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004227 sta_id = iwl3945_hw_find_station(priv, addr);
Zhu Yib481de92007-09-25 17:54:57 -07004228 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -08004229 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
Johannes Berge1749612008-10-27 15:59:26 -07004230 addr);
Zhu Yib481de92007-09-25 17:54:57 -07004231 return -EINVAL;
4232 }
4233
4234 mutex_lock(&priv->mutex);
4235
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004236 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004237
Zhu Yib481de92007-09-25 17:54:57 -07004238 switch (cmd) {
4239 case SET_KEY:
Winkler, Tomas42986792009-01-19 15:30:22 -08004240 ret = iwl3945_update_sta_key_info(priv, key, sta_id);
4241 if (!ret) {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004242 iwl_set_rxon_hwcrypto(priv, 1);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004243 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004244 key->hw_key_idx = sta_id;
Tomas Winklere1623442009-01-27 14:27:56 -08004245 IWL_DEBUG_MAC80211(priv,
4246 "set_key success, using hwcrypto\n");
Zhu Yib481de92007-09-25 17:54:57 -07004247 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
4248 }
4249 break;
4250 case DISABLE_KEY:
Winkler, Tomas42986792009-01-19 15:30:22 -08004251 ret = iwl3945_clear_sta_key_info(priv, sta_id);
4252 if (!ret) {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004253 iwl_set_rxon_hwcrypto(priv, 0);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004254 iwl3945_commit_rxon(priv);
Tomas Winklere1623442009-01-27 14:27:56 -08004255 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07004256 }
4257 break;
4258 default:
Winkler, Tomas42986792009-01-19 15:30:22 -08004259 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07004260 }
4261
Tomas Winklere1623442009-01-27 14:27:56 -08004262 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004263 mutex_unlock(&priv->mutex);
4264
Winkler, Tomas42986792009-01-19 15:30:22 -08004265 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004266}
4267
Johannes Berge100bb62008-04-30 18:51:21 +02004268static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
Zhu Yib481de92007-09-25 17:54:57 -07004269 const struct ieee80211_tx_queue_params *params)
4270{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004271 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004272 unsigned long flags;
4273 int q;
Zhu Yib481de92007-09-25 17:54:57 -07004274
Tomas Winklere1623442009-01-27 14:27:56 -08004275 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004276
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004277 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004278 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004279 return -EIO;
4280 }
4281
4282 if (queue >= AC_NUM) {
Tomas Winklere1623442009-01-27 14:27:56 -08004283 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
Zhu Yib481de92007-09-25 17:54:57 -07004284 return 0;
4285 }
4286
Zhu Yib481de92007-09-25 17:54:57 -07004287 q = AC_NUM - 1 - queue;
4288
4289 spin_lock_irqsave(&priv->lock, flags);
4290
4291 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
4292 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
4293 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
4294 priv->qos_data.def_qos_parm.ac[q].edca_txop =
Johannes Berg3330d7be2008-02-10 16:49:38 +01004295 cpu_to_le16((params->txop * 32));
Zhu Yib481de92007-09-25 17:54:57 -07004296
4297 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
4298 priv->qos_data.qos_active = 1;
4299
4300 spin_unlock_irqrestore(&priv->lock, flags);
4301
4302 mutex_lock(&priv->mutex);
Johannes Berg05c914f2008-09-11 00:01:58 +02004303 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004304 iwl3945_activate_qos(priv, 1);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004305 else if (priv->assoc_id && iwl_is_associated(priv))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004306 iwl3945_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004307
4308 mutex_unlock(&priv->mutex);
4309
Tomas Winklere1623442009-01-27 14:27:56 -08004310 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004311 return 0;
4312}
4313
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004314static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004315 struct ieee80211_tx_queue_stats *stats)
4316{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004317 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004318 int i, avail;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08004319 struct iwl_tx_queue *txq;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004320 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07004321 unsigned long flags;
4322
Tomas Winklere1623442009-01-27 14:27:56 -08004323 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004324
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004325 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004326 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004327 return -EIO;
4328 }
4329
4330 spin_lock_irqsave(&priv->lock, flags);
4331
4332 for (i = 0; i < AC_NUM; i++) {
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08004333 txq = &priv->txq[i];
Zhu Yib481de92007-09-25 17:54:57 -07004334 q = &txq->q;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004335 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07004336
Johannes Berg57ffc582008-04-29 17:18:59 +02004337 stats[i].len = q->n_window - avail;
4338 stats[i].limit = q->n_window - q->high_mark;
4339 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07004340
4341 }
4342 spin_unlock_irqrestore(&priv->lock, flags);
4343
Tomas Winklere1623442009-01-27 14:27:56 -08004344 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004345
4346 return 0;
4347}
4348
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004349static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07004350{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004351 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004352 unsigned long flags;
4353
4354 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08004355 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004356
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004357 iwl_reset_qos(priv);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08004358
Zhu Yib481de92007-09-25 17:54:57 -07004359 spin_lock_irqsave(&priv->lock, flags);
4360 priv->assoc_id = 0;
4361 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004362
4363 /* new association get rid of ibss beacon skb */
4364 if (priv->ibss_beacon)
4365 dev_kfree_skb(priv->ibss_beacon);
4366
4367 priv->ibss_beacon = NULL;
4368
4369 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08004370 priv->timestamp = 0;
Johannes Berg05c914f2008-09-11 00:01:58 +02004371 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
Zhu Yib481de92007-09-25 17:54:57 -07004372 priv->beacon_int = 0;
4373
4374 spin_unlock_irqrestore(&priv->lock, flags);
4375
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004376 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004377 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +08004378 mutex_unlock(&priv->mutex);
4379 return;
4380 }
4381
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004382 /* we are restarting association process
4383 * clear RXON_FILTER_ASSOC_MSK bit
4384 */
Johannes Berg05c914f2008-09-11 00:01:58 +02004385 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004386 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004387 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004388 iwl3945_commit_rxon(priv);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004389 }
4390
Zhu Yib481de92007-09-25 17:54:57 -07004391 /* Per mac80211.h: This is only used in IBSS mode... */
Johannes Berg05c914f2008-09-11 00:01:58 +02004392 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004393
Tomas Winklere1623442009-01-27 14:27:56 -08004394 IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07004395 mutex_unlock(&priv->mutex);
4396 return;
4397 }
4398
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004399 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004400
4401 mutex_unlock(&priv->mutex);
4402
Tomas Winklere1623442009-01-27 14:27:56 -08004403 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004404
4405}
4406
Johannes Berge039fa42008-05-15 12:55:29 +02004407static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07004408{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004409 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004410 unsigned long flags;
4411
Tomas Winklere1623442009-01-27 14:27:56 -08004412 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004413
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004414 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004415 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004416 return -EIO;
4417 }
4418
Johannes Berg05c914f2008-09-11 00:01:58 +02004419 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Tomas Winklere1623442009-01-27 14:27:56 -08004420 IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07004421 return -EIO;
4422 }
4423
4424 spin_lock_irqsave(&priv->lock, flags);
4425
4426 if (priv->ibss_beacon)
4427 dev_kfree_skb(priv->ibss_beacon);
4428
4429 priv->ibss_beacon = skb;
4430
4431 priv->assoc_id = 0;
4432
Tomas Winklere1623442009-01-27 14:27:56 -08004433 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004434 spin_unlock_irqrestore(&priv->lock, flags);
4435
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004436 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004437
Abhijeet Kolekardc4b1e72008-09-03 11:26:30 +08004438 iwl3945_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004439
Zhu Yib481de92007-09-25 17:54:57 -07004440
4441 return 0;
4442}
4443
4444/*****************************************************************************
4445 *
4446 * sysfs attributes
4447 *
4448 *****************************************************************************/
4449
Samuel Ortizd08853a2009-01-23 13:45:17 -08004450#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07004451
4452/*
4453 * The following adds a new attribute to the sysfs representation
4454 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
4455 * used for controlling the debug level.
4456 *
4457 * See the level definitions in iwl for details.
4458 */
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004459static ssize_t show_debug_level(struct device *d,
4460 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07004461{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004462 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004463
4464 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07004465}
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004466static ssize_t store_debug_level(struct device *d,
4467 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07004468 const char *buf, size_t count)
4469{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004470 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004471 unsigned long val;
4472 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07004473
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004474 ret = strict_strtoul(buf, 0, &val);
4475 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08004476 IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07004477 else
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004478 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07004479
4480 return strnlen(buf, count);
4481}
4482
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004483static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
4484 show_debug_level, store_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07004485
Samuel Ortizd08853a2009-01-23 13:45:17 -08004486#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07004487
Zhu Yib481de92007-09-25 17:54:57 -07004488static ssize_t show_temperature(struct device *d,
4489 struct device_attribute *attr, char *buf)
4490{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004491 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004492
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004493 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004494 return -EAGAIN;
4495
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004496 return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
Zhu Yib481de92007-09-25 17:54:57 -07004497}
4498
4499static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
4500
Zhu Yib481de92007-09-25 17:54:57 -07004501static ssize_t show_tx_power(struct device *d,
4502 struct device_attribute *attr, char *buf)
4503{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004504 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08004505 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07004506}
4507
4508static ssize_t store_tx_power(struct device *d,
4509 struct device_attribute *attr,
4510 const char *buf, size_t count)
4511{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004512 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004513 char *p = (char *)buf;
4514 u32 val;
4515
4516 val = simple_strtoul(p, &p, 10);
4517 if (p == buf)
Tomas Winkler978785a2008-12-19 10:37:31 +08004518 IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07004519 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004520 iwl3945_hw_reg_set_txpower(priv, val);
Zhu Yib481de92007-09-25 17:54:57 -07004521
4522 return count;
4523}
4524
4525static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
4526
4527static ssize_t show_flags(struct device *d,
4528 struct device_attribute *attr, char *buf)
4529{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004530 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004531
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004532 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
Zhu Yib481de92007-09-25 17:54:57 -07004533}
4534
4535static ssize_t store_flags(struct device *d,
4536 struct device_attribute *attr,
4537 const char *buf, size_t count)
4538{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004539 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004540 u32 flags = simple_strtoul(buf, NULL, 0);
4541
4542 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004543 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
Zhu Yib481de92007-09-25 17:54:57 -07004544 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004545 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004546 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004547 else {
Tomas Winklere1623442009-01-27 14:27:56 -08004548 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
Zhu Yib481de92007-09-25 17:54:57 -07004549 flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004550 priv->staging_rxon.flags = cpu_to_le32(flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004551 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004552 }
4553 }
4554 mutex_unlock(&priv->mutex);
4555
4556 return count;
4557}
4558
4559static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
4560
4561static ssize_t show_filter_flags(struct device *d,
4562 struct device_attribute *attr, char *buf)
4563{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004564 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004565
4566 return sprintf(buf, "0x%04X\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004567 le32_to_cpu(priv->active_rxon.filter_flags));
Zhu Yib481de92007-09-25 17:54:57 -07004568}
4569
4570static ssize_t store_filter_flags(struct device *d,
4571 struct device_attribute *attr,
4572 const char *buf, size_t count)
4573{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004574 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004575 u32 filter_flags = simple_strtoul(buf, NULL, 0);
4576
4577 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004578 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
Zhu Yib481de92007-09-25 17:54:57 -07004579 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004580 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004581 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004582 else {
Tomas Winklere1623442009-01-27 14:27:56 -08004583 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
Zhu Yib481de92007-09-25 17:54:57 -07004584 "0x%04X\n", filter_flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004585 priv->staging_rxon.filter_flags =
Zhu Yib481de92007-09-25 17:54:57 -07004586 cpu_to_le32(filter_flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004587 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004588 }
4589 }
4590 mutex_unlock(&priv->mutex);
4591
4592 return count;
4593}
4594
4595static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
4596 store_filter_flags);
4597
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004598#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004599
4600static ssize_t show_measurement(struct device *d,
4601 struct device_attribute *attr, char *buf)
4602{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004603 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler600c0e12008-12-19 10:37:04 +08004604 struct iwl_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004605 u32 size = sizeof(measure_report), len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03004606 u8 *data = (u8 *)&measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004607 unsigned long flags;
4608
4609 spin_lock_irqsave(&priv->lock, flags);
4610 if (!(priv->measurement_status & MEASUREMENT_READY)) {
4611 spin_unlock_irqrestore(&priv->lock, flags);
4612 return 0;
4613 }
4614 memcpy(&measure_report, &priv->measure_report, size);
4615 priv->measurement_status = 0;
4616 spin_unlock_irqrestore(&priv->lock, flags);
4617
4618 while (size && (PAGE_SIZE - len)) {
4619 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4620 PAGE_SIZE - len, 1);
4621 len = strlen(buf);
4622 if (PAGE_SIZE - len)
4623 buf[len++] = '\n';
4624
4625 ofs += 16;
4626 size -= min(size, 16U);
4627 }
4628
4629 return len;
4630}
4631
4632static ssize_t store_measurement(struct device *d,
4633 struct device_attribute *attr,
4634 const char *buf, size_t count)
4635{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004636 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004637 struct ieee80211_measurement_params params = {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004638 .channel = le16_to_cpu(priv->active_rxon.channel),
Zhu Yib481de92007-09-25 17:54:57 -07004639 .start_time = cpu_to_le64(priv->last_tsf),
4640 .duration = cpu_to_le16(1),
4641 };
4642 u8 type = IWL_MEASURE_BASIC;
4643 u8 buffer[32];
4644 u8 channel;
4645
4646 if (count) {
4647 char *p = buffer;
4648 strncpy(buffer, buf, min(sizeof(buffer), count));
4649 channel = simple_strtoul(p, NULL, 0);
4650 if (channel)
4651 params.channel = channel;
4652
4653 p = buffer;
4654 while (*p && *p != ' ')
4655 p++;
4656 if (*p)
4657 type = simple_strtoul(p + 1, NULL, 0);
4658 }
4659
Tomas Winklere1623442009-01-27 14:27:56 -08004660 IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on "
Zhu Yib481de92007-09-25 17:54:57 -07004661 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004662 iwl3945_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07004663
4664 return count;
4665}
4666
4667static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
4668 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004669#endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07004670
Zhu Yib481de92007-09-25 17:54:57 -07004671static ssize_t store_retry_rate(struct device *d,
4672 struct device_attribute *attr,
4673 const char *buf, size_t count)
4674{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004675 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004676
4677 priv->retry_rate = simple_strtoul(buf, NULL, 0);
4678 if (priv->retry_rate <= 0)
4679 priv->retry_rate = 1;
4680
4681 return count;
4682}
4683
4684static ssize_t show_retry_rate(struct device *d,
4685 struct device_attribute *attr, char *buf)
4686{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004687 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004688 return sprintf(buf, "%d", priv->retry_rate);
4689}
4690
4691static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
4692 store_retry_rate);
4693
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004694
Zhu Yib481de92007-09-25 17:54:57 -07004695static ssize_t store_power_level(struct device *d,
4696 struct device_attribute *attr,
4697 const char *buf, size_t count)
4698{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004699 struct iwl_priv *priv = dev_get_drvdata(d);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004700 int ret;
4701 unsigned long mode;
Zhu Yib481de92007-09-25 17:54:57 -07004702
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004703
Zhu Yib481de92007-09-25 17:54:57 -07004704 mutex_lock(&priv->mutex);
4705
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004706 if (!iwl_is_ready(priv)) {
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004707 ret = -EAGAIN;
Zhu Yib481de92007-09-25 17:54:57 -07004708 goto out;
4709 }
4710
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004711 ret = strict_strtoul(buf, 10, &mode);
4712 if (ret)
4713 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004714
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004715 ret = iwl_power_set_user_mode(priv, mode);
4716 if (ret) {
4717 IWL_DEBUG_MAC80211(priv, "failed setting power mode.\n");
4718 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004719 }
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004720 ret = count;
Zhu Yib481de92007-09-25 17:54:57 -07004721
4722 out:
4723 mutex_unlock(&priv->mutex);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004724 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004725}
4726
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004727static ssize_t show_power_level(struct device *d,
4728 struct device_attribute *attr, char *buf)
4729{
4730 struct iwl_priv *priv = dev_get_drvdata(d);
4731 int mode = priv->power_data.user_power_setting;
4732 int system = priv->power_data.system_power_setting;
4733 int level = priv->power_data.power_mode;
4734 char *p = buf;
4735
4736 switch (system) {
4737 case IWL_POWER_SYS_AUTO:
4738 p += sprintf(p, "SYSTEM:auto");
4739 break;
4740 case IWL_POWER_SYS_AC:
4741 p += sprintf(p, "SYSTEM:ac");
4742 break;
4743 case IWL_POWER_SYS_BATTERY:
4744 p += sprintf(p, "SYSTEM:battery");
4745 break;
4746 }
4747
4748 p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
4749 "fixed" : "auto");
4750 p += sprintf(p, "\tINDEX:%d", level);
4751 p += sprintf(p, "\n");
4752 return p - buf + 1;
4753}
4754
4755static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR,
4756 show_power_level, store_power_level);
4757
Zhu Yib481de92007-09-25 17:54:57 -07004758#define MAX_WX_STRING 80
4759
4760/* Values are in microsecond */
4761static const s32 timeout_duration[] = {
4762 350000,
4763 250000,
4764 75000,
4765 37000,
4766 25000,
4767};
4768static const s32 period_duration[] = {
4769 400000,
4770 700000,
4771 1000000,
4772 1000000,
4773 1000000
4774};
4775
Zhu Yib481de92007-09-25 17:54:57 -07004776static ssize_t show_channels(struct device *d,
4777 struct device_attribute *attr, char *buf)
4778{
Johannes Berg8318d782008-01-24 19:38:38 +01004779 /* all this shit doesn't belong into sysfs anyway */
4780 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07004781}
4782
4783static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
4784
4785static ssize_t show_statistics(struct device *d,
4786 struct device_attribute *attr, char *buf)
4787{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004788 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004789 u32 size = sizeof(struct iwl3945_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07004790 u32 len = 0, ofs = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004791 u8 *data = (u8 *)&priv->statistics_39;
Zhu Yib481de92007-09-25 17:54:57 -07004792 int rc = 0;
4793
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004794 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004795 return -EAGAIN;
4796
4797 mutex_lock(&priv->mutex);
Samuel Ortiz17f841c2009-01-23 13:45:20 -08004798 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004799 mutex_unlock(&priv->mutex);
4800
4801 if (rc) {
4802 len = sprintf(buf,
4803 "Error sending statistics request: 0x%08X\n", rc);
4804 return len;
4805 }
4806
4807 while (size && (PAGE_SIZE - len)) {
4808 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4809 PAGE_SIZE - len, 1);
4810 len = strlen(buf);
4811 if (PAGE_SIZE - len)
4812 buf[len++] = '\n';
4813
4814 ofs += 16;
4815 size -= min(size, 16U);
4816 }
4817
4818 return len;
4819}
4820
4821static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
4822
4823static ssize_t show_antenna(struct device *d,
4824 struct device_attribute *attr, char *buf)
4825{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004826 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004827
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004828 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004829 return -EAGAIN;
4830
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08004831 return sprintf(buf, "%d\n", iwl3945_mod_params.antenna);
Zhu Yib481de92007-09-25 17:54:57 -07004832}
4833
4834static ssize_t store_antenna(struct device *d,
4835 struct device_attribute *attr,
4836 const char *buf, size_t count)
4837{
Winkler, Tomas7530f852009-01-27 14:27:53 -08004838 struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004839 int ant;
Zhu Yib481de92007-09-25 17:54:57 -07004840
4841 if (count == 0)
4842 return 0;
4843
4844 if (sscanf(buf, "%1i", &ant) != 1) {
Tomas Winklere1623442009-01-27 14:27:56 -08004845 IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004846 return count;
4847 }
4848
4849 if ((ant >= 0) && (ant <= 2)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004850 IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant);
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08004851 iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant;
Zhu Yib481de92007-09-25 17:54:57 -07004852 } else
Tomas Winklere1623442009-01-27 14:27:56 -08004853 IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant);
Zhu Yib481de92007-09-25 17:54:57 -07004854
4855
4856 return count;
4857}
4858
4859static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
4860
4861static ssize_t show_status(struct device *d,
4862 struct device_attribute *attr, char *buf)
4863{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004864 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004865 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004866 return -EAGAIN;
4867 return sprintf(buf, "0x%08x\n", (int)priv->status);
4868}
4869
4870static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
4871
4872static ssize_t dump_error_log(struct device *d,
4873 struct device_attribute *attr,
4874 const char *buf, size_t count)
4875{
4876 char *p = (char *)buf;
4877
4878 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004879 iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07004880
4881 return strnlen(buf, count);
4882}
4883
4884static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
4885
4886static ssize_t dump_event_log(struct device *d,
4887 struct device_attribute *attr,
4888 const char *buf, size_t count)
4889{
4890 char *p = (char *)buf;
4891
4892 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004893 iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07004894
4895 return strnlen(buf, count);
4896}
4897
4898static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
4899
4900/*****************************************************************************
4901 *
Tomas Winklera96a27f2008-10-23 23:48:56 -07004902 * driver setup and tear down
Zhu Yib481de92007-09-25 17:54:57 -07004903 *
4904 *****************************************************************************/
4905
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004906static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004907{
Reinette Chatred21050c2009-02-13 11:51:18 -08004908 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07004909
4910 init_waitqueue_head(&priv->wait_command_queue);
4911
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004912 INIT_WORK(&priv->up, iwl3945_bg_up);
4913 INIT_WORK(&priv->restart, iwl3945_bg_restart);
4914 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01004915 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004916 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004917 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
4918 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
Helmut Schaa26635162009-01-15 09:38:44 +01004919 INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll);
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08004920 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
4921 INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
4922 INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
4923 INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
Zhu Yib481de92007-09-25 17:54:57 -07004924
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004925 iwl3945_hw_setup_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004926
4927 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004928 iwl3945_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07004929}
4930
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004931static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004932{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004933 iwl3945_hw_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004934
Joonwoo Parke47eb6a2007-11-29 10:42:49 +09004935 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004936 cancel_delayed_work(&priv->scan_check);
4937 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004938 cancel_work_sync(&priv->beacon_update);
4939}
4940
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004941static struct attribute *iwl3945_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07004942 &dev_attr_antenna.attr,
4943 &dev_attr_channels.attr,
4944 &dev_attr_dump_errors.attr,
4945 &dev_attr_dump_events.attr,
4946 &dev_attr_flags.attr,
4947 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004948#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004949 &dev_attr_measurement.attr,
4950#endif
4951 &dev_attr_power_level.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004952 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004953 &dev_attr_statistics.attr,
4954 &dev_attr_status.attr,
4955 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004956 &dev_attr_tx_power.attr,
Samuel Ortizd08853a2009-01-23 13:45:17 -08004957#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004958 &dev_attr_debug_level.attr,
4959#endif
Zhu Yib481de92007-09-25 17:54:57 -07004960 NULL
4961};
4962
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004963static struct attribute_group iwl3945_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07004964 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004965 .attrs = iwl3945_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07004966};
4967
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004968static struct ieee80211_ops iwl3945_hw_ops = {
4969 .tx = iwl3945_mac_tx,
4970 .start = iwl3945_mac_start,
4971 .stop = iwl3945_mac_stop,
4972 .add_interface = iwl3945_mac_add_interface,
4973 .remove_interface = iwl3945_mac_remove_interface,
4974 .config = iwl3945_mac_config,
4975 .config_interface = iwl3945_mac_config_interface,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004976 .configure_filter = iwl_configure_filter,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004977 .set_key = iwl3945_mac_set_key,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004978 .get_tx_stats = iwl3945_mac_get_tx_stats,
4979 .conf_tx = iwl3945_mac_conf_tx,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004980 .reset_tsf = iwl3945_mac_reset_tsf,
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004981 .bss_info_changed = iwl3945_bss_info_changed,
Abhijeet Kolekare9dde6f62009-02-18 15:54:27 -08004982 .hw_scan = iwl_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07004983};
4984
Winkler, Tomase52119c2008-12-22 11:31:19 +08004985static int iwl3945_init_drv(struct iwl_priv *priv)
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004986{
4987 int ret;
Samuel Ortize6148912009-01-23 13:45:15 -08004988 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004989
4990 priv->retry_rate = 1;
4991 priv->ibss_beacon = NULL;
4992
4993 spin_lock_init(&priv->lock);
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08004994 spin_lock_init(&priv->power_data.lock);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004995 spin_lock_init(&priv->sta_lock);
4996 spin_lock_init(&priv->hcmd_lock);
4997
4998 INIT_LIST_HEAD(&priv->free_frames);
4999
5000 mutex_init(&priv->mutex);
5001
5002 /* Clear the driver's (not device's) station table */
5003 iwl3945_clear_stations_table(priv);
5004
5005 priv->data_retry_limit = -1;
5006 priv->ieee_channels = NULL;
5007 priv->ieee_rates = NULL;
5008 priv->band = IEEE80211_BAND_2GHZ;
5009
5010 priv->iw_mode = NL80211_IFTYPE_STATION;
5011
5012 iwl_reset_qos(priv);
5013
5014 priv->qos_data.qos_active = 0;
5015 priv->qos_data.qos_cap.val = 0;
5016
5017 priv->rates_mask = IWL_RATES_MASK;
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08005018 /* If power management is turned on, default to CAM mode */
5019 priv->power_mode = IWL_POWER_MODE_CAM;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08005020 priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005021
Samuel Ortize6148912009-01-23 13:45:15 -08005022 if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
5023 IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
5024 eeprom->version);
5025 ret = -EINVAL;
5026 goto err;
5027 }
5028 ret = iwl_init_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005029 if (ret) {
5030 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
5031 goto err;
5032 }
5033
Samuel Ortize6148912009-01-23 13:45:15 -08005034 /* Set up txpower settings in driver for all channels */
5035 if (iwl3945_txpower_set_from_eeprom(priv)) {
5036 ret = -EIO;
5037 goto err_free_channel_map;
5038 }
5039
Samuel Ortiz534166d2009-01-23 13:45:16 -08005040 ret = iwlcore_init_geos(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005041 if (ret) {
5042 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
5043 goto err_free_channel_map;
5044 }
Samuel Ortiz534166d2009-01-23 13:45:16 -08005045 iwl3945_init_hw_rates(priv, priv->ieee_rates);
5046
5047 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
5048 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
5049 &priv->bands[IEEE80211_BAND_2GHZ];
5050 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
5051 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
5052 &priv->bands[IEEE80211_BAND_5GHZ];
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005053
5054 return 0;
5055
5056err_free_channel_map:
Samuel Ortize6148912009-01-23 13:45:15 -08005057 iwl_free_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005058err:
5059 return ret;
5060}
5061
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005062static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07005063{
5064 int err = 0;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005065 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07005066 struct ieee80211_hw *hw;
Kolekar, Abhijeetc0f20d92008-12-19 10:37:19 +08005067 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Samuel Ortize6148912009-01-23 13:45:15 -08005068 struct iwl3945_eeprom *eeprom;
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005069 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07005070
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005071 /***********************
5072 * 1. Allocating HW data
5073 * ********************/
5074
Zhu Yib481de92007-09-25 17:54:57 -07005075 /* mac80211 allocates memory for this device instance, including
5076 * space for this driver's private structure */
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005077 hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
Zhu Yib481de92007-09-25 17:54:57 -07005078 if (hw == NULL) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005079 printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
Zhu Yib481de92007-09-25 17:54:57 -07005080 err = -ENOMEM;
5081 goto out;
5082 }
Zhu Yib481de92007-09-25 17:54:57 -07005083 priv = hw->priv;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005084 SET_IEEE80211_DEV(hw, &pdev->dev);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005085
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005086 if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) ||
5087 (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005088 IWL_ERR(priv,
5089 "invalid queues_num, should be between %d and %d\n",
5090 IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES);
Samuel Ortiza3139c52008-12-19 10:37:09 +08005091 err = -EINVAL;
5092 goto out;
5093 }
5094
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005095 /*
5096 * Disabling hardware scan means that mac80211 will perform scans
5097 * "the hard way", rather than using device's scan.
5098 */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005099 if (iwl3945_mod_params.disable_hw_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08005100 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005101 iwl3945_hw_ops.hw_scan = NULL;
5102 }
5103
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005104
Tomas Winklere1623442009-01-27 14:27:56 -08005105 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005106 priv->cfg = cfg;
5107 priv->pci_dev = pdev;
5108
Samuel Ortizd08853a2009-01-23 13:45:17 -08005109#ifdef CONFIG_IWLWIFI_DEBUG
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005110 priv->debug_level = iwl3945_mod_params.debug;
5111 atomic_set(&priv->restrict_refcnt, 0);
5112#endif
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005113 hw->rate_control_algorithm = "iwl-3945-rs";
5114 hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
5115
Bruno Randolf566bfe52008-05-08 19:15:40 +02005116 /* Tell mac80211 our characteristics */
Johannes Berg605a0bd2008-07-15 10:10:01 +02005117 hw->flags = IEEE80211_HW_SIGNAL_DBM |
Bruno Randolf566bfe52008-05-08 19:15:40 +02005118 IEEE80211_HW_NOISE_DBM;
Zhu Yib481de92007-09-25 17:54:57 -07005119
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -07005120 hw->wiphy->interface_modes =
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -07005121 BIT(NL80211_IFTYPE_STATION) |
5122 BIT(NL80211_IFTYPE_ADHOC);
5123
Luis R. Rodriguez2a44f912009-01-22 15:05:49 -08005124 hw->wiphy->custom_regulatory = true;
Luis R. Rodriguezea4a82dc2008-11-12 14:22:04 -08005125
Johannes Berg2a519312009-02-10 21:25:55 +01005126 hw->wiphy->max_scan_ssids = 1;
5127
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005128 /* 4 EDCA QOS priorities */
Zhu Yib481de92007-09-25 17:54:57 -07005129 hw->queues = 4;
5130
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005131 /***************************
5132 * 2. Initializing PCI bus
5133 * *************************/
Zhu Yib481de92007-09-25 17:54:57 -07005134 if (pci_enable_device(pdev)) {
5135 err = -ENODEV;
5136 goto out_ieee80211_free_hw;
5137 }
5138
5139 pci_set_master(pdev);
5140
Zhu Yib481de92007-09-25 17:54:57 -07005141 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
5142 if (!err)
5143 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
5144 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08005145 IWL_WARN(priv, "No suitable DMA available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07005146 goto out_pci_disable_device;
5147 }
5148
5149 pci_set_drvdata(pdev, priv);
5150 err = pci_request_regions(pdev, DRV_NAME);
5151 if (err)
5152 goto out_pci_disable_device;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005153
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005154 /***********************
5155 * 3. Read REV Register
5156 * ********************/
Zhu Yib481de92007-09-25 17:54:57 -07005157 priv->hw_base = pci_iomap(pdev, 0, 0);
5158 if (!priv->hw_base) {
5159 err = -ENODEV;
5160 goto out_pci_release_regions;
5161 }
5162
Tomas Winklere1623442009-01-27 14:27:56 -08005163 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Zhu Yib481de92007-09-25 17:54:57 -07005164 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08005165 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Zhu Yib481de92007-09-25 17:54:57 -07005166
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005167 /* We disable the RETRY_TIMEOUT register (0x41) to keep
5168 * PCI Tx retries from interfering with C3 CPU state */
5169 pci_write_config_byte(pdev, 0x41, 0x00);
Zhu Yib481de92007-09-25 17:54:57 -07005170
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005171 /* amp init */
5172 err = priv->cfg->ops->lib->apm_ops.init(priv);
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005173 if (err < 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08005174 IWL_DEBUG_INFO(priv, "Failed to init APMG\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005175 goto out_iounmap;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005176 }
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005177
5178 /***********************
5179 * 4. Read EEPROM
5180 * ********************/
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005181
Zhu Yi5a669262008-01-14 17:46:18 -08005182 /* Read the EEPROM */
Samuel Ortize6148912009-01-23 13:45:15 -08005183 err = iwl_eeprom_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005184 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005185 IWL_ERR(priv, "Unable to init EEPROM\n");
Zhu Yi5a669262008-01-14 17:46:18 -08005186 goto out_remove_sysfs;
5187 }
5188 /* MAC Address location in EEPROM same for 3945/4965 */
Samuel Ortize6148912009-01-23 13:45:15 -08005189 eeprom = (struct iwl3945_eeprom *)priv->eeprom;
5190 memcpy(priv->mac_addr, eeprom->mac_address, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08005191 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
Zhu Yi5a669262008-01-14 17:46:18 -08005192 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
5193
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005194 /***********************
5195 * 5. Setup HW Constants
5196 * ********************/
5197 /* Device-specific setup */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005198 if (iwl3945_hw_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005199 IWL_ERR(priv, "failed to set hw settings\n");
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005200 goto out_iounmap;
5201 }
5202
5203 /***********************
5204 * 6. Setup priv
5205 * ********************/
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005206
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005207 err = iwl3945_init_drv(priv);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005208 if (err) {
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005209 IWL_ERR(priv, "initializing driver failed\n");
5210 goto out_free_geos;
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005211 }
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005212
Tomas Winkler978785a2008-12-19 10:37:31 +08005213 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
5214 priv->cfg->name);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005215
5216 /***********************************
5217 * 7. Initialize Module Parameters
5218 * **********************************/
5219
5220 /* Initialize module parameter values here */
5221 /* Disable radio (SW RF KILL) via parameter when loading driver */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005222 if (iwl3945_mod_params.disable) {
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005223 set_bit(STATUS_RF_KILL_SW, &priv->status);
Tomas Winklere1623442009-01-27 14:27:56 -08005224 IWL_DEBUG_INFO(priv, "Radio disabled.\n");
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005225 }
5226
5227
5228 /***********************
5229 * 8. Setup Services
5230 * ********************/
5231
5232 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08005233 iwl_disable_interrupts(priv);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005234 spin_unlock_irqrestore(&priv->lock, flags);
5235
Helmut Schaa26635162009-01-15 09:38:44 +01005236 pci_enable_msi(priv->pci_dev);
5237
5238 err = request_irq(priv->pci_dev->irq, iwl3945_isr, IRQF_SHARED,
5239 DRV_NAME, priv);
5240 if (err) {
5241 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
5242 goto out_disable_msi;
5243 }
5244
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005245 err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
5246 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005247 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005248 goto out_release_irq;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005249 }
5250
Samuel Ortiz8ccde882009-01-27 14:27:52 -08005251 iwl_set_rxon_channel(priv,
5252 &priv->bands[IEEE80211_BAND_2GHZ].channels[5]);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005253 iwl3945_setup_deferred_work(priv);
5254 iwl3945_setup_rx_handlers(priv);
5255
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005256 /*********************************
Helmut Schaa26635162009-01-15 09:38:44 +01005257 * 9. Setup and Register mac80211
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005258 * *******************************/
5259
Zhu Yi5a669262008-01-14 17:46:18 -08005260 err = ieee80211_register_hw(priv->hw);
5261 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005262 IWL_ERR(priv, "Failed to register network device: %d\n", err);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005263 goto out_remove_sysfs;
Zhu Yib481de92007-09-25 17:54:57 -07005264 }
5265
Zhu Yi5a669262008-01-14 17:46:18 -08005266 priv->hw->conf.beacon_int = 100;
5267 priv->mac80211_registered = 1;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005268
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005269 err = iwl_rfkill_init(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005270 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08005271 IWL_ERR(priv, "Unable to initialize RFKILL system. "
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005272 "Ignoring error: %d\n", err);
5273
Helmut Schaa26635162009-01-15 09:38:44 +01005274 /* Start monitoring the killswitch */
5275 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
5276 2 * HZ);
5277
Zhu Yib481de92007-09-25 17:54:57 -07005278 return 0;
5279
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005280 out_remove_sysfs:
5281 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005282 out_free_geos:
Samuel Ortiz534166d2009-01-23 13:45:16 -08005283 iwlcore_free_geos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005284
5285 out_release_irq:
Helmut Schaa26635162009-01-15 09:38:44 +01005286 free_irq(priv->pci_dev->irq, priv);
Zhu Yib481de92007-09-25 17:54:57 -07005287 destroy_workqueue(priv->workqueue);
5288 priv->workqueue = NULL;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005289 iwl3945_unset_hw_params(priv);
Helmut Schaa26635162009-01-15 09:38:44 +01005290 out_disable_msi:
5291 pci_disable_msi(priv->pci_dev);
Zhu Yib481de92007-09-25 17:54:57 -07005292 out_iounmap:
5293 pci_iounmap(pdev, priv->hw_base);
5294 out_pci_release_regions:
5295 pci_release_regions(pdev);
5296 out_pci_disable_device:
5297 pci_disable_device(pdev);
5298 pci_set_drvdata(pdev, NULL);
5299 out_ieee80211_free_hw:
5300 ieee80211_free_hw(priv->hw);
5301 out:
5302 return err;
5303}
5304
Reinette Chatrec83dbf62008-03-21 13:53:41 -07005305static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07005306{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005307 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005308 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07005309
5310 if (!priv)
5311 return;
5312
Tomas Winklere1623442009-01-27 14:27:56 -08005313 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07005314
Zhu Yib481de92007-09-25 17:54:57 -07005315 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08005316
Kolekar, Abhijeetd552bfb2008-12-19 10:37:41 +08005317 if (priv->mac80211_registered) {
5318 ieee80211_unregister_hw(priv->hw);
5319 priv->mac80211_registered = 0;
5320 } else {
5321 iwl3945_down(priv);
5322 }
Zhu Yib481de92007-09-25 17:54:57 -07005323
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005324 /* make sure we flush any pending irq or
5325 * tasklet for the driver
5326 */
5327 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08005328 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005329 spin_unlock_irqrestore(&priv->lock, flags);
5330
5331 iwl_synchronize_irq(priv);
5332
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005333 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07005334
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005335 iwl_rfkill_unregister(priv);
Helmut Schaa26635162009-01-15 09:38:44 +01005336 cancel_delayed_work(&priv->rfkill_poll);
5337
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005338 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005339
5340 if (priv->rxq.bd)
Winkler, Tomas51af3d32008-12-22 11:31:23 +08005341 iwl_rx_queue_free(priv, &priv->rxq);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005342 iwl3945_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005343
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005344 iwl3945_unset_hw_params(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005345 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005346
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08005347 /*netif_stop_queue(dev); */
5348 flush_workqueue(priv->workqueue);
5349
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005350 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07005351 * priv->workqueue... so we can't take down the workqueue
5352 * until now... */
5353 destroy_workqueue(priv->workqueue);
5354 priv->workqueue = NULL;
5355
Helmut Schaa26635162009-01-15 09:38:44 +01005356 free_irq(pdev->irq, priv);
5357 pci_disable_msi(pdev);
5358
Zhu Yib481de92007-09-25 17:54:57 -07005359 pci_iounmap(pdev, priv->hw_base);
5360 pci_release_regions(pdev);
5361 pci_disable_device(pdev);
5362 pci_set_drvdata(pdev, NULL);
5363
Samuel Ortize6148912009-01-23 13:45:15 -08005364 iwl_free_channel_map(priv);
Samuel Ortiz534166d2009-01-23 13:45:16 -08005365 iwlcore_free_geos(priv);
Winkler, Tomas805cee52009-01-19 15:30:28 -08005366 kfree(priv->scan);
Zhu Yib481de92007-09-25 17:54:57 -07005367 if (priv->ibss_beacon)
5368 dev_kfree_skb(priv->ibss_beacon);
5369
5370 ieee80211_free_hw(priv->hw);
5371}
5372
5373#ifdef CONFIG_PM
5374
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005375static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07005376{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005377 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005378
Zhu Yie655b9f2008-01-24 02:19:38 -08005379 if (priv->is_open) {
5380 set_bit(STATUS_IN_SUSPEND, &priv->status);
5381 iwl3945_mac_stop(priv->hw);
5382 priv->is_open = 1;
5383 }
Helmut Schaa26635162009-01-15 09:38:44 +01005384 pci_save_state(pdev);
5385 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005386 pci_set_power_state(pdev, PCI_D3hot);
5387
Zhu Yib481de92007-09-25 17:54:57 -07005388 return 0;
5389}
5390
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005391static int iwl3945_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07005392{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005393 struct iwl_priv *priv = pci_get_drvdata(pdev);
Winkler, Tomas450154e2009-01-27 14:27:55 -08005394 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07005395
Zhu Yib481de92007-09-25 17:54:57 -07005396 pci_set_power_state(pdev, PCI_D0);
Winkler, Tomas450154e2009-01-27 14:27:55 -08005397 ret = pci_enable_device(pdev);
5398 if (ret)
5399 return ret;
Helmut Schaa26635162009-01-15 09:38:44 +01005400 pci_restore_state(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005401
Zhu Yie655b9f2008-01-24 02:19:38 -08005402 if (priv->is_open)
5403 iwl3945_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07005404
Zhu Yie655b9f2008-01-24 02:19:38 -08005405 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07005406 return 0;
5407}
5408
5409#endif /* CONFIG_PM */
5410
5411/*****************************************************************************
5412 *
5413 * driver and module entry point
5414 *
5415 *****************************************************************************/
5416
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005417static struct pci_driver iwl3945_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07005418 .name = DRV_NAME,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005419 .id_table = iwl3945_hw_card_ids,
5420 .probe = iwl3945_pci_probe,
5421 .remove = __devexit_p(iwl3945_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07005422#ifdef CONFIG_PM
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005423 .suspend = iwl3945_pci_suspend,
5424 .resume = iwl3945_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07005425#endif
5426};
5427
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005428static int __init iwl3945_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07005429{
5430
5431 int ret;
5432 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
5433 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005434
5435 ret = iwl3945_rate_control_register();
5436 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005437 printk(KERN_ERR DRV_NAME
5438 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005439 return ret;
5440 }
5441
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005442 ret = pci_register_driver(&iwl3945_driver);
Zhu Yib481de92007-09-25 17:54:57 -07005443 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005444 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005445 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07005446 }
Zhu Yib481de92007-09-25 17:54:57 -07005447
5448 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005449
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005450error_register:
5451 iwl3945_rate_control_unregister();
5452 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07005453}
5454
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005455static void __exit iwl3945_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07005456{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005457 pci_unregister_driver(&iwl3945_driver);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005458 iwl3945_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07005459}
5460
Reinette Chatrea0987a82008-12-02 12:14:06 -08005461MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
Zhu Yi25cb6ca2008-09-11 11:45:22 +08005462
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005463module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005464MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005465module_param_named(disable, iwl3945_mod_params.disable, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005466MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -08005467module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
5468MODULE_PARM_DESC(swcrypto,
5469 "using software crypto (default 1 [software])\n");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005470module_param_named(debug, iwl3945_mod_params.debug, uint, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005471MODULE_PARM_DESC(debug, "debug output mask");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005472module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005473MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
5474
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005475module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005476MODULE_PARM_DESC(queues_num, "number of hw queues.");
5477
Samuel Ortizaf48d042009-01-23 13:45:19 -08005478module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, 0444);
5479MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error");
5480
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005481module_exit(iwl3945_exit);
5482module_init(iwl3945_init);