blob: ff4d0e41d7c492237d5740b423be5918b526bc3f [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Reinette Chatre01f81622009-01-08 10:20:02 -08003 * Copyright(c) 2003 - 2009 Intel Corporation. All rights reserved.
Zhu Yib481de92007-09-25 17:54:57 -07004 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
Winkler, Tomas759ef892008-12-09 11:28:58 -080025 * Intel Linux Wireless <ilw@linux.intel.com>
Zhu Yib481de92007-09-25 17:54:57 -070026 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
Zhu Yib481de92007-09-25 17:54:57 -070030#include <linux/kernel.h>
31#include <linux/module.h>
Zhu Yib481de92007-09-25 17:54:57 -070032#include <linux/init.h>
33#include <linux/pci.h>
34#include <linux/dma-mapping.h>
35#include <linux/delay.h>
36#include <linux/skbuff.h>
37#include <linux/netdevice.h>
38#include <linux/wireless.h>
39#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070040#include <linux/etherdevice.h>
41#include <linux/if_arp.h>
42
43#include <net/ieee80211_radiotap.h>
John W. Linville7e272fc2008-09-24 18:13:14 -040044#include <net/lib80211.h>
Zhu Yib481de92007-09-25 17:54:57 -070045#include <net/mac80211.h>
46
47#include <asm/div64.h>
48
Samuel Ortiza3139c52008-12-19 10:37:09 +080049#define DRV_NAME "iwl3945"
50
Winkler, Tomasdbb66542008-12-22 11:31:14 +080051#include "iwl-fh.h"
52#include "iwl-3945-fh.h"
Tomas Winkler600c0e12008-12-19 10:37:04 +080053#include "iwl-commands.h"
Samuel Ortiz17f841c2009-01-23 13:45:20 -080054#include "iwl-sta.h"
Zhu Yib481de92007-09-25 17:54:57 -070055#include "iwl-3945.h"
56#include "iwl-helpers.h"
Kolekar, Abhijeet5747d472008-12-19 10:37:18 +080057#include "iwl-core.h"
Samuel Ortizd20b3c62008-12-19 10:37:15 +080058#include "iwl-dev.h"
Zhu Yib481de92007-09-25 17:54:57 -070059
Zhu Yib481de92007-09-25 17:54:57 -070060/*
61 * module name, copyright, version, etc.
Zhu Yib481de92007-09-25 17:54:57 -070062 */
63
64#define DRV_DESCRIPTION \
65"Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
66
Samuel Ortizd08853a2009-01-23 13:45:17 -080067#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070068#define VD "d"
69#else
70#define VD
71#endif
72
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080073#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -070074#define VS "s"
75#else
76#define VS
77#endif
78
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080079#define IWL39_VERSION "1.2.26k" VD VS
Reinette Chatre01f81622009-01-08 10:20:02 -080080#define DRV_COPYRIGHT "Copyright(c) 2003-2009 Intel Corporation"
Tomas Winklera7b75202008-12-11 10:33:41 -080081#define DRV_AUTHOR "<ilw@linux.intel.com>"
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080082#define DRV_VERSION IWL39_VERSION
Zhu Yib481de92007-09-25 17:54:57 -070083
Zhu Yib481de92007-09-25 17:54:57 -070084
85MODULE_DESCRIPTION(DRV_DESCRIPTION);
86MODULE_VERSION(DRV_VERSION);
Tomas Winklera7b75202008-12-11 10:33:41 -080087MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
Zhu Yib481de92007-09-25 17:54:57 -070088MODULE_LICENSE("GPL");
89
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080090 /* module parameters */
91struct iwl_mod_params iwl3945_mod_params = {
92 .num_of_queues = IWL39_MAX_NUM_QUEUES,
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -080093 .sw_crypto = 1,
Samuel Ortizaf48d042009-01-23 13:45:19 -080094 .restart_fw = 1,
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080095 /* the rest are 0 by default */
96};
97
Zhu Yib481de92007-09-25 17:54:57 -070098/*************** STATION TABLE MANAGEMENT ****
Ben Cahill9fbab512007-11-29 11:09:47 +080099 * mac80211 should be examined to determine if sta_info is duplicating
Zhu Yib481de92007-09-25 17:54:57 -0700100 * the functionality provided here
101 */
102
103/**************************************************************/
Ian Schram01ebd062007-10-25 17:15:22 +0800104#if 0 /* temporary disable till we add real remove station */
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800105/**
106 * iwl3945_remove_station - Remove driver's knowledge of station.
107 *
108 * NOTE: This does not remove station from device's station table.
109 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800110static u8 iwl3945_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
Zhu Yib481de92007-09-25 17:54:57 -0700111{
112 int index = IWL_INVALID_STATION;
113 int i;
114 unsigned long flags;
115
116 spin_lock_irqsave(&priv->sta_lock, flags);
117
118 if (is_ap)
119 index = IWL_AP_ID;
120 else if (is_broadcast_ether_addr(addr))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800121 index = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700122 else
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800123 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800124 if (priv->stations_39[i].used &&
125 !compare_ether_addr(priv->stations_39[i].sta.sta.addr,
Zhu Yib481de92007-09-25 17:54:57 -0700126 addr)) {
127 index = i;
128 break;
129 }
130
131 if (unlikely(index == IWL_INVALID_STATION))
132 goto out;
133
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800134 if (priv->stations_39[index].used) {
135 priv->stations_39[index].used = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700136 priv->num_stations--;
137 }
138
139 BUG_ON(priv->num_stations < 0);
140
141out:
142 spin_unlock_irqrestore(&priv->sta_lock, flags);
143 return 0;
144}
Zhu Yi556f8db2007-09-27 11:27:33 +0800145#endif
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800146
147/**
148 * iwl3945_clear_stations_table - Clear the driver's station table
149 *
150 * NOTE: This does not clear or otherwise alter the device's station table.
151 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800152static void iwl3945_clear_stations_table(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700153{
154 unsigned long flags;
155
156 spin_lock_irqsave(&priv->sta_lock, flags);
157
158 priv->num_stations = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800159 memset(priv->stations_39, 0, sizeof(priv->stations_39));
Zhu Yib481de92007-09-25 17:54:57 -0700160
161 spin_unlock_irqrestore(&priv->sta_lock, flags);
162}
163
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800164/**
165 * iwl3945_add_station - Add station to station tables in driver and device
166 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800167u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags)
Zhu Yib481de92007-09-25 17:54:57 -0700168{
169 int i;
170 int index = IWL_INVALID_STATION;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800171 struct iwl3945_station_entry *station;
Zhu Yib481de92007-09-25 17:54:57 -0700172 unsigned long flags_spin;
Zhu Yic14c5212007-09-27 11:27:35 +0800173 u8 rate;
Zhu Yib481de92007-09-25 17:54:57 -0700174
175 spin_lock_irqsave(&priv->sta_lock, flags_spin);
176 if (is_ap)
177 index = IWL_AP_ID;
178 else if (is_broadcast_ether_addr(addr))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800179 index = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700180 else
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800181 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800182 if (!compare_ether_addr(priv->stations_39[i].sta.sta.addr,
Zhu Yib481de92007-09-25 17:54:57 -0700183 addr)) {
184 index = i;
185 break;
186 }
187
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800188 if (!priv->stations_39[i].used &&
Zhu Yib481de92007-09-25 17:54:57 -0700189 index == IWL_INVALID_STATION)
190 index = i;
191 }
192
Ian Schram01ebd062007-10-25 17:15:22 +0800193 /* These two conditions has the same outcome but keep them separate
Zhu Yib481de92007-09-25 17:54:57 -0700194 since they have different meaning */
195 if (unlikely(index == IWL_INVALID_STATION)) {
196 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
197 return index;
198 }
199
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800200 if (priv->stations_39[index].used &&
201 !compare_ether_addr(priv->stations_39[index].sta.sta.addr, addr)) {
Zhu Yib481de92007-09-25 17:54:57 -0700202 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
203 return index;
204 }
205
Tomas Winklere1623442009-01-27 14:27:56 -0800206 IWL_DEBUG_ASSOC(priv, "Add STA ID %d: %pM\n", index, addr);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800207 station = &priv->stations_39[index];
Zhu Yib481de92007-09-25 17:54:57 -0700208 station->used = 1;
209 priv->num_stations++;
210
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800211 /* Set up the REPLY_ADD_STA command to send to device */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800212 memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd));
Zhu Yib481de92007-09-25 17:54:57 -0700213 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
214 station->sta.mode = 0;
215 station->sta.sta.sta_id = index;
216 station->sta.station_flags = 0;
217
Johannes Berg8318d782008-01-24 19:38:38 +0100218 if (priv->band == IEEE80211_BAND_5GHZ)
Tomas Winkler69946332007-10-25 17:15:27 +0800219 rate = IWL_RATE_6M_PLCP;
220 else
221 rate = IWL_RATE_1M_PLCP;
Zhu Yic14c5212007-09-27 11:27:35 +0800222
223 /* Turn on both antennas for the station... */
224 station->sta.rate_n_flags =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800225 iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK);
Zhu Yic14c5212007-09-27 11:27:35 +0800226
Zhu Yib481de92007-09-25 17:54:57 -0700227 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800228
229 /* Add station to device's station table */
Samuel Ortiz17f841c2009-01-23 13:45:20 -0800230 iwl_send_add_sta(priv,
231 (struct iwl_addsta_cmd *)&station->sta, flags);
Zhu Yib481de92007-09-25 17:54:57 -0700232 return index;
233
234}
235
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800236static int iwl3945_send_rxon_assoc(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700237{
238 int rc = 0;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800239 struct iwl_rx_packet *res = NULL;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800240 struct iwl3945_rxon_assoc_cmd rxon_assoc;
Winkler, Tomasc2d79b482008-12-19 10:37:34 +0800241 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700242 .id = REPLY_RXON_ASSOC,
243 .len = sizeof(rxon_assoc),
244 .meta.flags = CMD_WANT_SKB,
245 .data = &rxon_assoc,
246 };
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800247 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
248 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
Zhu Yib481de92007-09-25 17:54:57 -0700249
250 if ((rxon1->flags == rxon2->flags) &&
251 (rxon1->filter_flags == rxon2->filter_flags) &&
252 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
253 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800254 IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700255 return 0;
256 }
257
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800258 rxon_assoc.flags = priv->staging_rxon.flags;
259 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
260 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
261 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
Zhu Yib481de92007-09-25 17:54:57 -0700262 rxon_assoc.reserved = 0;
263
Samuel Ortiz518099a2009-01-19 15:30:27 -0800264 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700265 if (rc)
266 return rc;
267
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800268 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700269 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800270 IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -0700271 rc = -EIO;
272 }
273
274 priv->alloc_rxb_skb--;
275 dev_kfree_skb_any(cmd.meta.u.skb);
276
277 return rc;
278}
279
280/**
Samuel Ortiz7e4bca52009-01-23 13:45:18 -0800281 * iwl3945_get_antenna_flags - Get antenna flags for RXON command
282 * @priv: eeprom and antenna fields are used to determine antenna flags
283 *
284 * priv->eeprom39 is used to determine if antenna AUX/MAIN are reversed
285 * iwl3945_mod_params.antenna specifies the antenna diversity mode:
286 *
287 * IWL_ANTENNA_DIVERSITY - NIC selects best antenna by itself
288 * IWL_ANTENNA_MAIN - Force MAIN antenna
289 * IWL_ANTENNA_AUX - Force AUX antenna
290 */
291__le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv)
292{
293 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
294
295 switch (iwl3945_mod_params.antenna) {
296 case IWL_ANTENNA_DIVERSITY:
297 return 0;
298
299 case IWL_ANTENNA_MAIN:
300 if (eeprom->antenna_switch_type)
301 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
302 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
303
304 case IWL_ANTENNA_AUX:
305 if (eeprom->antenna_switch_type)
306 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
307 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
308 }
309
310 /* bad antenna selector value */
311 IWL_ERR(priv, "Bad antenna selector value (0x%x)\n",
312 iwl3945_mod_params.antenna);
313
314 return 0; /* "diversity" is default if error */
315}
316
317/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800318 * iwl3945_commit_rxon - commit staging_rxon to hardware
Zhu Yib481de92007-09-25 17:54:57 -0700319 *
Ian Schram01ebd062007-10-25 17:15:22 +0800320 * The RXON command in staging_rxon is committed to the hardware and
Zhu Yib481de92007-09-25 17:54:57 -0700321 * the active_rxon structure is updated with the new data. This
322 * function correctly transitions out of the RXON_ASSOC_MSK state if
323 * a HW tune is required based on the RXON structure changes.
324 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800325static int iwl3945_commit_rxon(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700326{
327 /* cast away the const for active_rxon in this function */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800328 struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
329 struct iwl3945_rxon_cmd *staging_rxon = (void *)&priv->staging_rxon;
Zhu Yib481de92007-09-25 17:54:57 -0700330 int rc = 0;
Abhijeet Kolekar83370312009-03-06 13:52:54 -0800331 bool new_assoc =
332 !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK);
Zhu Yib481de92007-09-25 17:54:57 -0700333
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800334 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700335 return -1;
336
337 /* always get timestamp with Rx frame */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800338 staging_rxon->flags |= RXON_FLG_TSF2HOST_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700339
340 /* select antenna */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800341 staging_rxon->flags &=
Zhu Yib481de92007-09-25 17:54:57 -0700342 ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800343 staging_rxon->flags |= iwl3945_get_antenna_flags(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700344
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800345 rc = iwl_check_rxon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700346 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800347 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700348 return -EINVAL;
349 }
350
351 /* If we don't need to send a full RXON, we can use
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800352 * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -0700353 * and other flags for the current radio configuration. */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800354 if (!iwl_full_rxon_required(priv)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800355 rc = iwl3945_send_rxon_assoc(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700356 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800357 IWL_ERR(priv, "Error setting RXON_ASSOC "
Zhu Yib481de92007-09-25 17:54:57 -0700358 "configuration (%d).\n", rc);
359 return rc;
360 }
361
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800362 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700363
364 return 0;
365 }
366
367 /* If we are currently associated and the new config requires
368 * an RXON_ASSOC and the new config wants the associated mask enabled,
369 * we must clear the associated from the active configuration
370 * before we apply the new config */
Abhijeet Kolekar83370312009-03-06 13:52:54 -0800371 if (iwl_is_associated(priv) && new_assoc) {
Tomas Winklere1623442009-01-27 14:27:56 -0800372 IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
Zhu Yib481de92007-09-25 17:54:57 -0700373 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
374
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800375 /*
376 * reserved4 and 5 could have been filled by the iwlcore code.
377 * Let's clear them before pushing to the 3945.
378 */
379 active_rxon->reserved4 = 0;
380 active_rxon->reserved5 = 0;
Samuel Ortiz518099a2009-01-19 15:30:27 -0800381 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800382 sizeof(struct iwl3945_rxon_cmd),
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800383 &priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -0700384
385 /* If the mask clearing failed then we set
386 * active_rxon back to what it was previously */
387 if (rc) {
388 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
Winkler, Tomas15b16872008-12-19 10:37:33 +0800389 IWL_ERR(priv, "Error clearing ASSOC_MSK on current "
Zhu Yib481de92007-09-25 17:54:57 -0700390 "configuration (%d).\n", rc);
391 return rc;
392 }
Zhu Yib481de92007-09-25 17:54:57 -0700393 }
394
Tomas Winklere1623442009-01-27 14:27:56 -0800395 IWL_DEBUG_INFO(priv, "Sending RXON\n"
Zhu Yib481de92007-09-25 17:54:57 -0700396 "* with%s RXON_FILTER_ASSOC_MSK\n"
397 "* channel = %d\n"
Johannes Berge1749612008-10-27 15:59:26 -0700398 "* bssid = %pM\n",
Abhijeet Kolekar83370312009-03-06 13:52:54 -0800399 (new_assoc ? "" : "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
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800410 iwl_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
411
Zhu Yib481de92007-09-25 17:54:57 -0700412 /* Apply the new configuration */
Samuel Ortiz518099a2009-01-19 15:30:27 -0800413 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800414 sizeof(struct iwl3945_rxon_cmd),
415 staging_rxon);
Zhu Yib481de92007-09-25 17:54:57 -0700416 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800417 IWL_ERR(priv, "Error setting new configuration (%d).\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700418 return rc;
419 }
420
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800421 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700422
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800423 iwl3945_clear_stations_table(priv);
Zhu Yi556f8db2007-09-27 11:27:33 +0800424
Zhu Yib481de92007-09-25 17:54:57 -0700425 /* If we issue a new RXON command which required a tune then we must
426 * send a new TXPOWER command or we won't be able to Tx any frames */
Samuel Ortiz75bcfae2009-01-23 13:45:11 -0800427 rc = priv->cfg->ops->lib->send_tx_power(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700428 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800429 IWL_ERR(priv, "Error setting Tx power (%d).\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700430 return rc;
431 }
432
433 /* Add the broadcast address so we can send broadcast frames */
Kolekar, Abhijeetb5323d32008-12-19 10:37:22 +0800434 if (iwl3945_add_station(priv, iwl_bcast_addr, 0, 0) ==
Zhu Yib481de92007-09-25 17:54:57 -0700435 IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800436 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700437 return -EIO;
438 }
439
440 /* If we have set the ASSOC_MSK and we are in BSS mode then
441 * add the IWL_AP_ID to the station rate table */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800442 if (iwl_is_associated(priv) &&
Johannes Berg05c914f2008-09-11 00:01:58 +0200443 (priv->iw_mode == NL80211_IFTYPE_STATION))
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800444 if (iwl3945_add_station(priv, priv->active_rxon.bssid_addr,
445 1, 0)
Zhu Yib481de92007-09-25 17:54:57 -0700446 == IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800447 IWL_ERR(priv, "Error adding AP address for transmit\n");
Zhu Yib481de92007-09-25 17:54:57 -0700448 return -EIO;
449 }
450
Johannes Berg8318d782008-01-24 19:38:38 +0100451 /* Init the hardware's rate fallback order based on the band */
Zhu Yib481de92007-09-25 17:54:57 -0700452 rc = iwl3945_init_hw_rate_table(priv);
453 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800454 IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700455 return -EIO;
456 }
457
458 return 0;
459}
460
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800461static int iwl3945_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700462 struct ieee80211_key_conf *keyconf,
463 u8 sta_id)
464{
465 unsigned long flags;
466 __le16 key_flags = 0;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800467 int ret;
Zhu Yib481de92007-09-25 17:54:57 -0700468
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800469 key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
470 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
471
472 if (sta_id == priv->hw_params.bcast_sta_id)
473 key_flags |= STA_KEY_MULTICAST_MSK;
474
475 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
476 keyconf->hw_key_idx = keyconf->keyidx;
477 key_flags &= ~STA_KEY_FLG_INVALID;
478
Zhu Yib481de92007-09-25 17:54:57 -0700479 spin_lock_irqsave(&priv->sta_lock, flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800480 priv->stations_39[sta_id].keyinfo.alg = keyconf->alg;
481 priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen;
482 memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700483 keyconf->keylen);
484
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800485 memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700486 keyconf->keylen);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800487
Abhijeet Kolekar43da9192009-03-17 21:51:53 -0700488 if ((priv->stations_39[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800489 == STA_KEY_FLG_NO_ENC)
Abhijeet Kolekar43da9192009-03-17 21:51:53 -0700490 priv->stations_39[sta_id].sta.key.key_offset =
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800491 iwl_get_free_ucode_key_index(priv);
492 /* else, we are overriding an existing key => no need to allocated room
493 * in uCode. */
494
Abhijeet Kolekar43da9192009-03-17 21:51:53 -0700495 WARN(priv->stations_39[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800496 "no space for a new key");
497
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800498 priv->stations_39[sta_id].sta.key.key_flags = key_flags;
499 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
500 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700501
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800502 IWL_DEBUG_INFO(priv, "hwcrypto: modify ucode station key info\n");
503
504 ret = iwl_send_add_sta(priv,
505 (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, CMD_ASYNC);
506
Zhu Yib481de92007-09-25 17:54:57 -0700507 spin_unlock_irqrestore(&priv->sta_lock, flags);
508
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800509 return ret;
510}
511
512static int iwl3945_set_tkip_dynamic_key_info(struct iwl_priv *priv,
513 struct ieee80211_key_conf *keyconf,
514 u8 sta_id)
515{
516 return -EOPNOTSUPP;
517}
518
519static int iwl3945_set_wep_dynamic_key_info(struct iwl_priv *priv,
520 struct ieee80211_key_conf *keyconf,
521 u8 sta_id)
522{
523 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -0700524}
525
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800526static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
Zhu Yib481de92007-09-25 17:54:57 -0700527{
528 unsigned long flags;
529
530 spin_lock_irqsave(&priv->sta_lock, flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800531 memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key));
532 memset(&priv->stations_39[sta_id].sta.key, 0,
Tomas Winkler4c897252008-12-19 10:37:05 +0800533 sizeof(struct iwl4965_keyinfo));
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800534 priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
535 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
536 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700537 spin_unlock_irqrestore(&priv->sta_lock, flags);
538
Tomas Winklere1623442009-01-27 14:27:56 -0800539 IWL_DEBUG_INFO(priv, "hwcrypto: clear ucode station key info\n");
Samuel Ortiz17f841c2009-01-23 13:45:20 -0800540 iwl_send_add_sta(priv,
541 (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700542 return 0;
543}
544
Abhijeet Kolekarfa11d522009-03-11 11:17:54 -0700545static int iwl3945_set_dynamic_key(struct iwl_priv *priv,
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800546 struct ieee80211_key_conf *keyconf, u8 sta_id)
547{
548 int ret = 0;
549
550 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
551
552 switch (keyconf->alg) {
553 case ALG_CCMP:
554 ret = iwl3945_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
555 break;
556 case ALG_TKIP:
557 ret = iwl3945_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
558 break;
559 case ALG_WEP:
560 ret = iwl3945_set_wep_dynamic_key_info(priv, keyconf, sta_id);
561 break;
562 default:
Abhijeet Kolekar1e680232009-03-17 21:51:50 -0700563 IWL_ERR(priv, "Unknown alg: %s alg = %d\n", __func__, keyconf->alg);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800564 ret = -EINVAL;
565 }
566
567 IWL_DEBUG_WEP(priv, "Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n",
568 keyconf->alg, keyconf->keylen, keyconf->keyidx,
569 sta_id, ret);
570
571 return ret;
572}
573
574static int iwl3945_remove_static_key(struct iwl_priv *priv)
575{
576 int ret = -EOPNOTSUPP;
577
578 return ret;
579}
580
581static int iwl3945_set_static_key(struct iwl_priv *priv,
582 struct ieee80211_key_conf *key)
583{
584 if (key->alg == ALG_WEP)
585 return -EOPNOTSUPP;
586
587 IWL_ERR(priv, "Static key invalid: alg %d\n", key->alg);
588 return -EINVAL;
589}
590
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800591static void iwl3945_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700592{
593 struct list_head *element;
594
Tomas Winklere1623442009-01-27 14:27:56 -0800595 IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
Zhu Yib481de92007-09-25 17:54:57 -0700596 priv->frames_count);
597
598 while (!list_empty(&priv->free_frames)) {
599 element = priv->free_frames.next;
600 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800601 kfree(list_entry(element, struct iwl3945_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700602 priv->frames_count--;
603 }
604
605 if (priv->frames_count) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800606 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
Zhu Yib481de92007-09-25 17:54:57 -0700607 priv->frames_count);
608 priv->frames_count = 0;
609 }
610}
611
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800612static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700613{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800614 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700615 struct list_head *element;
616 if (list_empty(&priv->free_frames)) {
617 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
618 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800619 IWL_ERR(priv, "Could not allocate frame!\n");
Zhu Yib481de92007-09-25 17:54:57 -0700620 return NULL;
621 }
622
623 priv->frames_count++;
624 return frame;
625 }
626
627 element = priv->free_frames.next;
628 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800629 return list_entry(element, struct iwl3945_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700630}
631
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800632static void iwl3945_free_frame(struct iwl_priv *priv, struct iwl3945_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700633{
634 memset(frame, 0, sizeof(*frame));
635 list_add(&frame->list, &priv->free_frames);
636}
637
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800638unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700639 struct ieee80211_hdr *hdr,
Rami Rosen73ec1cc2008-12-16 09:37:07 +0200640 int left)
Zhu Yib481de92007-09-25 17:54:57 -0700641{
642
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800643 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200644 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
645 (priv->iw_mode != NL80211_IFTYPE_AP)))
Zhu Yib481de92007-09-25 17:54:57 -0700646 return 0;
647
648 if (priv->ibss_beacon->len > left)
649 return 0;
650
651 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
652
653 return priv->ibss_beacon->len;
654}
655
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800656static int iwl3945_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700657{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800658 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700659 unsigned int frame_size;
660 int rc;
661 u8 rate;
662
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800663 frame = iwl3945_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700664
665 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800666 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
Zhu Yib481de92007-09-25 17:54:57 -0700667 "command.\n");
668 return -ENOMEM;
669 }
670
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800671 rate = iwl_rate_get_lowest_plcp(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700672
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800673 frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -0700674
Samuel Ortiz518099a2009-01-19 15:30:27 -0800675 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700676 &frame->u.cmd[0]);
677
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800678 iwl3945_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700679
680 return rc;
681}
682
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800683static void iwl3945_unset_hw_params(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700684{
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800685 if (priv->shared_virt)
Zhu Yib481de92007-09-25 17:54:57 -0700686 pci_free_consistent(priv->pci_dev,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800687 sizeof(struct iwl3945_shared),
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800688 priv->shared_virt,
689 priv->shared_phys);
Zhu Yib481de92007-09-25 17:54:57 -0700690}
691
Zhu Yib481de92007-09-25 17:54:57 -0700692#define MAX_UCODE_BEACON_INTERVAL 1024
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -0800693#define INTEL_CONN_LISTEN_INTERVAL cpu_to_le16(0xA)
Zhu Yib481de92007-09-25 17:54:57 -0700694
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800695static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -0700696{
697 u16 new_val = 0;
698 u16 beacon_factor = 0;
699
700 beacon_factor =
701 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
702 / MAX_UCODE_BEACON_INTERVAL;
703 new_val = beacon_val / beacon_factor;
704
705 return cpu_to_le16(new_val);
706}
707
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800708static void iwl3945_setup_rxon_timing(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700709{
710 u64 interval_tm_unit;
711 u64 tsf, result;
712 unsigned long flags;
713 struct ieee80211_conf *conf = NULL;
714 u16 beacon_int = 0;
715
716 conf = ieee80211_get_hw_conf(priv->hw);
717
718 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler28afaf92008-12-19 10:37:06 +0800719 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
Zhu Yib481de92007-09-25 17:54:57 -0700720 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
721
Tomas Winkler28afaf92008-12-19 10:37:06 +0800722 tsf = priv->timestamp;
Zhu Yib481de92007-09-25 17:54:57 -0700723
724 beacon_int = priv->beacon_int;
725 spin_unlock_irqrestore(&priv->lock, flags);
726
Johannes Berg05c914f2008-09-11 00:01:58 +0200727 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Zhu Yib481de92007-09-25 17:54:57 -0700728 if (beacon_int == 0) {
729 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
730 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
731 } else {
732 priv->rxon_timing.beacon_interval =
733 cpu_to_le16(beacon_int);
734 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800735 iwl3945_adjust_beacon_interval(
Zhu Yib481de92007-09-25 17:54:57 -0700736 le16_to_cpu(priv->rxon_timing.beacon_interval));
737 }
738
739 priv->rxon_timing.atim_window = 0;
740 } else {
741 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800742 iwl3945_adjust_beacon_interval(conf->beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -0700743 /* TODO: we need to get atim_window from upper stack
744 * for now we set to 0 */
745 priv->rxon_timing.atim_window = 0;
746 }
747
748 interval_tm_unit =
749 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
750 result = do_div(tsf, interval_tm_unit);
751 priv->rxon_timing.beacon_init_val =
752 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
753
Tomas Winklere1623442009-01-27 14:27:56 -0800754 IWL_DEBUG_ASSOC(priv,
755 "beacon interval %d beacon timer %d beacon tim %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700756 le16_to_cpu(priv->rxon_timing.beacon_interval),
757 le32_to_cpu(priv->rxon_timing.beacon_init_val),
758 le16_to_cpu(priv->rxon_timing.atim_window));
759}
760
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800761static int iwl3945_set_mode(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -0700762{
Johannes Berg05c914f2008-09-11 00:01:58 +0200763 if (mode == NL80211_IFTYPE_ADHOC) {
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800764 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -0700765
Samuel Ortize6148912009-01-23 13:45:15 -0800766 ch_info = iwl_get_channel_info(priv,
Johannes Berg8318d782008-01-24 19:38:38 +0100767 priv->band,
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800768 le16_to_cpu(priv->staging_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700769
770 if (!ch_info || !is_channel_ibss(ch_info)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800771 IWL_ERR(priv, "channel %d not IBSS channel\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800772 le16_to_cpu(priv->staging_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700773 return -EINVAL;
774 }
775 }
776
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800777 iwl_connection_init_rx_config(priv, mode);
Zhu Yib481de92007-09-25 17:54:57 -0700778
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800779 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700780
Tomas Winklera96a27f2008-10-23 23:48:56 -0700781 /* don't commit rxon if rf-kill is on*/
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800782 if (!iwl_is_ready_rf(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +0800783 return -EAGAIN;
784
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800785 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700786
787 return 0;
788}
789
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800790static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
Johannes Berge039fa42008-05-15 12:55:29 +0200791 struct ieee80211_tx_info *info,
Winkler, Tomasc2d79b482008-12-19 10:37:34 +0800792 struct iwl_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -0700793 struct sk_buff *skb_frag,
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800794 int sta_id)
Zhu Yib481de92007-09-25 17:54:57 -0700795{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800796 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
Ivo van Doorn1c014422008-04-17 19:41:02 +0200797 struct iwl3945_hw_key *keyinfo =
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800798 &priv->stations_39[sta_id].keyinfo;
Zhu Yib481de92007-09-25 17:54:57 -0700799
800 switch (keyinfo->alg) {
801 case ALG_CCMP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800802 tx->sec_ctl = TX_CMD_SEC_CCM;
803 memcpy(tx->key, keyinfo->key, keyinfo->keylen);
Tomas Winklere1623442009-01-27 14:27:56 -0800804 IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
Zhu Yib481de92007-09-25 17:54:57 -0700805 break;
806
807 case ALG_TKIP:
Zhu Yib481de92007-09-25 17:54:57 -0700808 break;
809
810 case ALG_WEP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800811 tx->sec_ctl = TX_CMD_SEC_WEP |
Johannes Berge039fa42008-05-15 12:55:29 +0200812 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
Zhu Yib481de92007-09-25 17:54:57 -0700813
814 if (keyinfo->keylen == 13)
Winkler, Tomase52119c2008-12-22 11:31:19 +0800815 tx->sec_ctl |= TX_CMD_SEC_KEY128;
Zhu Yib481de92007-09-25 17:54:57 -0700816
Winkler, Tomase52119c2008-12-22 11:31:19 +0800817 memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen);
Zhu Yib481de92007-09-25 17:54:57 -0700818
Tomas Winklere1623442009-01-27 14:27:56 -0800819 IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
Johannes Berge039fa42008-05-15 12:55:29 +0200820 "with key %d\n", info->control.hw_key->hw_key_idx);
Zhu Yib481de92007-09-25 17:54:57 -0700821 break;
822
Zhu Yib481de92007-09-25 17:54:57 -0700823 default:
Tomas Winkler978785a2008-12-19 10:37:31 +0800824 IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg);
Zhu Yib481de92007-09-25 17:54:57 -0700825 break;
826 }
827}
828
829/*
830 * handle build REPLY_TX command notification.
831 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800832static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
Winkler, Tomasc2d79b482008-12-19 10:37:34 +0800833 struct iwl_cmd *cmd,
Johannes Berge039fa42008-05-15 12:55:29 +0200834 struct ieee80211_tx_info *info,
Winkler, Tomase52119c2008-12-22 11:31:19 +0800835 struct ieee80211_hdr *hdr, u8 std_id)
Zhu Yib481de92007-09-25 17:54:57 -0700836{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800837 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
838 __le32 tx_flags = tx->tx_flags;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700839 __le16 fc = hdr->frame_control;
Johannes Berge6a98542008-10-21 12:40:02 +0200840 u8 rc_flags = info->control.rates[0].flags;
Zhu Yib481de92007-09-25 17:54:57 -0700841
Winkler, Tomase52119c2008-12-22 11:31:19 +0800842 tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Johannes Berge039fa42008-05-15 12:55:29 +0200843 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
Zhu Yib481de92007-09-25 17:54:57 -0700844 tx_flags |= TX_CMD_FLG_ACK_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700845 if (ieee80211_is_mgmt(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700846 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700847 if (ieee80211_is_probe_resp(fc) &&
Zhu Yib481de92007-09-25 17:54:57 -0700848 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
849 tx_flags |= TX_CMD_FLG_TSF_MSK;
850 } else {
851 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
852 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
853 }
854
Winkler, Tomase52119c2008-12-22 11:31:19 +0800855 tx->sta_id = std_id;
Harvey Harrison8b7b1e02008-06-11 14:21:56 -0700856 if (ieee80211_has_morefrags(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700857 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
858
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700859 if (ieee80211_is_data_qos(fc)) {
860 u8 *qc = ieee80211_get_qos_ctl(hdr);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800861 tx->tid_tspec = qc[0] & 0xf;
Zhu Yib481de92007-09-25 17:54:57 -0700862 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800863 } else {
Zhu Yib481de92007-09-25 17:54:57 -0700864 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800865 }
Zhu Yib481de92007-09-25 17:54:57 -0700866
Johannes Berge6a98542008-10-21 12:40:02 +0200867 if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
Zhu Yib481de92007-09-25 17:54:57 -0700868 tx_flags |= TX_CMD_FLG_RTS_MSK;
869 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
Johannes Berge6a98542008-10-21 12:40:02 +0200870 } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
Zhu Yib481de92007-09-25 17:54:57 -0700871 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
872 tx_flags |= TX_CMD_FLG_CTS_MSK;
873 }
874
875 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
876 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
877
878 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700879 if (ieee80211_is_mgmt(fc)) {
880 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
Winkler, Tomase52119c2008-12-22 11:31:19 +0800881 tx->timeout.pm_frame_timeout = cpu_to_le16(3);
Zhu Yib481de92007-09-25 17:54:57 -0700882 else
Winkler, Tomase52119c2008-12-22 11:31:19 +0800883 tx->timeout.pm_frame_timeout = cpu_to_le16(2);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700884 } else {
Winkler, Tomase52119c2008-12-22 11:31:19 +0800885 tx->timeout.pm_frame_timeout = 0;
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -0700886#ifdef CONFIG_IWLWIFI_LEDS
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700887 priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
888#endif
889 }
Zhu Yib481de92007-09-25 17:54:57 -0700890
Winkler, Tomase52119c2008-12-22 11:31:19 +0800891 tx->driver_txop = 0;
892 tx->tx_flags = tx_flags;
893 tx->next_frame_len = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700894}
895
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800896/**
897 * iwl3945_get_sta_id - Find station's index within station table
898 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800899static int iwl3945_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
Zhu Yib481de92007-09-25 17:54:57 -0700900{
901 int sta_id;
902 u16 fc = le16_to_cpu(hdr->frame_control);
903
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800904 /* If this frame is broadcast or management, use broadcast station id */
Zhu Yib481de92007-09-25 17:54:57 -0700905 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
906 is_multicast_ether_addr(hdr->addr1))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800907 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700908
909 switch (priv->iw_mode) {
910
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800911 /* If we are a client station in a BSS network, use the special
912 * AP station entry (that's the only station we communicate with) */
Johannes Berg05c914f2008-09-11 00:01:58 +0200913 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -0700914 return IWL_AP_ID;
915
916 /* If we are an AP, then find the station, or use BCAST */
Johannes Berg05c914f2008-09-11 00:01:58 +0200917 case NL80211_IFTYPE_AP:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800918 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700919 if (sta_id != IWL_INVALID_STATION)
920 return sta_id;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800921 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700922
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800923 /* If this frame is going out to an IBSS network, find the station,
924 * or create a new station table entry */
Johannes Berg05c914f2008-09-11 00:01:58 +0200925 case NL80211_IFTYPE_ADHOC: {
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800926 /* Create new station table entry */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800927 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700928 if (sta_id != IWL_INVALID_STATION)
929 return sta_id;
930
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800931 sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
Zhu Yib481de92007-09-25 17:54:57 -0700932
933 if (sta_id != IWL_INVALID_STATION)
934 return sta_id;
935
Tomas Winklere1623442009-01-27 14:27:56 -0800936 IWL_DEBUG_DROP(priv, "Station %pM not in station map. "
Zhu Yib481de92007-09-25 17:54:57 -0700937 "Defaulting to broadcast...\n",
Johannes Berge1749612008-10-27 15:59:26 -0700938 hdr->addr1);
Samuel Ortiz40b8ec02008-12-19 10:37:08 +0800939 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800940 return priv->hw_params.bcast_sta_id;
Joe Perches0795af52007-10-03 17:59:30 -0700941 }
Stefanik Gábor914233d2008-06-30 17:23:30 +0800942 /* If we are in monitor mode, use BCAST. This is required for
943 * packet injection. */
Johannes Berg05c914f2008-09-11 00:01:58 +0200944 case NL80211_IFTYPE_MONITOR:
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800945 return priv->hw_params.bcast_sta_id;
Stefanik Gábor914233d2008-06-30 17:23:30 +0800946
Zhu Yib481de92007-09-25 17:54:57 -0700947 default:
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800948 IWL_WARN(priv, "Unknown mode of operation: %d\n",
949 priv->iw_mode);
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800950 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700951 }
952}
953
954/*
955 * start REPLY_TX command process
956 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800957static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -0700958{
959 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berge039fa42008-05-15 12:55:29 +0200960 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800961 struct iwl3945_tx_cmd *tx;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800962 struct iwl_tx_queue *txq = NULL;
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800963 struct iwl_queue *q = NULL;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800964 struct iwl_cmd *out_cmd = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700965 dma_addr_t phys_addr;
966 dma_addr_t txcmd_phys;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800967 int txq_id = skb_get_queue_mapping(skb);
Reinette Chatredf833b12009-04-21 10:55:48 -0700968 u16 len, idx, len_org, hdr_len; /* TODO: len_org is not used */
Tomas Winkler54dbb522008-05-15 13:54:06 +0800969 u8 id;
970 u8 unicast;
Zhu Yib481de92007-09-25 17:54:57 -0700971 u8 sta_id;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800972 u8 tid = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700973 u16 seq_number = 0;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700974 __le16 fc;
Zhu Yib481de92007-09-25 17:54:57 -0700975 u8 wait_write_ptr = 0;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800976 u8 *qc = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700977 unsigned long flags;
978 int rc;
979
980 spin_lock_irqsave(&priv->lock, flags);
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800981 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800982 IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
Zhu Yib481de92007-09-25 17:54:57 -0700983 goto drop_unlock;
984 }
985
Johannes Berge039fa42008-05-15 12:55:29 +0200986 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800987 IWL_ERR(priv, "ERROR: No TX rate available.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700988 goto drop_unlock;
989 }
990
991 unicast = !is_multicast_ether_addr(hdr->addr1);
992 id = 0;
993
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700994 fc = hdr->frame_control;
Zhu Yib481de92007-09-25 17:54:57 -0700995
Samuel Ortizd08853a2009-01-23 13:45:17 -0800996#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -0700997 if (ieee80211_is_auth(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800998 IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700999 else if (ieee80211_is_assoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -08001000 IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001001 else if (ieee80211_is_reassoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -08001002 IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
Zhu Yib481de92007-09-25 17:54:57 -07001003#endif
1004
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08001005 /* drop all data frame if we are not associated */
Stefanik Gábor914233d2008-06-30 17:23:30 +08001006 if (ieee80211_is_data(fc) &&
Johannes Berg05c914f2008-09-11 00:01:58 +02001007 (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001008 (!iwl_is_associated(priv) ||
Johannes Berg05c914f2008-09-11 00:01:58 +02001009 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
Tomas Winklere1623442009-01-27 14:27:56 -08001010 IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n");
Zhu Yib481de92007-09-25 17:54:57 -07001011 goto drop_unlock;
1012 }
1013
1014 spin_unlock_irqrestore(&priv->lock, flags);
1015
Harvey Harrison7294ec92008-07-15 18:43:59 -07001016 hdr_len = ieee80211_hdrlen(fc);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001017
1018 /* Find (or create) index into station table for destination station */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001019 sta_id = iwl3945_get_sta_id(priv, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07001020 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -08001021 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07001022 hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07001023 goto drop;
1024 }
1025
Tomas Winklere1623442009-01-27 14:27:56 -08001026 IWL_DEBUG_RATE(priv, "station Id %d\n", sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07001027
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001028 if (ieee80211_is_data_qos(fc)) {
1029 qc = ieee80211_get_qos_ctl(hdr);
Harvey Harrison7294ec92008-07-15 18:43:59 -07001030 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001031 seq_number = priv->stations_39[sta_id].tid[tid].seq_number &
Zhu Yib481de92007-09-25 17:54:57 -07001032 IEEE80211_SCTL_SEQ;
1033 hdr->seq_ctrl = cpu_to_le16(seq_number) |
1034 (hdr->seq_ctrl &
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -08001035 cpu_to_le16(IEEE80211_SCTL_FRAG));
Zhu Yib481de92007-09-25 17:54:57 -07001036 seq_number += 0x10;
1037 }
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001038
1039 /* Descriptor for chosen Tx queue */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001040 txq = &priv->txq[txq_id];
Zhu Yib481de92007-09-25 17:54:57 -07001041 q = &txq->q;
1042
1043 spin_lock_irqsave(&priv->lock, flags);
1044
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001045 idx = get_cmd_index(q, q->write_ptr, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001046
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001047 /* Set up driver data for this TFD */
Winkler, Tomasdbb66542008-12-22 11:31:14 +08001048 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001049 txq->txb[q->write_ptr].skb[0] = skb;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001050
1051 /* Init first empty entry in queue's array of Tx/cmd buffers */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001052 out_cmd = txq->cmd[idx];
Winkler, Tomase52119c2008-12-22 11:31:19 +08001053 tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
Zhu Yib481de92007-09-25 17:54:57 -07001054 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
Winkler, Tomase52119c2008-12-22 11:31:19 +08001055 memset(tx, 0, sizeof(*tx));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001056
1057 /*
1058 * Set up the Tx-command (not MAC!) header.
1059 * Store the chosen Tx queue and TFD index within the sequence field;
1060 * after Tx, uCode's Tx response will return this value so driver can
1061 * locate the frame within the tx queue and do post-tx processing.
1062 */
Zhu Yib481de92007-09-25 17:54:57 -07001063 out_cmd->hdr.cmd = REPLY_TX;
1064 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001065 INDEX_TO_SEQ(q->write_ptr)));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001066
1067 /* Copy MAC header from skb into command buffer */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001068 memcpy(tx->hdr, hdr, hdr_len);
Zhu Yib481de92007-09-25 17:54:57 -07001069
Reinette Chatredf833b12009-04-21 10:55:48 -07001070
1071 if (info->control.hw_key)
1072 iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, sta_id);
1073
1074 /* TODO need this for burst mode later on */
1075 iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
1076
1077 /* set is_hcca to 0; it probably will never be implemented */
1078 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
1079
1080 /* Total # bytes to be transmitted */
1081 len = (u16)skb->len;
1082 tx->len = cpu_to_le16(len);
1083
1084
1085 tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
1086 tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
1087
1088 if (!ieee80211_has_morefrags(hdr->frame_control)) {
1089 txq->need_update = 1;
1090 if (qc)
1091 priv->stations_39[sta_id].tid[tid].seq_number = seq_number;
1092 } else {
1093 wait_write_ptr = 1;
1094 txq->need_update = 0;
1095 }
1096
1097 IWL_DEBUG_TX(priv, "sequence nr = 0X%x \n",
1098 le16_to_cpu(out_cmd->hdr.sequence));
1099 IWL_DEBUG_TX(priv, "tx_flags = 0X%x \n", le32_to_cpu(tx->tx_flags));
1100 iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx));
1101 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr,
1102 ieee80211_hdrlen(fc));
1103
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001104 /*
1105 * Use the first empty entry in this queue's command buffer array
1106 * to contain the Tx command and MAC header concatenated together
1107 * (payload data will be in another buffer).
1108 * Size of this varies, due to varying MAC header length.
1109 * If end is not dword aligned, we'll have 2 extra bytes at the end
1110 * of the MAC header (device reads on dword boundaries).
1111 * We'll tell device about this padding later.
1112 */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001113 len = sizeof(struct iwl3945_tx_cmd) +
Tomas Winkler4c897252008-12-19 10:37:05 +08001114 sizeof(struct iwl_cmd_header) + hdr_len;
Zhu Yib481de92007-09-25 17:54:57 -07001115
1116 len_org = len;
1117 len = (len + 3) & ~3;
1118
1119 if (len_org != len)
1120 len_org = 1;
1121 else
1122 len_org = 0;
1123
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001124 /* Physical address of this Tx command's header (not MAC header!),
1125 * within command buffer array. */
Reinette Chatredf833b12009-04-21 10:55:48 -07001126 txcmd_phys = pci_map_single(priv->pci_dev, &out_cmd->hdr,
1127 len, PCI_DMA_TODEVICE);
1128 /* we do not map meta data ... so we can safely access address to
1129 * provide to unmap command*/
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001130 pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys);
Reinette Chatredf833b12009-04-21 10:55:48 -07001131 pci_unmap_len_set(&out_cmd->meta, len, len);
Zhu Yib481de92007-09-25 17:54:57 -07001132
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001133 /* Add buffer containing Tx command and MAC(!) header to TFD's
1134 * first entry */
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001135 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1136 txcmd_phys, len, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001137
Zhu Yib481de92007-09-25 17:54:57 -07001138
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001139 /* Set up TFD's 2nd entry to point directly to remainder of skb,
1140 * if any (802.11 null frames have no payload). */
Zhu Yib481de92007-09-25 17:54:57 -07001141 len = skb->len - hdr_len;
1142 if (len) {
1143 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
1144 len, PCI_DMA_TODEVICE);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001145 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1146 phys_addr, len,
1147 0, U32_PAD(len));
Zhu Yib481de92007-09-25 17:54:57 -07001148 }
1149
Zhu Yib481de92007-09-25 17:54:57 -07001150
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001151 /* Tell device the write index *just past* this latest filled TFD */
Tomas Winklerc54b6792008-03-06 17:36:53 -08001152 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001153 rc = iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001154 spin_unlock_irqrestore(&priv->lock, flags);
1155
1156 if (rc)
1157 return rc;
1158
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001159 if ((iwl_queue_space(q) < q->high_mark)
Zhu Yib481de92007-09-25 17:54:57 -07001160 && priv->mac80211_registered) {
1161 if (wait_write_ptr) {
1162 spin_lock_irqsave(&priv->lock, flags);
1163 txq->need_update = 1;
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001164 iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001165 spin_unlock_irqrestore(&priv->lock, flags);
1166 }
1167
Johannes Berge4e72fb2009-03-23 17:28:42 +01001168 iwl_stop_queue(priv, skb_get_queue_mapping(skb));
Zhu Yib481de92007-09-25 17:54:57 -07001169 }
1170
1171 return 0;
1172
1173drop_unlock:
1174 spin_unlock_irqrestore(&priv->lock, flags);
1175drop:
1176 return -1;
1177}
1178
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001179#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07001180
1181#include "iwl-spectrum.h"
1182
1183#define BEACON_TIME_MASK_LOW 0x00FFFFFF
1184#define BEACON_TIME_MASK_HIGH 0xFF000000
1185#define TIME_UNIT 1024
1186
1187/*
1188 * extended beacon time format
1189 * time in usec will be changed into a 32-bit value in 8:24 format
1190 * the high 1 byte is the beacon counts
1191 * the lower 3 bytes is the time in usec within one beacon interval
1192 */
1193
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001194static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001195{
1196 u32 quot;
1197 u32 rem;
1198 u32 interval = beacon_interval * 1024;
1199
1200 if (!interval || !usec)
1201 return 0;
1202
1203 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
1204 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
1205
1206 return (quot << 24) + rem;
1207}
1208
1209/* base is usually what we get from ucode with each received frame,
1210 * the same as HW timer counter counting down
1211 */
1212
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001213static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001214{
1215 u32 base_low = base & BEACON_TIME_MASK_LOW;
1216 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
1217 u32 interval = beacon_interval * TIME_UNIT;
1218 u32 res = (base & BEACON_TIME_MASK_HIGH) +
1219 (addon & BEACON_TIME_MASK_HIGH);
1220
1221 if (base_low > addon_low)
1222 res += base_low - addon_low;
1223 else if (base_low < addon_low) {
1224 res += interval + base_low - addon_low;
1225 res += (1 << 24);
1226 } else
1227 res += (1 << 24);
1228
1229 return cpu_to_le32(res);
1230}
1231
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001232static int iwl3945_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001233 struct ieee80211_measurement_params *params,
1234 u8 type)
1235{
Tomas Winkler600c0e12008-12-19 10:37:04 +08001236 struct iwl_spectrum_cmd spectrum;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001237 struct iwl_rx_packet *res;
Winkler, Tomasc2d79b482008-12-19 10:37:34 +08001238 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001239 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
1240 .data = (void *)&spectrum,
1241 .meta.flags = CMD_WANT_SKB,
1242 };
1243 u32 add_time = le64_to_cpu(params->start_time);
1244 int rc;
1245 int spectrum_resp_status;
1246 int duration = le16_to_cpu(params->duration);
1247
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001248 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001249 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001250 iwl3945_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -07001251 le64_to_cpu(params->start_time) - priv->last_tsf,
1252 le16_to_cpu(priv->rxon_timing.beacon_interval));
1253
1254 memset(&spectrum, 0, sizeof(spectrum));
1255
1256 spectrum.channel_count = cpu_to_le16(1);
1257 spectrum.flags =
1258 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
1259 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
1260 cmd.len = sizeof(spectrum);
1261 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
1262
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001263 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001264 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001265 iwl3945_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -07001266 add_time,
1267 le16_to_cpu(priv->rxon_timing.beacon_interval));
1268 else
1269 spectrum.start_time = 0;
1270
1271 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
1272 spectrum.channels[0].channel = params->channel;
1273 spectrum.channels[0].type = type;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001274 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
Zhu Yib481de92007-09-25 17:54:57 -07001275 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
1276 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
1277
Samuel Ortiz518099a2009-01-19 15:30:27 -08001278 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001279 if (rc)
1280 return rc;
1281
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001282 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001283 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001284 IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -07001285 rc = -EIO;
1286 }
1287
1288 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
1289 switch (spectrum_resp_status) {
1290 case 0: /* Command will be handled */
1291 if (res->u.spectrum.id != 0xff) {
Tomas Winklere1623442009-01-27 14:27:56 -08001292 IWL_DEBUG_INFO(priv, "Replaced existing measurement: %d\n",
Ian Schrambc434dd2007-10-25 17:15:29 +08001293 res->u.spectrum.id);
Zhu Yib481de92007-09-25 17:54:57 -07001294 priv->measurement_status &= ~MEASUREMENT_READY;
1295 }
1296 priv->measurement_status |= MEASUREMENT_ACTIVE;
1297 rc = 0;
1298 break;
1299
1300 case 1: /* Command will not be handled */
1301 rc = -EAGAIN;
1302 break;
1303 }
1304
1305 dev_kfree_skb_any(cmd.meta.u.skb);
1306
1307 return rc;
1308}
1309#endif
1310
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001311static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001312 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001313{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001314 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
1315 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -07001316 struct delayed_work *pwork;
1317
1318 palive = &pkt->u.alive_frame;
1319
Tomas Winklere1623442009-01-27 14:27:56 -08001320 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
Zhu Yib481de92007-09-25 17:54:57 -07001321 "0x%01X 0x%01X\n",
1322 palive->is_valid, palive->ver_type,
1323 palive->ver_subtype);
1324
1325 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
Tomas Winklere1623442009-01-27 14:27:56 -08001326 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001327 memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
1328 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001329 pwork = &priv->init_alive_start;
1330 } else {
Tomas Winklere1623442009-01-27 14:27:56 -08001331 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001332 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001333 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001334 pwork = &priv->alive_start;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001335 iwl3945_disable_events(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001336 }
1337
1338 /* We delay the ALIVE response by 5ms to
1339 * give the HW RF Kill time to activate... */
1340 if (palive->is_valid == UCODE_VALID_OK)
1341 queue_delayed_work(priv->workqueue, pwork,
1342 msecs_to_jiffies(5));
1343 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001344 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001345}
1346
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001347static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001348 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001349{
Helmut Schaac7e035a2009-01-19 13:02:15 +01001350#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001351 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Helmut Schaac7e035a2009-01-19 13:02:15 +01001352#endif
Zhu Yib481de92007-09-25 17:54:57 -07001353
Tomas Winklere1623442009-01-27 14:27:56 -08001354 IWL_DEBUG_RX(priv, "Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
Zhu Yib481de92007-09-25 17:54:57 -07001355 return;
1356}
1357
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001358static void iwl3945_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07001359{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001360 struct iwl_priv *priv =
1361 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07001362 struct sk_buff *beacon;
1363
1364 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02001365 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07001366
1367 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001368 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07001369 return;
1370 }
1371
1372 mutex_lock(&priv->mutex);
1373 /* new beacon skb is allocated every time; dispose previous.*/
1374 if (priv->ibss_beacon)
1375 dev_kfree_skb(priv->ibss_beacon);
1376
1377 priv->ibss_beacon = beacon;
1378 mutex_unlock(&priv->mutex);
1379
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001380 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001381}
1382
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001383static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001384 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001385{
Samuel Ortizd08853a2009-01-23 13:45:17 -08001386#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001387 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001388 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
Zhu Yib481de92007-09-25 17:54:57 -07001389 u8 rate = beacon->beacon_notify_hdr.rate;
1390
Tomas Winklere1623442009-01-27 14:27:56 -08001391 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
Zhu Yib481de92007-09-25 17:54:57 -07001392 "tsf %d %d rate %d\n",
1393 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
1394 beacon->beacon_notify_hdr.failure_frame,
1395 le32_to_cpu(beacon->ibss_mgr_status),
1396 le32_to_cpu(beacon->high_tsf),
1397 le32_to_cpu(beacon->low_tsf), rate);
1398#endif
1399
Johannes Berg05c914f2008-09-11 00:01:58 +02001400 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -07001401 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1402 queue_work(priv->workqueue, &priv->beacon_update);
1403}
1404
Zhu Yib481de92007-09-25 17:54:57 -07001405/* Handle notification from uCode that card's power state is changing
1406 * due to software, hardware, or critical temperature RFKILL */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001407static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001408 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001409{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001410 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001411 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1412 unsigned long status = priv->status;
1413
Tomas Winklere1623442009-01-27 14:27:56 -08001414 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n",
Zhu Yib481de92007-09-25 17:54:57 -07001415 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1416 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1417
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001418 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001419 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1420
1421 if (flags & HW_CARD_DISABLED)
1422 set_bit(STATUS_RF_KILL_HW, &priv->status);
1423 else
1424 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1425
1426
1427 if (flags & SW_CARD_DISABLED)
1428 set_bit(STATUS_RF_KILL_SW, &priv->status);
1429 else
1430 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1431
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08001432 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001433
1434 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1435 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1436 (test_bit(STATUS_RF_KILL_SW, &status) !=
1437 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1438 queue_work(priv->workqueue, &priv->rf_kill);
1439 else
1440 wake_up_interruptible(&priv->wait_command_queue);
1441}
1442
1443/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001444 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07001445 *
1446 * Setup the RX handlers for each of the reply types sent from the uCode
1447 * to the host.
1448 *
1449 * This function chains into the hardware specific files for them to setup
1450 * any hardware specific handlers as well.
1451 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001452static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001453{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001454 priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
1455 priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
Abhijeet Kolekar261b9c32009-02-18 15:54:29 -08001456 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001457 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -08001458 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001459 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -08001460 iwl_rx_pm_debug_statistics_notif;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001461 priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001462
Ben Cahill9fbab512007-11-29 11:09:47 +08001463 /*
1464 * The same handler is used for both the REPLY to a discrete
1465 * statistics request from the host as well as for the periodic
1466 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07001467 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001468 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
1469 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
Zhu Yib481de92007-09-25 17:54:57 -07001470
Abhijeet Kolekar261b9c32009-02-18 15:54:29 -08001471 iwl_setup_spectrum_handlers(priv);
Abhijeet Kolekarcade0eb2009-02-18 15:54:26 -08001472 iwl_setup_rx_scan_handlers(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001473 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001474
Ben Cahill9fbab512007-11-29 11:09:47 +08001475 /* Set up hardware specific Rx handlers */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001476 iwl3945_hw_rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001477}
1478
Zhu Yib481de92007-09-25 17:54:57 -07001479/************************** RX-FUNCTIONS ****************************/
1480/*
1481 * Rx theory of operation
1482 *
1483 * The host allocates 32 DMA target addresses and passes the host address
1484 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
1485 * 0 to 31
1486 *
1487 * Rx Queue Indexes
1488 * The host/firmware share two index registers for managing the Rx buffers.
1489 *
1490 * The READ index maps to the first position that the firmware may be writing
1491 * to -- the driver can read up to (but not including) this position and get
1492 * good data.
1493 * The READ index is managed by the firmware once the card is enabled.
1494 *
1495 * The WRITE index maps to the last position the driver has read from -- the
1496 * position preceding WRITE is the last slot the firmware can place a packet.
1497 *
1498 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
1499 * WRITE = READ.
1500 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001501 * During initialization, the host sets up the READ queue position to the first
Zhu Yib481de92007-09-25 17:54:57 -07001502 * INDEX position, and WRITE to the last (READ - 1 wrapped)
1503 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001504 * When the firmware places a packet in a buffer, it will advance the READ index
Zhu Yib481de92007-09-25 17:54:57 -07001505 * and fire the RX interrupt. The driver can then query the READ index and
1506 * process as many packets as possible, moving the WRITE index forward as it
1507 * resets the Rx queue buffers with new memory.
1508 *
1509 * The management in the driver is as follows:
1510 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
1511 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Ian Schram01ebd062007-10-25 17:15:22 +08001512 * to replenish the iwl->rxq->rx_free.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001513 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
Zhu Yib481de92007-09-25 17:54:57 -07001514 * iwl->rxq is replenished and the READ INDEX is updated (updating the
1515 * 'processed' and 'read' driver indexes as well)
1516 * + A received packet is processed and handed to the kernel network stack,
1517 * detached from the iwl->rxq. The driver 'processed' index is updated.
1518 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
1519 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
1520 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
1521 * were enough free buffers and RX_STALLED is set it is cleared.
1522 *
1523 *
1524 * Driver sequence:
1525 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001526 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001527 * iwl3945_rx_queue_restock
Ben Cahill9fbab512007-11-29 11:09:47 +08001528 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
Zhu Yib481de92007-09-25 17:54:57 -07001529 * queue, updates firmware pointers, and updates
1530 * the WRITE index. If insufficient rx_free buffers
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001531 * are available, schedules iwl3945_rx_replenish
Zhu Yib481de92007-09-25 17:54:57 -07001532 *
1533 * -- enable interrupts --
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001534 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
Zhu Yib481de92007-09-25 17:54:57 -07001535 * READ INDEX, detaching the SKB from the pool.
1536 * Moves the packet buffer from queue to rx_used.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001537 * Calls iwl3945_rx_queue_restock to refill any empty
Zhu Yib481de92007-09-25 17:54:57 -07001538 * slots.
1539 * ...
1540 *
1541 */
1542
1543/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001544 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
Zhu Yib481de92007-09-25 17:54:57 -07001545 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001546static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001547 dma_addr_t dma_addr)
1548{
1549 return cpu_to_le32((u32)dma_addr);
1550}
1551
1552/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001553 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
Zhu Yib481de92007-09-25 17:54:57 -07001554 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001555 * If there are slots in the RX queue that need to be restocked,
Zhu Yib481de92007-09-25 17:54:57 -07001556 * and we have free pre-allocated buffers, fill the ranks as much
Ben Cahill9fbab512007-11-29 11:09:47 +08001557 * as we can, pulling from rx_free.
Zhu Yib481de92007-09-25 17:54:57 -07001558 *
1559 * This moves the 'write' index forward to catch up with 'processed', and
1560 * also updates the memory address in the firmware to reference the new
1561 * target buffer.
1562 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001563static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001564{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001565 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001566 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001567 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001568 unsigned long flags;
1569 int write, rc;
1570
1571 spin_lock_irqsave(&rxq->lock, flags);
1572 write = rxq->write & ~0x7;
Winkler, Tomas37d68312009-01-08 10:19:54 -08001573 while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001574 /* Get next free Rx buffer, remove from free list */
Zhu Yib481de92007-09-25 17:54:57 -07001575 element = rxq->rx_free.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001576 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Zhu Yib481de92007-09-25 17:54:57 -07001577 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001578
1579 /* Point to Rx buffer via next RBD in circular buffer */
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001580 rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
Zhu Yib481de92007-09-25 17:54:57 -07001581 rxq->queue[rxq->write] = rxb;
1582 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
1583 rxq->free_count--;
1584 }
1585 spin_unlock_irqrestore(&rxq->lock, flags);
1586 /* If the pre-allocated buffer pool is dropping low, schedule to
1587 * refill it */
1588 if (rxq->free_count <= RX_LOW_WATERMARK)
1589 queue_work(priv->workqueue, &priv->rx_replenish);
1590
1591
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001592 /* If we've added more space for the firmware to place data, tell it.
1593 * Increment device's write pointer in multiples of 8. */
Zhu Yib481de92007-09-25 17:54:57 -07001594 if ((write != (rxq->write & ~0x7))
1595 || (abs(rxq->write - rxq->read) > 7)) {
1596 spin_lock_irqsave(&rxq->lock, flags);
1597 rxq->need_update = 1;
1598 spin_unlock_irqrestore(&rxq->lock, flags);
Winkler, Tomas141c43a2009-01-08 10:19:53 -08001599 rc = iwl_rx_queue_update_write_ptr(priv, rxq);
Zhu Yib481de92007-09-25 17:54:57 -07001600 if (rc)
1601 return rc;
1602 }
1603
1604 return 0;
1605}
1606
1607/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001608 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
Zhu Yib481de92007-09-25 17:54:57 -07001609 *
1610 * When moving to rx_free an SKB is allocated for the slot.
1611 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001612 * Also restock the Rx queue via iwl3945_rx_queue_restock.
Ian Schram01ebd062007-10-25 17:15:22 +08001613 * This is called as a scheduled work item (except for during initialization)
Zhu Yib481de92007-09-25 17:54:57 -07001614 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001615static void iwl3945_rx_allocate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001616{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001617 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001618 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001619 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001620 unsigned long flags;
1621 spin_lock_irqsave(&rxq->lock, flags);
1622 while (!list_empty(&rxq->rx_used)) {
1623 element = rxq->rx_used.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001624 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001625
1626 /* Alloc a new receive buffer */
Zhu Yib481de92007-09-25 17:54:57 -07001627 rxb->skb =
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001628 alloc_skb(priv->hw_params.rx_buf_size,
1629 __GFP_NOWARN | GFP_ATOMIC);
Zhu Yib481de92007-09-25 17:54:57 -07001630 if (!rxb->skb) {
1631 if (net_ratelimit())
Tomas Winkler978785a2008-12-19 10:37:31 +08001632 IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
Zhu Yib481de92007-09-25 17:54:57 -07001633 /* We don't reschedule replenish work here -- we will
1634 * call the restock method and if it still needs
1635 * more buffers it will schedule replenish */
1636 break;
1637 }
Zhu Yi12342c42007-12-20 11:27:32 +08001638
1639 /* If radiotap head is required, reserve some headroom here.
1640 * The physical head count is a variable rx_stats->phy_count.
1641 * We reserve 4 bytes here. Plus these extra bytes, the
1642 * headroom of the physical head should be enough for the
1643 * radiotap head that iwl3945 supported. See iwl3945_rt.
1644 */
1645 skb_reserve(rxb->skb, 4);
1646
Zhu Yib481de92007-09-25 17:54:57 -07001647 priv->alloc_rxb_skb++;
1648 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001649
1650 /* Get physical address of RB/SKB */
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001651 rxb->real_dma_addr = pci_map_single(priv->pci_dev,
1652 rxb->skb->data,
1653 priv->hw_params.rx_buf_size,
1654 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001655 list_add_tail(&rxb->list, &rxq->rx_free);
1656 rxq->free_count++;
1657 }
1658 spin_unlock_irqrestore(&rxq->lock, flags);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001659}
1660
Reinette Chatredf833b12009-04-21 10:55:48 -07001661void iwl3945_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
1662{
1663 unsigned long flags;
1664 int i;
1665 spin_lock_irqsave(&rxq->lock, flags);
1666 INIT_LIST_HEAD(&rxq->rx_free);
1667 INIT_LIST_HEAD(&rxq->rx_used);
1668 /* Fill the rx_used queue with _all_ of the Rx buffers */
1669 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
1670 /* In the reset function, these buffers may have been allocated
1671 * to an SKB, so we need to unmap and free potential storage */
1672 if (rxq->pool[i].skb != NULL) {
1673 pci_unmap_single(priv->pci_dev,
1674 rxq->pool[i].real_dma_addr,
1675 priv->hw_params.rx_buf_size,
1676 PCI_DMA_FROMDEVICE);
1677 priv->alloc_rxb_skb--;
1678 dev_kfree_skb(rxq->pool[i].skb);
1679 rxq->pool[i].skb = NULL;
1680 }
1681 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
1682 }
1683
1684 /* Set us so that we have processed and used all buffers, but have
1685 * not restocked the Rx queue with fresh buffers */
1686 rxq->read = rxq->write = 0;
1687 rxq->free_count = 0;
1688 spin_unlock_irqrestore(&rxq->lock, flags);
1689}
Reinette Chatredf833b12009-04-21 10:55:48 -07001690
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001691/*
1692 * this should be called while priv->lock is locked
1693 */
Tomas Winkler4fd1f842007-12-05 20:59:58 +02001694static void __iwl3945_rx_replenish(void *data)
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001695{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001696 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001697
1698 iwl3945_rx_allocate(priv);
1699 iwl3945_rx_queue_restock(priv);
1700}
1701
1702
1703void iwl3945_rx_replenish(void *data)
1704{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001705 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001706 unsigned long flags;
1707
1708 iwl3945_rx_allocate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001709
1710 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001711 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001712 spin_unlock_irqrestore(&priv->lock, flags);
1713}
1714
Reinette Chatredf833b12009-04-21 10:55:48 -07001715/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
1716 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
1717 * This free routine walks the list of POOL entries and if SKB is set to
1718 * non NULL it is unmapped and freed
1719 */
1720static void iwl3945_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
1721{
1722 int i;
1723 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
1724 if (rxq->pool[i].skb != NULL) {
1725 pci_unmap_single(priv->pci_dev,
1726 rxq->pool[i].real_dma_addr,
1727 priv->hw_params.rx_buf_size,
1728 PCI_DMA_FROMDEVICE);
1729 dev_kfree_skb(rxq->pool[i].skb);
1730 }
1731 }
1732
1733 pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd,
1734 rxq->dma_addr);
1735 pci_free_consistent(priv->pci_dev, sizeof(struct iwl_rb_status),
1736 rxq->rb_stts, rxq->rb_stts_dma);
1737 rxq->bd = NULL;
1738 rxq->rb_stts = NULL;
1739}
Reinette Chatredf833b12009-04-21 10:55:48 -07001740
1741
Zhu Yib481de92007-09-25 17:54:57 -07001742/* Convert linear signal-to-noise ratio into dB */
1743static u8 ratio2dB[100] = {
1744/* 0 1 2 3 4 5 6 7 8 9 */
1745 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
1746 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
1747 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
1748 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
1749 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
1750 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
1751 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
1752 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
1753 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
1754 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
1755};
1756
1757/* Calculates a relative dB value from a ratio of linear
1758 * (i.e. not dB) signal levels.
1759 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001760int iwl3945_calc_db_from_ratio(int sig_ratio)
Zhu Yib481de92007-09-25 17:54:57 -07001761{
Adrian Bunk221c80c2008-02-02 23:19:01 +02001762 /* 1000:1 or higher just report as 60 dB */
1763 if (sig_ratio >= 1000)
Zhu Yib481de92007-09-25 17:54:57 -07001764 return 60;
1765
Adrian Bunk221c80c2008-02-02 23:19:01 +02001766 /* 100:1 or higher, divide by 10 and use table,
Zhu Yib481de92007-09-25 17:54:57 -07001767 * add 20 dB to make up for divide by 10 */
Adrian Bunk221c80c2008-02-02 23:19:01 +02001768 if (sig_ratio >= 100)
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001769 return 20 + (int)ratio2dB[sig_ratio/10];
Zhu Yib481de92007-09-25 17:54:57 -07001770
1771 /* We shouldn't see this */
1772 if (sig_ratio < 1)
1773 return 0;
1774
1775 /* Use table for ratios 1:1 - 99:1 */
1776 return (int)ratio2dB[sig_ratio];
1777}
1778
1779#define PERFECT_RSSI (-20) /* dBm */
1780#define WORST_RSSI (-95) /* dBm */
1781#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
1782
1783/* Calculate an indication of rx signal quality (a percentage, not dBm!).
1784 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
1785 * about formulas used below. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001786int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
Zhu Yib481de92007-09-25 17:54:57 -07001787{
1788 int sig_qual;
1789 int degradation = PERFECT_RSSI - rssi_dbm;
1790
1791 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
1792 * as indicator; formula is (signal dbm - noise dbm).
1793 * SNR at or above 40 is a great signal (100%).
1794 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
1795 * Weakest usable signal is usually 10 - 15 dB SNR. */
1796 if (noise_dbm) {
1797 if (rssi_dbm - noise_dbm >= 40)
1798 return 100;
1799 else if (rssi_dbm < noise_dbm)
1800 return 0;
1801 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
1802
1803 /* Else use just the signal level.
1804 * This formula is a least squares fit of data points collected and
1805 * compared with a reference system that had a percentage (%) display
1806 * for signal quality. */
1807 } else
1808 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
1809 (15 * RSSI_RANGE + 62 * degradation)) /
1810 (RSSI_RANGE * RSSI_RANGE);
1811
1812 if (sig_qual > 100)
1813 sig_qual = 100;
1814 else if (sig_qual < 1)
1815 sig_qual = 0;
1816
1817 return sig_qual;
1818}
1819
1820/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001821 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001822 *
1823 * Uses the priv->rx_handlers callback function array to invoke
1824 * the appropriate handlers, including command responses,
1825 * frame-received notifications, and other notifications.
1826 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001827static void iwl3945_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001828{
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001829 struct iwl_rx_mem_buffer *rxb;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001830 struct iwl_rx_packet *pkt;
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001831 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001832 u32 r, i;
1833 int reclaim;
1834 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001835 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001836 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07001837
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001838 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1839 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8cd812b2008-12-19 10:37:43 +08001840 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07001841 i = rxq->read;
1842
Winkler, Tomas37d68312009-01-08 10:19:54 -08001843 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001844 fill_rx = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001845 /* Rx interrupt, but nothing sent from uCode */
1846 if (i == r)
Tomas Winklere1623442009-01-27 14:27:56 -08001847 IWL_DEBUG(priv, IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001848
1849 while (i != r) {
1850 rxb = rxq->queue[i];
1851
Ben Cahill9fbab512007-11-29 11:09:47 +08001852 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001853 * then a bug has been introduced in the queue refilling
1854 * routines -- catch it here */
1855 BUG_ON(rxb == NULL);
1856
1857 rxq->queue[i] = NULL;
1858
Reinette Chatredf833b12009-04-21 10:55:48 -07001859 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
1860 priv->hw_params.rx_buf_size,
1861 PCI_DMA_FROMDEVICE);
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001862 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001863
1864 /* Reclaim a command buffer only if this packet is a response
1865 * to a (driver-originated) command.
1866 * If the packet (e.g. Rx frame) originated from uCode,
1867 * there is no command buffer to reclaim.
1868 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1869 * but apparently a few don't get set; catch them here. */
1870 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1871 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1872 (pkt->hdr.cmd != REPLY_TX);
1873
1874 /* Based on type of command response or notification,
1875 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001876 * rx_handlers table. See iwl3945_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001877 if (priv->rx_handlers[pkt->hdr.cmd]) {
Tomas Winklere1623442009-01-27 14:27:56 -08001878 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07001879 "r = %d, i = %d, %s, 0x%02x\n", r, i,
1880 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
1881 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1882 } else {
1883 /* No handling needed */
Tomas Winklere1623442009-01-27 14:27:56 -08001884 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07001885 "r %d i %d No handler needed for %s, 0x%02x\n",
1886 r, i, get_cmd_string(pkt->hdr.cmd),
1887 pkt->hdr.cmd);
1888 }
1889
1890 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001891 /* Invoke any callbacks, transfer the skb to caller, and
Samuel Ortiz518099a2009-01-19 15:30:27 -08001892 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001893 * as we reclaim the driver command queue */
1894 if (rxb && rxb->skb)
Abhijeet Kolekar732587a2009-03-11 11:17:57 -07001895 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001896 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001897 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07001898 }
1899
1900 /* For now we just don't re-use anything. We can tweak this
1901 * later to try and re-use notification packets and SKBs that
1902 * fail to Rx correctly */
1903 if (rxb->skb != NULL) {
1904 priv->alloc_rxb_skb--;
1905 dev_kfree_skb_any(rxb->skb);
1906 rxb->skb = NULL;
1907 }
1908
Zhu Yib481de92007-09-25 17:54:57 -07001909 spin_lock_irqsave(&rxq->lock, flags);
1910 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1911 spin_unlock_irqrestore(&rxq->lock, flags);
1912 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001913 /* If there are a lot of unused frames,
1914 * restock the Rx queue so ucode won't assert. */
1915 if (fill_rx) {
1916 count++;
1917 if (count >= 8) {
1918 priv->rxq.read = i;
1919 __iwl3945_rx_replenish(priv);
1920 count = 0;
1921 }
1922 }
Zhu Yib481de92007-09-25 17:54:57 -07001923 }
1924
1925 /* Backtrack one entry */
1926 priv->rxq.read = i;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001927 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001928}
1929
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001930/* call this function to flush any scheduled tasklet */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001931static inline void iwl_synchronize_irq(struct iwl_priv *priv)
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001932{
Tomas Winklera96a27f2008-10-23 23:48:56 -07001933 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001934 synchronize_irq(priv->pci_dev->irq);
1935 tasklet_kill(&priv->irq_tasklet);
1936}
1937
Zhu Yib481de92007-09-25 17:54:57 -07001938static const char *desc_lookup(int i)
1939{
1940 switch (i) {
1941 case 1:
1942 return "FAIL";
1943 case 2:
1944 return "BAD_PARAM";
1945 case 3:
1946 return "BAD_CHECKSUM";
1947 case 4:
1948 return "NMI_INTERRUPT";
1949 case 5:
1950 return "SYSASSERT";
1951 case 6:
1952 return "FATAL_ERROR";
1953 }
1954
1955 return "UNKNOWN";
1956}
1957
1958#define ERROR_START_OFFSET (1 * sizeof(u32))
1959#define ERROR_ELEM_SIZE (7 * sizeof(u32))
1960
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001961static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001962{
1963 u32 i;
1964 u32 desc, time, count, base, data1;
1965 u32 blink1, blink2, ilink1, ilink2;
1966 int rc;
1967
1968 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
1969
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001970 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001971 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07001972 return;
1973 }
1974
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001975 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001976 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001977 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001978 return;
1979 }
1980
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001981 count = iwl_read_targ_mem(priv, base);
Zhu Yib481de92007-09-25 17:54:57 -07001982
1983 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001984 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
1985 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
1986 priv->status, count);
Zhu Yib481de92007-09-25 17:54:57 -07001987 }
1988
Winkler, Tomas15b16872008-12-19 10:37:33 +08001989 IWL_ERR(priv, "Desc Time asrtPC blink2 "
Zhu Yib481de92007-09-25 17:54:57 -07001990 "ilink1 nmiPC Line\n");
1991 for (i = ERROR_START_OFFSET;
1992 i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
1993 i += ERROR_ELEM_SIZE) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001994 desc = iwl_read_targ_mem(priv, base + i);
Zhu Yib481de92007-09-25 17:54:57 -07001995 time =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001996 iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001997 blink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001998 iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001999 blink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002000 iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002001 ilink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002002 iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002003 ilink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002004 iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002005 data1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002006 iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002007
Winkler, Tomas15b16872008-12-19 10:37:33 +08002008 IWL_ERR(priv,
2009 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
2010 desc_lookup(desc), desc, time, blink1, blink2,
2011 ilink1, ilink2, data1);
Zhu Yib481de92007-09-25 17:54:57 -07002012 }
2013
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002014 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002015
2016}
2017
Ben Cahillf58177b2007-11-29 11:09:43 +08002018#define EVENT_START_OFFSET (6 * sizeof(u32))
Zhu Yib481de92007-09-25 17:54:57 -07002019
2020/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002021 * iwl3945_print_event_log - Dump error event log to syslog
Zhu Yib481de92007-09-25 17:54:57 -07002022 *
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002023 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
Zhu Yib481de92007-09-25 17:54:57 -07002024 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002025static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
Zhu Yib481de92007-09-25 17:54:57 -07002026 u32 num_events, u32 mode)
2027{
2028 u32 i;
2029 u32 base; /* SRAM byte address of event log header */
2030 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
2031 u32 ptr; /* SRAM byte address of log data */
2032 u32 ev, time, data; /* event log data */
2033
2034 if (num_events == 0)
2035 return;
2036
2037 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
2038
2039 if (mode == 0)
2040 event_size = 2 * sizeof(u32);
2041 else
2042 event_size = 3 * sizeof(u32);
2043
2044 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
2045
2046 /* "time" is actually "data" for mode 0 (no timestamp).
2047 * place event id # at far right for easier visual parsing. */
2048 for (i = 0; i < num_events; i++) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002049 ev = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002050 ptr += sizeof(u32);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002051 time = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002052 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002053 if (mode == 0) {
2054 /* data, ev */
2055 IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
2056 } else {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002057 data = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002058 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002059 IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
Zhu Yib481de92007-09-25 17:54:57 -07002060 }
2061 }
2062}
2063
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002064static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002065{
2066 int rc;
2067 u32 base; /* SRAM byte address of event log header */
2068 u32 capacity; /* event log capacity in # entries */
2069 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
2070 u32 num_wraps; /* # times uCode wrapped to top of log */
2071 u32 next_entry; /* index of next entry to be written by uCode */
2072 u32 size; /* # entries that we'll print */
2073
2074 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002075 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002076 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07002077 return;
2078 }
2079
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002080 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002081 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002082 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002083 return;
2084 }
2085
2086 /* event log header */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002087 capacity = iwl_read_targ_mem(priv, base);
2088 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
2089 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
2090 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
Zhu Yib481de92007-09-25 17:54:57 -07002091
2092 size = num_wraps ? capacity : next_entry;
2093
2094 /* bail out if nothing in log */
2095 if (size == 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002096 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002097 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002098 return;
2099 }
2100
Winkler, Tomas15b16872008-12-19 10:37:33 +08002101 IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07002102 size, num_wraps);
2103
2104 /* if uCode has wrapped back to top of log, start at the oldest entry,
2105 * i.e the next one that uCode would fill. */
2106 if (num_wraps)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002107 iwl3945_print_event_log(priv, next_entry,
Zhu Yib481de92007-09-25 17:54:57 -07002108 capacity - next_entry, mode);
2109
2110 /* (then/else) start at top of log */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002111 iwl3945_print_event_log(priv, 0, next_entry, mode);
Zhu Yib481de92007-09-25 17:54:57 -07002112
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002113 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002114}
2115
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002116static void iwl3945_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002117{
2118 unsigned long flags;
2119
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002120 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
2121 sizeof(priv->staging_rxon));
2122 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002123 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002124
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002125 iwl3945_add_station(priv, priv->bssid, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002126
2127 spin_lock_irqsave(&priv->lock, flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002128 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07002129 priv->error_recovering = 0;
2130 spin_unlock_irqrestore(&priv->lock, flags);
2131}
2132
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002133static void iwl3945_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002134{
2135 u32 inta, handled = 0;
2136 u32 inta_fh;
2137 unsigned long flags;
Samuel Ortizd08853a2009-01-23 13:45:17 -08002138#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07002139 u32 inta_mask;
2140#endif
2141
2142 spin_lock_irqsave(&priv->lock, flags);
2143
2144 /* Ack/clear/reset pending uCode interrupts.
2145 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
2146 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002147 inta = iwl_read32(priv, CSR_INT);
2148 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07002149
2150 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
2151 * Any new interrupts that happen after this, either while we're
2152 * in this tasklet, or later, will show up in next ISR/tasklet. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002153 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
2154 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07002155
Samuel Ortizd08853a2009-01-23 13:45:17 -08002156#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002157 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08002158 /* just for debug */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002159 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Tomas Winklere1623442009-01-27 14:27:56 -08002160 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002161 inta, inta_mask, inta_fh);
2162 }
2163#endif
2164
2165 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
2166 * atomic, make sure that inta covers all the interrupts that
2167 * we've discovered, even if FH interrupt came in just after
2168 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002169 if (inta_fh & CSR39_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002170 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002171 if (inta_fh & CSR39_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002172 inta |= CSR_INT_BIT_FH_TX;
2173
2174 /* Now service all interrupt bits discovered above. */
2175 if (inta & CSR_INT_BIT_HW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002176 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002177
2178 /* Tell the device to stop sending interrupts */
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002179 iwl_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002180
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002181 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002182
2183 handled |= CSR_INT_BIT_HW_ERR;
2184
2185 spin_unlock_irqrestore(&priv->lock, flags);
2186
2187 return;
2188 }
2189
Samuel Ortizd08853a2009-01-23 13:45:17 -08002190#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002191 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07002192 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002193 if (inta & CSR_INT_BIT_SCD)
Tomas Winklere1623442009-01-27 14:27:56 -08002194 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
Joonwoo Park25c03d82008-01-23 10:15:20 -08002195 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002196
2197 /* Alive notification via Rx interrupt will do the real work */
2198 if (inta & CSR_INT_BIT_ALIVE)
Tomas Winklere1623442009-01-27 14:27:56 -08002199 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002200 }
2201#endif
2202 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002203 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07002204
Zhu Yib481de92007-09-25 17:54:57 -07002205 /* Error detected by uCode */
2206 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002207 IWL_ERR(priv, "Microcode SW error detected. "
2208 "Restarting 0x%X.\n", inta);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002209 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002210 handled |= CSR_INT_BIT_SW_ERR;
2211 }
2212
2213 /* uCode wakes up after power-down sleep */
2214 if (inta & CSR_INT_BIT_WAKEUP) {
Tomas Winklere1623442009-01-27 14:27:56 -08002215 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
Winkler, Tomas141c43a2009-01-08 10:19:53 -08002216 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08002217 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
2218 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
2219 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
2220 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
2221 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
2222 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07002223
2224 handled |= CSR_INT_BIT_WAKEUP;
2225 }
2226
2227 /* All uCode command responses, including Tx command responses,
2228 * Rx "responses" (frame-received notification), and other
2229 * notifications from uCode come through here*/
2230 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002231 iwl3945_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002232 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
2233 }
2234
2235 if (inta & CSR_INT_BIT_FH_TX) {
Tomas Winklere1623442009-01-27 14:27:56 -08002236 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002237
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002238 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
2239 if (!iwl_grab_nic_access(priv)) {
2240 iwl_write_direct32(priv, FH39_TCSR_CREDIT
Tomas Winklerbddadf82008-12-19 10:37:01 +08002241 (FH39_SRVC_CHNL), 0x0);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002242 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002243 }
2244 handled |= CSR_INT_BIT_FH_TX;
2245 }
2246
2247 if (inta & ~handled)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002248 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Zhu Yib481de92007-09-25 17:54:57 -07002249
2250 if (inta & ~CSR_INI_SET_MASK) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002251 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Zhu Yib481de92007-09-25 17:54:57 -07002252 inta & ~CSR_INI_SET_MASK);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002253 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07002254 }
2255
2256 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002257 /* only Re-enable if disabled by irq */
2258 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002259 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002260
Samuel Ortizd08853a2009-01-23 13:45:17 -08002261#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002262 if (priv->debug_level & (IWL_DL_ISR)) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002263 inta = iwl_read32(priv, CSR_INT);
2264 inta_mask = iwl_read32(priv, CSR_INT_MASK);
2265 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Tomas Winklere1623442009-01-27 14:27:56 -08002266 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
Zhu Yib481de92007-09-25 17:54:57 -07002267 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
2268 }
2269#endif
2270 spin_unlock_irqrestore(&priv->lock, flags);
2271}
2272
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002273static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01002274 enum ieee80211_band band,
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08002275 u8 is_active, u8 n_probes,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002276 struct iwl3945_scan_channel *scan_ch)
Zhu Yib481de92007-09-25 17:54:57 -07002277{
2278 const struct ieee80211_channel *channels = NULL;
Johannes Berg8318d782008-01-24 19:38:38 +01002279 const struct ieee80211_supported_band *sband;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08002280 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07002281 u16 passive_dwell = 0;
2282 u16 active_dwell = 0;
2283 int added, i;
2284
Kolekar, Abhijeetcbba18c2008-12-19 10:37:42 +08002285 sband = iwl_get_hw_mode(priv, band);
Johannes Berg8318d782008-01-24 19:38:38 +01002286 if (!sband)
Zhu Yib481de92007-09-25 17:54:57 -07002287 return 0;
2288
Johannes Berg8318d782008-01-24 19:38:38 +01002289 channels = sband->channels;
Zhu Yib481de92007-09-25 17:54:57 -07002290
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08002291 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
2292 passive_dwell = iwl_get_passive_dwell_time(priv, band);
Zhu Yib481de92007-09-25 17:54:57 -07002293
Abhijeet Kolekar8f4807a2008-09-03 11:26:31 +08002294 if (passive_dwell <= active_dwell)
2295 passive_dwell = active_dwell + 1;
2296
Johannes Berg8318d782008-01-24 19:38:38 +01002297 for (i = 0, added = 0; i < sband->n_channels; i++) {
Johannes Berg182e2e62008-04-04 10:41:56 +02002298 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
2299 continue;
2300
Johannes Berg8318d782008-01-24 19:38:38 +01002301 scan_ch->channel = channels[i].hw_value;
Zhu Yib481de92007-09-25 17:54:57 -07002302
Samuel Ortize6148912009-01-23 13:45:15 -08002303 ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
Zhu Yib481de92007-09-25 17:54:57 -07002304 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002305 IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
Zhu Yib481de92007-09-25 17:54:57 -07002306 scan_ch->channel);
2307 continue;
2308 }
2309
Zhu Yib481de92007-09-25 17:54:57 -07002310 scan_ch->active_dwell = cpu_to_le16(active_dwell);
2311 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002312 /* If passive , set up for auto-switch
2313 * and use long active_dwell time.
2314 */
2315 if (!is_active || is_channel_passive(ch_info) ||
2316 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
2317 scan_ch->type = 0; /* passive */
2318 if (IWL_UCODE_API(priv->ucode_ver) == 1)
2319 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
2320 } else {
2321 scan_ch->type = 1; /* active */
2322 }
2323
2324 /* Set direct probe bits. These may be used both for active
2325 * scan channels (probes gets sent right away),
2326 * or for passive channels (probes get se sent only after
2327 * hearing clear Rx packet).*/
2328 if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
2329 if (n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002330 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002331 } else {
2332 /* uCode v1 does not allow setting direct probe bits on
2333 * passive channel. */
2334 if ((scan_ch->type & 1) && n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002335 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002336 }
Zhu Yib481de92007-09-25 17:54:57 -07002337
Ben Cahill9fbab512007-11-29 11:09:47 +08002338 /* Set txpower levels to defaults */
Zhu Yib481de92007-09-25 17:54:57 -07002339 scan_ch->tpc.dsp_atten = 110;
2340 /* scan_pwr_info->tpc.dsp_atten; */
2341
2342 /*scan_pwr_info->tpc.tx_gain; */
Johannes Berg8318d782008-01-24 19:38:38 +01002343 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -07002344 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
2345 else {
2346 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
2347 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
Ben Cahill9fbab512007-11-29 11:09:47 +08002348 * power level:
Reinette Chatre8a1b0242008-01-14 17:46:25 -08002349 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
Zhu Yib481de92007-09-25 17:54:57 -07002350 */
2351 }
2352
Tomas Winklere1623442009-01-27 14:27:56 -08002353 IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n",
Zhu Yib481de92007-09-25 17:54:57 -07002354 scan_ch->channel,
2355 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
2356 (scan_ch->type & 1) ?
2357 active_dwell : passive_dwell);
2358
2359 scan_ch++;
2360 added++;
2361 }
2362
Tomas Winklere1623442009-01-27 14:27:56 -08002363 IWL_DEBUG_SCAN(priv, "total channels to scan %d \n", added);
Zhu Yib481de92007-09-25 17:54:57 -07002364 return added;
2365}
2366
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002367static void iwl3945_init_hw_rates(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002368 struct ieee80211_rate *rates)
2369{
2370 int i;
2371
2372 for (i = 0; i < IWL_RATE_COUNT; i++) {
Johannes Berg8318d782008-01-24 19:38:38 +01002373 rates[i].bitrate = iwl3945_rates[i].ieee * 5;
2374 rates[i].hw_value = i; /* Rate scaling will work on indexes */
2375 rates[i].hw_value_short = i;
2376 rates[i].flags = 0;
Samuel Ortizd9829a62008-12-19 10:37:12 +08002377 if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
Zhu Yib481de92007-09-25 17:54:57 -07002378 /*
Johannes Berg8318d782008-01-24 19:38:38 +01002379 * If CCK != 1M then set short preamble rate flag.
Zhu Yib481de92007-09-25 17:54:57 -07002380 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002381 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
Johannes Berg8318d782008-01-24 19:38:38 +01002382 0 : IEEE80211_RATE_SHORT_PREAMBLE;
Zhu Yib481de92007-09-25 17:54:57 -07002383 }
Zhu Yib481de92007-09-25 17:54:57 -07002384 }
2385}
2386
Zhu Yib481de92007-09-25 17:54:57 -07002387/******************************************************************************
2388 *
2389 * uCode download functions
2390 *
2391 ******************************************************************************/
2392
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002393static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002394{
Tomas Winkler98c92212008-01-14 17:46:20 -08002395 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
2396 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
2397 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
2398 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
2399 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
2400 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07002401}
2402
2403/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002404 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002405 * looking at all data.
2406 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002407static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002408{
2409 u32 val;
2410 u32 save_len = len;
2411 int rc = 0;
2412 u32 errcnt;
2413
Tomas Winklere1623442009-01-27 14:27:56 -08002414 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002415
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002416 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002417 if (rc)
2418 return rc;
2419
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002420 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002421 IWL39_RTC_INST_LOWER_BOUND);
Zhu Yib481de92007-09-25 17:54:57 -07002422
2423 errcnt = 0;
2424 for (; len > 0; len -= sizeof(u32), image++) {
2425 /* read data comes through single port, auto-incr addr */
2426 /* NOTE: Use the debugless read so we don't flood kernel log
2427 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002428 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002429 if (val != le32_to_cpu(*image)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002430 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002431 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2432 save_len - len, val, le32_to_cpu(*image));
2433 rc = -EIO;
2434 errcnt++;
2435 if (errcnt >= 20)
2436 break;
2437 }
2438 }
2439
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002440 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002441
2442 if (!errcnt)
Tomas Winklere1623442009-01-27 14:27:56 -08002443 IWL_DEBUG_INFO(priv,
2444 "ucode image in INSTRUCTION memory is good\n");
Zhu Yib481de92007-09-25 17:54:57 -07002445
2446 return rc;
2447}
2448
2449
2450/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002451 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002452 * using sample data 100 bytes apart. If these sample points are good,
2453 * it's a pretty good bet that everything between them is good, too.
2454 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002455static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002456{
2457 u32 val;
2458 int rc = 0;
2459 u32 errcnt = 0;
2460 u32 i;
2461
Tomas Winklere1623442009-01-27 14:27:56 -08002462 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002463
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002464 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002465 if (rc)
2466 return rc;
2467
2468 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
2469 /* read data comes through single port, auto-incr addr */
2470 /* NOTE: Use the debugless read so we don't flood kernel log
2471 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002472 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002473 i + IWL39_RTC_INST_LOWER_BOUND);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002474 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002475 if (val != le32_to_cpu(*image)) {
2476#if 0 /* Enable this if you want to see details */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002477 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002478 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2479 i, val, *image);
2480#endif
2481 rc = -EIO;
2482 errcnt++;
2483 if (errcnt >= 3)
2484 break;
2485 }
2486 }
2487
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002488 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002489
2490 return rc;
2491}
2492
2493
2494/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002495 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
Zhu Yib481de92007-09-25 17:54:57 -07002496 * and verify its contents
2497 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002498static int iwl3945_verify_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002499{
2500 __le32 *image;
2501 u32 len;
2502 int rc = 0;
2503
2504 /* Try bootstrap */
2505 image = (__le32 *)priv->ucode_boot.v_addr;
2506 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002507 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002508 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002509 IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002510 return 0;
2511 }
2512
2513 /* Try initialize */
2514 image = (__le32 *)priv->ucode_init.v_addr;
2515 len = priv->ucode_init.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002516 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002517 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002518 IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002519 return 0;
2520 }
2521
2522 /* Try runtime/protocol */
2523 image = (__le32 *)priv->ucode_code.v_addr;
2524 len = priv->ucode_code.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002525 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002526 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002527 IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002528 return 0;
2529 }
2530
Winkler, Tomas15b16872008-12-19 10:37:33 +08002531 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
Zhu Yib481de92007-09-25 17:54:57 -07002532
Ben Cahill9fbab512007-11-29 11:09:47 +08002533 /* Since nothing seems to match, show first several data entries in
2534 * instruction SRAM, so maybe visual inspection will give a clue.
2535 * Selection of bootstrap image (vs. other images) is arbitrary. */
Zhu Yib481de92007-09-25 17:54:57 -07002536 image = (__le32 *)priv->ucode_boot.v_addr;
2537 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002538 rc = iwl3945_verify_inst_full(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002539
2540 return rc;
2541}
2542
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002543static void iwl3945_nic_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002544{
2545 /* Remove all resets to allow NIC to operate */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002546 iwl_write32(priv, CSR_RESET, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002547}
2548
2549/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002550 * iwl3945_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07002551 *
2552 * Copy into buffers for card to fetch via bus-mastering
2553 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002554static int iwl3945_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002555{
Kolekar, Abhijeeta78fe752008-12-19 10:37:21 +08002556 struct iwl_ucode *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002557 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07002558 const struct firmware *ucode_raw;
2559 /* firmware file name contains uCode/driver compatibility version */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002560 const char *name_pre = priv->cfg->fw_name_pre;
2561 const unsigned int api_max = priv->cfg->ucode_api_max;
2562 const unsigned int api_min = priv->cfg->ucode_api_min;
2563 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07002564 u8 *src;
2565 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002566 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07002567
2568 /* Ask kernel firmware_class module to get the boot firmware off disk.
2569 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002570 for (index = api_max; index >= api_min; index--) {
2571 sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
2572 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
2573 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002574 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002575 buf, ret);
2576 if (ret == -ENOENT)
2577 continue;
2578 else
2579 goto error;
2580 } else {
2581 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002582 IWL_ERR(priv, "Loaded firmware %s, "
2583 "which is deprecated. "
2584 " Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002585 buf, api_max);
Tomas Winklere1623442009-01-27 14:27:56 -08002586 IWL_DEBUG_INFO(priv, "Got firmware '%s' file "
2587 "(%zd bytes) from disk\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002588 buf, ucode_raw->size);
2589 break;
2590 }
Zhu Yib481de92007-09-25 17:54:57 -07002591 }
2592
Reinette Chatrea0987a82008-12-02 12:14:06 -08002593 if (ret < 0)
2594 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07002595
2596 /* Make sure that we got at least our header! */
2597 if (ucode_raw->size < sizeof(*ucode)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002598 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002599 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002600 goto err_release;
2601 }
2602
2603 /* Data from ucode file: header followed by uCode images */
2604 ucode = (void *)ucode_raw->data;
2605
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08002606 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08002607 api_ver = IWL_UCODE_API(priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07002608 inst_size = le32_to_cpu(ucode->inst_size);
2609 data_size = le32_to_cpu(ucode->data_size);
2610 init_size = le32_to_cpu(ucode->init_size);
2611 init_data_size = le32_to_cpu(ucode->init_data_size);
2612 boot_size = le32_to_cpu(ucode->boot_size);
2613
Reinette Chatrea0987a82008-12-02 12:14:06 -08002614 /* api_ver should match the api version forming part of the
2615 * firmware filename ... but we don't check for that and only rely
Nick Andrew877d0312009-01-26 11:06:57 +01002616 * on the API version read from firmware header from here on forward */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002617
2618 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002619 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002620 "Driver supports v%u, firmware is v%u.\n",
2621 api_max, api_ver);
2622 priv->ucode_ver = 0;
2623 ret = -EINVAL;
2624 goto err_release;
2625 }
2626 if (api_ver != api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002627 IWL_ERR(priv, "Firmware has old API version. Expected %u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002628 "got %u. New firmware can be obtained "
2629 "from http://www.intellinuxwireless.org.\n",
2630 api_max, api_ver);
2631
Tomas Winkler978785a2008-12-19 10:37:31 +08002632 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
2633 IWL_UCODE_MAJOR(priv->ucode_ver),
2634 IWL_UCODE_MINOR(priv->ucode_ver),
2635 IWL_UCODE_API(priv->ucode_ver),
2636 IWL_UCODE_SERIAL(priv->ucode_ver));
2637
Tomas Winklere1623442009-01-27 14:27:56 -08002638 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002639 priv->ucode_ver);
Tomas Winklere1623442009-01-27 14:27:56 -08002640 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
2641 inst_size);
2642 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
2643 data_size);
2644 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
2645 init_size);
2646 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
2647 init_data_size);
2648 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
2649 boot_size);
Zhu Yib481de92007-09-25 17:54:57 -07002650
Reinette Chatrea0987a82008-12-02 12:14:06 -08002651
Zhu Yib481de92007-09-25 17:54:57 -07002652 /* Verify size of file vs. image size info in file's header */
2653 if (ucode_raw->size < sizeof(*ucode) +
2654 inst_size + data_size + init_size +
2655 init_data_size + boot_size) {
2656
Tomas Winklere1623442009-01-27 14:27:56 -08002657 IWL_DEBUG_INFO(priv, "uCode file size %zd too small\n",
2658 ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002659 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002660 goto err_release;
2661 }
2662
2663 /* Verify that uCode images will fit in card's SRAM */
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002664 if (inst_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002665 IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002666 inst_size);
2667 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002668 goto err_release;
2669 }
2670
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002671 if (data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002672 IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002673 data_size);
2674 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002675 goto err_release;
2676 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002677 if (init_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002678 IWL_DEBUG_INFO(priv,
2679 "uCode init instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002680 init_size);
2681 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002682 goto err_release;
2683 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002684 if (init_data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002685 IWL_DEBUG_INFO(priv,
2686 "uCode init data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002687 init_data_size);
2688 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002689 goto err_release;
2690 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002691 if (boot_size > IWL39_MAX_BSM_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002692 IWL_DEBUG_INFO(priv,
2693 "uCode boot instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002694 boot_size);
2695 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002696 goto err_release;
2697 }
2698
2699 /* Allocate ucode buffers for card's bus-master loading ... */
2700
2701 /* Runtime instructions and 2 copies of data:
2702 * 1) unmodified from disk
2703 * 2) backup cache for save/restore during power-downs */
2704 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002705 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07002706
2707 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002708 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07002709
2710 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002711 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07002712
2713 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
Tomas Winkler90e759d2007-11-29 11:09:41 +08002714 !priv->ucode_data_backup.v_addr)
Zhu Yib481de92007-09-25 17:54:57 -07002715 goto err_pci_alloc;
2716
Tomas Winkler90e759d2007-11-29 11:09:41 +08002717 /* Initialization instructions and data */
2718 if (init_size && init_data_size) {
2719 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002720 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002721
2722 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002723 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002724
2725 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
2726 goto err_pci_alloc;
2727 }
2728
2729 /* Bootstrap (instructions only, no data) */
2730 if (boot_size) {
2731 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002732 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002733
2734 if (!priv->ucode_boot.v_addr)
2735 goto err_pci_alloc;
2736 }
2737
Zhu Yib481de92007-09-25 17:54:57 -07002738 /* Copy images into buffers for card's bus-master reads ... */
2739
2740 /* Runtime instructions (first block of data in file) */
2741 src = &ucode->data[0];
2742 len = priv->ucode_code.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002743 IWL_DEBUG_INFO(priv,
2744 "Copying (but not loading) uCode instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002745 memcpy(priv->ucode_code.v_addr, src, len);
Tomas Winklere1623442009-01-27 14:27:56 -08002746 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002747 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
2748
2749 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002750 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
Zhu Yib481de92007-09-25 17:54:57 -07002751 src = &ucode->data[inst_size];
2752 len = priv->ucode_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002753 IWL_DEBUG_INFO(priv,
2754 "Copying (but not loading) uCode data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002755 memcpy(priv->ucode_data.v_addr, src, len);
2756 memcpy(priv->ucode_data_backup.v_addr, src, len);
2757
2758 /* Initialization instructions (3rd block) */
2759 if (init_size) {
2760 src = &ucode->data[inst_size + data_size];
2761 len = priv->ucode_init.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002762 IWL_DEBUG_INFO(priv,
2763 "Copying (but not loading) init instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002764 memcpy(priv->ucode_init.v_addr, src, len);
2765 }
2766
2767 /* Initialization data (4th block) */
2768 if (init_data_size) {
2769 src = &ucode->data[inst_size + data_size + init_size];
2770 len = priv->ucode_init_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002771 IWL_DEBUG_INFO(priv,
2772 "Copying (but not loading) init data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002773 memcpy(priv->ucode_init_data.v_addr, src, len);
2774 }
2775
2776 /* Bootstrap instructions (5th block) */
2777 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
2778 len = priv->ucode_boot.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002779 IWL_DEBUG_INFO(priv,
2780 "Copying (but not loading) boot instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002781 memcpy(priv->ucode_boot.v_addr, src, len);
2782
2783 /* We have our copies now, allow OS release its copies */
2784 release_firmware(ucode_raw);
2785 return 0;
2786
2787 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08002788 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002789 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002790 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002791
2792 err_release:
2793 release_firmware(ucode_raw);
2794
2795 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08002796 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002797}
2798
2799
2800/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002801 * iwl3945_set_ucode_ptrs - Set uCode address location
Zhu Yib481de92007-09-25 17:54:57 -07002802 *
2803 * Tell initialization uCode where to find runtime uCode.
2804 *
2805 * BSM registers initially contain pointers to initialization uCode.
2806 * We need to replace them to load runtime uCode inst and data,
2807 * and to save runtime data when powering down.
2808 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002809static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002810{
2811 dma_addr_t pinst;
2812 dma_addr_t pdata;
2813 int rc = 0;
2814 unsigned long flags;
2815
2816 /* bits 31:0 for 3945 */
2817 pinst = priv->ucode_code.p_addr;
2818 pdata = priv->ucode_data_backup.p_addr;
2819
2820 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002821 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002822 if (rc) {
2823 spin_unlock_irqrestore(&priv->lock, flags);
2824 return rc;
2825 }
2826
2827 /* Tell bootstrap uCode where to find image to load */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002828 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
2829 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
2830 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002831 priv->ucode_data.len);
2832
Tomas Winklera96a27f2008-10-23 23:48:56 -07002833 /* Inst byte count must be last to set up, bit 31 signals uCode
Zhu Yib481de92007-09-25 17:54:57 -07002834 * that all new ptr/size info is in place */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002835 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002836 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
2837
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002838 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002839
2840 spin_unlock_irqrestore(&priv->lock, flags);
2841
Tomas Winklere1623442009-01-27 14:27:56 -08002842 IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002843
2844 return rc;
2845}
2846
2847/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002848 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002849 *
2850 * Called after REPLY_ALIVE notification received from "initialize" uCode.
2851 *
Zhu Yib481de92007-09-25 17:54:57 -07002852 * Tell "initialize" uCode to go ahead and load the runtime uCode.
Ben Cahill9fbab512007-11-29 11:09:47 +08002853 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002854static void iwl3945_init_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002855{
2856 /* Check alive response for "valid" sign from uCode */
2857 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
2858 /* We had an error bringing up the hardware, so take it
2859 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002860 IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002861 goto restart;
2862 }
2863
2864 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
2865 * This is a paranoid check, because we would not have gotten the
2866 * "initialize" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002867 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002868 /* Runtime instruction load was bad;
2869 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002870 IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002871 goto restart;
2872 }
2873
2874 /* Send pointers to protocol/runtime uCode image ... init code will
2875 * load and launch runtime uCode, which will send us another "Alive"
2876 * notification. */
Tomas Winklere1623442009-01-27 14:27:56 -08002877 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002878 if (iwl3945_set_ucode_ptrs(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002879 /* Runtime instruction load won't happen;
2880 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002881 IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002882 goto restart;
2883 }
2884 return;
2885
2886 restart:
2887 queue_work(priv->workqueue, &priv->restart);
2888}
2889
2890
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08002891/* temporary */
2892static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw,
2893 struct sk_buff *skb);
2894
Zhu Yib481de92007-09-25 17:54:57 -07002895/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002896 * iwl3945_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002897 * from protocol/runtime uCode (initialization uCode's
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002898 * Alive gets handled by iwl3945_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07002899 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002900static void iwl3945_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002901{
2902 int rc = 0;
2903 int thermal_spin = 0;
2904 u32 rfkill;
2905
Tomas Winklere1623442009-01-27 14:27:56 -08002906 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002907
2908 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
2909 /* We had an error bringing up the hardware, so take it
2910 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002911 IWL_DEBUG_INFO(priv, "Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002912 goto restart;
2913 }
2914
2915 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
2916 * This is a paranoid check, because we would not have gotten the
2917 * "runtime" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002918 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002919 /* Runtime instruction load was bad;
2920 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002921 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002922 goto restart;
2923 }
2924
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002925 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002926
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002927 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002928 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002929 IWL_WARN(priv, "Can not read RFKILL status from adapter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002930 return;
2931 }
2932
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002933 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
Tomas Winklere1623442009-01-27 14:27:56 -08002934 IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002935 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002936
2937 if (rfkill & 0x1) {
2938 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winklera96a27f2008-10-23 23:48:56 -07002939 /* if RFKILL is not on, then wait for thermal
Zhu Yib481de92007-09-25 17:54:57 -07002940 * sensor in adapter to kick in */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002941 while (iwl3945_hw_get_temperature(priv) == 0) {
Zhu Yib481de92007-09-25 17:54:57 -07002942 thermal_spin++;
2943 udelay(10);
2944 }
2945
2946 if (thermal_spin)
Tomas Winklere1623442009-01-27 14:27:56 -08002947 IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n",
Zhu Yib481de92007-09-25 17:54:57 -07002948 thermal_spin * 10);
2949 } else
2950 set_bit(STATUS_RF_KILL_HW, &priv->status);
2951
Ben Cahill9fbab512007-11-29 11:09:47 +08002952 /* After the ALIVE response, we can send commands to 3945 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07002953 set_bit(STATUS_ALIVE, &priv->status);
2954
2955 /* Clear out the uCode error bit if it is set */
2956 clear_bit(STATUS_FW_ERROR, &priv->status);
2957
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002958 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002959 return;
2960
Johannes Berg36d68252008-05-15 12:55:26 +02002961 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002962
2963 priv->active_rate = priv->rates_mask;
2964 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
2965
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08002966 iwl_power_update_mode(priv, false);
Zhu Yib481de92007-09-25 17:54:57 -07002967
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002968 if (iwl_is_associated(priv)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002969 struct iwl3945_rxon_cmd *active_rxon =
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002970 (struct iwl3945_rxon_cmd *)(&priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07002971
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002972 memcpy(&priv->staging_rxon, &priv->active_rxon,
2973 sizeof(priv->staging_rxon));
Zhu Yib481de92007-09-25 17:54:57 -07002974 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2975 } else {
2976 /* Initialize our rx_config data */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002977 iwl_connection_init_rx_config(priv, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002978 }
2979
Ben Cahill9fbab512007-11-29 11:09:47 +08002980 /* Configure Bluetooth device coexistence support */
Samuel Ortiz17f841c2009-01-23 13:45:20 -08002981 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002982
2983 /* Configure the adapter for unassociated operation */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002984 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002985
Zhu Yib481de92007-09-25 17:54:57 -07002986 iwl3945_reg_txpower_periodic(priv);
2987
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07002988 iwl3945_led_register(priv);
2989
Tomas Winklere1623442009-01-27 14:27:56 -08002990 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07002991 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002992 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07002993
2994 if (priv->error_recovering)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002995 iwl3945_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002996
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08002997 /* reassociate for ADHOC mode */
2998 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
2999 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
3000 priv->vif);
3001 if (beacon)
3002 iwl3945_mac_beacon_update(priv->hw, beacon);
3003 }
3004
Zhu Yib481de92007-09-25 17:54:57 -07003005 return;
3006
3007 restart:
3008 queue_work(priv->workqueue, &priv->restart);
3009}
3010
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003011static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07003012
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003013static void __iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003014{
3015 unsigned long flags;
3016 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
3017 struct ieee80211_conf *conf = NULL;
3018
Tomas Winklere1623442009-01-27 14:27:56 -08003019 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07003020
3021 conf = ieee80211_get_hw_conf(priv->hw);
3022
3023 if (!exit_pending)
3024 set_bit(STATUS_EXIT_PENDING, &priv->status);
3025
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07003026 iwl3945_led_unregister(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003027 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003028
3029 /* Unblock any waiting calls */
3030 wake_up_interruptible_all(&priv->wait_command_queue);
3031
Zhu Yib481de92007-09-25 17:54:57 -07003032 /* Wipe out the EXIT_PENDING status bit if we are not actually
3033 * exiting the module */
3034 if (!exit_pending)
3035 clear_bit(STATUS_EXIT_PENDING, &priv->status);
3036
3037 /* stop and reset the on-board processor */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003038 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07003039
3040 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003041 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08003042 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003043 spin_unlock_irqrestore(&priv->lock, flags);
3044 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003045
3046 if (priv->mac80211_registered)
3047 ieee80211_stop_queues(priv->hw);
3048
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003049 /* If we have not previously called iwl3945_init() then
Zhu Yib481de92007-09-25 17:54:57 -07003050 * clear all bits but the RF Kill and SUSPEND bits and return */
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003051 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003052 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3053 STATUS_RF_KILL_HW |
3054 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3055 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08003056 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3057 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07003058 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003059 STATUS_IN_SUSPEND |
3060 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3061 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07003062 goto exit;
3063 }
3064
3065 /* ...otherwise clear out all the status bits but the RF Kill and
3066 * SUSPEND bits and continue taking the NIC down. */
3067 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3068 STATUS_RF_KILL_HW |
3069 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3070 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08003071 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3072 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07003073 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
3074 STATUS_IN_SUSPEND |
3075 test_bit(STATUS_FW_ERROR, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003076 STATUS_FW_ERROR |
3077 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3078 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07003079
Abbas, Mohamede9414b62009-01-20 21:33:55 -08003080 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003081 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003082 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07003083 spin_unlock_irqrestore(&priv->lock, flags);
3084
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003085 iwl3945_hw_txq_ctx_stop(priv);
3086 iwl3945_hw_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003087
3088 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003089 if (!iwl_grab_nic_access(priv)) {
3090 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07003091 APMG_CLK_VAL_DMA_CLK_RQT);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003092 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003093 }
3094 spin_unlock_irqrestore(&priv->lock, flags);
3095
3096 udelay(5);
3097
Abbas, Mohamede9414b62009-01-20 21:33:55 -08003098 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
3099 priv->cfg->ops->lib->apm_ops.stop(priv);
3100 else
3101 priv->cfg->ops->lib->apm_ops.reset(priv);
3102
Zhu Yib481de92007-09-25 17:54:57 -07003103 exit:
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08003104 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07003105
3106 if (priv->ibss_beacon)
3107 dev_kfree_skb(priv->ibss_beacon);
3108 priv->ibss_beacon = NULL;
3109
3110 /* clear out any free frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003111 iwl3945_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003112}
3113
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003114static void iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003115{
3116 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003117 __iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003118 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08003119
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003120 iwl3945_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003121}
3122
3123#define MAX_HW_RESTARTS 5
3124
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003125static int __iwl3945_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003126{
3127 int rc, i;
3128
3129 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003130 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003131 return -EIO;
3132 }
3133
3134 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003135 IWL_WARN(priv, "Radio disabled by SW RF kill (module "
Zhu Yib481de92007-09-25 17:54:57 -07003136 "parameter)\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003137 return -ENODEV;
3138 }
3139
Reinette Chatree903fbd2008-01-30 22:05:15 -08003140 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003141 IWL_ERR(priv, "ucode not available for device bring up\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08003142 return -EIO;
3143 }
3144
Zhu Yie655b9f2008-01-24 02:19:38 -08003145 /* If platform's RF_KILL switch is NOT set to KILL */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003146 if (iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yie655b9f2008-01-24 02:19:38 -08003147 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3148 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3149 else {
3150 set_bit(STATUS_RF_KILL_HW, &priv->status);
3151 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003152 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003153 return -ENODEV;
3154 }
Zhu Yib481de92007-09-25 17:54:57 -07003155 }
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02003156
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003157 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07003158
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003159 rc = iwl3945_hw_nic_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003160 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003161 IWL_ERR(priv, "Unable to int nic\n");
Zhu Yib481de92007-09-25 17:54:57 -07003162 return rc;
3163 }
3164
3165 /* make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003166 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3167 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07003168 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
3169
3170 /* clear (again), then enable host interrupts */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003171 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08003172 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003173
3174 /* really make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003175 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3176 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07003177
3178 /* Copy original ucode data image from disk into backup cache.
3179 * This will be used to initialize the on-board processor's
3180 * data SRAM for a clean start when the runtime program first loads. */
3181 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a66926a2008-01-14 17:46:18 -08003182 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07003183
Zhu Yie655b9f2008-01-24 02:19:38 -08003184 /* We return success when we resume from suspend and rf_kill is on. */
3185 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
3186 return 0;
3187
Zhu Yib481de92007-09-25 17:54:57 -07003188 for (i = 0; i < MAX_HW_RESTARTS; i++) {
3189
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003190 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003191
3192 /* load bootstrap state machine,
3193 * load bootstrap program into processor's memory,
3194 * prepare to load the "initialize" uCode */
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08003195 priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003196
3197 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003198 IWL_ERR(priv,
3199 "Unable to set up bootstrap uCode: %d\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -07003200 continue;
3201 }
3202
3203 /* start card; "initialize" will load runtime ucode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003204 iwl3945_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003205
Tomas Winklere1623442009-01-27 14:27:56 -08003206 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003207
3208 return 0;
3209 }
3210
3211 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003212 __iwl3945_down(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003213 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003214
3215 /* tried to restart and config the device for as long as our
3216 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08003217 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07003218 return -EIO;
3219}
3220
3221
3222/*****************************************************************************
3223 *
3224 * Workqueue callbacks
3225 *
3226 *****************************************************************************/
3227
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003228static void iwl3945_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003229{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003230 struct iwl_priv *priv =
3231 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003232
3233 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3234 return;
3235
3236 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003237 iwl3945_init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003238 mutex_unlock(&priv->mutex);
3239}
3240
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003241static void iwl3945_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003242{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003243 struct iwl_priv *priv =
3244 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003245
3246 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3247 return;
3248
3249 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003250 iwl3945_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003251 mutex_unlock(&priv->mutex);
3252}
3253
Helmut Schaa26635162009-01-15 09:38:44 +01003254static void iwl3945_rfkill_poll(struct work_struct *data)
3255{
3256 struct iwl_priv *priv =
3257 container_of(data, struct iwl_priv, rfkill_poll.work);
3258 unsigned long status = priv->status;
3259
3260 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3261 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3262 else
3263 set_bit(STATUS_RF_KILL_HW, &priv->status);
3264
3265 if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status))
3266 queue_work(priv->workqueue, &priv->rf_kill);
3267
3268 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3269 round_jiffies_relative(2 * HZ));
3270
3271}
3272
Zhu Yib481de92007-09-25 17:54:57 -07003273#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003274static void iwl3945_bg_request_scan(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003275{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003276 struct iwl_priv *priv =
3277 container_of(data, struct iwl_priv, request_scan);
Winkler, Tomasc2d79b482008-12-19 10:37:34 +08003278 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07003279 .id = REPLY_SCAN_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003280 .len = sizeof(struct iwl3945_scan_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07003281 .meta.flags = CMD_SIZE_HUGE,
3282 };
3283 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003284 struct iwl3945_scan_cmd *scan;
Zhu Yib481de92007-09-25 17:54:57 -07003285 struct ieee80211_conf *conf = NULL;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003286 u8 n_probes = 2;
Johannes Berg8318d782008-01-24 19:38:38 +01003287 enum ieee80211_band band;
John W. Linville9387b7c2008-09-30 20:59:05 -04003288 DECLARE_SSID_BUF(ssid);
Zhu Yib481de92007-09-25 17:54:57 -07003289
3290 conf = ieee80211_get_hw_conf(priv->hw);
3291
3292 mutex_lock(&priv->mutex);
3293
Reinette Chatrefbc9f972009-05-15 16:13:46 -07003294 cancel_delayed_work(&priv->scan_check);
3295
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003296 if (!iwl_is_ready(priv)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003297 IWL_WARN(priv, "request scan called when driver not ready.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003298 goto done;
3299 }
3300
Tomas Winklera96a27f2008-10-23 23:48:56 -07003301 /* Make sure the scan wasn't canceled before this queued work
Zhu Yib481de92007-09-25 17:54:57 -07003302 * was given the chance to run... */
3303 if (!test_bit(STATUS_SCANNING, &priv->status))
3304 goto done;
3305
3306 /* This should never be called or scheduled if there is currently
3307 * a scan active in the hardware. */
3308 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003309 IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests "
3310 "Ignoring second request.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003311 rc = -EIO;
3312 goto done;
3313 }
3314
3315 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003316 IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n");
Zhu Yib481de92007-09-25 17:54:57 -07003317 goto done;
3318 }
3319
3320 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003321 IWL_DEBUG_HC(priv,
3322 "Scan request while abort pending. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003323 goto done;
3324 }
3325
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003326 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003327 IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n");
Zhu Yib481de92007-09-25 17:54:57 -07003328 goto done;
3329 }
3330
3331 if (!test_bit(STATUS_READY, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003332 IWL_DEBUG_HC(priv,
3333 "Scan request while uninitialized. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003334 goto done;
3335 }
3336
3337 if (!priv->scan_bands) {
Tomas Winklere1623442009-01-27 14:27:56 -08003338 IWL_DEBUG_HC(priv, "Aborting scan due to no requested bands\n");
Zhu Yib481de92007-09-25 17:54:57 -07003339 goto done;
3340 }
3341
Winkler, Tomas805cee52009-01-19 15:30:28 -08003342 if (!priv->scan) {
3343 priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
Zhu Yib481de92007-09-25 17:54:57 -07003344 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
Winkler, Tomas805cee52009-01-19 15:30:28 -08003345 if (!priv->scan) {
Zhu Yib481de92007-09-25 17:54:57 -07003346 rc = -ENOMEM;
3347 goto done;
3348 }
3349 }
Winkler, Tomas805cee52009-01-19 15:30:28 -08003350 scan = priv->scan;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003351 memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07003352
3353 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
3354 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
3355
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003356 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003357 u16 interval = 0;
3358 u32 extra;
3359 u32 suspend_time = 100;
3360 u32 scan_suspend_time = 100;
3361 unsigned long flags;
3362
Tomas Winklere1623442009-01-27 14:27:56 -08003363 IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
Zhu Yib481de92007-09-25 17:54:57 -07003364
3365 spin_lock_irqsave(&priv->lock, flags);
3366 interval = priv->beacon_int;
3367 spin_unlock_irqrestore(&priv->lock, flags);
3368
3369 scan->suspend_time = 0;
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003370 scan->max_out_time = cpu_to_le32(200 * 1024);
Zhu Yib481de92007-09-25 17:54:57 -07003371 if (!interval)
3372 interval = suspend_time;
3373 /*
3374 * suspend time format:
3375 * 0-19: beacon interval in usec (time before exec.)
3376 * 20-23: 0
3377 * 24-31: number of beacons (suspend between channels)
3378 */
3379
3380 extra = (suspend_time / interval) << 24;
3381 scan_suspend_time = 0xFF0FFFFF &
3382 (extra | ((suspend_time % interval) * 1024));
3383
3384 scan->suspend_time = cpu_to_le32(scan_suspend_time);
Tomas Winklere1623442009-01-27 14:27:56 -08003385 IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003386 scan_suspend_time, interval);
3387 }
3388
3389 /* We should add the ability for user to lock to PASSIVE ONLY */
3390 if (priv->one_direct_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08003391 IWL_DEBUG_SCAN(priv, "Kicking off one direct scan for '%s'\n",
3392 print_ssid(ssid, priv->direct_ssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04003393 priv->direct_ssid_len));
Zhu Yib481de92007-09-25 17:54:57 -07003394 scan->direct_scan[0].id = WLAN_EID_SSID;
3395 scan->direct_scan[0].len = priv->direct_ssid_len;
3396 memcpy(scan->direct_scan[0].ssid,
3397 priv->direct_ssid, priv->direct_ssid_len);
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003398 n_probes++;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003399 } else
Tomas Winklere1623442009-01-27 14:27:56 -08003400 IWL_DEBUG_SCAN(priv, "Kicking off one indirect scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003401
3402 /* We don't build a direct scan probe request; the uCode will do
3403 * that based on the direct_mask added to each channel entry */
Zhu Yib481de92007-09-25 17:54:57 -07003404 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08003405 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07003406 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
3407
3408 /* flags + rate selection */
3409
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003410 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003411 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
3412 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
3413 scan->good_CRC_th = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01003414 band = IEEE80211_BAND_2GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003415 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003416 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
3417 scan->good_CRC_th = IWL_GOOD_CRC_TH;
Johannes Berg8318d782008-01-24 19:38:38 +01003418 band = IEEE80211_BAND_5GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003419 } else {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003420 IWL_WARN(priv, "Invalid scan band count\n");
Zhu Yib481de92007-09-25 17:54:57 -07003421 goto done;
3422 }
3423
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08003424 scan->tx_cmd.len = cpu_to_le16(
3425 iwl_fill_probe_req(priv, band,
3426 (struct ieee80211_mgmt *)scan->data,
3427 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
3428
Zhu Yib481de92007-09-25 17:54:57 -07003429 /* select Rx antennas */
3430 scan->flags |= iwl3945_get_antenna_flags(priv);
3431
Johannes Berg05c914f2008-09-11 00:01:58 +02003432 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
Zhu Yib481de92007-09-25 17:54:57 -07003433 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
3434
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003435 scan->channel_count =
3436 iwl3945_get_channels_for_scan(priv, band, 1, /* active */
3437 n_probes,
3438 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
Zhu Yib481de92007-09-25 17:54:57 -07003439
Reinette Chatre14b54332008-11-04 12:21:35 -08003440 if (scan->channel_count == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08003441 IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
Reinette Chatre14b54332008-11-04 12:21:35 -08003442 goto done;
3443 }
3444
Zhu Yib481de92007-09-25 17:54:57 -07003445 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003446 scan->channel_count * sizeof(struct iwl3945_scan_channel);
Zhu Yib481de92007-09-25 17:54:57 -07003447 cmd.data = scan;
3448 scan->len = cpu_to_le16(cmd.len);
3449
3450 set_bit(STATUS_SCAN_HW, &priv->status);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003451 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07003452 if (rc)
3453 goto done;
3454
3455 queue_delayed_work(priv->workqueue, &priv->scan_check,
3456 IWL_SCAN_CHECK_WATCHDOG);
3457
3458 mutex_unlock(&priv->mutex);
3459 return;
3460
3461 done:
Mohamed Abbas2420ebc2008-11-04 12:21:34 -08003462 /* can not perform scan make sure we clear scanning
3463 * bits from status so next scan request can be performed.
3464 * if we dont clear scanning status bit here all next scan
3465 * will fail
3466 */
3467 clear_bit(STATUS_SCAN_HW, &priv->status);
3468 clear_bit(STATUS_SCANNING, &priv->status);
3469
Ian Schram01ebd062007-10-25 17:15:22 +08003470 /* inform mac80211 scan aborted */
Zhu Yib481de92007-09-25 17:54:57 -07003471 queue_work(priv->workqueue, &priv->scan_completed);
3472 mutex_unlock(&priv->mutex);
3473}
3474
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003475static void iwl3945_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003476{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003477 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07003478
3479 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3480 return;
3481
3482 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003483 __iwl3945_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003484 mutex_unlock(&priv->mutex);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003485 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003486}
3487
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003488static void iwl3945_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003489{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003490 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07003491
3492 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3493 return;
3494
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003495 iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003496 queue_work(priv->workqueue, &priv->up);
3497}
3498
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003499static void iwl3945_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003500{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003501 struct iwl_priv *priv =
3502 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07003503
3504 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3505 return;
3506
3507 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003508 iwl3945_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003509 mutex_unlock(&priv->mutex);
3510}
3511
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003512#define IWL_DELAY_NEXT_SCAN (HZ*2)
3513
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003514static void iwl3945_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003515{
Zhu Yib481de92007-09-25 17:54:57 -07003516 int rc = 0;
3517 struct ieee80211_conf *conf = NULL;
3518
Johannes Berg05c914f2008-09-11 00:01:58 +02003519 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003520 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07003521 return;
3522 }
3523
3524
Tomas Winklere1623442009-01-27 14:27:56 -08003525 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003526 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07003527
3528 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3529 return;
3530
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003531 if (!priv->vif || !priv->is_open)
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003532 return;
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003533
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003534 iwl_scan_cancel_timeout(priv, 200);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003535
Zhu Yib481de92007-09-25 17:54:57 -07003536 conf = ieee80211_get_hw_conf(priv->hw);
3537
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003538 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003539 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003540
Tomas Winkler28afaf92008-12-19 10:37:06 +08003541 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003542 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003543 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07003544 sizeof(priv->rxon_timing), &priv->rxon_timing);
3545 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003546 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003547 "Attempting to continue.\n");
3548
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003549 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003550
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003551 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003552
Tomas Winklere1623442009-01-27 14:27:56 -08003553 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003554 priv->assoc_id, priv->beacon_int);
3555
3556 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003557 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003558 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003559 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003560
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003561 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003562 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003563 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003564 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003565 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003566
Johannes Berg05c914f2008-09-11 00:01:58 +02003567 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003568 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003569
3570 }
3571
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003572 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003573
3574 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02003575 case NL80211_IFTYPE_STATION:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003576 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07003577 break;
3578
Johannes Berg05c914f2008-09-11 00:01:58 +02003579 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07003580
Abhijeet Kolekarce546fd2008-11-19 15:32:22 -08003581 priv->assoc_id = 1;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003582 iwl3945_add_station(priv, priv->bssid, 0, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003583 iwl3945_sync_sta(priv, IWL_STA_ID,
Johannes Berg8318d782008-01-24 19:38:38 +01003584 (priv->band == IEEE80211_BAND_5GHZ) ?
Zhu Yib481de92007-09-25 17:54:57 -07003585 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
3586 CMD_ASYNC);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003587 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
3588 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003589
3590 break;
3591
3592 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08003593 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003594 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003595 break;
3596 }
3597
Abhijeet Kolekar14d2aac2009-02-27 16:21:24 -08003598 iwl_activate_qos(priv, 0);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08003599
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003600 /* we have just associated, don't start scan too early */
3601 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08003602}
3603
Johannes Berge8975582008-10-09 12:18:51 +02003604static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003605
Zhu Yib481de92007-09-25 17:54:57 -07003606/*****************************************************************************
3607 *
3608 * mac80211 entry point functions
3609 *
3610 *****************************************************************************/
3611
Zhu Yi5a66926a2008-01-14 17:46:18 -08003612#define UCODE_READY_TIMEOUT (2 * HZ)
3613
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003614static int iwl3945_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003615{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003616 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003617 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003618
Tomas Winklere1623442009-01-27 14:27:56 -08003619 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003620
3621 /* we should be verifying the device is ready to be opened */
3622 mutex_lock(&priv->mutex);
3623
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003624 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
Zhu Yi5a66926a2008-01-14 17:46:18 -08003625 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
3626 * ucode filename and max sizes are card-specific. */
3627
3628 if (!priv->ucode_code.len) {
3629 ret = iwl3945_read_ucode(priv);
3630 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003631 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003632 mutex_unlock(&priv->mutex);
3633 goto out_release_irq;
3634 }
3635 }
3636
Zhu Yie655b9f2008-01-24 02:19:38 -08003637 ret = __iwl3945_up(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003638
Zhu Yib481de92007-09-25 17:54:57 -07003639 mutex_unlock(&priv->mutex);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003640
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003641 iwl_rfkill_set_hw_state(priv);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02003642
Zhu Yie655b9f2008-01-24 02:19:38 -08003643 if (ret)
3644 goto out_release_irq;
3645
Tomas Winklere1623442009-01-27 14:27:56 -08003646 IWL_DEBUG_INFO(priv, "Start UP work.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003647
3648 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
3649 return 0;
3650
Zhu Yi5a66926a2008-01-14 17:46:18 -08003651 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
3652 * mac80211 will not be run successfully. */
3653 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
3654 test_bit(STATUS_READY, &priv->status),
3655 UCODE_READY_TIMEOUT);
3656 if (!ret) {
3657 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003658 IWL_ERR(priv,
3659 "Wait for START_ALIVE timeout after %dms.\n",
3660 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Zhu Yi5a66926a2008-01-14 17:46:18 -08003661 ret = -ETIMEDOUT;
3662 goto out_release_irq;
3663 }
3664 }
3665
Helmut Schaa26635162009-01-15 09:38:44 +01003666 /* ucode is running and will send rfkill notifications,
3667 * no need to poll the killswitch state anymore */
3668 cancel_delayed_work(&priv->rfkill_poll);
3669
Zhu Yie655b9f2008-01-24 02:19:38 -08003670 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08003671 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003672 return 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003673
3674out_release_irq:
Zhu Yie655b9f2008-01-24 02:19:38 -08003675 priv->is_open = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08003676 IWL_DEBUG_MAC80211(priv, "leave - failed\n");
Zhu Yi5a66926a2008-01-14 17:46:18 -08003677 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003678}
3679
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003680static void iwl3945_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003681{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003682 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003683
Tomas Winklere1623442009-01-27 14:27:56 -08003684 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003685
Zhu Yie655b9f2008-01-24 02:19:38 -08003686 if (!priv->is_open) {
Tomas Winklere1623442009-01-27 14:27:56 -08003687 IWL_DEBUG_MAC80211(priv, "leave - skip\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003688 return;
3689 }
3690
Zhu Yib481de92007-09-25 17:54:57 -07003691 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003692
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003693 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08003694 /* stop mac, cancel any scan request and clear
3695 * RXON_FILTER_ASSOC_MSK BIT
3696 */
Zhu Yi5a66926a2008-01-14 17:46:18 -08003697 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003698 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003699 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003700 }
3701
Zhu Yi5a66926a2008-01-14 17:46:18 -08003702 iwl3945_down(priv);
3703
3704 flush_workqueue(priv->workqueue);
Helmut Schaa26635162009-01-15 09:38:44 +01003705
3706 /* start polling the killswitch state again */
3707 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3708 round_jiffies_relative(2 * HZ));
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003709
Tomas Winklere1623442009-01-27 14:27:56 -08003710 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003711}
3712
Johannes Berge039fa42008-05-15 12:55:29 +02003713static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003714{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003715 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003716
Tomas Winklere1623442009-01-27 14:27:56 -08003717 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003718
Tomas Winklere1623442009-01-27 14:27:56 -08003719 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02003720 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07003721
Johannes Berge039fa42008-05-15 12:55:29 +02003722 if (iwl3945_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07003723 dev_kfree_skb_any(skb);
3724
Tomas Winklere1623442009-01-27 14:27:56 -08003725 IWL_DEBUG_MAC80211(priv, "leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08003726 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07003727}
3728
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003729static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003730 struct ieee80211_if_init_conf *conf)
3731{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003732 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003733 unsigned long flags;
3734
Tomas Winklere1623442009-01-27 14:27:56 -08003735 IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07003736
Johannes Berg32bfd352007-12-19 01:31:26 +01003737 if (priv->vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08003738 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
Tomas Winkler864792e2007-11-27 21:00:52 +02003739 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07003740 }
3741
3742 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01003743 priv->vif = conf->vif;
Zhu, Yi60294de2008-10-29 14:05:45 -07003744 priv->iw_mode = conf->type;
Zhu Yib481de92007-09-25 17:54:57 -07003745
3746 spin_unlock_irqrestore(&priv->lock, flags);
3747
3748 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02003749
3750 if (conf->mac_addr) {
Tomas Winklere1623442009-01-27 14:27:56 -08003751 IWL_DEBUG_MAC80211(priv, "Set: %pM\n", conf->mac_addr);
Tomas Winkler864792e2007-11-27 21:00:52 +02003752 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
3753 }
3754
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003755 if (iwl_is_ready(priv))
Zhu Yi5a66926a2008-01-14 17:46:18 -08003756 iwl3945_set_mode(priv, conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07003757
Zhu Yib481de92007-09-25 17:54:57 -07003758 mutex_unlock(&priv->mutex);
3759
Tomas Winklere1623442009-01-27 14:27:56 -08003760 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003761 return 0;
3762}
3763
3764/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003765 * iwl3945_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07003766 *
3767 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
3768 * be set inappropriately and the driver currently sets the hardware up to
3769 * use it whenever needed.
3770 */
Johannes Berge8975582008-10-09 12:18:51 +02003771static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed)
Zhu Yib481de92007-09-25 17:54:57 -07003772{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003773 struct iwl_priv *priv = hw->priv;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08003774 const struct iwl_channel_info *ch_info;
Johannes Berge8975582008-10-09 12:18:51 +02003775 struct ieee80211_conf *conf = &hw->conf;
Zhu Yib481de92007-09-25 17:54:57 -07003776 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08003777 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003778
3779 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08003780 IWL_DEBUG_MAC80211(priv, "enter to channel %d\n",
3781 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07003782
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003783 if (!iwl_is_ready(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003784 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08003785 ret = -EIO;
3786 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003787 }
3788
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08003789 if (unlikely(!iwl3945_mod_params.disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07003790 test_bit(STATUS_SCANNING, &priv->status))) {
Tomas Winklere1623442009-01-27 14:27:56 -08003791 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
Zhu Yia0646472007-12-20 14:10:01 +08003792 set_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003793 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08003794 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07003795 }
3796
3797 spin_lock_irqsave(&priv->lock, flags);
3798
Samuel Ortize6148912009-01-23 13:45:15 -08003799 ch_info = iwl_get_channel_info(priv, conf->channel->band,
3800 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07003801 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003802 IWL_DEBUG_SCAN(priv,
3803 "Channel %d [%d] is INVALID for this band.\n",
3804 conf->channel->hw_value, conf->channel->band);
3805 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
Zhu Yib481de92007-09-25 17:54:57 -07003806 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003807 ret = -EINVAL;
3808 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003809 }
3810
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003811 iwl_set_rxon_channel(priv, conf->channel);
Zhu Yib481de92007-09-25 17:54:57 -07003812
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003813 iwl_set_flags_for_band(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07003814
3815 /* The list of supported rates and rate mask can be different
3816 * for each phymode; since the phymode may have changed, reset
3817 * the rate mask to what mac80211 lists */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003818 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003819
3820 spin_unlock_irqrestore(&priv->lock, flags);
3821
3822#ifdef IEEE80211_CONF_CHANNEL_SWITCH
3823 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003824 iwl3945_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003825 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003826 }
3827#endif
3828
Mohamed Abbas37fec382009-03-17 21:51:42 -07003829 if (changed & IEEE80211_CONF_CHANGE_RADIO_ENABLED) {
3830 if (conf->radio_enabled &&
3831 iwl_radio_kill_sw_enable_radio(priv)) {
3832 IWL_DEBUG_MAC80211(priv, "leave - RF-KILL - "
3833 "waiting for uCode\n");
3834 goto out;
3835 }
Zhu Yib481de92007-09-25 17:54:57 -07003836
Mohamed Abbas37fec382009-03-17 21:51:42 -07003837 if (!conf->radio_enabled) {
3838 iwl_radio_kill_sw_disable_radio(priv);
3839 IWL_DEBUG_MAC80211(priv, "leave - radio disabled\n");
3840 goto out;
3841 }
Zhu Yib481de92007-09-25 17:54:57 -07003842 }
3843
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003844 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003845 IWL_DEBUG_MAC80211(priv, "leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08003846 ret = -EIO;
3847 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003848 }
3849
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003850 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003851
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003852 if (memcmp(&priv->active_rxon,
3853 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003854 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003855 else
Tomas Winklere1623442009-01-27 14:27:56 -08003856 IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration\n");
Zhu Yib481de92007-09-25 17:54:57 -07003857
Tomas Winklere1623442009-01-27 14:27:56 -08003858 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003859
Zhu Yi76bb77e2007-11-22 10:53:22 +08003860out:
Zhu Yia0646472007-12-20 14:10:01 +08003861 clear_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003862 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003863 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003864}
3865
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003866static void iwl3945_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003867{
3868 int rc = 0;
3869
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08003870 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07003871 return;
3872
3873 /* The following should be done only at AP bring up */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003874 if (!(iwl_is_associated(priv))) {
Zhu Yib481de92007-09-25 17:54:57 -07003875
3876 /* RXON - unassoc (to set timing command) */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003877 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003878 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003879
3880 /* RXON Timing */
Tomas Winkler28afaf92008-12-19 10:37:06 +08003881 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003882 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003883 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
3884 sizeof(priv->rxon_timing),
3885 &priv->rxon_timing);
Zhu Yib481de92007-09-25 17:54:57 -07003886 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003887 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003888 "Attempting to continue.\n");
3889
3890 /* FIXME: what should be the assoc_id for AP? */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003891 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003892 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003893 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003894 RXON_FLG_SHORT_PREAMBLE_MSK;
3895 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003896 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003897 ~RXON_FLG_SHORT_PREAMBLE_MSK;
3898
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003899 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003900 if (priv->assoc_capability &
3901 WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003902 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003903 RXON_FLG_SHORT_SLOT_MSK;
3904 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003905 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003906 ~RXON_FLG_SHORT_SLOT_MSK;
3907
Johannes Berg05c914f2008-09-11 00:01:58 +02003908 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003909 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003910 ~RXON_FLG_SHORT_SLOT_MSK;
3911 }
3912 /* restore RXON assoc */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003913 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003914 iwl3945_commit_rxon(priv);
Kolekar, Abhijeetb5323d32008-12-19 10:37:22 +08003915 iwl3945_add_station(priv, iwl_bcast_addr, 0, 0);
Zhu Yi556f8db2007-09-27 11:27:33 +08003916 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003917 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003918
3919 /* FIXME - we need to add code here to detect a totally new
3920 * configuration, reset the AP, unassoc, rxon timing, assoc,
3921 * clear sta table, add BCAST sta... */
3922}
3923
Johannes Berg32bfd352007-12-19 01:31:26 +01003924static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
3925 struct ieee80211_vif *vif,
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003926 struct ieee80211_if_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07003927{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003928 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003929 int rc;
3930
3931 if (conf == NULL)
3932 return -EIO;
3933
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08003934 if (priv->vif != vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08003935 IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08003936 return 0;
3937 }
3938
Johannes Berg9d139c82008-07-09 14:40:37 +02003939 /* handle this temporarily here */
Johannes Berg05c914f2008-09-11 00:01:58 +02003940 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Johannes Berg9d139c82008-07-09 14:40:37 +02003941 conf->changed & IEEE80211_IFCC_BEACON) {
3942 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
3943 if (!beacon)
3944 return -ENOMEM;
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003945 mutex_lock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02003946 rc = iwl3945_mac_beacon_update(hw, beacon);
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003947 mutex_unlock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02003948 if (rc)
3949 return rc;
3950 }
3951
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003952 if (!iwl_is_alive(priv))
Zhu Yi5a66926a2008-01-14 17:46:18 -08003953 return -EAGAIN;
3954
Zhu Yib481de92007-09-25 17:54:57 -07003955 mutex_lock(&priv->mutex);
3956
Zhu Yib481de92007-09-25 17:54:57 -07003957 if (conf->bssid)
Tomas Winklere1623442009-01-27 14:27:56 -08003958 IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07003959
Johannes Berg4150c572007-09-17 01:29:23 -04003960/*
3961 * very dubious code was here; the probe filtering flag is never set:
3962 *
Zhu Yib481de92007-09-25 17:54:57 -07003963 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
3964 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04003965 */
Zhu Yib481de92007-09-25 17:54:57 -07003966
Johannes Berg05c914f2008-09-11 00:01:58 +02003967 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07003968 if (!conf->bssid) {
3969 conf->bssid = priv->mac_addr;
3970 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08003971 IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07003972 conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07003973 }
3974 if (priv->ibss_beacon)
3975 dev_kfree_skb(priv->ibss_beacon);
3976
Johannes Berg9d139c82008-07-09 14:40:37 +02003977 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
Zhu Yib481de92007-09-25 17:54:57 -07003978 }
3979
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003980 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08003981 goto done;
3982
Zhu Yib481de92007-09-25 17:54:57 -07003983 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
3984 !is_multicast_ether_addr(conf->bssid)) {
3985 /* If there is currently a HW scan going on in the background
3986 * then we need to cancel it else the RXON below will fail. */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003987 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003988 IWL_WARN(priv, "Aborted scan still in progress "
Zhu Yib481de92007-09-25 17:54:57 -07003989 "after 100ms\n");
Tomas Winklere1623442009-01-27 14:27:56 -08003990 IWL_DEBUG_MAC80211(priv, "leaving:scan abort failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07003991 mutex_unlock(&priv->mutex);
3992 return -EAGAIN;
3993 }
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003994 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07003995
3996 /* TODO: Audit driver for usage of these members and see
3997 * if mac80211 deprecates them (priv->bssid looks like it
3998 * shouldn't be there, but I haven't scanned the IBSS code
3999 * to verify) - jpk */
4000 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
4001
Johannes Berg05c914f2008-09-11 00:01:58 +02004002 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004003 iwl3945_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004004 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004005 rc = iwl3945_commit_rxon(priv);
Johannes Berg05c914f2008-09-11 00:01:58 +02004006 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004007 iwl3945_add_station(priv,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004008 priv->active_rxon.bssid_addr, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004009 }
4010
4011 } else {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004012 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004013 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004014 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004015 }
4016
Mohamed Abbasfde35712007-11-29 11:10:15 +08004017 done:
Tomas Winklere1623442009-01-27 14:27:56 -08004018 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004019 mutex_unlock(&priv->mutex);
4020
4021 return 0;
4022}
4023
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004024static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004025 struct ieee80211_if_init_conf *conf)
4026{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004027 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004028
Tomas Winklere1623442009-01-27 14:27:56 -08004029 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004030
4031 mutex_lock(&priv->mutex);
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004032
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004033 if (iwl_is_ready_rf(priv)) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004034 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004035 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Mohamed Abbasfde35712007-11-29 11:10:15 +08004036 iwl3945_commit_rxon(priv);
4037 }
Johannes Berg32bfd352007-12-19 01:31:26 +01004038 if (priv->vif == conf->vif) {
4039 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07004040 memset(priv->bssid, 0, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07004041 }
4042 mutex_unlock(&priv->mutex);
4043
Tomas Winklere1623442009-01-27 14:27:56 -08004044 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004045}
4046
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004047#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
4048
4049static void iwl3945_bss_info_changed(struct ieee80211_hw *hw,
4050 struct ieee80211_vif *vif,
4051 struct ieee80211_bss_conf *bss_conf,
4052 u32 changes)
4053{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004054 struct iwl_priv *priv = hw->priv;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004055
Tomas Winklere1623442009-01-27 14:27:56 -08004056 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004057
4058 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
Tomas Winklere1623442009-01-27 14:27:56 -08004059 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004060 bss_conf->use_short_preamble);
4061 if (bss_conf->use_short_preamble)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004062 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004063 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004064 priv->staging_rxon.flags &=
4065 ~RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004066 }
4067
4068 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
Tomas Winklere1623442009-01-27 14:27:56 -08004069 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n",
4070 bss_conf->use_cts_prot);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004071 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004072 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004073 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004074 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004075 }
4076
4077 if (changes & BSS_CHANGED_ASSOC) {
Tomas Winklere1623442009-01-27 14:27:56 -08004078 IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004079 /* This should never happen as this function should
4080 * never be called from interrupt context. */
4081 if (WARN_ON_ONCE(in_interrupt()))
4082 return;
4083 if (bss_conf->assoc) {
4084 priv->assoc_id = bss_conf->aid;
4085 priv->beacon_int = bss_conf->beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08004086 priv->timestamp = bss_conf->timestamp;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004087 priv->assoc_capability = bss_conf->assoc_capability;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08004088 priv->power_data.dtim_period = bss_conf->dtim_period;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004089 priv->next_scan_jiffies = jiffies +
4090 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
4091 mutex_lock(&priv->mutex);
4092 iwl3945_post_associate(priv);
4093 mutex_unlock(&priv->mutex);
4094 } else {
4095 priv->assoc_id = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08004096 IWL_DEBUG_MAC80211(priv,
4097 "DISASSOC %d\n", bss_conf->assoc);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004098 }
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004099 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
Tomas Winklere1623442009-01-27 14:27:56 -08004100 IWL_DEBUG_MAC80211(priv,
4101 "Associated Changes %d\n", changes);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004102 iwl3945_send_rxon_assoc(priv);
4103 }
4104
4105}
4106
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004107static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01004108 struct ieee80211_vif *vif,
4109 struct ieee80211_sta *sta,
4110 struct ieee80211_key_conf *key)
Zhu Yib481de92007-09-25 17:54:57 -07004111{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004112 struct iwl_priv *priv = hw->priv;
Johannes Bergdc822b52008-12-29 12:55:09 +01004113 const u8 *addr;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08004114 int ret = 0;
4115 u8 sta_id = IWL_INVALID_STATION;
4116 u8 static_key;
Zhu Yib481de92007-09-25 17:54:57 -07004117
Tomas Winklere1623442009-01-27 14:27:56 -08004118 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004119
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004120 if (iwl3945_mod_params.sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08004121 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07004122 return -EOPNOTSUPP;
4123 }
4124
Winkler, Tomas42986792009-01-19 15:30:22 -08004125 addr = sta ? sta->addr : iwl_bcast_addr;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08004126 static_key = !iwl_is_associated(priv);
4127
4128 if (!static_key) {
4129 sta_id = iwl3945_hw_find_station(priv, addr);
4130 if (sta_id == IWL_INVALID_STATION) {
Joe Perches12514392009-04-16 16:23:26 -07004131 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08004132 addr);
4133 return -EINVAL;
4134 }
Zhu Yib481de92007-09-25 17:54:57 -07004135 }
4136
4137 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004138 iwl_scan_cancel_timeout(priv, 100);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08004139 mutex_unlock(&priv->mutex);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004140
Zhu Yib481de92007-09-25 17:54:57 -07004141 switch (cmd) {
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08004142 case SET_KEY:
4143 if (static_key)
4144 ret = iwl3945_set_static_key(priv, key);
4145 else
4146 ret = iwl3945_set_dynamic_key(priv, key, sta_id);
4147 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07004148 break;
4149 case DISABLE_KEY:
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08004150 if (static_key)
4151 ret = iwl3945_remove_static_key(priv);
4152 else
4153 ret = iwl3945_clear_sta_key_info(priv, sta_id);
4154 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07004155 break;
4156 default:
Winkler, Tomas42986792009-01-19 15:30:22 -08004157 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07004158 }
4159
Tomas Winklere1623442009-01-27 14:27:56 -08004160 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004161
Winkler, Tomas42986792009-01-19 15:30:22 -08004162 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004163}
4164
Johannes Berge100bb62008-04-30 18:51:21 +02004165static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
Zhu Yib481de92007-09-25 17:54:57 -07004166 const struct ieee80211_tx_queue_params *params)
4167{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004168 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004169 unsigned long flags;
4170 int q;
Zhu Yib481de92007-09-25 17:54:57 -07004171
Tomas Winklere1623442009-01-27 14:27:56 -08004172 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004173
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004174 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004175 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004176 return -EIO;
4177 }
4178
4179 if (queue >= AC_NUM) {
Tomas Winklere1623442009-01-27 14:27:56 -08004180 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
Zhu Yib481de92007-09-25 17:54:57 -07004181 return 0;
4182 }
4183
Zhu Yib481de92007-09-25 17:54:57 -07004184 q = AC_NUM - 1 - queue;
4185
4186 spin_lock_irqsave(&priv->lock, flags);
4187
4188 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
4189 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
4190 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
4191 priv->qos_data.def_qos_parm.ac[q].edca_txop =
Johannes Berg3330d7b2008-02-10 16:49:38 +01004192 cpu_to_le16((params->txop * 32));
Zhu Yib481de92007-09-25 17:54:57 -07004193
4194 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
4195 priv->qos_data.qos_active = 1;
4196
4197 spin_unlock_irqrestore(&priv->lock, flags);
4198
4199 mutex_lock(&priv->mutex);
Johannes Berg05c914f2008-09-11 00:01:58 +02004200 if (priv->iw_mode == NL80211_IFTYPE_AP)
Abhijeet Kolekar14d2aac2009-02-27 16:21:24 -08004201 iwl_activate_qos(priv, 1);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004202 else if (priv->assoc_id && iwl_is_associated(priv))
Abhijeet Kolekar14d2aac2009-02-27 16:21:24 -08004203 iwl_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004204
4205 mutex_unlock(&priv->mutex);
4206
Tomas Winklere1623442009-01-27 14:27:56 -08004207 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004208 return 0;
4209}
4210
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004211static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004212 struct ieee80211_tx_queue_stats *stats)
4213{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004214 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004215 int i, avail;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08004216 struct iwl_tx_queue *txq;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004217 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07004218 unsigned long flags;
4219
Tomas Winklere1623442009-01-27 14:27:56 -08004220 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004221
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004222 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004223 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004224 return -EIO;
4225 }
4226
4227 spin_lock_irqsave(&priv->lock, flags);
4228
4229 for (i = 0; i < AC_NUM; i++) {
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08004230 txq = &priv->txq[i];
Zhu Yib481de92007-09-25 17:54:57 -07004231 q = &txq->q;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004232 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07004233
Johannes Berg57ffc582008-04-29 17:18:59 +02004234 stats[i].len = q->n_window - avail;
4235 stats[i].limit = q->n_window - q->high_mark;
4236 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07004237
4238 }
4239 spin_unlock_irqrestore(&priv->lock, flags);
4240
Tomas Winklere1623442009-01-27 14:27:56 -08004241 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004242
4243 return 0;
4244}
4245
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004246static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07004247{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004248 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004249 unsigned long flags;
4250
4251 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08004252 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004253
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004254 iwl_reset_qos(priv);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08004255
Zhu Yib481de92007-09-25 17:54:57 -07004256 spin_lock_irqsave(&priv->lock, flags);
4257 priv->assoc_id = 0;
4258 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004259
4260 /* new association get rid of ibss beacon skb */
4261 if (priv->ibss_beacon)
4262 dev_kfree_skb(priv->ibss_beacon);
4263
4264 priv->ibss_beacon = NULL;
4265
4266 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08004267 priv->timestamp = 0;
Johannes Berg05c914f2008-09-11 00:01:58 +02004268 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
Zhu Yib481de92007-09-25 17:54:57 -07004269 priv->beacon_int = 0;
4270
4271 spin_unlock_irqrestore(&priv->lock, flags);
4272
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004273 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004274 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +08004275 mutex_unlock(&priv->mutex);
4276 return;
4277 }
4278
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004279 /* we are restarting association process
4280 * clear RXON_FILTER_ASSOC_MSK bit
4281 */
Johannes Berg05c914f2008-09-11 00:01:58 +02004282 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004283 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004284 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004285 iwl3945_commit_rxon(priv);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004286 }
4287
Zhu Yib481de92007-09-25 17:54:57 -07004288 /* Per mac80211.h: This is only used in IBSS mode... */
Johannes Berg05c914f2008-09-11 00:01:58 +02004289 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004290
Tomas Winklere1623442009-01-27 14:27:56 -08004291 IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07004292 mutex_unlock(&priv->mutex);
4293 return;
4294 }
4295
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004296 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004297
4298 mutex_unlock(&priv->mutex);
4299
Tomas Winklere1623442009-01-27 14:27:56 -08004300 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004301
4302}
4303
Johannes Berge039fa42008-05-15 12:55:29 +02004304static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07004305{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004306 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004307 unsigned long flags;
Abhijeet Kolekar7c4cbb62009-02-27 16:21:20 -08004308 __le64 timestamp;
Zhu Yib481de92007-09-25 17:54:57 -07004309
Tomas Winklere1623442009-01-27 14:27:56 -08004310 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004311
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004312 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004313 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004314 return -EIO;
4315 }
4316
Johannes Berg05c914f2008-09-11 00:01:58 +02004317 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Tomas Winklere1623442009-01-27 14:27:56 -08004318 IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07004319 return -EIO;
4320 }
4321
4322 spin_lock_irqsave(&priv->lock, flags);
4323
4324 if (priv->ibss_beacon)
4325 dev_kfree_skb(priv->ibss_beacon);
4326
4327 priv->ibss_beacon = skb;
4328
4329 priv->assoc_id = 0;
Abhijeet Kolekar7c4cbb62009-02-27 16:21:20 -08004330 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
4331 priv->timestamp = le64_to_cpu(timestamp);
Zhu Yib481de92007-09-25 17:54:57 -07004332
Tomas Winklere1623442009-01-27 14:27:56 -08004333 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004334 spin_unlock_irqrestore(&priv->lock, flags);
4335
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004336 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004337
Abhijeet Kolekardc4b1e72008-09-03 11:26:30 +08004338 iwl3945_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004339
Zhu Yib481de92007-09-25 17:54:57 -07004340
4341 return 0;
4342}
4343
4344/*****************************************************************************
4345 *
4346 * sysfs attributes
4347 *
4348 *****************************************************************************/
4349
Samuel Ortizd08853a2009-01-23 13:45:17 -08004350#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07004351
4352/*
4353 * The following adds a new attribute to the sysfs representation
4354 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
4355 * used for controlling the debug level.
4356 *
4357 * See the level definitions in iwl for details.
4358 */
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004359static ssize_t show_debug_level(struct device *d,
4360 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07004361{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004362 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004363
4364 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07004365}
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004366static ssize_t store_debug_level(struct device *d,
4367 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07004368 const char *buf, size_t count)
4369{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004370 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004371 unsigned long val;
4372 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07004373
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004374 ret = strict_strtoul(buf, 0, &val);
4375 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08004376 IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07004377 else
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004378 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07004379
4380 return strnlen(buf, count);
4381}
4382
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004383static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
4384 show_debug_level, store_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07004385
Samuel Ortizd08853a2009-01-23 13:45:17 -08004386#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07004387
Zhu Yib481de92007-09-25 17:54:57 -07004388static ssize_t show_temperature(struct device *d,
4389 struct device_attribute *attr, char *buf)
4390{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004391 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004392
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004393 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004394 return -EAGAIN;
4395
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004396 return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
Zhu Yib481de92007-09-25 17:54:57 -07004397}
4398
4399static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
4400
Zhu Yib481de92007-09-25 17:54:57 -07004401static ssize_t show_tx_power(struct device *d,
4402 struct device_attribute *attr, char *buf)
4403{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004404 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08004405 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07004406}
4407
4408static ssize_t store_tx_power(struct device *d,
4409 struct device_attribute *attr,
4410 const char *buf, size_t count)
4411{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004412 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004413 char *p = (char *)buf;
4414 u32 val;
4415
4416 val = simple_strtoul(p, &p, 10);
4417 if (p == buf)
Tomas Winkler978785a2008-12-19 10:37:31 +08004418 IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07004419 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004420 iwl3945_hw_reg_set_txpower(priv, val);
Zhu Yib481de92007-09-25 17:54:57 -07004421
4422 return count;
4423}
4424
4425static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
4426
4427static ssize_t show_flags(struct device *d,
4428 struct device_attribute *attr, char *buf)
4429{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004430 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004431
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004432 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
Zhu Yib481de92007-09-25 17:54:57 -07004433}
4434
4435static ssize_t store_flags(struct device *d,
4436 struct device_attribute *attr,
4437 const char *buf, size_t count)
4438{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004439 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004440 u32 flags = simple_strtoul(buf, NULL, 0);
4441
4442 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004443 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
Zhu Yib481de92007-09-25 17:54:57 -07004444 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004445 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004446 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004447 else {
Tomas Winklere1623442009-01-27 14:27:56 -08004448 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
Zhu Yib481de92007-09-25 17:54:57 -07004449 flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004450 priv->staging_rxon.flags = cpu_to_le32(flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004451 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004452 }
4453 }
4454 mutex_unlock(&priv->mutex);
4455
4456 return count;
4457}
4458
4459static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
4460
4461static ssize_t show_filter_flags(struct device *d,
4462 struct device_attribute *attr, char *buf)
4463{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004464 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004465
4466 return sprintf(buf, "0x%04X\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004467 le32_to_cpu(priv->active_rxon.filter_flags));
Zhu Yib481de92007-09-25 17:54:57 -07004468}
4469
4470static ssize_t store_filter_flags(struct device *d,
4471 struct device_attribute *attr,
4472 const char *buf, size_t count)
4473{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004474 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004475 u32 filter_flags = simple_strtoul(buf, NULL, 0);
4476
4477 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004478 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
Zhu Yib481de92007-09-25 17:54:57 -07004479 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004480 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004481 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004482 else {
Tomas Winklere1623442009-01-27 14:27:56 -08004483 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
Zhu Yib481de92007-09-25 17:54:57 -07004484 "0x%04X\n", filter_flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004485 priv->staging_rxon.filter_flags =
Zhu Yib481de92007-09-25 17:54:57 -07004486 cpu_to_le32(filter_flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004487 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004488 }
4489 }
4490 mutex_unlock(&priv->mutex);
4491
4492 return count;
4493}
4494
4495static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
4496 store_filter_flags);
4497
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004498#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004499
4500static ssize_t show_measurement(struct device *d,
4501 struct device_attribute *attr, char *buf)
4502{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004503 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler600c0e12008-12-19 10:37:04 +08004504 struct iwl_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004505 u32 size = sizeof(measure_report), len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03004506 u8 *data = (u8 *)&measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004507 unsigned long flags;
4508
4509 spin_lock_irqsave(&priv->lock, flags);
4510 if (!(priv->measurement_status & MEASUREMENT_READY)) {
4511 spin_unlock_irqrestore(&priv->lock, flags);
4512 return 0;
4513 }
4514 memcpy(&measure_report, &priv->measure_report, size);
4515 priv->measurement_status = 0;
4516 spin_unlock_irqrestore(&priv->lock, flags);
4517
4518 while (size && (PAGE_SIZE - len)) {
4519 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4520 PAGE_SIZE - len, 1);
4521 len = strlen(buf);
4522 if (PAGE_SIZE - len)
4523 buf[len++] = '\n';
4524
4525 ofs += 16;
4526 size -= min(size, 16U);
4527 }
4528
4529 return len;
4530}
4531
4532static ssize_t store_measurement(struct device *d,
4533 struct device_attribute *attr,
4534 const char *buf, size_t count)
4535{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004536 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004537 struct ieee80211_measurement_params params = {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004538 .channel = le16_to_cpu(priv->active_rxon.channel),
Zhu Yib481de92007-09-25 17:54:57 -07004539 .start_time = cpu_to_le64(priv->last_tsf),
4540 .duration = cpu_to_le16(1),
4541 };
4542 u8 type = IWL_MEASURE_BASIC;
4543 u8 buffer[32];
4544 u8 channel;
4545
4546 if (count) {
4547 char *p = buffer;
4548 strncpy(buffer, buf, min(sizeof(buffer), count));
4549 channel = simple_strtoul(p, NULL, 0);
4550 if (channel)
4551 params.channel = channel;
4552
4553 p = buffer;
4554 while (*p && *p != ' ')
4555 p++;
4556 if (*p)
4557 type = simple_strtoul(p + 1, NULL, 0);
4558 }
4559
Tomas Winklere1623442009-01-27 14:27:56 -08004560 IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on "
Zhu Yib481de92007-09-25 17:54:57 -07004561 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004562 iwl3945_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07004563
4564 return count;
4565}
4566
4567static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
4568 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004569#endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07004570
Zhu Yib481de92007-09-25 17:54:57 -07004571static ssize_t store_retry_rate(struct device *d,
4572 struct device_attribute *attr,
4573 const char *buf, size_t count)
4574{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004575 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004576
4577 priv->retry_rate = simple_strtoul(buf, NULL, 0);
4578 if (priv->retry_rate <= 0)
4579 priv->retry_rate = 1;
4580
4581 return count;
4582}
4583
4584static ssize_t show_retry_rate(struct device *d,
4585 struct device_attribute *attr, char *buf)
4586{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004587 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004588 return sprintf(buf, "%d", priv->retry_rate);
4589}
4590
4591static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
4592 store_retry_rate);
4593
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004594
Zhu Yib481de92007-09-25 17:54:57 -07004595static ssize_t store_power_level(struct device *d,
4596 struct device_attribute *attr,
4597 const char *buf, size_t count)
4598{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004599 struct iwl_priv *priv = dev_get_drvdata(d);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004600 int ret;
4601 unsigned long mode;
Zhu Yib481de92007-09-25 17:54:57 -07004602
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004603
Zhu Yib481de92007-09-25 17:54:57 -07004604 mutex_lock(&priv->mutex);
4605
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004606 ret = strict_strtoul(buf, 10, &mode);
4607 if (ret)
4608 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004609
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004610 ret = iwl_power_set_user_mode(priv, mode);
4611 if (ret) {
4612 IWL_DEBUG_MAC80211(priv, "failed setting power mode.\n");
4613 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004614 }
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004615 ret = count;
Zhu Yib481de92007-09-25 17:54:57 -07004616
4617 out:
4618 mutex_unlock(&priv->mutex);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004619 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004620}
4621
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004622static ssize_t show_power_level(struct device *d,
4623 struct device_attribute *attr, char *buf)
4624{
4625 struct iwl_priv *priv = dev_get_drvdata(d);
4626 int mode = priv->power_data.user_power_setting;
4627 int system = priv->power_data.system_power_setting;
4628 int level = priv->power_data.power_mode;
4629 char *p = buf;
4630
4631 switch (system) {
4632 case IWL_POWER_SYS_AUTO:
4633 p += sprintf(p, "SYSTEM:auto");
4634 break;
4635 case IWL_POWER_SYS_AC:
4636 p += sprintf(p, "SYSTEM:ac");
4637 break;
4638 case IWL_POWER_SYS_BATTERY:
4639 p += sprintf(p, "SYSTEM:battery");
4640 break;
4641 }
4642
4643 p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
4644 "fixed" : "auto");
4645 p += sprintf(p, "\tINDEX:%d", level);
4646 p += sprintf(p, "\n");
4647 return p - buf + 1;
4648}
4649
4650static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR,
4651 show_power_level, store_power_level);
4652
Zhu Yib481de92007-09-25 17:54:57 -07004653#define MAX_WX_STRING 80
4654
4655/* Values are in microsecond */
4656static const s32 timeout_duration[] = {
4657 350000,
4658 250000,
4659 75000,
4660 37000,
4661 25000,
4662};
4663static const s32 period_duration[] = {
4664 400000,
4665 700000,
4666 1000000,
4667 1000000,
4668 1000000
4669};
4670
Zhu Yib481de92007-09-25 17:54:57 -07004671static ssize_t show_channels(struct device *d,
4672 struct device_attribute *attr, char *buf)
4673{
Johannes Berg8318d782008-01-24 19:38:38 +01004674 /* all this shit doesn't belong into sysfs anyway */
4675 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07004676}
4677
4678static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
4679
4680static ssize_t show_statistics(struct device *d,
4681 struct device_attribute *attr, char *buf)
4682{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004683 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004684 u32 size = sizeof(struct iwl3945_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07004685 u32 len = 0, ofs = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004686 u8 *data = (u8 *)&priv->statistics_39;
Zhu Yib481de92007-09-25 17:54:57 -07004687 int rc = 0;
4688
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004689 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004690 return -EAGAIN;
4691
4692 mutex_lock(&priv->mutex);
Samuel Ortiz17f841c2009-01-23 13:45:20 -08004693 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004694 mutex_unlock(&priv->mutex);
4695
4696 if (rc) {
4697 len = sprintf(buf,
4698 "Error sending statistics request: 0x%08X\n", rc);
4699 return len;
4700 }
4701
4702 while (size && (PAGE_SIZE - len)) {
4703 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4704 PAGE_SIZE - len, 1);
4705 len = strlen(buf);
4706 if (PAGE_SIZE - len)
4707 buf[len++] = '\n';
4708
4709 ofs += 16;
4710 size -= min(size, 16U);
4711 }
4712
4713 return len;
4714}
4715
4716static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
4717
4718static ssize_t show_antenna(struct device *d,
4719 struct device_attribute *attr, char *buf)
4720{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004721 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004722
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004723 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004724 return -EAGAIN;
4725
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08004726 return sprintf(buf, "%d\n", iwl3945_mod_params.antenna);
Zhu Yib481de92007-09-25 17:54:57 -07004727}
4728
4729static ssize_t store_antenna(struct device *d,
4730 struct device_attribute *attr,
4731 const char *buf, size_t count)
4732{
Winkler, Tomas7530f852009-01-27 14:27:53 -08004733 struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004734 int ant;
Zhu Yib481de92007-09-25 17:54:57 -07004735
4736 if (count == 0)
4737 return 0;
4738
4739 if (sscanf(buf, "%1i", &ant) != 1) {
Tomas Winklere1623442009-01-27 14:27:56 -08004740 IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004741 return count;
4742 }
4743
4744 if ((ant >= 0) && (ant <= 2)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004745 IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant);
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08004746 iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant;
Zhu Yib481de92007-09-25 17:54:57 -07004747 } else
Tomas Winklere1623442009-01-27 14:27:56 -08004748 IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant);
Zhu Yib481de92007-09-25 17:54:57 -07004749
4750
4751 return count;
4752}
4753
4754static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
4755
4756static ssize_t show_status(struct device *d,
4757 struct device_attribute *attr, char *buf)
4758{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004759 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004760 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004761 return -EAGAIN;
4762 return sprintf(buf, "0x%08x\n", (int)priv->status);
4763}
4764
4765static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
4766
4767static ssize_t dump_error_log(struct device *d,
4768 struct device_attribute *attr,
4769 const char *buf, size_t count)
4770{
4771 char *p = (char *)buf;
4772
4773 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004774 iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07004775
4776 return strnlen(buf, count);
4777}
4778
4779static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
4780
4781static ssize_t dump_event_log(struct device *d,
4782 struct device_attribute *attr,
4783 const char *buf, size_t count)
4784{
4785 char *p = (char *)buf;
4786
4787 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004788 iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07004789
4790 return strnlen(buf, count);
4791}
4792
4793static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
4794
4795/*****************************************************************************
4796 *
Tomas Winklera96a27f2008-10-23 23:48:56 -07004797 * driver setup and tear down
Zhu Yib481de92007-09-25 17:54:57 -07004798 *
4799 *****************************************************************************/
4800
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004801static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004802{
Reinette Chatred21050c2009-02-13 11:51:18 -08004803 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07004804
4805 init_waitqueue_head(&priv->wait_command_queue);
4806
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004807 INIT_WORK(&priv->up, iwl3945_bg_up);
4808 INIT_WORK(&priv->restart, iwl3945_bg_restart);
4809 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01004810 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004811 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004812 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
4813 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
Helmut Schaa26635162009-01-15 09:38:44 +01004814 INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll);
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08004815 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
4816 INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
4817 INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
4818 INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
Zhu Yib481de92007-09-25 17:54:57 -07004819
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004820 iwl3945_hw_setup_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004821
4822 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004823 iwl3945_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07004824}
4825
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004826static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004827{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004828 iwl3945_hw_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004829
Joonwoo Parke47eb6a2007-11-29 10:42:49 +09004830 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004831 cancel_delayed_work(&priv->scan_check);
4832 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004833 cancel_work_sync(&priv->beacon_update);
4834}
4835
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004836static struct attribute *iwl3945_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07004837 &dev_attr_antenna.attr,
4838 &dev_attr_channels.attr,
4839 &dev_attr_dump_errors.attr,
4840 &dev_attr_dump_events.attr,
4841 &dev_attr_flags.attr,
4842 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004843#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004844 &dev_attr_measurement.attr,
4845#endif
4846 &dev_attr_power_level.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004847 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004848 &dev_attr_statistics.attr,
4849 &dev_attr_status.attr,
4850 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004851 &dev_attr_tx_power.attr,
Samuel Ortizd08853a2009-01-23 13:45:17 -08004852#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004853 &dev_attr_debug_level.attr,
4854#endif
Zhu Yib481de92007-09-25 17:54:57 -07004855 NULL
4856};
4857
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004858static struct attribute_group iwl3945_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07004859 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004860 .attrs = iwl3945_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07004861};
4862
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004863static struct ieee80211_ops iwl3945_hw_ops = {
4864 .tx = iwl3945_mac_tx,
4865 .start = iwl3945_mac_start,
4866 .stop = iwl3945_mac_stop,
4867 .add_interface = iwl3945_mac_add_interface,
4868 .remove_interface = iwl3945_mac_remove_interface,
4869 .config = iwl3945_mac_config,
4870 .config_interface = iwl3945_mac_config_interface,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004871 .configure_filter = iwl_configure_filter,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004872 .set_key = iwl3945_mac_set_key,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004873 .get_tx_stats = iwl3945_mac_get_tx_stats,
4874 .conf_tx = iwl3945_mac_conf_tx,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004875 .reset_tsf = iwl3945_mac_reset_tsf,
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004876 .bss_info_changed = iwl3945_bss_info_changed,
Abhijeet Kolekare9dde6f62009-02-18 15:54:27 -08004877 .hw_scan = iwl_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07004878};
4879
Winkler, Tomase52119c2008-12-22 11:31:19 +08004880static int iwl3945_init_drv(struct iwl_priv *priv)
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004881{
4882 int ret;
Samuel Ortize6148912009-01-23 13:45:15 -08004883 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004884
4885 priv->retry_rate = 1;
4886 priv->ibss_beacon = NULL;
4887
4888 spin_lock_init(&priv->lock);
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08004889 spin_lock_init(&priv->power_data.lock);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004890 spin_lock_init(&priv->sta_lock);
4891 spin_lock_init(&priv->hcmd_lock);
4892
4893 INIT_LIST_HEAD(&priv->free_frames);
4894
4895 mutex_init(&priv->mutex);
4896
4897 /* Clear the driver's (not device's) station table */
4898 iwl3945_clear_stations_table(priv);
4899
4900 priv->data_retry_limit = -1;
4901 priv->ieee_channels = NULL;
4902 priv->ieee_rates = NULL;
4903 priv->band = IEEE80211_BAND_2GHZ;
4904
4905 priv->iw_mode = NL80211_IFTYPE_STATION;
4906
4907 iwl_reset_qos(priv);
4908
4909 priv->qos_data.qos_active = 0;
4910 priv->qos_data.qos_cap.val = 0;
4911
4912 priv->rates_mask = IWL_RATES_MASK;
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004913 /* If power management is turned on, default to CAM mode */
4914 priv->power_mode = IWL_POWER_MODE_CAM;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08004915 priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004916
Samuel Ortize6148912009-01-23 13:45:15 -08004917 if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
4918 IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
4919 eeprom->version);
4920 ret = -EINVAL;
4921 goto err;
4922 }
4923 ret = iwl_init_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004924 if (ret) {
4925 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
4926 goto err;
4927 }
4928
Samuel Ortize6148912009-01-23 13:45:15 -08004929 /* Set up txpower settings in driver for all channels */
4930 if (iwl3945_txpower_set_from_eeprom(priv)) {
4931 ret = -EIO;
4932 goto err_free_channel_map;
4933 }
4934
Samuel Ortiz534166d2009-01-23 13:45:16 -08004935 ret = iwlcore_init_geos(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004936 if (ret) {
4937 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
4938 goto err_free_channel_map;
4939 }
Samuel Ortiz534166d2009-01-23 13:45:16 -08004940 iwl3945_init_hw_rates(priv, priv->ieee_rates);
4941
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004942 return 0;
4943
4944err_free_channel_map:
Samuel Ortize6148912009-01-23 13:45:15 -08004945 iwl_free_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004946err:
4947 return ret;
4948}
4949
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004950static int iwl3945_setup_mac(struct iwl_priv *priv)
4951{
4952 int ret;
4953 struct ieee80211_hw *hw = priv->hw;
4954
4955 hw->rate_control_algorithm = "iwl-3945-rs";
4956 hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
4957
4958 /* Tell mac80211 our characteristics */
4959 hw->flags = IEEE80211_HW_SIGNAL_DBM |
Mohamed Abbasb1c60192009-03-17 21:51:47 -07004960 IEEE80211_HW_NOISE_DBM |
4961 IEEE80211_HW_SPECTRUM_MGMT;
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004962
4963 hw->wiphy->interface_modes =
4964 BIT(NL80211_IFTYPE_STATION) |
4965 BIT(NL80211_IFTYPE_ADHOC);
4966
4967 hw->wiphy->custom_regulatory = true;
4968
Johannes Bergd60cc91a2009-04-09 09:56:02 +02004969 hw->wiphy->max_scan_ssids = 1; /* WILL FIX */
4970
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004971 /* Default value; 4 EDCA QOS priorities */
4972 hw->queues = 4;
4973
4974 hw->conf.beacon_int = 100;
4975
4976 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
4977 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
4978 &priv->bands[IEEE80211_BAND_2GHZ];
4979
4980 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
4981 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
4982 &priv->bands[IEEE80211_BAND_5GHZ];
4983
4984 ret = ieee80211_register_hw(priv->hw);
4985 if (ret) {
4986 IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
4987 return ret;
4988 }
4989 priv->mac80211_registered = 1;
4990
4991 return 0;
4992}
4993
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004994static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07004995{
4996 int err = 0;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004997 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07004998 struct ieee80211_hw *hw;
Kolekar, Abhijeetc0f20d92008-12-19 10:37:19 +08004999 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Samuel Ortize6148912009-01-23 13:45:15 -08005000 struct iwl3945_eeprom *eeprom;
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005001 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07005002
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005003 /***********************
5004 * 1. Allocating HW data
5005 * ********************/
5006
Zhu Yib481de92007-09-25 17:54:57 -07005007 /* mac80211 allocates memory for this device instance, including
5008 * space for this driver's private structure */
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005009 hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
Zhu Yib481de92007-09-25 17:54:57 -07005010 if (hw == NULL) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005011 printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
Zhu Yib481de92007-09-25 17:54:57 -07005012 err = -ENOMEM;
5013 goto out;
5014 }
Zhu Yib481de92007-09-25 17:54:57 -07005015 priv = hw->priv;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005016 SET_IEEE80211_DEV(hw, &pdev->dev);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005017
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005018 if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) ||
5019 (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005020 IWL_ERR(priv,
5021 "invalid queues_num, should be between %d and %d\n",
5022 IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES);
Samuel Ortiza3139c52008-12-19 10:37:09 +08005023 err = -EINVAL;
Reinette Chatrec8f16132009-02-27 16:21:22 -08005024 goto out_ieee80211_free_hw;
Samuel Ortiza3139c52008-12-19 10:37:09 +08005025 }
5026
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005027 /*
5028 * Disabling hardware scan means that mac80211 will perform scans
5029 * "the hard way", rather than using device's scan.
5030 */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005031 if (iwl3945_mod_params.disable_hw_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08005032 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005033 iwl3945_hw_ops.hw_scan = NULL;
5034 }
5035
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005036
Tomas Winklere1623442009-01-27 14:27:56 -08005037 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005038 priv->cfg = cfg;
5039 priv->pci_dev = pdev;
5040
Samuel Ortizd08853a2009-01-23 13:45:17 -08005041#ifdef CONFIG_IWLWIFI_DEBUG
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005042 priv->debug_level = iwl3945_mod_params.debug;
5043 atomic_set(&priv->restrict_refcnt, 0);
5044#endif
Zhu Yib481de92007-09-25 17:54:57 -07005045
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005046 /***************************
5047 * 2. Initializing PCI bus
5048 * *************************/
Zhu Yib481de92007-09-25 17:54:57 -07005049 if (pci_enable_device(pdev)) {
5050 err = -ENODEV;
5051 goto out_ieee80211_free_hw;
5052 }
5053
5054 pci_set_master(pdev);
5055
Yang Hongyang284901a2009-04-06 19:01:15 -07005056 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Zhu Yib481de92007-09-25 17:54:57 -07005057 if (!err)
Yang Hongyang284901a2009-04-06 19:01:15 -07005058 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Zhu Yib481de92007-09-25 17:54:57 -07005059 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08005060 IWL_WARN(priv, "No suitable DMA available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07005061 goto out_pci_disable_device;
5062 }
5063
5064 pci_set_drvdata(pdev, priv);
5065 err = pci_request_regions(pdev, DRV_NAME);
5066 if (err)
5067 goto out_pci_disable_device;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005068
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005069 /***********************
5070 * 3. Read REV Register
5071 * ********************/
Zhu Yib481de92007-09-25 17:54:57 -07005072 priv->hw_base = pci_iomap(pdev, 0, 0);
5073 if (!priv->hw_base) {
5074 err = -ENODEV;
5075 goto out_pci_release_regions;
5076 }
5077
Tomas Winklere1623442009-01-27 14:27:56 -08005078 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Zhu Yib481de92007-09-25 17:54:57 -07005079 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08005080 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Zhu Yib481de92007-09-25 17:54:57 -07005081
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005082 /* We disable the RETRY_TIMEOUT register (0x41) to keep
5083 * PCI Tx retries from interfering with C3 CPU state */
5084 pci_write_config_byte(pdev, 0x41, 0x00);
Zhu Yib481de92007-09-25 17:54:57 -07005085
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005086 /* amp init */
5087 err = priv->cfg->ops->lib->apm_ops.init(priv);
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005088 if (err < 0) {
David S. Millerd5df2a12009-03-10 05:04:16 -07005089 IWL_DEBUG_INFO(priv, "Failed to init the card\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005090 goto out_iounmap;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005091 }
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005092
5093 /***********************
5094 * 4. Read EEPROM
5095 * ********************/
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005096
Zhu Yi5a66926a2008-01-14 17:46:18 -08005097 /* Read the EEPROM */
Samuel Ortize6148912009-01-23 13:45:15 -08005098 err = iwl_eeprom_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005099 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005100 IWL_ERR(priv, "Unable to init EEPROM\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08005101 goto out_iounmap;
Zhu Yi5a66926a2008-01-14 17:46:18 -08005102 }
5103 /* MAC Address location in EEPROM same for 3945/4965 */
Samuel Ortize6148912009-01-23 13:45:15 -08005104 eeprom = (struct iwl3945_eeprom *)priv->eeprom;
5105 memcpy(priv->mac_addr, eeprom->mac_address, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08005106 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
Zhu Yi5a66926a2008-01-14 17:46:18 -08005107 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
5108
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005109 /***********************
5110 * 5. Setup HW Constants
5111 * ********************/
5112 /* Device-specific setup */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005113 if (iwl3945_hw_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005114 IWL_ERR(priv, "failed to set hw settings\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08005115 goto out_eeprom_free;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005116 }
5117
5118 /***********************
5119 * 6. Setup priv
5120 * ********************/
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005121
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005122 err = iwl3945_init_drv(priv);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005123 if (err) {
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005124 IWL_ERR(priv, "initializing driver failed\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08005125 goto out_unset_hw_params;
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005126 }
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005127
Tomas Winkler978785a2008-12-19 10:37:31 +08005128 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
5129 priv->cfg->name);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005130
5131 /***********************************
5132 * 7. Initialize Module Parameters
5133 * **********************************/
5134
5135 /* Initialize module parameter values here */
5136 /* Disable radio (SW RF KILL) via parameter when loading driver */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005137 if (iwl3945_mod_params.disable) {
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005138 set_bit(STATUS_RF_KILL_SW, &priv->status);
Tomas Winklere1623442009-01-27 14:27:56 -08005139 IWL_DEBUG_INFO(priv, "Radio disabled.\n");
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005140 }
5141
5142
5143 /***********************
5144 * 8. Setup Services
5145 * ********************/
5146
5147 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08005148 iwl_disable_interrupts(priv);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005149 spin_unlock_irqrestore(&priv->lock, flags);
5150
Helmut Schaa26635162009-01-15 09:38:44 +01005151 pci_enable_msi(priv->pci_dev);
5152
Abhijeet Kolekarf17d08a2009-02-18 15:54:31 -08005153 err = request_irq(priv->pci_dev->irq, iwl_isr, IRQF_SHARED,
Helmut Schaa26635162009-01-15 09:38:44 +01005154 DRV_NAME, priv);
5155 if (err) {
5156 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
5157 goto out_disable_msi;
5158 }
5159
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005160 err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
5161 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005162 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005163 goto out_release_irq;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005164 }
5165
Samuel Ortiz8ccde882009-01-27 14:27:52 -08005166 iwl_set_rxon_channel(priv,
5167 &priv->bands[IEEE80211_BAND_2GHZ].channels[5]);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005168 iwl3945_setup_deferred_work(priv);
5169 iwl3945_setup_rx_handlers(priv);
5170
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005171 /*********************************
Helmut Schaa26635162009-01-15 09:38:44 +01005172 * 9. Setup and Register mac80211
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005173 * *******************************/
5174
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08005175 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005176
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08005177 err = iwl3945_setup_mac(priv);
5178 if (err)
5179 goto out_remove_sysfs;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005180
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005181 err = iwl_rfkill_init(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005182 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08005183 IWL_ERR(priv, "Unable to initialize RFKILL system. "
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005184 "Ignoring error: %d\n", err);
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08005185 else
5186 iwl_rfkill_set_hw_state(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005187
Helmut Schaa26635162009-01-15 09:38:44 +01005188 /* Start monitoring the killswitch */
5189 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
5190 2 * HZ);
5191
Zhu Yib481de92007-09-25 17:54:57 -07005192 return 0;
5193
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005194 out_remove_sysfs:
Zhu Yib481de92007-09-25 17:54:57 -07005195 destroy_workqueue(priv->workqueue);
5196 priv->workqueue = NULL;
Reinette Chatrec8f16132009-02-27 16:21:22 -08005197 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
5198 out_release_irq:
5199 free_irq(priv->pci_dev->irq, priv);
Helmut Schaa26635162009-01-15 09:38:44 +01005200 out_disable_msi:
5201 pci_disable_msi(priv->pci_dev);
Reinette Chatrec8f16132009-02-27 16:21:22 -08005202 iwlcore_free_geos(priv);
5203 iwl_free_channel_map(priv);
5204 out_unset_hw_params:
5205 iwl3945_unset_hw_params(priv);
5206 out_eeprom_free:
5207 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005208 out_iounmap:
5209 pci_iounmap(pdev, priv->hw_base);
5210 out_pci_release_regions:
5211 pci_release_regions(pdev);
5212 out_pci_disable_device:
Zhu Yib481de92007-09-25 17:54:57 -07005213 pci_set_drvdata(pdev, NULL);
Reinette Chatre623d5632009-03-03 11:37:04 -08005214 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005215 out_ieee80211_free_hw:
5216 ieee80211_free_hw(priv->hw);
5217 out:
5218 return err;
5219}
5220
Reinette Chatrec83dbf62008-03-21 13:53:41 -07005221static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07005222{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005223 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005224 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07005225
5226 if (!priv)
5227 return;
5228
Tomas Winklere1623442009-01-27 14:27:56 -08005229 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07005230
Zhu Yib481de92007-09-25 17:54:57 -07005231 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08005232
Kolekar, Abhijeetd552bfb2008-12-19 10:37:41 +08005233 if (priv->mac80211_registered) {
5234 ieee80211_unregister_hw(priv->hw);
5235 priv->mac80211_registered = 0;
5236 } else {
5237 iwl3945_down(priv);
5238 }
Zhu Yib481de92007-09-25 17:54:57 -07005239
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005240 /* make sure we flush any pending irq or
5241 * tasklet for the driver
5242 */
5243 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08005244 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005245 spin_unlock_irqrestore(&priv->lock, flags);
5246
5247 iwl_synchronize_irq(priv);
5248
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005249 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07005250
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005251 iwl_rfkill_unregister(priv);
Reinette Chatre71d449b2009-04-20 14:37:01 -07005252 cancel_delayed_work_sync(&priv->rfkill_poll);
Helmut Schaa26635162009-01-15 09:38:44 +01005253
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005254 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005255
5256 if (priv->rxq.bd)
Reinette Chatredf833b12009-04-21 10:55:48 -07005257 iwl3945_rx_queue_free(priv, &priv->rxq);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005258 iwl3945_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005259
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005260 iwl3945_unset_hw_params(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005261 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005262
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08005263 /*netif_stop_queue(dev); */
5264 flush_workqueue(priv->workqueue);
5265
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005266 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07005267 * priv->workqueue... so we can't take down the workqueue
5268 * until now... */
5269 destroy_workqueue(priv->workqueue);
5270 priv->workqueue = NULL;
5271
Helmut Schaa26635162009-01-15 09:38:44 +01005272 free_irq(pdev->irq, priv);
5273 pci_disable_msi(pdev);
5274
Zhu Yib481de92007-09-25 17:54:57 -07005275 pci_iounmap(pdev, priv->hw_base);
5276 pci_release_regions(pdev);
5277 pci_disable_device(pdev);
5278 pci_set_drvdata(pdev, NULL);
5279
Samuel Ortize6148912009-01-23 13:45:15 -08005280 iwl_free_channel_map(priv);
Samuel Ortiz534166d2009-01-23 13:45:16 -08005281 iwlcore_free_geos(priv);
Winkler, Tomas805cee52009-01-19 15:30:28 -08005282 kfree(priv->scan);
Zhu Yib481de92007-09-25 17:54:57 -07005283 if (priv->ibss_beacon)
5284 dev_kfree_skb(priv->ibss_beacon);
5285
5286 ieee80211_free_hw(priv->hw);
5287}
5288
5289#ifdef CONFIG_PM
5290
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005291static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07005292{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005293 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005294
Zhu Yie655b9f2008-01-24 02:19:38 -08005295 if (priv->is_open) {
5296 set_bit(STATUS_IN_SUSPEND, &priv->status);
5297 iwl3945_mac_stop(priv->hw);
5298 priv->is_open = 1;
5299 }
Helmut Schaa26635162009-01-15 09:38:44 +01005300 pci_save_state(pdev);
5301 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005302 pci_set_power_state(pdev, PCI_D3hot);
5303
Zhu Yib481de92007-09-25 17:54:57 -07005304 return 0;
5305}
5306
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005307static int iwl3945_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07005308{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005309 struct iwl_priv *priv = pci_get_drvdata(pdev);
Winkler, Tomas450154e2009-01-27 14:27:55 -08005310 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07005311
Zhu Yib481de92007-09-25 17:54:57 -07005312 pci_set_power_state(pdev, PCI_D0);
Winkler, Tomas450154e2009-01-27 14:27:55 -08005313 ret = pci_enable_device(pdev);
5314 if (ret)
5315 return ret;
Helmut Schaa26635162009-01-15 09:38:44 +01005316 pci_restore_state(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005317
Zhu Yie655b9f2008-01-24 02:19:38 -08005318 if (priv->is_open)
5319 iwl3945_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07005320
Zhu Yie655b9f2008-01-24 02:19:38 -08005321 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07005322 return 0;
5323}
5324
5325#endif /* CONFIG_PM */
5326
5327/*****************************************************************************
5328 *
5329 * driver and module entry point
5330 *
5331 *****************************************************************************/
5332
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005333static struct pci_driver iwl3945_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07005334 .name = DRV_NAME,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005335 .id_table = iwl3945_hw_card_ids,
5336 .probe = iwl3945_pci_probe,
5337 .remove = __devexit_p(iwl3945_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07005338#ifdef CONFIG_PM
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005339 .suspend = iwl3945_pci_suspend,
5340 .resume = iwl3945_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07005341#endif
5342};
5343
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005344static int __init iwl3945_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07005345{
5346
5347 int ret;
5348 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
5349 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005350
5351 ret = iwl3945_rate_control_register();
5352 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005353 printk(KERN_ERR DRV_NAME
5354 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005355 return ret;
5356 }
5357
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005358 ret = pci_register_driver(&iwl3945_driver);
Zhu Yib481de92007-09-25 17:54:57 -07005359 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005360 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005361 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07005362 }
Zhu Yib481de92007-09-25 17:54:57 -07005363
5364 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005365
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005366error_register:
5367 iwl3945_rate_control_unregister();
5368 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07005369}
5370
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005371static void __exit iwl3945_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07005372{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005373 pci_unregister_driver(&iwl3945_driver);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005374 iwl3945_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07005375}
5376
Reinette Chatrea0987a82008-12-02 12:14:06 -08005377MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
Zhu Yi25cb6ca2008-09-11 11:45:22 +08005378
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005379module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005380MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005381module_param_named(disable, iwl3945_mod_params.disable, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005382MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -08005383module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
5384MODULE_PARM_DESC(swcrypto,
5385 "using software crypto (default 1 [software])\n");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005386module_param_named(debug, iwl3945_mod_params.debug, uint, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005387MODULE_PARM_DESC(debug, "debug output mask");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005388module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005389MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
5390
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005391module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005392MODULE_PARM_DESC(queues_num, "number of hw queues.");
5393
Samuel Ortizaf48d042009-01-23 13:45:19 -08005394module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, 0444);
5395MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error");
5396
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005397module_exit(iwl3945_exit);
5398module_init(iwl3945_init);