blob: 617c4235d97127777ad23d1675072004b6e88c7b [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Reinette Chatre01f81622009-01-08 10:20:02 -08003 * Copyright(c) 2003 - 2009 Intel Corporation. All rights reserved.
Zhu Yib481de92007-09-25 17:54:57 -07004 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
Winkler, Tomas759ef892008-12-09 11:28:58 -080025 * Intel Linux Wireless <ilw@linux.intel.com>
Zhu Yib481de92007-09-25 17:54:57 -070026 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
Zhu Yib481de92007-09-25 17:54:57 -070030#include <linux/kernel.h>
31#include <linux/module.h>
Zhu Yib481de92007-09-25 17:54:57 -070032#include <linux/init.h>
33#include <linux/pci.h>
34#include <linux/dma-mapping.h>
35#include <linux/delay.h>
36#include <linux/skbuff.h>
37#include <linux/netdevice.h>
38#include <linux/wireless.h>
39#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070040#include <linux/etherdevice.h>
41#include <linux/if_arp.h>
42
43#include <net/ieee80211_radiotap.h>
John W. Linville7e272fc2008-09-24 18:13:14 -040044#include <net/lib80211.h>
Zhu Yib481de92007-09-25 17:54:57 -070045#include <net/mac80211.h>
46
47#include <asm/div64.h>
48
Samuel Ortiza3139c52008-12-19 10:37:09 +080049#define DRV_NAME "iwl3945"
50
Winkler, Tomasdbb66542008-12-22 11:31:14 +080051#include "iwl-fh.h"
52#include "iwl-3945-fh.h"
Tomas Winkler600c0e12008-12-19 10:37:04 +080053#include "iwl-commands.h"
Samuel Ortiz17f841c2009-01-23 13:45:20 -080054#include "iwl-sta.h"
Zhu Yib481de92007-09-25 17:54:57 -070055#include "iwl-3945.h"
56#include "iwl-helpers.h"
Kolekar, Abhijeet5747d472008-12-19 10:37:18 +080057#include "iwl-core.h"
Samuel Ortizd20b3c62008-12-19 10:37:15 +080058#include "iwl-dev.h"
Zhu Yib481de92007-09-25 17:54:57 -070059
Zhu Yib481de92007-09-25 17:54:57 -070060/*
61 * module name, copyright, version, etc.
Zhu Yib481de92007-09-25 17:54:57 -070062 */
63
64#define DRV_DESCRIPTION \
65"Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
66
Samuel Ortizd08853a2009-01-23 13:45:17 -080067#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070068#define VD "d"
69#else
70#define VD
71#endif
72
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080073#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -070074#define VS "s"
75#else
76#define VS
77#endif
78
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080079#define IWL39_VERSION "1.2.26k" VD VS
Reinette Chatre01f81622009-01-08 10:20:02 -080080#define DRV_COPYRIGHT "Copyright(c) 2003-2009 Intel Corporation"
Tomas Winklera7b75202008-12-11 10:33:41 -080081#define DRV_AUTHOR "<ilw@linux.intel.com>"
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080082#define DRV_VERSION IWL39_VERSION
Zhu Yib481de92007-09-25 17:54:57 -070083
Zhu Yib481de92007-09-25 17:54:57 -070084
85MODULE_DESCRIPTION(DRV_DESCRIPTION);
86MODULE_VERSION(DRV_VERSION);
Tomas Winklera7b75202008-12-11 10:33:41 -080087MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
Zhu Yib481de92007-09-25 17:54:57 -070088MODULE_LICENSE("GPL");
89
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080090 /* module parameters */
91struct iwl_mod_params iwl3945_mod_params = {
92 .num_of_queues = IWL39_MAX_NUM_QUEUES,
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -080093 .sw_crypto = 1,
Samuel Ortizaf48d042009-01-23 13:45:19 -080094 .restart_fw = 1,
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080095 /* the rest are 0 by default */
96};
97
Zhu Yib481de92007-09-25 17:54:57 -070098/*************** STATION TABLE MANAGEMENT ****
Ben Cahill9fbab512007-11-29 11:09:47 +080099 * mac80211 should be examined to determine if sta_info is duplicating
Zhu Yib481de92007-09-25 17:54:57 -0700100 * the functionality provided here
101 */
102
103/**************************************************************/
Ian Schram01ebd062007-10-25 17:15:22 +0800104#if 0 /* temporary disable till we add real remove station */
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800105/**
106 * iwl3945_remove_station - Remove driver's knowledge of station.
107 *
108 * NOTE: This does not remove station from device's station table.
109 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800110static u8 iwl3945_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
Zhu Yib481de92007-09-25 17:54:57 -0700111{
112 int index = IWL_INVALID_STATION;
113 int i;
114 unsigned long flags;
115
116 spin_lock_irqsave(&priv->sta_lock, flags);
117
118 if (is_ap)
119 index = IWL_AP_ID;
120 else if (is_broadcast_ether_addr(addr))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800121 index = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700122 else
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800123 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800124 if (priv->stations_39[i].used &&
125 !compare_ether_addr(priv->stations_39[i].sta.sta.addr,
Zhu Yib481de92007-09-25 17:54:57 -0700126 addr)) {
127 index = i;
128 break;
129 }
130
131 if (unlikely(index == IWL_INVALID_STATION))
132 goto out;
133
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800134 if (priv->stations_39[index].used) {
135 priv->stations_39[index].used = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700136 priv->num_stations--;
137 }
138
139 BUG_ON(priv->num_stations < 0);
140
141out:
142 spin_unlock_irqrestore(&priv->sta_lock, flags);
143 return 0;
144}
Zhu Yi556f8db2007-09-27 11:27:33 +0800145#endif
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800146
147/**
148 * iwl3945_clear_stations_table - Clear the driver's station table
149 *
150 * NOTE: This does not clear or otherwise alter the device's station table.
151 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800152static void iwl3945_clear_stations_table(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700153{
154 unsigned long flags;
155
156 spin_lock_irqsave(&priv->sta_lock, flags);
157
158 priv->num_stations = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800159 memset(priv->stations_39, 0, sizeof(priv->stations_39));
Zhu Yib481de92007-09-25 17:54:57 -0700160
161 spin_unlock_irqrestore(&priv->sta_lock, flags);
162}
163
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800164/**
165 * iwl3945_add_station - Add station to station tables in driver and device
166 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800167u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags)
Zhu Yib481de92007-09-25 17:54:57 -0700168{
169 int i;
170 int index = IWL_INVALID_STATION;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800171 struct iwl3945_station_entry *station;
Zhu Yib481de92007-09-25 17:54:57 -0700172 unsigned long flags_spin;
Zhu Yic14c5212007-09-27 11:27:35 +0800173 u8 rate;
Zhu Yib481de92007-09-25 17:54:57 -0700174
175 spin_lock_irqsave(&priv->sta_lock, flags_spin);
176 if (is_ap)
177 index = IWL_AP_ID;
178 else if (is_broadcast_ether_addr(addr))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800179 index = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700180 else
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800181 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800182 if (!compare_ether_addr(priv->stations_39[i].sta.sta.addr,
Zhu Yib481de92007-09-25 17:54:57 -0700183 addr)) {
184 index = i;
185 break;
186 }
187
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800188 if (!priv->stations_39[i].used &&
Zhu Yib481de92007-09-25 17:54:57 -0700189 index == IWL_INVALID_STATION)
190 index = i;
191 }
192
Ian Schram01ebd062007-10-25 17:15:22 +0800193 /* These two conditions has the same outcome but keep them separate
Zhu Yib481de92007-09-25 17:54:57 -0700194 since they have different meaning */
195 if (unlikely(index == IWL_INVALID_STATION)) {
196 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
197 return index;
198 }
199
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800200 if (priv->stations_39[index].used &&
201 !compare_ether_addr(priv->stations_39[index].sta.sta.addr, addr)) {
Zhu Yib481de92007-09-25 17:54:57 -0700202 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
203 return index;
204 }
205
Tomas Winklere1623442009-01-27 14:27:56 -0800206 IWL_DEBUG_ASSOC(priv, "Add STA ID %d: %pM\n", index, addr);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800207 station = &priv->stations_39[index];
Zhu Yib481de92007-09-25 17:54:57 -0700208 station->used = 1;
209 priv->num_stations++;
210
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800211 /* Set up the REPLY_ADD_STA command to send to device */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800212 memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd));
Zhu Yib481de92007-09-25 17:54:57 -0700213 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
214 station->sta.mode = 0;
215 station->sta.sta.sta_id = index;
216 station->sta.station_flags = 0;
217
Johannes Berg8318d782008-01-24 19:38:38 +0100218 if (priv->band == IEEE80211_BAND_5GHZ)
Tomas Winkler69946332007-10-25 17:15:27 +0800219 rate = IWL_RATE_6M_PLCP;
220 else
221 rate = IWL_RATE_1M_PLCP;
Zhu Yic14c5212007-09-27 11:27:35 +0800222
223 /* Turn on both antennas for the station... */
224 station->sta.rate_n_flags =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800225 iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK);
Zhu Yic14c5212007-09-27 11:27:35 +0800226
Zhu Yib481de92007-09-25 17:54:57 -0700227 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800228
229 /* Add station to device's station table */
Samuel Ortiz17f841c2009-01-23 13:45:20 -0800230 iwl_send_add_sta(priv,
231 (struct iwl_addsta_cmd *)&station->sta, flags);
Zhu Yib481de92007-09-25 17:54:57 -0700232 return index;
233
234}
235
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800236static int iwl3945_send_rxon_assoc(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700237{
238 int rc = 0;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800239 struct iwl_rx_packet *res = NULL;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800240 struct iwl3945_rxon_assoc_cmd rxon_assoc;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800241 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700242 .id = REPLY_RXON_ASSOC,
243 .len = sizeof(rxon_assoc),
244 .meta.flags = CMD_WANT_SKB,
245 .data = &rxon_assoc,
246 };
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800247 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
248 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
Zhu Yib481de92007-09-25 17:54:57 -0700249
250 if ((rxon1->flags == rxon2->flags) &&
251 (rxon1->filter_flags == rxon2->filter_flags) &&
252 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
253 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800254 IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700255 return 0;
256 }
257
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800258 rxon_assoc.flags = priv->staging_rxon.flags;
259 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
260 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
261 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
Zhu Yib481de92007-09-25 17:54:57 -0700262 rxon_assoc.reserved = 0;
263
Samuel Ortiz518099a2009-01-19 15:30:27 -0800264 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700265 if (rc)
266 return rc;
267
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800268 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700269 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800270 IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -0700271 rc = -EIO;
272 }
273
274 priv->alloc_rxb_skb--;
275 dev_kfree_skb_any(cmd.meta.u.skb);
276
277 return rc;
278}
279
280/**
Samuel Ortiz7e4bca52009-01-23 13:45:18 -0800281 * iwl3945_get_antenna_flags - Get antenna flags for RXON command
282 * @priv: eeprom and antenna fields are used to determine antenna flags
283 *
284 * priv->eeprom39 is used to determine if antenna AUX/MAIN are reversed
285 * iwl3945_mod_params.antenna specifies the antenna diversity mode:
286 *
287 * IWL_ANTENNA_DIVERSITY - NIC selects best antenna by itself
288 * IWL_ANTENNA_MAIN - Force MAIN antenna
289 * IWL_ANTENNA_AUX - Force AUX antenna
290 */
291__le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv)
292{
293 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
294
295 switch (iwl3945_mod_params.antenna) {
296 case IWL_ANTENNA_DIVERSITY:
297 return 0;
298
299 case IWL_ANTENNA_MAIN:
300 if (eeprom->antenna_switch_type)
301 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
302 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
303
304 case IWL_ANTENNA_AUX:
305 if (eeprom->antenna_switch_type)
306 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
307 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
308 }
309
310 /* bad antenna selector value */
311 IWL_ERR(priv, "Bad antenna selector value (0x%x)\n",
312 iwl3945_mod_params.antenna);
313
314 return 0; /* "diversity" is default if error */
315}
316
317/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800318 * iwl3945_commit_rxon - commit staging_rxon to hardware
Zhu Yib481de92007-09-25 17:54:57 -0700319 *
Ian Schram01ebd062007-10-25 17:15:22 +0800320 * The RXON command in staging_rxon is committed to the hardware and
Zhu Yib481de92007-09-25 17:54:57 -0700321 * the active_rxon structure is updated with the new data. This
322 * function correctly transitions out of the RXON_ASSOC_MSK state if
323 * a HW tune is required based on the RXON structure changes.
324 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800325static int iwl3945_commit_rxon(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700326{
327 /* cast away the const for active_rxon in this function */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800328 struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
329 struct iwl3945_rxon_cmd *staging_rxon = (void *)&priv->staging_rxon;
Zhu Yib481de92007-09-25 17:54:57 -0700330 int rc = 0;
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
785 cancel_delayed_work(&priv->scan_check);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -0800786 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800787 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
Tomas Winklere1623442009-01-27 14:27:56 -0800788 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +0800789 return -EAGAIN;
790 }
791
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800792 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700793
794 return 0;
795}
796
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800797static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
Johannes Berge039fa42008-05-15 12:55:29 +0200798 struct ieee80211_tx_info *info,
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800799 struct iwl_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -0700800 struct sk_buff *skb_frag,
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800801 int sta_id)
Zhu Yib481de92007-09-25 17:54:57 -0700802{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800803 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
Ivo van Doorn1c014422008-04-17 19:41:02 +0200804 struct iwl3945_hw_key *keyinfo =
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800805 &priv->stations_39[sta_id].keyinfo;
Zhu Yib481de92007-09-25 17:54:57 -0700806
807 switch (keyinfo->alg) {
808 case ALG_CCMP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800809 tx->sec_ctl = TX_CMD_SEC_CCM;
810 memcpy(tx->key, keyinfo->key, keyinfo->keylen);
Tomas Winklere1623442009-01-27 14:27:56 -0800811 IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
Zhu Yib481de92007-09-25 17:54:57 -0700812 break;
813
814 case ALG_TKIP:
Zhu Yib481de92007-09-25 17:54:57 -0700815 break;
816
817 case ALG_WEP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800818 tx->sec_ctl = TX_CMD_SEC_WEP |
Johannes Berge039fa42008-05-15 12:55:29 +0200819 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
Zhu Yib481de92007-09-25 17:54:57 -0700820
821 if (keyinfo->keylen == 13)
Winkler, Tomase52119c2008-12-22 11:31:19 +0800822 tx->sec_ctl |= TX_CMD_SEC_KEY128;
Zhu Yib481de92007-09-25 17:54:57 -0700823
Winkler, Tomase52119c2008-12-22 11:31:19 +0800824 memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen);
Zhu Yib481de92007-09-25 17:54:57 -0700825
Tomas Winklere1623442009-01-27 14:27:56 -0800826 IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
Johannes Berge039fa42008-05-15 12:55:29 +0200827 "with key %d\n", info->control.hw_key->hw_key_idx);
Zhu Yib481de92007-09-25 17:54:57 -0700828 break;
829
Zhu Yib481de92007-09-25 17:54:57 -0700830 default:
Tomas Winkler978785a2008-12-19 10:37:31 +0800831 IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg);
Zhu Yib481de92007-09-25 17:54:57 -0700832 break;
833 }
834}
835
836/*
837 * handle build REPLY_TX command notification.
838 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800839static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800840 struct iwl_cmd *cmd,
Johannes Berge039fa42008-05-15 12:55:29 +0200841 struct ieee80211_tx_info *info,
Winkler, Tomase52119c2008-12-22 11:31:19 +0800842 struct ieee80211_hdr *hdr, u8 std_id)
Zhu Yib481de92007-09-25 17:54:57 -0700843{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800844 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
845 __le32 tx_flags = tx->tx_flags;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700846 __le16 fc = hdr->frame_control;
Johannes Berge6a98542008-10-21 12:40:02 +0200847 u8 rc_flags = info->control.rates[0].flags;
Zhu Yib481de92007-09-25 17:54:57 -0700848
Winkler, Tomase52119c2008-12-22 11:31:19 +0800849 tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Johannes Berge039fa42008-05-15 12:55:29 +0200850 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
Zhu Yib481de92007-09-25 17:54:57 -0700851 tx_flags |= TX_CMD_FLG_ACK_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700852 if (ieee80211_is_mgmt(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700853 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700854 if (ieee80211_is_probe_resp(fc) &&
Zhu Yib481de92007-09-25 17:54:57 -0700855 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
856 tx_flags |= TX_CMD_FLG_TSF_MSK;
857 } else {
858 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
859 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
860 }
861
Winkler, Tomase52119c2008-12-22 11:31:19 +0800862 tx->sta_id = std_id;
Harvey Harrison8b7b1e02008-06-11 14:21:56 -0700863 if (ieee80211_has_morefrags(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700864 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
865
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700866 if (ieee80211_is_data_qos(fc)) {
867 u8 *qc = ieee80211_get_qos_ctl(hdr);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800868 tx->tid_tspec = qc[0] & 0xf;
Zhu Yib481de92007-09-25 17:54:57 -0700869 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800870 } else {
Zhu Yib481de92007-09-25 17:54:57 -0700871 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800872 }
Zhu Yib481de92007-09-25 17:54:57 -0700873
Johannes Berge6a98542008-10-21 12:40:02 +0200874 if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
Zhu Yib481de92007-09-25 17:54:57 -0700875 tx_flags |= TX_CMD_FLG_RTS_MSK;
876 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
Johannes Berge6a98542008-10-21 12:40:02 +0200877 } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
Zhu Yib481de92007-09-25 17:54:57 -0700878 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
879 tx_flags |= TX_CMD_FLG_CTS_MSK;
880 }
881
882 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
883 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
884
885 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700886 if (ieee80211_is_mgmt(fc)) {
887 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
Winkler, Tomase52119c2008-12-22 11:31:19 +0800888 tx->timeout.pm_frame_timeout = cpu_to_le16(3);
Zhu Yib481de92007-09-25 17:54:57 -0700889 else
Winkler, Tomase52119c2008-12-22 11:31:19 +0800890 tx->timeout.pm_frame_timeout = cpu_to_le16(2);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700891 } else {
Winkler, Tomase52119c2008-12-22 11:31:19 +0800892 tx->timeout.pm_frame_timeout = 0;
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -0700893#ifdef CONFIG_IWLWIFI_LEDS
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700894 priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
895#endif
896 }
Zhu Yib481de92007-09-25 17:54:57 -0700897
Winkler, Tomase52119c2008-12-22 11:31:19 +0800898 tx->driver_txop = 0;
899 tx->tx_flags = tx_flags;
900 tx->next_frame_len = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700901}
902
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800903/**
904 * iwl3945_get_sta_id - Find station's index within station table
905 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800906static int iwl3945_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
Zhu Yib481de92007-09-25 17:54:57 -0700907{
908 int sta_id;
909 u16 fc = le16_to_cpu(hdr->frame_control);
910
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800911 /* If this frame is broadcast or management, use broadcast station id */
Zhu Yib481de92007-09-25 17:54:57 -0700912 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
913 is_multicast_ether_addr(hdr->addr1))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800914 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700915
916 switch (priv->iw_mode) {
917
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800918 /* If we are a client station in a BSS network, use the special
919 * AP station entry (that's the only station we communicate with) */
Johannes Berg05c914f2008-09-11 00:01:58 +0200920 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -0700921 return IWL_AP_ID;
922
923 /* If we are an AP, then find the station, or use BCAST */
Johannes Berg05c914f2008-09-11 00:01:58 +0200924 case NL80211_IFTYPE_AP:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800925 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700926 if (sta_id != IWL_INVALID_STATION)
927 return sta_id;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800928 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700929
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800930 /* If this frame is going out to an IBSS network, find the station,
931 * or create a new station table entry */
Johannes Berg05c914f2008-09-11 00:01:58 +0200932 case NL80211_IFTYPE_ADHOC: {
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800933 /* Create new station table entry */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800934 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700935 if (sta_id != IWL_INVALID_STATION)
936 return sta_id;
937
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800938 sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
Zhu Yib481de92007-09-25 17:54:57 -0700939
940 if (sta_id != IWL_INVALID_STATION)
941 return sta_id;
942
Tomas Winklere1623442009-01-27 14:27:56 -0800943 IWL_DEBUG_DROP(priv, "Station %pM not in station map. "
Zhu Yib481de92007-09-25 17:54:57 -0700944 "Defaulting to broadcast...\n",
Johannes Berge1749612008-10-27 15:59:26 -0700945 hdr->addr1);
Samuel Ortiz40b8ec02008-12-19 10:37:08 +0800946 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800947 return priv->hw_params.bcast_sta_id;
Joe Perches0795af52007-10-03 17:59:30 -0700948 }
Stefanik Gábor914233d2008-06-30 17:23:30 +0800949 /* If we are in monitor mode, use BCAST. This is required for
950 * packet injection. */
Johannes Berg05c914f2008-09-11 00:01:58 +0200951 case NL80211_IFTYPE_MONITOR:
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800952 return priv->hw_params.bcast_sta_id;
Stefanik Gábor914233d2008-06-30 17:23:30 +0800953
Zhu Yib481de92007-09-25 17:54:57 -0700954 default:
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800955 IWL_WARN(priv, "Unknown mode of operation: %d\n",
956 priv->iw_mode);
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800957 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700958 }
959}
960
961/*
962 * start REPLY_TX command process
963 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800964static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -0700965{
966 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berge039fa42008-05-15 12:55:29 +0200967 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800968 struct iwl3945_tx_cmd *tx;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800969 struct iwl_tx_queue *txq = NULL;
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800970 struct iwl_queue *q = NULL;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800971 struct iwl_cmd *out_cmd = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700972 dma_addr_t phys_addr;
973 dma_addr_t txcmd_phys;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800974 int txq_id = skb_get_queue_mapping(skb);
Reinette Chatredf833b12009-04-21 10:55:48 -0700975 u16 len, idx, len_org, hdr_len; /* TODO: len_org is not used */
Tomas Winkler54dbb522008-05-15 13:54:06 +0800976 u8 id;
977 u8 unicast;
Zhu Yib481de92007-09-25 17:54:57 -0700978 u8 sta_id;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800979 u8 tid = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700980 u16 seq_number = 0;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700981 __le16 fc;
Zhu Yib481de92007-09-25 17:54:57 -0700982 u8 wait_write_ptr = 0;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800983 u8 *qc = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700984 unsigned long flags;
985 int rc;
986
987 spin_lock_irqsave(&priv->lock, flags);
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800988 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800989 IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
Zhu Yib481de92007-09-25 17:54:57 -0700990 goto drop_unlock;
991 }
992
Johannes Berge039fa42008-05-15 12:55:29 +0200993 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800994 IWL_ERR(priv, "ERROR: No TX rate available.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700995 goto drop_unlock;
996 }
997
998 unicast = !is_multicast_ether_addr(hdr->addr1);
999 id = 0;
1000
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001001 fc = hdr->frame_control;
Zhu Yib481de92007-09-25 17:54:57 -07001002
Samuel Ortizd08853a2009-01-23 13:45:17 -08001003#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001004 if (ieee80211_is_auth(fc))
Tomas Winklere1623442009-01-27 14:27:56 -08001005 IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001006 else if (ieee80211_is_assoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -08001007 IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001008 else if (ieee80211_is_reassoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -08001009 IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
Zhu Yib481de92007-09-25 17:54:57 -07001010#endif
1011
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08001012 /* drop all data frame if we are not associated */
Stefanik Gábor914233d2008-06-30 17:23:30 +08001013 if (ieee80211_is_data(fc) &&
Johannes Berg05c914f2008-09-11 00:01:58 +02001014 (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001015 (!iwl_is_associated(priv) ||
Johannes Berg05c914f2008-09-11 00:01:58 +02001016 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
Tomas Winklere1623442009-01-27 14:27:56 -08001017 IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n");
Zhu Yib481de92007-09-25 17:54:57 -07001018 goto drop_unlock;
1019 }
1020
1021 spin_unlock_irqrestore(&priv->lock, flags);
1022
Harvey Harrison7294ec92008-07-15 18:43:59 -07001023 hdr_len = ieee80211_hdrlen(fc);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001024
1025 /* Find (or create) index into station table for destination station */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001026 sta_id = iwl3945_get_sta_id(priv, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07001027 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -08001028 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07001029 hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07001030 goto drop;
1031 }
1032
Tomas Winklere1623442009-01-27 14:27:56 -08001033 IWL_DEBUG_RATE(priv, "station Id %d\n", sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07001034
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001035 if (ieee80211_is_data_qos(fc)) {
1036 qc = ieee80211_get_qos_ctl(hdr);
Harvey Harrison7294ec92008-07-15 18:43:59 -07001037 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001038 seq_number = priv->stations_39[sta_id].tid[tid].seq_number &
Zhu Yib481de92007-09-25 17:54:57 -07001039 IEEE80211_SCTL_SEQ;
1040 hdr->seq_ctrl = cpu_to_le16(seq_number) |
1041 (hdr->seq_ctrl &
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -08001042 cpu_to_le16(IEEE80211_SCTL_FRAG));
Zhu Yib481de92007-09-25 17:54:57 -07001043 seq_number += 0x10;
1044 }
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001045
1046 /* Descriptor for chosen Tx queue */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001047 txq = &priv->txq[txq_id];
Zhu Yib481de92007-09-25 17:54:57 -07001048 q = &txq->q;
1049
1050 spin_lock_irqsave(&priv->lock, flags);
1051
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001052 idx = get_cmd_index(q, q->write_ptr, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001053
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001054 /* Set up driver data for this TFD */
Winkler, Tomasdbb66542008-12-22 11:31:14 +08001055 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001056 txq->txb[q->write_ptr].skb[0] = skb;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001057
1058 /* Init first empty entry in queue's array of Tx/cmd buffers */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001059 out_cmd = txq->cmd[idx];
Winkler, Tomase52119c2008-12-22 11:31:19 +08001060 tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
Zhu Yib481de92007-09-25 17:54:57 -07001061 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
Winkler, Tomase52119c2008-12-22 11:31:19 +08001062 memset(tx, 0, sizeof(*tx));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001063
1064 /*
1065 * Set up the Tx-command (not MAC!) header.
1066 * Store the chosen Tx queue and TFD index within the sequence field;
1067 * after Tx, uCode's Tx response will return this value so driver can
1068 * locate the frame within the tx queue and do post-tx processing.
1069 */
Zhu Yib481de92007-09-25 17:54:57 -07001070 out_cmd->hdr.cmd = REPLY_TX;
1071 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001072 INDEX_TO_SEQ(q->write_ptr)));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001073
1074 /* Copy MAC header from skb into command buffer */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001075 memcpy(tx->hdr, hdr, hdr_len);
Zhu Yib481de92007-09-25 17:54:57 -07001076
Reinette Chatredf833b12009-04-21 10:55:48 -07001077
1078 if (info->control.hw_key)
1079 iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, sta_id);
1080
1081 /* TODO need this for burst mode later on */
1082 iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
1083
1084 /* set is_hcca to 0; it probably will never be implemented */
1085 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
1086
1087 /* Total # bytes to be transmitted */
1088 len = (u16)skb->len;
1089 tx->len = cpu_to_le16(len);
1090
1091
1092 tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
1093 tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
1094
1095 if (!ieee80211_has_morefrags(hdr->frame_control)) {
1096 txq->need_update = 1;
1097 if (qc)
1098 priv->stations_39[sta_id].tid[tid].seq_number = seq_number;
1099 } else {
1100 wait_write_ptr = 1;
1101 txq->need_update = 0;
1102 }
1103
1104 IWL_DEBUG_TX(priv, "sequence nr = 0X%x \n",
1105 le16_to_cpu(out_cmd->hdr.sequence));
1106 IWL_DEBUG_TX(priv, "tx_flags = 0X%x \n", le32_to_cpu(tx->tx_flags));
1107 iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx));
1108 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr,
1109 ieee80211_hdrlen(fc));
1110
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001111 /*
1112 * Use the first empty entry in this queue's command buffer array
1113 * to contain the Tx command and MAC header concatenated together
1114 * (payload data will be in another buffer).
1115 * Size of this varies, due to varying MAC header length.
1116 * If end is not dword aligned, we'll have 2 extra bytes at the end
1117 * of the MAC header (device reads on dword boundaries).
1118 * We'll tell device about this padding later.
1119 */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001120 len = sizeof(struct iwl3945_tx_cmd) +
Tomas Winkler4c897252008-12-19 10:37:05 +08001121 sizeof(struct iwl_cmd_header) + hdr_len;
Zhu Yib481de92007-09-25 17:54:57 -07001122
1123 len_org = len;
1124 len = (len + 3) & ~3;
1125
1126 if (len_org != len)
1127 len_org = 1;
1128 else
1129 len_org = 0;
1130
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001131 /* Physical address of this Tx command's header (not MAC header!),
1132 * within command buffer array. */
Reinette Chatredf833b12009-04-21 10:55:48 -07001133 txcmd_phys = pci_map_single(priv->pci_dev, &out_cmd->hdr,
1134 len, PCI_DMA_TODEVICE);
1135 /* we do not map meta data ... so we can safely access address to
1136 * provide to unmap command*/
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001137 pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys);
Reinette Chatredf833b12009-04-21 10:55:48 -07001138 pci_unmap_len_set(&out_cmd->meta, len, len);
Zhu Yib481de92007-09-25 17:54:57 -07001139
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001140 /* Add buffer containing Tx command and MAC(!) header to TFD's
1141 * first entry */
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001142 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1143 txcmd_phys, len, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001144
Zhu Yib481de92007-09-25 17:54:57 -07001145
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001146 /* Set up TFD's 2nd entry to point directly to remainder of skb,
1147 * if any (802.11 null frames have no payload). */
Zhu Yib481de92007-09-25 17:54:57 -07001148 len = skb->len - hdr_len;
1149 if (len) {
1150 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
1151 len, PCI_DMA_TODEVICE);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001152 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1153 phys_addr, len,
1154 0, U32_PAD(len));
Zhu Yib481de92007-09-25 17:54:57 -07001155 }
1156
Zhu Yib481de92007-09-25 17:54:57 -07001157
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001158 /* Tell device the write index *just past* this latest filled TFD */
Tomas Winklerc54b6792008-03-06 17:36:53 -08001159 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001160 rc = iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001161 spin_unlock_irqrestore(&priv->lock, flags);
1162
1163 if (rc)
1164 return rc;
1165
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001166 if ((iwl_queue_space(q) < q->high_mark)
Zhu Yib481de92007-09-25 17:54:57 -07001167 && priv->mac80211_registered) {
1168 if (wait_write_ptr) {
1169 spin_lock_irqsave(&priv->lock, flags);
1170 txq->need_update = 1;
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001171 iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001172 spin_unlock_irqrestore(&priv->lock, flags);
1173 }
1174
Johannes Berge4e72fb2009-03-23 17:28:42 +01001175 iwl_stop_queue(priv, skb_get_queue_mapping(skb));
Zhu Yib481de92007-09-25 17:54:57 -07001176 }
1177
1178 return 0;
1179
1180drop_unlock:
1181 spin_unlock_irqrestore(&priv->lock, flags);
1182drop:
1183 return -1;
1184}
1185
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001186#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07001187
1188#include "iwl-spectrum.h"
1189
1190#define BEACON_TIME_MASK_LOW 0x00FFFFFF
1191#define BEACON_TIME_MASK_HIGH 0xFF000000
1192#define TIME_UNIT 1024
1193
1194/*
1195 * extended beacon time format
1196 * time in usec will be changed into a 32-bit value in 8:24 format
1197 * the high 1 byte is the beacon counts
1198 * the lower 3 bytes is the time in usec within one beacon interval
1199 */
1200
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001201static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001202{
1203 u32 quot;
1204 u32 rem;
1205 u32 interval = beacon_interval * 1024;
1206
1207 if (!interval || !usec)
1208 return 0;
1209
1210 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
1211 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
1212
1213 return (quot << 24) + rem;
1214}
1215
1216/* base is usually what we get from ucode with each received frame,
1217 * the same as HW timer counter counting down
1218 */
1219
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001220static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001221{
1222 u32 base_low = base & BEACON_TIME_MASK_LOW;
1223 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
1224 u32 interval = beacon_interval * TIME_UNIT;
1225 u32 res = (base & BEACON_TIME_MASK_HIGH) +
1226 (addon & BEACON_TIME_MASK_HIGH);
1227
1228 if (base_low > addon_low)
1229 res += base_low - addon_low;
1230 else if (base_low < addon_low) {
1231 res += interval + base_low - addon_low;
1232 res += (1 << 24);
1233 } else
1234 res += (1 << 24);
1235
1236 return cpu_to_le32(res);
1237}
1238
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001239static int iwl3945_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001240 struct ieee80211_measurement_params *params,
1241 u8 type)
1242{
Tomas Winkler600c0e12008-12-19 10:37:04 +08001243 struct iwl_spectrum_cmd spectrum;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001244 struct iwl_rx_packet *res;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08001245 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001246 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
1247 .data = (void *)&spectrum,
1248 .meta.flags = CMD_WANT_SKB,
1249 };
1250 u32 add_time = le64_to_cpu(params->start_time);
1251 int rc;
1252 int spectrum_resp_status;
1253 int duration = le16_to_cpu(params->duration);
1254
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001255 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001256 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001257 iwl3945_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -07001258 le64_to_cpu(params->start_time) - priv->last_tsf,
1259 le16_to_cpu(priv->rxon_timing.beacon_interval));
1260
1261 memset(&spectrum, 0, sizeof(spectrum));
1262
1263 spectrum.channel_count = cpu_to_le16(1);
1264 spectrum.flags =
1265 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
1266 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
1267 cmd.len = sizeof(spectrum);
1268 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
1269
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001270 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001271 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001272 iwl3945_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -07001273 add_time,
1274 le16_to_cpu(priv->rxon_timing.beacon_interval));
1275 else
1276 spectrum.start_time = 0;
1277
1278 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
1279 spectrum.channels[0].channel = params->channel;
1280 spectrum.channels[0].type = type;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001281 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
Zhu Yib481de92007-09-25 17:54:57 -07001282 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
1283 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
1284
Samuel Ortiz518099a2009-01-19 15:30:27 -08001285 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001286 if (rc)
1287 return rc;
1288
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001289 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001290 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001291 IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -07001292 rc = -EIO;
1293 }
1294
1295 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
1296 switch (spectrum_resp_status) {
1297 case 0: /* Command will be handled */
1298 if (res->u.spectrum.id != 0xff) {
Tomas Winklere1623442009-01-27 14:27:56 -08001299 IWL_DEBUG_INFO(priv, "Replaced existing measurement: %d\n",
Ian Schrambc434dd2007-10-25 17:15:29 +08001300 res->u.spectrum.id);
Zhu Yib481de92007-09-25 17:54:57 -07001301 priv->measurement_status &= ~MEASUREMENT_READY;
1302 }
1303 priv->measurement_status |= MEASUREMENT_ACTIVE;
1304 rc = 0;
1305 break;
1306
1307 case 1: /* Command will not be handled */
1308 rc = -EAGAIN;
1309 break;
1310 }
1311
1312 dev_kfree_skb_any(cmd.meta.u.skb);
1313
1314 return rc;
1315}
1316#endif
1317
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001318static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001319 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001320{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001321 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
1322 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -07001323 struct delayed_work *pwork;
1324
1325 palive = &pkt->u.alive_frame;
1326
Tomas Winklere1623442009-01-27 14:27:56 -08001327 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
Zhu Yib481de92007-09-25 17:54:57 -07001328 "0x%01X 0x%01X\n",
1329 palive->is_valid, palive->ver_type,
1330 palive->ver_subtype);
1331
1332 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
Tomas Winklere1623442009-01-27 14:27:56 -08001333 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001334 memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
1335 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001336 pwork = &priv->init_alive_start;
1337 } else {
Tomas Winklere1623442009-01-27 14:27:56 -08001338 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001339 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001340 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001341 pwork = &priv->alive_start;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001342 iwl3945_disable_events(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001343 }
1344
1345 /* We delay the ALIVE response by 5ms to
1346 * give the HW RF Kill time to activate... */
1347 if (palive->is_valid == UCODE_VALID_OK)
1348 queue_delayed_work(priv->workqueue, pwork,
1349 msecs_to_jiffies(5));
1350 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001351 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001352}
1353
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001354static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001355 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001356{
Helmut Schaac7e035a2009-01-19 13:02:15 +01001357#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001358 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Helmut Schaac7e035a2009-01-19 13:02:15 +01001359#endif
Zhu Yib481de92007-09-25 17:54:57 -07001360
Tomas Winklere1623442009-01-27 14:27:56 -08001361 IWL_DEBUG_RX(priv, "Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
Zhu Yib481de92007-09-25 17:54:57 -07001362 return;
1363}
1364
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001365static void iwl3945_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07001366{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001367 struct iwl_priv *priv =
1368 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07001369 struct sk_buff *beacon;
1370
1371 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02001372 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07001373
1374 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001375 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07001376 return;
1377 }
1378
1379 mutex_lock(&priv->mutex);
1380 /* new beacon skb is allocated every time; dispose previous.*/
1381 if (priv->ibss_beacon)
1382 dev_kfree_skb(priv->ibss_beacon);
1383
1384 priv->ibss_beacon = beacon;
1385 mutex_unlock(&priv->mutex);
1386
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001387 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001388}
1389
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001390static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001391 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001392{
Samuel Ortizd08853a2009-01-23 13:45:17 -08001393#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001394 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001395 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
Zhu Yib481de92007-09-25 17:54:57 -07001396 u8 rate = beacon->beacon_notify_hdr.rate;
1397
Tomas Winklere1623442009-01-27 14:27:56 -08001398 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
Zhu Yib481de92007-09-25 17:54:57 -07001399 "tsf %d %d rate %d\n",
1400 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
1401 beacon->beacon_notify_hdr.failure_frame,
1402 le32_to_cpu(beacon->ibss_mgr_status),
1403 le32_to_cpu(beacon->high_tsf),
1404 le32_to_cpu(beacon->low_tsf), rate);
1405#endif
1406
Johannes Berg05c914f2008-09-11 00:01:58 +02001407 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -07001408 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1409 queue_work(priv->workqueue, &priv->beacon_update);
1410}
1411
Zhu Yib481de92007-09-25 17:54:57 -07001412/* Handle notification from uCode that card's power state is changing
1413 * due to software, hardware, or critical temperature RFKILL */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001414static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001415 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001416{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001417 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001418 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1419 unsigned long status = priv->status;
1420
Tomas Winklere1623442009-01-27 14:27:56 -08001421 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n",
Zhu Yib481de92007-09-25 17:54:57 -07001422 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1423 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1424
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001425 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001426 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1427
1428 if (flags & HW_CARD_DISABLED)
1429 set_bit(STATUS_RF_KILL_HW, &priv->status);
1430 else
1431 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1432
1433
1434 if (flags & SW_CARD_DISABLED)
1435 set_bit(STATUS_RF_KILL_SW, &priv->status);
1436 else
1437 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1438
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08001439 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001440
1441 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1442 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1443 (test_bit(STATUS_RF_KILL_SW, &status) !=
1444 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1445 queue_work(priv->workqueue, &priv->rf_kill);
1446 else
1447 wake_up_interruptible(&priv->wait_command_queue);
1448}
1449
1450/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001451 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07001452 *
1453 * Setup the RX handlers for each of the reply types sent from the uCode
1454 * to the host.
1455 *
1456 * This function chains into the hardware specific files for them to setup
1457 * any hardware specific handlers as well.
1458 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001459static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001460{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001461 priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
1462 priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
Abhijeet Kolekar261b9c32009-02-18 15:54:29 -08001463 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001464 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -08001465 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001466 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -08001467 iwl_rx_pm_debug_statistics_notif;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001468 priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001469
Ben Cahill9fbab512007-11-29 11:09:47 +08001470 /*
1471 * The same handler is used for both the REPLY to a discrete
1472 * statistics request from the host as well as for the periodic
1473 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07001474 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001475 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
1476 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
Zhu Yib481de92007-09-25 17:54:57 -07001477
Abhijeet Kolekar261b9c32009-02-18 15:54:29 -08001478 iwl_setup_spectrum_handlers(priv);
Abhijeet Kolekarcade0eb2009-02-18 15:54:26 -08001479 iwl_setup_rx_scan_handlers(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001480 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001481
Ben Cahill9fbab512007-11-29 11:09:47 +08001482 /* Set up hardware specific Rx handlers */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001483 iwl3945_hw_rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001484}
1485
Zhu Yib481de92007-09-25 17:54:57 -07001486/************************** RX-FUNCTIONS ****************************/
1487/*
1488 * Rx theory of operation
1489 *
1490 * The host allocates 32 DMA target addresses and passes the host address
1491 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
1492 * 0 to 31
1493 *
1494 * Rx Queue Indexes
1495 * The host/firmware share two index registers for managing the Rx buffers.
1496 *
1497 * The READ index maps to the first position that the firmware may be writing
1498 * to -- the driver can read up to (but not including) this position and get
1499 * good data.
1500 * The READ index is managed by the firmware once the card is enabled.
1501 *
1502 * The WRITE index maps to the last position the driver has read from -- the
1503 * position preceding WRITE is the last slot the firmware can place a packet.
1504 *
1505 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
1506 * WRITE = READ.
1507 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001508 * During initialization, the host sets up the READ queue position to the first
Zhu Yib481de92007-09-25 17:54:57 -07001509 * INDEX position, and WRITE to the last (READ - 1 wrapped)
1510 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001511 * When the firmware places a packet in a buffer, it will advance the READ index
Zhu Yib481de92007-09-25 17:54:57 -07001512 * and fire the RX interrupt. The driver can then query the READ index and
1513 * process as many packets as possible, moving the WRITE index forward as it
1514 * resets the Rx queue buffers with new memory.
1515 *
1516 * The management in the driver is as follows:
1517 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
1518 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Ian Schram01ebd062007-10-25 17:15:22 +08001519 * to replenish the iwl->rxq->rx_free.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001520 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
Zhu Yib481de92007-09-25 17:54:57 -07001521 * iwl->rxq is replenished and the READ INDEX is updated (updating the
1522 * 'processed' and 'read' driver indexes as well)
1523 * + A received packet is processed and handed to the kernel network stack,
1524 * detached from the iwl->rxq. The driver 'processed' index is updated.
1525 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
1526 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
1527 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
1528 * were enough free buffers and RX_STALLED is set it is cleared.
1529 *
1530 *
1531 * Driver sequence:
1532 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001533 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001534 * iwl3945_rx_queue_restock
Ben Cahill9fbab512007-11-29 11:09:47 +08001535 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
Zhu Yib481de92007-09-25 17:54:57 -07001536 * queue, updates firmware pointers, and updates
1537 * the WRITE index. If insufficient rx_free buffers
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001538 * are available, schedules iwl3945_rx_replenish
Zhu Yib481de92007-09-25 17:54:57 -07001539 *
1540 * -- enable interrupts --
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001541 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
Zhu Yib481de92007-09-25 17:54:57 -07001542 * READ INDEX, detaching the SKB from the pool.
1543 * Moves the packet buffer from queue to rx_used.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001544 * Calls iwl3945_rx_queue_restock to refill any empty
Zhu Yib481de92007-09-25 17:54:57 -07001545 * slots.
1546 * ...
1547 *
1548 */
1549
1550/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001551 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
Zhu Yib481de92007-09-25 17:54:57 -07001552 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001553static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001554 dma_addr_t dma_addr)
1555{
1556 return cpu_to_le32((u32)dma_addr);
1557}
1558
1559/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001560 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
Zhu Yib481de92007-09-25 17:54:57 -07001561 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001562 * If there are slots in the RX queue that need to be restocked,
Zhu Yib481de92007-09-25 17:54:57 -07001563 * and we have free pre-allocated buffers, fill the ranks as much
Ben Cahill9fbab512007-11-29 11:09:47 +08001564 * as we can, pulling from rx_free.
Zhu Yib481de92007-09-25 17:54:57 -07001565 *
1566 * This moves the 'write' index forward to catch up with 'processed', and
1567 * also updates the memory address in the firmware to reference the new
1568 * target buffer.
1569 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001570static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001571{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001572 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001573 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001574 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001575 unsigned long flags;
1576 int write, rc;
1577
1578 spin_lock_irqsave(&rxq->lock, flags);
1579 write = rxq->write & ~0x7;
Winkler, Tomas37d68312009-01-08 10:19:54 -08001580 while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001581 /* Get next free Rx buffer, remove from free list */
Zhu Yib481de92007-09-25 17:54:57 -07001582 element = rxq->rx_free.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001583 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Zhu Yib481de92007-09-25 17:54:57 -07001584 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001585
1586 /* Point to Rx buffer via next RBD in circular buffer */
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001587 rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
Zhu Yib481de92007-09-25 17:54:57 -07001588 rxq->queue[rxq->write] = rxb;
1589 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
1590 rxq->free_count--;
1591 }
1592 spin_unlock_irqrestore(&rxq->lock, flags);
1593 /* If the pre-allocated buffer pool is dropping low, schedule to
1594 * refill it */
1595 if (rxq->free_count <= RX_LOW_WATERMARK)
1596 queue_work(priv->workqueue, &priv->rx_replenish);
1597
1598
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001599 /* If we've added more space for the firmware to place data, tell it.
1600 * Increment device's write pointer in multiples of 8. */
Zhu Yib481de92007-09-25 17:54:57 -07001601 if ((write != (rxq->write & ~0x7))
1602 || (abs(rxq->write - rxq->read) > 7)) {
1603 spin_lock_irqsave(&rxq->lock, flags);
1604 rxq->need_update = 1;
1605 spin_unlock_irqrestore(&rxq->lock, flags);
Winkler, Tomas141c43a2009-01-08 10:19:53 -08001606 rc = iwl_rx_queue_update_write_ptr(priv, rxq);
Zhu Yib481de92007-09-25 17:54:57 -07001607 if (rc)
1608 return rc;
1609 }
1610
1611 return 0;
1612}
1613
1614/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001615 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
Zhu Yib481de92007-09-25 17:54:57 -07001616 *
1617 * When moving to rx_free an SKB is allocated for the slot.
1618 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001619 * Also restock the Rx queue via iwl3945_rx_queue_restock.
Ian Schram01ebd062007-10-25 17:15:22 +08001620 * This is called as a scheduled work item (except for during initialization)
Zhu Yib481de92007-09-25 17:54:57 -07001621 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001622static void iwl3945_rx_allocate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001623{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001624 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001625 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001626 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001627 unsigned long flags;
1628 spin_lock_irqsave(&rxq->lock, flags);
1629 while (!list_empty(&rxq->rx_used)) {
1630 element = rxq->rx_used.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001631 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001632
1633 /* Alloc a new receive buffer */
Zhu Yib481de92007-09-25 17:54:57 -07001634 rxb->skb =
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001635 alloc_skb(priv->hw_params.rx_buf_size,
1636 __GFP_NOWARN | GFP_ATOMIC);
Zhu Yib481de92007-09-25 17:54:57 -07001637 if (!rxb->skb) {
1638 if (net_ratelimit())
Tomas Winkler978785a2008-12-19 10:37:31 +08001639 IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
Zhu Yib481de92007-09-25 17:54:57 -07001640 /* We don't reschedule replenish work here -- we will
1641 * call the restock method and if it still needs
1642 * more buffers it will schedule replenish */
1643 break;
1644 }
Zhu Yi12342c42007-12-20 11:27:32 +08001645
1646 /* If radiotap head is required, reserve some headroom here.
1647 * The physical head count is a variable rx_stats->phy_count.
1648 * We reserve 4 bytes here. Plus these extra bytes, the
1649 * headroom of the physical head should be enough for the
1650 * radiotap head that iwl3945 supported. See iwl3945_rt.
1651 */
1652 skb_reserve(rxb->skb, 4);
1653
Zhu Yib481de92007-09-25 17:54:57 -07001654 priv->alloc_rxb_skb++;
1655 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001656
1657 /* Get physical address of RB/SKB */
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001658 rxb->real_dma_addr = pci_map_single(priv->pci_dev,
1659 rxb->skb->data,
1660 priv->hw_params.rx_buf_size,
1661 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001662 list_add_tail(&rxb->list, &rxq->rx_free);
1663 rxq->free_count++;
1664 }
1665 spin_unlock_irqrestore(&rxq->lock, flags);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001666}
1667
Reinette Chatredf833b12009-04-21 10:55:48 -07001668void iwl3945_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
1669{
1670 unsigned long flags;
1671 int i;
1672 spin_lock_irqsave(&rxq->lock, flags);
1673 INIT_LIST_HEAD(&rxq->rx_free);
1674 INIT_LIST_HEAD(&rxq->rx_used);
1675 /* Fill the rx_used queue with _all_ of the Rx buffers */
1676 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
1677 /* In the reset function, these buffers may have been allocated
1678 * to an SKB, so we need to unmap and free potential storage */
1679 if (rxq->pool[i].skb != NULL) {
1680 pci_unmap_single(priv->pci_dev,
1681 rxq->pool[i].real_dma_addr,
1682 priv->hw_params.rx_buf_size,
1683 PCI_DMA_FROMDEVICE);
1684 priv->alloc_rxb_skb--;
1685 dev_kfree_skb(rxq->pool[i].skb);
1686 rxq->pool[i].skb = NULL;
1687 }
1688 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
1689 }
1690
1691 /* Set us so that we have processed and used all buffers, but have
1692 * not restocked the Rx queue with fresh buffers */
1693 rxq->read = rxq->write = 0;
1694 rxq->free_count = 0;
1695 spin_unlock_irqrestore(&rxq->lock, flags);
1696}
1697EXPORT_SYMBOL(iwl3945_rx_queue_reset);
1698
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001699/*
1700 * this should be called while priv->lock is locked
1701 */
Tomas Winkler4fd1f842007-12-05 20:59:58 +02001702static void __iwl3945_rx_replenish(void *data)
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001703{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001704 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001705
1706 iwl3945_rx_allocate(priv);
1707 iwl3945_rx_queue_restock(priv);
1708}
1709
1710
1711void iwl3945_rx_replenish(void *data)
1712{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001713 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001714 unsigned long flags;
1715
1716 iwl3945_rx_allocate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001717
1718 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001719 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001720 spin_unlock_irqrestore(&priv->lock, flags);
1721}
1722
Reinette Chatredf833b12009-04-21 10:55:48 -07001723/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
1724 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
1725 * This free routine walks the list of POOL entries and if SKB is set to
1726 * non NULL it is unmapped and freed
1727 */
1728static void iwl3945_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
1729{
1730 int i;
1731 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
1732 if (rxq->pool[i].skb != NULL) {
1733 pci_unmap_single(priv->pci_dev,
1734 rxq->pool[i].real_dma_addr,
1735 priv->hw_params.rx_buf_size,
1736 PCI_DMA_FROMDEVICE);
1737 dev_kfree_skb(rxq->pool[i].skb);
1738 }
1739 }
1740
1741 pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd,
1742 rxq->dma_addr);
1743 pci_free_consistent(priv->pci_dev, sizeof(struct iwl_rb_status),
1744 rxq->rb_stts, rxq->rb_stts_dma);
1745 rxq->bd = NULL;
1746 rxq->rb_stts = NULL;
1747}
1748EXPORT_SYMBOL(iwl3945_rx_queue_free);
1749
1750
Zhu Yib481de92007-09-25 17:54:57 -07001751/* Convert linear signal-to-noise ratio into dB */
1752static u8 ratio2dB[100] = {
1753/* 0 1 2 3 4 5 6 7 8 9 */
1754 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
1755 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
1756 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
1757 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
1758 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
1759 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
1760 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
1761 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
1762 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
1763 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
1764};
1765
1766/* Calculates a relative dB value from a ratio of linear
1767 * (i.e. not dB) signal levels.
1768 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001769int iwl3945_calc_db_from_ratio(int sig_ratio)
Zhu Yib481de92007-09-25 17:54:57 -07001770{
Adrian Bunk221c80c2008-02-02 23:19:01 +02001771 /* 1000:1 or higher just report as 60 dB */
1772 if (sig_ratio >= 1000)
Zhu Yib481de92007-09-25 17:54:57 -07001773 return 60;
1774
Adrian Bunk221c80c2008-02-02 23:19:01 +02001775 /* 100:1 or higher, divide by 10 and use table,
Zhu Yib481de92007-09-25 17:54:57 -07001776 * add 20 dB to make up for divide by 10 */
Adrian Bunk221c80c2008-02-02 23:19:01 +02001777 if (sig_ratio >= 100)
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001778 return 20 + (int)ratio2dB[sig_ratio/10];
Zhu Yib481de92007-09-25 17:54:57 -07001779
1780 /* We shouldn't see this */
1781 if (sig_ratio < 1)
1782 return 0;
1783
1784 /* Use table for ratios 1:1 - 99:1 */
1785 return (int)ratio2dB[sig_ratio];
1786}
1787
1788#define PERFECT_RSSI (-20) /* dBm */
1789#define WORST_RSSI (-95) /* dBm */
1790#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
1791
1792/* Calculate an indication of rx signal quality (a percentage, not dBm!).
1793 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
1794 * about formulas used below. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001795int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
Zhu Yib481de92007-09-25 17:54:57 -07001796{
1797 int sig_qual;
1798 int degradation = PERFECT_RSSI - rssi_dbm;
1799
1800 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
1801 * as indicator; formula is (signal dbm - noise dbm).
1802 * SNR at or above 40 is a great signal (100%).
1803 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
1804 * Weakest usable signal is usually 10 - 15 dB SNR. */
1805 if (noise_dbm) {
1806 if (rssi_dbm - noise_dbm >= 40)
1807 return 100;
1808 else if (rssi_dbm < noise_dbm)
1809 return 0;
1810 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
1811
1812 /* Else use just the signal level.
1813 * This formula is a least squares fit of data points collected and
1814 * compared with a reference system that had a percentage (%) display
1815 * for signal quality. */
1816 } else
1817 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
1818 (15 * RSSI_RANGE + 62 * degradation)) /
1819 (RSSI_RANGE * RSSI_RANGE);
1820
1821 if (sig_qual > 100)
1822 sig_qual = 100;
1823 else if (sig_qual < 1)
1824 sig_qual = 0;
1825
1826 return sig_qual;
1827}
1828
1829/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001830 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001831 *
1832 * Uses the priv->rx_handlers callback function array to invoke
1833 * the appropriate handlers, including command responses,
1834 * frame-received notifications, and other notifications.
1835 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001836static void iwl3945_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001837{
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001838 struct iwl_rx_mem_buffer *rxb;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001839 struct iwl_rx_packet *pkt;
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001840 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001841 u32 r, i;
1842 int reclaim;
1843 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001844 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001845 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07001846
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001847 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1848 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8cd812b2008-12-19 10:37:43 +08001849 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07001850 i = rxq->read;
1851
Winkler, Tomas37d68312009-01-08 10:19:54 -08001852 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001853 fill_rx = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001854 /* Rx interrupt, but nothing sent from uCode */
1855 if (i == r)
Tomas Winklere1623442009-01-27 14:27:56 -08001856 IWL_DEBUG(priv, IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001857
1858 while (i != r) {
1859 rxb = rxq->queue[i];
1860
Ben Cahill9fbab512007-11-29 11:09:47 +08001861 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001862 * then a bug has been introduced in the queue refilling
1863 * routines -- catch it here */
1864 BUG_ON(rxb == NULL);
1865
1866 rxq->queue[i] = NULL;
1867
Reinette Chatredf833b12009-04-21 10:55:48 -07001868 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
1869 priv->hw_params.rx_buf_size,
1870 PCI_DMA_FROMDEVICE);
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001871 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001872
1873 /* Reclaim a command buffer only if this packet is a response
1874 * to a (driver-originated) command.
1875 * If the packet (e.g. Rx frame) originated from uCode,
1876 * there is no command buffer to reclaim.
1877 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1878 * but apparently a few don't get set; catch them here. */
1879 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1880 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1881 (pkt->hdr.cmd != REPLY_TX);
1882
1883 /* Based on type of command response or notification,
1884 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001885 * rx_handlers table. See iwl3945_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001886 if (priv->rx_handlers[pkt->hdr.cmd]) {
Tomas Winklere1623442009-01-27 14:27:56 -08001887 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07001888 "r = %d, i = %d, %s, 0x%02x\n", r, i,
1889 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
1890 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1891 } else {
1892 /* No handling needed */
Tomas Winklere1623442009-01-27 14:27:56 -08001893 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07001894 "r %d i %d No handler needed for %s, 0x%02x\n",
1895 r, i, get_cmd_string(pkt->hdr.cmd),
1896 pkt->hdr.cmd);
1897 }
1898
1899 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001900 /* Invoke any callbacks, transfer the skb to caller, and
Samuel Ortiz518099a2009-01-19 15:30:27 -08001901 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001902 * as we reclaim the driver command queue */
1903 if (rxb && rxb->skb)
Abhijeet Kolekar732587a2009-03-11 11:17:57 -07001904 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001905 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001906 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07001907 }
1908
1909 /* For now we just don't re-use anything. We can tweak this
1910 * later to try and re-use notification packets and SKBs that
1911 * fail to Rx correctly */
1912 if (rxb->skb != NULL) {
1913 priv->alloc_rxb_skb--;
1914 dev_kfree_skb_any(rxb->skb);
1915 rxb->skb = NULL;
1916 }
1917
Zhu Yib481de92007-09-25 17:54:57 -07001918 spin_lock_irqsave(&rxq->lock, flags);
1919 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1920 spin_unlock_irqrestore(&rxq->lock, flags);
1921 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001922 /* If there are a lot of unused frames,
1923 * restock the Rx queue so ucode won't assert. */
1924 if (fill_rx) {
1925 count++;
1926 if (count >= 8) {
1927 priv->rxq.read = i;
1928 __iwl3945_rx_replenish(priv);
1929 count = 0;
1930 }
1931 }
Zhu Yib481de92007-09-25 17:54:57 -07001932 }
1933
1934 /* Backtrack one entry */
1935 priv->rxq.read = i;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001936 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001937}
1938
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001939/* call this function to flush any scheduled tasklet */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001940static inline void iwl_synchronize_irq(struct iwl_priv *priv)
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001941{
Tomas Winklera96a27f2008-10-23 23:48:56 -07001942 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001943 synchronize_irq(priv->pci_dev->irq);
1944 tasklet_kill(&priv->irq_tasklet);
1945}
1946
Zhu Yib481de92007-09-25 17:54:57 -07001947static const char *desc_lookup(int i)
1948{
1949 switch (i) {
1950 case 1:
1951 return "FAIL";
1952 case 2:
1953 return "BAD_PARAM";
1954 case 3:
1955 return "BAD_CHECKSUM";
1956 case 4:
1957 return "NMI_INTERRUPT";
1958 case 5:
1959 return "SYSASSERT";
1960 case 6:
1961 return "FATAL_ERROR";
1962 }
1963
1964 return "UNKNOWN";
1965}
1966
1967#define ERROR_START_OFFSET (1 * sizeof(u32))
1968#define ERROR_ELEM_SIZE (7 * sizeof(u32))
1969
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001970static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001971{
1972 u32 i;
1973 u32 desc, time, count, base, data1;
1974 u32 blink1, blink2, ilink1, ilink2;
1975 int rc;
1976
1977 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
1978
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001979 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001980 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07001981 return;
1982 }
1983
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001984 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001985 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001986 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001987 return;
1988 }
1989
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001990 count = iwl_read_targ_mem(priv, base);
Zhu Yib481de92007-09-25 17:54:57 -07001991
1992 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001993 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
1994 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
1995 priv->status, count);
Zhu Yib481de92007-09-25 17:54:57 -07001996 }
1997
Winkler, Tomas15b16872008-12-19 10:37:33 +08001998 IWL_ERR(priv, "Desc Time asrtPC blink2 "
Zhu Yib481de92007-09-25 17:54:57 -07001999 "ilink1 nmiPC Line\n");
2000 for (i = ERROR_START_OFFSET;
2001 i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
2002 i += ERROR_ELEM_SIZE) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002003 desc = iwl_read_targ_mem(priv, base + i);
Zhu Yib481de92007-09-25 17:54:57 -07002004 time =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002005 iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002006 blink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002007 iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002008 blink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002009 iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002010 ilink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002011 iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002012 ilink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002013 iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002014 data1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002015 iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002016
Winkler, Tomas15b16872008-12-19 10:37:33 +08002017 IWL_ERR(priv,
2018 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
2019 desc_lookup(desc), desc, time, blink1, blink2,
2020 ilink1, ilink2, data1);
Zhu Yib481de92007-09-25 17:54:57 -07002021 }
2022
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002023 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002024
2025}
2026
Ben Cahillf58177b2007-11-29 11:09:43 +08002027#define EVENT_START_OFFSET (6 * sizeof(u32))
Zhu Yib481de92007-09-25 17:54:57 -07002028
2029/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002030 * iwl3945_print_event_log - Dump error event log to syslog
Zhu Yib481de92007-09-25 17:54:57 -07002031 *
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002032 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
Zhu Yib481de92007-09-25 17:54:57 -07002033 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002034static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
Zhu Yib481de92007-09-25 17:54:57 -07002035 u32 num_events, u32 mode)
2036{
2037 u32 i;
2038 u32 base; /* SRAM byte address of event log header */
2039 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
2040 u32 ptr; /* SRAM byte address of log data */
2041 u32 ev, time, data; /* event log data */
2042
2043 if (num_events == 0)
2044 return;
2045
2046 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
2047
2048 if (mode == 0)
2049 event_size = 2 * sizeof(u32);
2050 else
2051 event_size = 3 * sizeof(u32);
2052
2053 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
2054
2055 /* "time" is actually "data" for mode 0 (no timestamp).
2056 * place event id # at far right for easier visual parsing. */
2057 for (i = 0; i < num_events; i++) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002058 ev = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002059 ptr += sizeof(u32);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002060 time = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002061 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002062 if (mode == 0) {
2063 /* data, ev */
2064 IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
2065 } else {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002066 data = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002067 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002068 IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
Zhu Yib481de92007-09-25 17:54:57 -07002069 }
2070 }
2071}
2072
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002073static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002074{
2075 int rc;
2076 u32 base; /* SRAM byte address of event log header */
2077 u32 capacity; /* event log capacity in # entries */
2078 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
2079 u32 num_wraps; /* # times uCode wrapped to top of log */
2080 u32 next_entry; /* index of next entry to be written by uCode */
2081 u32 size; /* # entries that we'll print */
2082
2083 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002084 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002085 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07002086 return;
2087 }
2088
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002089 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002090 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002091 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002092 return;
2093 }
2094
2095 /* event log header */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002096 capacity = iwl_read_targ_mem(priv, base);
2097 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
2098 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
2099 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
Zhu Yib481de92007-09-25 17:54:57 -07002100
2101 size = num_wraps ? capacity : next_entry;
2102
2103 /* bail out if nothing in log */
2104 if (size == 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002105 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002106 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002107 return;
2108 }
2109
Winkler, Tomas15b16872008-12-19 10:37:33 +08002110 IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07002111 size, num_wraps);
2112
2113 /* if uCode has wrapped back to top of log, start at the oldest entry,
2114 * i.e the next one that uCode would fill. */
2115 if (num_wraps)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002116 iwl3945_print_event_log(priv, next_entry,
Zhu Yib481de92007-09-25 17:54:57 -07002117 capacity - next_entry, mode);
2118
2119 /* (then/else) start at top of log */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002120 iwl3945_print_event_log(priv, 0, next_entry, mode);
Zhu Yib481de92007-09-25 17:54:57 -07002121
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002122 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002123}
2124
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002125static void iwl3945_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002126{
2127 unsigned long flags;
2128
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002129 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
2130 sizeof(priv->staging_rxon));
2131 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002132 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002133
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002134 iwl3945_add_station(priv, priv->bssid, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002135
2136 spin_lock_irqsave(&priv->lock, flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002137 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07002138 priv->error_recovering = 0;
2139 spin_unlock_irqrestore(&priv->lock, flags);
2140}
2141
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002142static void iwl3945_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002143{
2144 u32 inta, handled = 0;
2145 u32 inta_fh;
2146 unsigned long flags;
Samuel Ortizd08853a2009-01-23 13:45:17 -08002147#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07002148 u32 inta_mask;
2149#endif
2150
2151 spin_lock_irqsave(&priv->lock, flags);
2152
2153 /* Ack/clear/reset pending uCode interrupts.
2154 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
2155 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002156 inta = iwl_read32(priv, CSR_INT);
2157 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07002158
2159 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
2160 * Any new interrupts that happen after this, either while we're
2161 * in this tasklet, or later, will show up in next ISR/tasklet. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002162 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
2163 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07002164
Samuel Ortizd08853a2009-01-23 13:45:17 -08002165#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002166 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08002167 /* just for debug */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002168 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Tomas Winklere1623442009-01-27 14:27:56 -08002169 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002170 inta, inta_mask, inta_fh);
2171 }
2172#endif
2173
2174 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
2175 * atomic, make sure that inta covers all the interrupts that
2176 * we've discovered, even if FH interrupt came in just after
2177 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002178 if (inta_fh & CSR39_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002179 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002180 if (inta_fh & CSR39_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002181 inta |= CSR_INT_BIT_FH_TX;
2182
2183 /* Now service all interrupt bits discovered above. */
2184 if (inta & CSR_INT_BIT_HW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002185 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002186
2187 /* Tell the device to stop sending interrupts */
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002188 iwl_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002189
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002190 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002191
2192 handled |= CSR_INT_BIT_HW_ERR;
2193
2194 spin_unlock_irqrestore(&priv->lock, flags);
2195
2196 return;
2197 }
2198
Samuel Ortizd08853a2009-01-23 13:45:17 -08002199#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002200 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07002201 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002202 if (inta & CSR_INT_BIT_SCD)
Tomas Winklere1623442009-01-27 14:27:56 -08002203 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
Joonwoo Park25c03d82008-01-23 10:15:20 -08002204 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002205
2206 /* Alive notification via Rx interrupt will do the real work */
2207 if (inta & CSR_INT_BIT_ALIVE)
Tomas Winklere1623442009-01-27 14:27:56 -08002208 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002209 }
2210#endif
2211 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002212 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07002213
Zhu Yib481de92007-09-25 17:54:57 -07002214 /* Error detected by uCode */
2215 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002216 IWL_ERR(priv, "Microcode SW error detected. "
2217 "Restarting 0x%X.\n", inta);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002218 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002219 handled |= CSR_INT_BIT_SW_ERR;
2220 }
2221
2222 /* uCode wakes up after power-down sleep */
2223 if (inta & CSR_INT_BIT_WAKEUP) {
Tomas Winklere1623442009-01-27 14:27:56 -08002224 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
Winkler, Tomas141c43a2009-01-08 10:19:53 -08002225 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08002226 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
2227 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
2228 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
2229 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
2230 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
2231 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07002232
2233 handled |= CSR_INT_BIT_WAKEUP;
2234 }
2235
2236 /* All uCode command responses, including Tx command responses,
2237 * Rx "responses" (frame-received notification), and other
2238 * notifications from uCode come through here*/
2239 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002240 iwl3945_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002241 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
2242 }
2243
2244 if (inta & CSR_INT_BIT_FH_TX) {
Tomas Winklere1623442009-01-27 14:27:56 -08002245 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002246
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002247 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
2248 if (!iwl_grab_nic_access(priv)) {
2249 iwl_write_direct32(priv, FH39_TCSR_CREDIT
Tomas Winklerbddadf82008-12-19 10:37:01 +08002250 (FH39_SRVC_CHNL), 0x0);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002251 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002252 }
2253 handled |= CSR_INT_BIT_FH_TX;
2254 }
2255
2256 if (inta & ~handled)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002257 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Zhu Yib481de92007-09-25 17:54:57 -07002258
2259 if (inta & ~CSR_INI_SET_MASK) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002260 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Zhu Yib481de92007-09-25 17:54:57 -07002261 inta & ~CSR_INI_SET_MASK);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002262 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07002263 }
2264
2265 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002266 /* only Re-enable if disabled by irq */
2267 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002268 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002269
Samuel Ortizd08853a2009-01-23 13:45:17 -08002270#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002271 if (priv->debug_level & (IWL_DL_ISR)) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002272 inta = iwl_read32(priv, CSR_INT);
2273 inta_mask = iwl_read32(priv, CSR_INT_MASK);
2274 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Tomas Winklere1623442009-01-27 14:27:56 -08002275 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
Zhu Yib481de92007-09-25 17:54:57 -07002276 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
2277 }
2278#endif
2279 spin_unlock_irqrestore(&priv->lock, flags);
2280}
2281
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002282static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01002283 enum ieee80211_band band,
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08002284 u8 is_active, u8 n_probes,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002285 struct iwl3945_scan_channel *scan_ch)
Zhu Yib481de92007-09-25 17:54:57 -07002286{
2287 const struct ieee80211_channel *channels = NULL;
Johannes Berg8318d782008-01-24 19:38:38 +01002288 const struct ieee80211_supported_band *sband;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08002289 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07002290 u16 passive_dwell = 0;
2291 u16 active_dwell = 0;
2292 int added, i;
2293
Kolekar, Abhijeetcbba18c2008-12-19 10:37:42 +08002294 sband = iwl_get_hw_mode(priv, band);
Johannes Berg8318d782008-01-24 19:38:38 +01002295 if (!sband)
Zhu Yib481de92007-09-25 17:54:57 -07002296 return 0;
2297
Johannes Berg8318d782008-01-24 19:38:38 +01002298 channels = sband->channels;
Zhu Yib481de92007-09-25 17:54:57 -07002299
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08002300 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
2301 passive_dwell = iwl_get_passive_dwell_time(priv, band);
Zhu Yib481de92007-09-25 17:54:57 -07002302
Abhijeet Kolekar8f4807a2008-09-03 11:26:31 +08002303 if (passive_dwell <= active_dwell)
2304 passive_dwell = active_dwell + 1;
2305
Johannes Berg8318d782008-01-24 19:38:38 +01002306 for (i = 0, added = 0; i < sband->n_channels; i++) {
Johannes Berg182e2e62008-04-04 10:41:56 +02002307 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
2308 continue;
2309
Johannes Berg8318d782008-01-24 19:38:38 +01002310 scan_ch->channel = channels[i].hw_value;
Zhu Yib481de92007-09-25 17:54:57 -07002311
Samuel Ortize6148912009-01-23 13:45:15 -08002312 ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
Zhu Yib481de92007-09-25 17:54:57 -07002313 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002314 IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
Zhu Yib481de92007-09-25 17:54:57 -07002315 scan_ch->channel);
2316 continue;
2317 }
2318
Zhu Yib481de92007-09-25 17:54:57 -07002319 scan_ch->active_dwell = cpu_to_le16(active_dwell);
2320 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002321 /* If passive , set up for auto-switch
2322 * and use long active_dwell time.
2323 */
2324 if (!is_active || is_channel_passive(ch_info) ||
2325 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
2326 scan_ch->type = 0; /* passive */
2327 if (IWL_UCODE_API(priv->ucode_ver) == 1)
2328 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
2329 } else {
2330 scan_ch->type = 1; /* active */
2331 }
2332
2333 /* Set direct probe bits. These may be used both for active
2334 * scan channels (probes gets sent right away),
2335 * or for passive channels (probes get se sent only after
2336 * hearing clear Rx packet).*/
2337 if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
2338 if (n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002339 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002340 } else {
2341 /* uCode v1 does not allow setting direct probe bits on
2342 * passive channel. */
2343 if ((scan_ch->type & 1) && n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002344 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002345 }
Zhu Yib481de92007-09-25 17:54:57 -07002346
Ben Cahill9fbab512007-11-29 11:09:47 +08002347 /* Set txpower levels to defaults */
Zhu Yib481de92007-09-25 17:54:57 -07002348 scan_ch->tpc.dsp_atten = 110;
2349 /* scan_pwr_info->tpc.dsp_atten; */
2350
2351 /*scan_pwr_info->tpc.tx_gain; */
Johannes Berg8318d782008-01-24 19:38:38 +01002352 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -07002353 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
2354 else {
2355 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
2356 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
Ben Cahill9fbab512007-11-29 11:09:47 +08002357 * power level:
Reinette Chatre8a1b0242008-01-14 17:46:25 -08002358 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
Zhu Yib481de92007-09-25 17:54:57 -07002359 */
2360 }
2361
Tomas Winklere1623442009-01-27 14:27:56 -08002362 IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n",
Zhu Yib481de92007-09-25 17:54:57 -07002363 scan_ch->channel,
2364 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
2365 (scan_ch->type & 1) ?
2366 active_dwell : passive_dwell);
2367
2368 scan_ch++;
2369 added++;
2370 }
2371
Tomas Winklere1623442009-01-27 14:27:56 -08002372 IWL_DEBUG_SCAN(priv, "total channels to scan %d \n", added);
Zhu Yib481de92007-09-25 17:54:57 -07002373 return added;
2374}
2375
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002376static void iwl3945_init_hw_rates(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002377 struct ieee80211_rate *rates)
2378{
2379 int i;
2380
2381 for (i = 0; i < IWL_RATE_COUNT; i++) {
Johannes Berg8318d782008-01-24 19:38:38 +01002382 rates[i].bitrate = iwl3945_rates[i].ieee * 5;
2383 rates[i].hw_value = i; /* Rate scaling will work on indexes */
2384 rates[i].hw_value_short = i;
2385 rates[i].flags = 0;
Samuel Ortizd9829a62008-12-19 10:37:12 +08002386 if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
Zhu Yib481de92007-09-25 17:54:57 -07002387 /*
Johannes Berg8318d782008-01-24 19:38:38 +01002388 * If CCK != 1M then set short preamble rate flag.
Zhu Yib481de92007-09-25 17:54:57 -07002389 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002390 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
Johannes Berg8318d782008-01-24 19:38:38 +01002391 0 : IEEE80211_RATE_SHORT_PREAMBLE;
Zhu Yib481de92007-09-25 17:54:57 -07002392 }
Zhu Yib481de92007-09-25 17:54:57 -07002393 }
2394}
2395
Zhu Yib481de92007-09-25 17:54:57 -07002396/******************************************************************************
2397 *
2398 * uCode download functions
2399 *
2400 ******************************************************************************/
2401
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002402static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002403{
Tomas Winkler98c92212008-01-14 17:46:20 -08002404 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
2405 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
2406 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
2407 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
2408 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
2409 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07002410}
2411
2412/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002413 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002414 * looking at all data.
2415 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002416static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002417{
2418 u32 val;
2419 u32 save_len = len;
2420 int rc = 0;
2421 u32 errcnt;
2422
Tomas Winklere1623442009-01-27 14:27:56 -08002423 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002424
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002425 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002426 if (rc)
2427 return rc;
2428
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002429 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002430 IWL39_RTC_INST_LOWER_BOUND);
Zhu Yib481de92007-09-25 17:54:57 -07002431
2432 errcnt = 0;
2433 for (; len > 0; len -= sizeof(u32), image++) {
2434 /* read data comes through single port, auto-incr addr */
2435 /* NOTE: Use the debugless read so we don't flood kernel log
2436 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002437 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002438 if (val != le32_to_cpu(*image)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002439 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002440 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2441 save_len - len, val, le32_to_cpu(*image));
2442 rc = -EIO;
2443 errcnt++;
2444 if (errcnt >= 20)
2445 break;
2446 }
2447 }
2448
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002449 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002450
2451 if (!errcnt)
Tomas Winklere1623442009-01-27 14:27:56 -08002452 IWL_DEBUG_INFO(priv,
2453 "ucode image in INSTRUCTION memory is good\n");
Zhu Yib481de92007-09-25 17:54:57 -07002454
2455 return rc;
2456}
2457
2458
2459/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002460 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002461 * using sample data 100 bytes apart. If these sample points are good,
2462 * it's a pretty good bet that everything between them is good, too.
2463 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002464static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002465{
2466 u32 val;
2467 int rc = 0;
2468 u32 errcnt = 0;
2469 u32 i;
2470
Tomas Winklere1623442009-01-27 14:27:56 -08002471 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002472
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002473 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002474 if (rc)
2475 return rc;
2476
2477 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
2478 /* read data comes through single port, auto-incr addr */
2479 /* NOTE: Use the debugless read so we don't flood kernel log
2480 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002481 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002482 i + IWL39_RTC_INST_LOWER_BOUND);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002483 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002484 if (val != le32_to_cpu(*image)) {
2485#if 0 /* Enable this if you want to see details */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002486 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002487 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2488 i, val, *image);
2489#endif
2490 rc = -EIO;
2491 errcnt++;
2492 if (errcnt >= 3)
2493 break;
2494 }
2495 }
2496
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002497 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002498
2499 return rc;
2500}
2501
2502
2503/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002504 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
Zhu Yib481de92007-09-25 17:54:57 -07002505 * and verify its contents
2506 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002507static int iwl3945_verify_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002508{
2509 __le32 *image;
2510 u32 len;
2511 int rc = 0;
2512
2513 /* Try bootstrap */
2514 image = (__le32 *)priv->ucode_boot.v_addr;
2515 len = priv->ucode_boot.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, "Bootstrap uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002519 return 0;
2520 }
2521
2522 /* Try initialize */
2523 image = (__le32 *)priv->ucode_init.v_addr;
2524 len = priv->ucode_init.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, "Initialize uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002528 return 0;
2529 }
2530
2531 /* Try runtime/protocol */
2532 image = (__le32 *)priv->ucode_code.v_addr;
2533 len = priv->ucode_code.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002534 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002535 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002536 IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002537 return 0;
2538 }
2539
Winkler, Tomas15b16872008-12-19 10:37:33 +08002540 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
Zhu Yib481de92007-09-25 17:54:57 -07002541
Ben Cahill9fbab512007-11-29 11:09:47 +08002542 /* Since nothing seems to match, show first several data entries in
2543 * instruction SRAM, so maybe visual inspection will give a clue.
2544 * Selection of bootstrap image (vs. other images) is arbitrary. */
Zhu Yib481de92007-09-25 17:54:57 -07002545 image = (__le32 *)priv->ucode_boot.v_addr;
2546 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002547 rc = iwl3945_verify_inst_full(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002548
2549 return rc;
2550}
2551
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002552static void iwl3945_nic_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002553{
2554 /* Remove all resets to allow NIC to operate */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002555 iwl_write32(priv, CSR_RESET, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002556}
2557
2558/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002559 * iwl3945_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07002560 *
2561 * Copy into buffers for card to fetch via bus-mastering
2562 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002563static int iwl3945_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002564{
Kolekar, Abhijeeta78fe752008-12-19 10:37:21 +08002565 struct iwl_ucode *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002566 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07002567 const struct firmware *ucode_raw;
2568 /* firmware file name contains uCode/driver compatibility version */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002569 const char *name_pre = priv->cfg->fw_name_pre;
2570 const unsigned int api_max = priv->cfg->ucode_api_max;
2571 const unsigned int api_min = priv->cfg->ucode_api_min;
2572 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07002573 u8 *src;
2574 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002575 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07002576
2577 /* Ask kernel firmware_class module to get the boot firmware off disk.
2578 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002579 for (index = api_max; index >= api_min; index--) {
2580 sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
2581 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
2582 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002583 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002584 buf, ret);
2585 if (ret == -ENOENT)
2586 continue;
2587 else
2588 goto error;
2589 } else {
2590 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002591 IWL_ERR(priv, "Loaded firmware %s, "
2592 "which is deprecated. "
2593 " Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002594 buf, api_max);
Tomas Winklere1623442009-01-27 14:27:56 -08002595 IWL_DEBUG_INFO(priv, "Got firmware '%s' file "
2596 "(%zd bytes) from disk\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002597 buf, ucode_raw->size);
2598 break;
2599 }
Zhu Yib481de92007-09-25 17:54:57 -07002600 }
2601
Reinette Chatrea0987a82008-12-02 12:14:06 -08002602 if (ret < 0)
2603 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07002604
2605 /* Make sure that we got at least our header! */
2606 if (ucode_raw->size < sizeof(*ucode)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002607 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002608 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002609 goto err_release;
2610 }
2611
2612 /* Data from ucode file: header followed by uCode images */
2613 ucode = (void *)ucode_raw->data;
2614
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08002615 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08002616 api_ver = IWL_UCODE_API(priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07002617 inst_size = le32_to_cpu(ucode->inst_size);
2618 data_size = le32_to_cpu(ucode->data_size);
2619 init_size = le32_to_cpu(ucode->init_size);
2620 init_data_size = le32_to_cpu(ucode->init_data_size);
2621 boot_size = le32_to_cpu(ucode->boot_size);
2622
Reinette Chatrea0987a82008-12-02 12:14:06 -08002623 /* api_ver should match the api version forming part of the
2624 * firmware filename ... but we don't check for that and only rely
Nick Andrew877d0312009-01-26 11:06:57 +01002625 * on the API version read from firmware header from here on forward */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002626
2627 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002628 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002629 "Driver supports v%u, firmware is v%u.\n",
2630 api_max, api_ver);
2631 priv->ucode_ver = 0;
2632 ret = -EINVAL;
2633 goto err_release;
2634 }
2635 if (api_ver != api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002636 IWL_ERR(priv, "Firmware has old API version. Expected %u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002637 "got %u. New firmware can be obtained "
2638 "from http://www.intellinuxwireless.org.\n",
2639 api_max, api_ver);
2640
Tomas Winkler978785a2008-12-19 10:37:31 +08002641 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
2642 IWL_UCODE_MAJOR(priv->ucode_ver),
2643 IWL_UCODE_MINOR(priv->ucode_ver),
2644 IWL_UCODE_API(priv->ucode_ver),
2645 IWL_UCODE_SERIAL(priv->ucode_ver));
2646
Tomas Winklere1623442009-01-27 14:27:56 -08002647 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002648 priv->ucode_ver);
Tomas Winklere1623442009-01-27 14:27:56 -08002649 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
2650 inst_size);
2651 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
2652 data_size);
2653 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
2654 init_size);
2655 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
2656 init_data_size);
2657 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
2658 boot_size);
Zhu Yib481de92007-09-25 17:54:57 -07002659
Reinette Chatrea0987a82008-12-02 12:14:06 -08002660
Zhu Yib481de92007-09-25 17:54:57 -07002661 /* Verify size of file vs. image size info in file's header */
2662 if (ucode_raw->size < sizeof(*ucode) +
2663 inst_size + data_size + init_size +
2664 init_data_size + boot_size) {
2665
Tomas Winklere1623442009-01-27 14:27:56 -08002666 IWL_DEBUG_INFO(priv, "uCode file size %zd too small\n",
2667 ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002668 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002669 goto err_release;
2670 }
2671
2672 /* Verify that uCode images will fit in card's SRAM */
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002673 if (inst_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002674 IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002675 inst_size);
2676 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002677 goto err_release;
2678 }
2679
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002680 if (data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002681 IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002682 data_size);
2683 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002684 goto err_release;
2685 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002686 if (init_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002687 IWL_DEBUG_INFO(priv,
2688 "uCode init instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002689 init_size);
2690 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002691 goto err_release;
2692 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002693 if (init_data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002694 IWL_DEBUG_INFO(priv,
2695 "uCode init data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002696 init_data_size);
2697 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002698 goto err_release;
2699 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002700 if (boot_size > IWL39_MAX_BSM_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002701 IWL_DEBUG_INFO(priv,
2702 "uCode boot instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002703 boot_size);
2704 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002705 goto err_release;
2706 }
2707
2708 /* Allocate ucode buffers for card's bus-master loading ... */
2709
2710 /* Runtime instructions and 2 copies of data:
2711 * 1) unmodified from disk
2712 * 2) backup cache for save/restore during power-downs */
2713 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002714 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07002715
2716 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002717 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07002718
2719 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002720 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07002721
2722 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
Tomas Winkler90e759d2007-11-29 11:09:41 +08002723 !priv->ucode_data_backup.v_addr)
Zhu Yib481de92007-09-25 17:54:57 -07002724 goto err_pci_alloc;
2725
Tomas Winkler90e759d2007-11-29 11:09:41 +08002726 /* Initialization instructions and data */
2727 if (init_size && init_data_size) {
2728 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002729 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002730
2731 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002732 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002733
2734 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
2735 goto err_pci_alloc;
2736 }
2737
2738 /* Bootstrap (instructions only, no data) */
2739 if (boot_size) {
2740 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002741 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002742
2743 if (!priv->ucode_boot.v_addr)
2744 goto err_pci_alloc;
2745 }
2746
Zhu Yib481de92007-09-25 17:54:57 -07002747 /* Copy images into buffers for card's bus-master reads ... */
2748
2749 /* Runtime instructions (first block of data in file) */
2750 src = &ucode->data[0];
2751 len = priv->ucode_code.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002752 IWL_DEBUG_INFO(priv,
2753 "Copying (but not loading) uCode instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002754 memcpy(priv->ucode_code.v_addr, src, len);
Tomas Winklere1623442009-01-27 14:27:56 -08002755 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002756 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
2757
2758 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002759 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
Zhu Yib481de92007-09-25 17:54:57 -07002760 src = &ucode->data[inst_size];
2761 len = priv->ucode_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002762 IWL_DEBUG_INFO(priv,
2763 "Copying (but not loading) uCode data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002764 memcpy(priv->ucode_data.v_addr, src, len);
2765 memcpy(priv->ucode_data_backup.v_addr, src, len);
2766
2767 /* Initialization instructions (3rd block) */
2768 if (init_size) {
2769 src = &ucode->data[inst_size + data_size];
2770 len = priv->ucode_init.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002771 IWL_DEBUG_INFO(priv,
2772 "Copying (but not loading) init instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002773 memcpy(priv->ucode_init.v_addr, src, len);
2774 }
2775
2776 /* Initialization data (4th block) */
2777 if (init_data_size) {
2778 src = &ucode->data[inst_size + data_size + init_size];
2779 len = priv->ucode_init_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002780 IWL_DEBUG_INFO(priv,
2781 "Copying (but not loading) init data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002782 memcpy(priv->ucode_init_data.v_addr, src, len);
2783 }
2784
2785 /* Bootstrap instructions (5th block) */
2786 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
2787 len = priv->ucode_boot.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002788 IWL_DEBUG_INFO(priv,
2789 "Copying (but not loading) boot instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002790 memcpy(priv->ucode_boot.v_addr, src, len);
2791
2792 /* We have our copies now, allow OS release its copies */
2793 release_firmware(ucode_raw);
2794 return 0;
2795
2796 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08002797 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002798 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002799 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002800
2801 err_release:
2802 release_firmware(ucode_raw);
2803
2804 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08002805 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002806}
2807
2808
2809/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002810 * iwl3945_set_ucode_ptrs - Set uCode address location
Zhu Yib481de92007-09-25 17:54:57 -07002811 *
2812 * Tell initialization uCode where to find runtime uCode.
2813 *
2814 * BSM registers initially contain pointers to initialization uCode.
2815 * We need to replace them to load runtime uCode inst and data,
2816 * and to save runtime data when powering down.
2817 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002818static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002819{
2820 dma_addr_t pinst;
2821 dma_addr_t pdata;
2822 int rc = 0;
2823 unsigned long flags;
2824
2825 /* bits 31:0 for 3945 */
2826 pinst = priv->ucode_code.p_addr;
2827 pdata = priv->ucode_data_backup.p_addr;
2828
2829 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002830 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002831 if (rc) {
2832 spin_unlock_irqrestore(&priv->lock, flags);
2833 return rc;
2834 }
2835
2836 /* Tell bootstrap uCode where to find image to load */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002837 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
2838 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
2839 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002840 priv->ucode_data.len);
2841
Tomas Winklera96a27f2008-10-23 23:48:56 -07002842 /* Inst byte count must be last to set up, bit 31 signals uCode
Zhu Yib481de92007-09-25 17:54:57 -07002843 * that all new ptr/size info is in place */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002844 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002845 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
2846
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002847 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002848
2849 spin_unlock_irqrestore(&priv->lock, flags);
2850
Tomas Winklere1623442009-01-27 14:27:56 -08002851 IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002852
2853 return rc;
2854}
2855
2856/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002857 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002858 *
2859 * Called after REPLY_ALIVE notification received from "initialize" uCode.
2860 *
Zhu Yib481de92007-09-25 17:54:57 -07002861 * Tell "initialize" uCode to go ahead and load the runtime uCode.
Ben Cahill9fbab512007-11-29 11:09:47 +08002862 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002863static void iwl3945_init_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002864{
2865 /* Check alive response for "valid" sign from uCode */
2866 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
2867 /* We had an error bringing up the hardware, so take it
2868 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002869 IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002870 goto restart;
2871 }
2872
2873 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
2874 * This is a paranoid check, because we would not have gotten the
2875 * "initialize" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002876 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002877 /* Runtime instruction load was bad;
2878 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002879 IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002880 goto restart;
2881 }
2882
2883 /* Send pointers to protocol/runtime uCode image ... init code will
2884 * load and launch runtime uCode, which will send us another "Alive"
2885 * notification. */
Tomas Winklere1623442009-01-27 14:27:56 -08002886 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002887 if (iwl3945_set_ucode_ptrs(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002888 /* Runtime instruction load won't happen;
2889 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002890 IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002891 goto restart;
2892 }
2893 return;
2894
2895 restart:
2896 queue_work(priv->workqueue, &priv->restart);
2897}
2898
2899
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08002900/* temporary */
2901static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw,
2902 struct sk_buff *skb);
2903
Zhu Yib481de92007-09-25 17:54:57 -07002904/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002905 * iwl3945_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002906 * from protocol/runtime uCode (initialization uCode's
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002907 * Alive gets handled by iwl3945_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07002908 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002909static void iwl3945_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002910{
2911 int rc = 0;
2912 int thermal_spin = 0;
2913 u32 rfkill;
2914
Tomas Winklere1623442009-01-27 14:27:56 -08002915 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002916
2917 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
2918 /* We had an error bringing up the hardware, so take it
2919 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002920 IWL_DEBUG_INFO(priv, "Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002921 goto restart;
2922 }
2923
2924 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
2925 * This is a paranoid check, because we would not have gotten the
2926 * "runtime" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002927 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002928 /* Runtime instruction load was bad;
2929 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002930 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002931 goto restart;
2932 }
2933
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002934 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002935
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002936 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002937 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002938 IWL_WARN(priv, "Can not read RFKILL status from adapter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002939 return;
2940 }
2941
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002942 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
Tomas Winklere1623442009-01-27 14:27:56 -08002943 IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002944 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002945
2946 if (rfkill & 0x1) {
2947 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winklera96a27f2008-10-23 23:48:56 -07002948 /* if RFKILL is not on, then wait for thermal
Zhu Yib481de92007-09-25 17:54:57 -07002949 * sensor in adapter to kick in */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002950 while (iwl3945_hw_get_temperature(priv) == 0) {
Zhu Yib481de92007-09-25 17:54:57 -07002951 thermal_spin++;
2952 udelay(10);
2953 }
2954
2955 if (thermal_spin)
Tomas Winklere1623442009-01-27 14:27:56 -08002956 IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n",
Zhu Yib481de92007-09-25 17:54:57 -07002957 thermal_spin * 10);
2958 } else
2959 set_bit(STATUS_RF_KILL_HW, &priv->status);
2960
Ben Cahill9fbab512007-11-29 11:09:47 +08002961 /* After the ALIVE response, we can send commands to 3945 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07002962 set_bit(STATUS_ALIVE, &priv->status);
2963
2964 /* Clear out the uCode error bit if it is set */
2965 clear_bit(STATUS_FW_ERROR, &priv->status);
2966
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002967 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002968 return;
2969
Johannes Berg36d68252008-05-15 12:55:26 +02002970 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002971
2972 priv->active_rate = priv->rates_mask;
2973 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
2974
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08002975 iwl_power_update_mode(priv, false);
Zhu Yib481de92007-09-25 17:54:57 -07002976
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002977 if (iwl_is_associated(priv)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002978 struct iwl3945_rxon_cmd *active_rxon =
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002979 (struct iwl3945_rxon_cmd *)(&priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07002980
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002981 memcpy(&priv->staging_rxon, &priv->active_rxon,
2982 sizeof(priv->staging_rxon));
Zhu Yib481de92007-09-25 17:54:57 -07002983 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2984 } else {
2985 /* Initialize our rx_config data */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002986 iwl_connection_init_rx_config(priv, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002987 }
2988
Ben Cahill9fbab512007-11-29 11:09:47 +08002989 /* Configure Bluetooth device coexistence support */
Samuel Ortiz17f841c2009-01-23 13:45:20 -08002990 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002991
2992 /* Configure the adapter for unassociated operation */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002993 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002994
Zhu Yib481de92007-09-25 17:54:57 -07002995 iwl3945_reg_txpower_periodic(priv);
2996
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07002997 iwl3945_led_register(priv);
2998
Tomas Winklere1623442009-01-27 14:27:56 -08002999 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07003000 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a669262008-01-14 17:46:18 -08003001 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07003002
3003 if (priv->error_recovering)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003004 iwl3945_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003005
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003006 /* reassociate for ADHOC mode */
3007 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
3008 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
3009 priv->vif);
3010 if (beacon)
3011 iwl3945_mac_beacon_update(priv->hw, beacon);
3012 }
3013
Zhu Yib481de92007-09-25 17:54:57 -07003014 return;
3015
3016 restart:
3017 queue_work(priv->workqueue, &priv->restart);
3018}
3019
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003020static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07003021
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003022static void __iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003023{
3024 unsigned long flags;
3025 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
3026 struct ieee80211_conf *conf = NULL;
3027
Tomas Winklere1623442009-01-27 14:27:56 -08003028 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07003029
3030 conf = ieee80211_get_hw_conf(priv->hw);
3031
3032 if (!exit_pending)
3033 set_bit(STATUS_EXIT_PENDING, &priv->status);
3034
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07003035 iwl3945_led_unregister(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003036 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003037
3038 /* Unblock any waiting calls */
3039 wake_up_interruptible_all(&priv->wait_command_queue);
3040
Zhu Yib481de92007-09-25 17:54:57 -07003041 /* Wipe out the EXIT_PENDING status bit if we are not actually
3042 * exiting the module */
3043 if (!exit_pending)
3044 clear_bit(STATUS_EXIT_PENDING, &priv->status);
3045
3046 /* stop and reset the on-board processor */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003047 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07003048
3049 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003050 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08003051 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003052 spin_unlock_irqrestore(&priv->lock, flags);
3053 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003054
3055 if (priv->mac80211_registered)
3056 ieee80211_stop_queues(priv->hw);
3057
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003058 /* If we have not previously called iwl3945_init() then
Zhu Yib481de92007-09-25 17:54:57 -07003059 * clear all bits but the RF Kill and SUSPEND bits and return */
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003060 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003061 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3062 STATUS_RF_KILL_HW |
3063 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3064 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08003065 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3066 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07003067 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003068 STATUS_IN_SUSPEND |
3069 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3070 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07003071 goto exit;
3072 }
3073
3074 /* ...otherwise clear out all the status bits but the RF Kill and
3075 * SUSPEND bits and continue taking the NIC down. */
3076 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3077 STATUS_RF_KILL_HW |
3078 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3079 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08003080 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3081 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07003082 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
3083 STATUS_IN_SUSPEND |
3084 test_bit(STATUS_FW_ERROR, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003085 STATUS_FW_ERROR |
3086 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3087 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07003088
Abbas, Mohamede9414b62009-01-20 21:33:55 -08003089 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003090 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003091 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07003092 spin_unlock_irqrestore(&priv->lock, flags);
3093
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003094 iwl3945_hw_txq_ctx_stop(priv);
3095 iwl3945_hw_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003096
3097 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003098 if (!iwl_grab_nic_access(priv)) {
3099 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07003100 APMG_CLK_VAL_DMA_CLK_RQT);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003101 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003102 }
3103 spin_unlock_irqrestore(&priv->lock, flags);
3104
3105 udelay(5);
3106
Abbas, Mohamede9414b62009-01-20 21:33:55 -08003107 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
3108 priv->cfg->ops->lib->apm_ops.stop(priv);
3109 else
3110 priv->cfg->ops->lib->apm_ops.reset(priv);
3111
Zhu Yib481de92007-09-25 17:54:57 -07003112 exit:
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08003113 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07003114
3115 if (priv->ibss_beacon)
3116 dev_kfree_skb(priv->ibss_beacon);
3117 priv->ibss_beacon = NULL;
3118
3119 /* clear out any free frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003120 iwl3945_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003121}
3122
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003123static void iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003124{
3125 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003126 __iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003127 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08003128
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003129 iwl3945_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003130}
3131
3132#define MAX_HW_RESTARTS 5
3133
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003134static int __iwl3945_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003135{
3136 int rc, i;
3137
3138 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003139 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003140 return -EIO;
3141 }
3142
3143 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003144 IWL_WARN(priv, "Radio disabled by SW RF kill (module "
Zhu Yib481de92007-09-25 17:54:57 -07003145 "parameter)\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003146 return -ENODEV;
3147 }
3148
Reinette Chatree903fbd2008-01-30 22:05:15 -08003149 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003150 IWL_ERR(priv, "ucode not available for device bring up\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08003151 return -EIO;
3152 }
3153
Zhu Yie655b9f2008-01-24 02:19:38 -08003154 /* If platform's RF_KILL switch is NOT set to KILL */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003155 if (iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yie655b9f2008-01-24 02:19:38 -08003156 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3157 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3158 else {
3159 set_bit(STATUS_RF_KILL_HW, &priv->status);
3160 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003161 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003162 return -ENODEV;
3163 }
Zhu Yib481de92007-09-25 17:54:57 -07003164 }
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02003165
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003166 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07003167
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003168 rc = iwl3945_hw_nic_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003169 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003170 IWL_ERR(priv, "Unable to int nic\n");
Zhu Yib481de92007-09-25 17:54:57 -07003171 return rc;
3172 }
3173
3174 /* 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,
Zhu Yib481de92007-09-25 17:54:57 -07003177 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
3178
3179 /* clear (again), then enable host interrupts */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003180 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08003181 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003182
3183 /* really make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003184 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3185 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07003186
3187 /* Copy original ucode data image from disk into backup cache.
3188 * This will be used to initialize the on-board processor's
3189 * data SRAM for a clean start when the runtime program first loads. */
3190 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a669262008-01-14 17:46:18 -08003191 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07003192
Zhu Yie655b9f2008-01-24 02:19:38 -08003193 /* We return success when we resume from suspend and rf_kill is on. */
3194 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
3195 return 0;
3196
Zhu Yib481de92007-09-25 17:54:57 -07003197 for (i = 0; i < MAX_HW_RESTARTS; i++) {
3198
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003199 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003200
3201 /* load bootstrap state machine,
3202 * load bootstrap program into processor's memory,
3203 * prepare to load the "initialize" uCode */
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08003204 priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003205
3206 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003207 IWL_ERR(priv,
3208 "Unable to set up bootstrap uCode: %d\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -07003209 continue;
3210 }
3211
3212 /* start card; "initialize" will load runtime ucode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003213 iwl3945_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003214
Tomas Winklere1623442009-01-27 14:27:56 -08003215 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003216
3217 return 0;
3218 }
3219
3220 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003221 __iwl3945_down(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003222 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003223
3224 /* tried to restart and config the device for as long as our
3225 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08003226 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07003227 return -EIO;
3228}
3229
3230
3231/*****************************************************************************
3232 *
3233 * Workqueue callbacks
3234 *
3235 *****************************************************************************/
3236
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003237static void iwl3945_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003238{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003239 struct iwl_priv *priv =
3240 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003241
3242 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3243 return;
3244
3245 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003246 iwl3945_init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003247 mutex_unlock(&priv->mutex);
3248}
3249
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003250static void iwl3945_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003251{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003252 struct iwl_priv *priv =
3253 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003254
3255 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3256 return;
3257
3258 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003259 iwl3945_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003260 mutex_unlock(&priv->mutex);
3261}
3262
Helmut Schaa26635162009-01-15 09:38:44 +01003263static void iwl3945_rfkill_poll(struct work_struct *data)
3264{
3265 struct iwl_priv *priv =
3266 container_of(data, struct iwl_priv, rfkill_poll.work);
3267 unsigned long status = priv->status;
3268
3269 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3270 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3271 else
3272 set_bit(STATUS_RF_KILL_HW, &priv->status);
3273
3274 if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status))
3275 queue_work(priv->workqueue, &priv->rf_kill);
3276
3277 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3278 round_jiffies_relative(2 * HZ));
3279
3280}
3281
Zhu Yib481de92007-09-25 17:54:57 -07003282#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003283static void iwl3945_bg_request_scan(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003284{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003285 struct iwl_priv *priv =
3286 container_of(data, struct iwl_priv, request_scan);
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08003287 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07003288 .id = REPLY_SCAN_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003289 .len = sizeof(struct iwl3945_scan_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07003290 .meta.flags = CMD_SIZE_HUGE,
3291 };
3292 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003293 struct iwl3945_scan_cmd *scan;
Zhu Yib481de92007-09-25 17:54:57 -07003294 struct ieee80211_conf *conf = NULL;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003295 u8 n_probes = 2;
Johannes Berg8318d782008-01-24 19:38:38 +01003296 enum ieee80211_band band;
John W. Linville9387b7c2008-09-30 20:59:05 -04003297 DECLARE_SSID_BUF(ssid);
Zhu Yib481de92007-09-25 17:54:57 -07003298
3299 conf = ieee80211_get_hw_conf(priv->hw);
3300
3301 mutex_lock(&priv->mutex);
3302
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003303 if (!iwl_is_ready(priv)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003304 IWL_WARN(priv, "request scan called when driver not ready.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003305 goto done;
3306 }
3307
Tomas Winklera96a27f2008-10-23 23:48:56 -07003308 /* Make sure the scan wasn't canceled before this queued work
Zhu Yib481de92007-09-25 17:54:57 -07003309 * was given the chance to run... */
3310 if (!test_bit(STATUS_SCANNING, &priv->status))
3311 goto done;
3312
3313 /* This should never be called or scheduled if there is currently
3314 * a scan active in the hardware. */
3315 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003316 IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests "
3317 "Ignoring second request.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003318 rc = -EIO;
3319 goto done;
3320 }
3321
3322 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003323 IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n");
Zhu Yib481de92007-09-25 17:54:57 -07003324 goto done;
3325 }
3326
3327 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003328 IWL_DEBUG_HC(priv,
3329 "Scan request while abort pending. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003330 goto done;
3331 }
3332
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003333 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003334 IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n");
Zhu Yib481de92007-09-25 17:54:57 -07003335 goto done;
3336 }
3337
3338 if (!test_bit(STATUS_READY, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003339 IWL_DEBUG_HC(priv,
3340 "Scan request while uninitialized. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003341 goto done;
3342 }
3343
3344 if (!priv->scan_bands) {
Tomas Winklere1623442009-01-27 14:27:56 -08003345 IWL_DEBUG_HC(priv, "Aborting scan due to no requested bands\n");
Zhu Yib481de92007-09-25 17:54:57 -07003346 goto done;
3347 }
3348
Winkler, Tomas805cee52009-01-19 15:30:28 -08003349 if (!priv->scan) {
3350 priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
Zhu Yib481de92007-09-25 17:54:57 -07003351 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
Winkler, Tomas805cee52009-01-19 15:30:28 -08003352 if (!priv->scan) {
Zhu Yib481de92007-09-25 17:54:57 -07003353 rc = -ENOMEM;
3354 goto done;
3355 }
3356 }
Winkler, Tomas805cee52009-01-19 15:30:28 -08003357 scan = priv->scan;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003358 memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07003359
3360 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
3361 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
3362
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003363 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003364 u16 interval = 0;
3365 u32 extra;
3366 u32 suspend_time = 100;
3367 u32 scan_suspend_time = 100;
3368 unsigned long flags;
3369
Tomas Winklere1623442009-01-27 14:27:56 -08003370 IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
Zhu Yib481de92007-09-25 17:54:57 -07003371
3372 spin_lock_irqsave(&priv->lock, flags);
3373 interval = priv->beacon_int;
3374 spin_unlock_irqrestore(&priv->lock, flags);
3375
3376 scan->suspend_time = 0;
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003377 scan->max_out_time = cpu_to_le32(200 * 1024);
Zhu Yib481de92007-09-25 17:54:57 -07003378 if (!interval)
3379 interval = suspend_time;
3380 /*
3381 * suspend time format:
3382 * 0-19: beacon interval in usec (time before exec.)
3383 * 20-23: 0
3384 * 24-31: number of beacons (suspend between channels)
3385 */
3386
3387 extra = (suspend_time / interval) << 24;
3388 scan_suspend_time = 0xFF0FFFFF &
3389 (extra | ((suspend_time % interval) * 1024));
3390
3391 scan->suspend_time = cpu_to_le32(scan_suspend_time);
Tomas Winklere1623442009-01-27 14:27:56 -08003392 IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003393 scan_suspend_time, interval);
3394 }
3395
3396 /* We should add the ability for user to lock to PASSIVE ONLY */
3397 if (priv->one_direct_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08003398 IWL_DEBUG_SCAN(priv, "Kicking off one direct scan for '%s'\n",
3399 print_ssid(ssid, priv->direct_ssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04003400 priv->direct_ssid_len));
Zhu Yib481de92007-09-25 17:54:57 -07003401 scan->direct_scan[0].id = WLAN_EID_SSID;
3402 scan->direct_scan[0].len = priv->direct_ssid_len;
3403 memcpy(scan->direct_scan[0].ssid,
3404 priv->direct_ssid, priv->direct_ssid_len);
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003405 n_probes++;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003406 } else
Tomas Winklere1623442009-01-27 14:27:56 -08003407 IWL_DEBUG_SCAN(priv, "Kicking off one indirect scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003408
3409 /* We don't build a direct scan probe request; the uCode will do
3410 * that based on the direct_mask added to each channel entry */
Zhu Yib481de92007-09-25 17:54:57 -07003411 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08003412 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07003413 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
3414
3415 /* flags + rate selection */
3416
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003417 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003418 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
3419 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
3420 scan->good_CRC_th = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01003421 band = IEEE80211_BAND_2GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003422 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003423 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
3424 scan->good_CRC_th = IWL_GOOD_CRC_TH;
Johannes Berg8318d782008-01-24 19:38:38 +01003425 band = IEEE80211_BAND_5GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003426 } else {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003427 IWL_WARN(priv, "Invalid scan band count\n");
Zhu Yib481de92007-09-25 17:54:57 -07003428 goto done;
3429 }
3430
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08003431 scan->tx_cmd.len = cpu_to_le16(
3432 iwl_fill_probe_req(priv, band,
3433 (struct ieee80211_mgmt *)scan->data,
3434 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
3435
Zhu Yib481de92007-09-25 17:54:57 -07003436 /* select Rx antennas */
3437 scan->flags |= iwl3945_get_antenna_flags(priv);
3438
Johannes Berg05c914f2008-09-11 00:01:58 +02003439 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
Zhu Yib481de92007-09-25 17:54:57 -07003440 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
3441
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003442 scan->channel_count =
3443 iwl3945_get_channels_for_scan(priv, band, 1, /* active */
3444 n_probes,
3445 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
Zhu Yib481de92007-09-25 17:54:57 -07003446
Reinette Chatre14b54332008-11-04 12:21:35 -08003447 if (scan->channel_count == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08003448 IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
Reinette Chatre14b54332008-11-04 12:21:35 -08003449 goto done;
3450 }
3451
Zhu Yib481de92007-09-25 17:54:57 -07003452 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003453 scan->channel_count * sizeof(struct iwl3945_scan_channel);
Zhu Yib481de92007-09-25 17:54:57 -07003454 cmd.data = scan;
3455 scan->len = cpu_to_le16(cmd.len);
3456
3457 set_bit(STATUS_SCAN_HW, &priv->status);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003458 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07003459 if (rc)
3460 goto done;
3461
3462 queue_delayed_work(priv->workqueue, &priv->scan_check,
3463 IWL_SCAN_CHECK_WATCHDOG);
3464
3465 mutex_unlock(&priv->mutex);
3466 return;
3467
3468 done:
Mohamed Abbas2420ebc2008-11-04 12:21:34 -08003469 /* can not perform scan make sure we clear scanning
3470 * bits from status so next scan request can be performed.
3471 * if we dont clear scanning status bit here all next scan
3472 * will fail
3473 */
3474 clear_bit(STATUS_SCAN_HW, &priv->status);
3475 clear_bit(STATUS_SCANNING, &priv->status);
3476
Ian Schram01ebd062007-10-25 17:15:22 +08003477 /* inform mac80211 scan aborted */
Zhu Yib481de92007-09-25 17:54:57 -07003478 queue_work(priv->workqueue, &priv->scan_completed);
3479 mutex_unlock(&priv->mutex);
3480}
3481
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003482static void iwl3945_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003483{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003484 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07003485
3486 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3487 return;
3488
3489 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003490 __iwl3945_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003491 mutex_unlock(&priv->mutex);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003492 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003493}
3494
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003495static void iwl3945_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003496{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003497 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07003498
3499 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3500 return;
3501
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003502 iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003503 queue_work(priv->workqueue, &priv->up);
3504}
3505
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003506static void iwl3945_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003507{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003508 struct iwl_priv *priv =
3509 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07003510
3511 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3512 return;
3513
3514 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003515 iwl3945_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003516 mutex_unlock(&priv->mutex);
3517}
3518
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003519#define IWL_DELAY_NEXT_SCAN (HZ*2)
3520
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003521static void iwl3945_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003522{
Zhu Yib481de92007-09-25 17:54:57 -07003523 int rc = 0;
3524 struct ieee80211_conf *conf = NULL;
3525
Johannes Berg05c914f2008-09-11 00:01:58 +02003526 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003527 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07003528 return;
3529 }
3530
3531
Tomas Winklere1623442009-01-27 14:27:56 -08003532 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003533 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07003534
3535 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3536 return;
3537
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003538 if (!priv->vif || !priv->is_open)
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003539 return;
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003540
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003541 iwl_scan_cancel_timeout(priv, 200);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003542
Zhu Yib481de92007-09-25 17:54:57 -07003543 conf = ieee80211_get_hw_conf(priv->hw);
3544
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003545 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003546 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003547
Tomas Winkler28afaf92008-12-19 10:37:06 +08003548 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003549 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003550 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07003551 sizeof(priv->rxon_timing), &priv->rxon_timing);
3552 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003553 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003554 "Attempting to continue.\n");
3555
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003556 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003557
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003558 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003559
Tomas Winklere1623442009-01-27 14:27:56 -08003560 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003561 priv->assoc_id, priv->beacon_int);
3562
3563 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003564 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003565 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003566 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003567
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003568 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003569 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003570 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003571 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003572 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003573
Johannes Berg05c914f2008-09-11 00:01:58 +02003574 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003575 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003576
3577 }
3578
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003579 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003580
3581 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02003582 case NL80211_IFTYPE_STATION:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003583 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07003584 break;
3585
Johannes Berg05c914f2008-09-11 00:01:58 +02003586 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07003587
Abhijeet Kolekarce546fd2008-11-19 15:32:22 -08003588 priv->assoc_id = 1;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003589 iwl3945_add_station(priv, priv->bssid, 0, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003590 iwl3945_sync_sta(priv, IWL_STA_ID,
Johannes Berg8318d782008-01-24 19:38:38 +01003591 (priv->band == IEEE80211_BAND_5GHZ) ?
Zhu Yib481de92007-09-25 17:54:57 -07003592 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
3593 CMD_ASYNC);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003594 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
3595 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003596
3597 break;
3598
3599 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08003600 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003601 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003602 break;
3603 }
3604
Abhijeet Kolekar14d2aac2009-02-27 16:21:24 -08003605 iwl_activate_qos(priv, 0);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08003606
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003607 /* we have just associated, don't start scan too early */
3608 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08003609}
3610
Johannes Berge8975582008-10-09 12:18:51 +02003611static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003612
Zhu Yib481de92007-09-25 17:54:57 -07003613/*****************************************************************************
3614 *
3615 * mac80211 entry point functions
3616 *
3617 *****************************************************************************/
3618
Zhu Yi5a669262008-01-14 17:46:18 -08003619#define UCODE_READY_TIMEOUT (2 * HZ)
3620
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003621static int iwl3945_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003622{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003623 struct iwl_priv *priv = hw->priv;
Zhu Yi5a669262008-01-14 17:46:18 -08003624 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003625
Tomas Winklere1623442009-01-27 14:27:56 -08003626 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003627
3628 /* we should be verifying the device is ready to be opened */
3629 mutex_lock(&priv->mutex);
3630
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003631 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
Zhu Yi5a669262008-01-14 17:46:18 -08003632 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
3633 * ucode filename and max sizes are card-specific. */
3634
3635 if (!priv->ucode_code.len) {
3636 ret = iwl3945_read_ucode(priv);
3637 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003638 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a669262008-01-14 17:46:18 -08003639 mutex_unlock(&priv->mutex);
3640 goto out_release_irq;
3641 }
3642 }
3643
Zhu Yie655b9f2008-01-24 02:19:38 -08003644 ret = __iwl3945_up(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08003645
Zhu Yib481de92007-09-25 17:54:57 -07003646 mutex_unlock(&priv->mutex);
Zhu Yi5a669262008-01-14 17:46:18 -08003647
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003648 iwl_rfkill_set_hw_state(priv);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02003649
Zhu Yie655b9f2008-01-24 02:19:38 -08003650 if (ret)
3651 goto out_release_irq;
3652
Tomas Winklere1623442009-01-27 14:27:56 -08003653 IWL_DEBUG_INFO(priv, "Start UP work.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003654
3655 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
3656 return 0;
3657
Zhu Yi5a669262008-01-14 17:46:18 -08003658 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
3659 * mac80211 will not be run successfully. */
3660 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
3661 test_bit(STATUS_READY, &priv->status),
3662 UCODE_READY_TIMEOUT);
3663 if (!ret) {
3664 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003665 IWL_ERR(priv,
3666 "Wait for START_ALIVE timeout after %dms.\n",
3667 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Zhu Yi5a669262008-01-14 17:46:18 -08003668 ret = -ETIMEDOUT;
3669 goto out_release_irq;
3670 }
3671 }
3672
Helmut Schaa26635162009-01-15 09:38:44 +01003673 /* ucode is running and will send rfkill notifications,
3674 * no need to poll the killswitch state anymore */
3675 cancel_delayed_work(&priv->rfkill_poll);
3676
Zhu Yie655b9f2008-01-24 02:19:38 -08003677 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08003678 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003679 return 0;
Zhu Yi5a669262008-01-14 17:46:18 -08003680
3681out_release_irq:
Zhu Yie655b9f2008-01-24 02:19:38 -08003682 priv->is_open = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08003683 IWL_DEBUG_MAC80211(priv, "leave - failed\n");
Zhu Yi5a669262008-01-14 17:46:18 -08003684 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003685}
3686
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003687static void iwl3945_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003688{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003689 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003690
Tomas Winklere1623442009-01-27 14:27:56 -08003691 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003692
Zhu Yie655b9f2008-01-24 02:19:38 -08003693 if (!priv->is_open) {
Tomas Winklere1623442009-01-27 14:27:56 -08003694 IWL_DEBUG_MAC80211(priv, "leave - skip\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003695 return;
3696 }
3697
Zhu Yib481de92007-09-25 17:54:57 -07003698 priv->is_open = 0;
Zhu Yi5a669262008-01-14 17:46:18 -08003699
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003700 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08003701 /* stop mac, cancel any scan request and clear
3702 * RXON_FILTER_ASSOC_MSK BIT
3703 */
Zhu Yi5a669262008-01-14 17:46:18 -08003704 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003705 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003706 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003707 }
3708
Zhu Yi5a669262008-01-14 17:46:18 -08003709 iwl3945_down(priv);
3710
3711 flush_workqueue(priv->workqueue);
Helmut Schaa26635162009-01-15 09:38:44 +01003712
3713 /* start polling the killswitch state again */
3714 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3715 round_jiffies_relative(2 * HZ));
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003716
Tomas Winklere1623442009-01-27 14:27:56 -08003717 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003718}
3719
Johannes Berge039fa42008-05-15 12:55:29 +02003720static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003721{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003722 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003723
Tomas Winklere1623442009-01-27 14:27:56 -08003724 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003725
Tomas Winklere1623442009-01-27 14:27:56 -08003726 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02003727 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07003728
Johannes Berge039fa42008-05-15 12:55:29 +02003729 if (iwl3945_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07003730 dev_kfree_skb_any(skb);
3731
Tomas Winklere1623442009-01-27 14:27:56 -08003732 IWL_DEBUG_MAC80211(priv, "leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08003733 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07003734}
3735
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003736static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003737 struct ieee80211_if_init_conf *conf)
3738{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003739 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003740 unsigned long flags;
3741
Tomas Winklere1623442009-01-27 14:27:56 -08003742 IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07003743
Johannes Berg32bfd352007-12-19 01:31:26 +01003744 if (priv->vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08003745 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
Tomas Winkler864792e2007-11-27 21:00:52 +02003746 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07003747 }
3748
3749 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01003750 priv->vif = conf->vif;
Zhu, Yi60294de2008-10-29 14:05:45 -07003751 priv->iw_mode = conf->type;
Zhu Yib481de92007-09-25 17:54:57 -07003752
3753 spin_unlock_irqrestore(&priv->lock, flags);
3754
3755 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02003756
3757 if (conf->mac_addr) {
Tomas Winklere1623442009-01-27 14:27:56 -08003758 IWL_DEBUG_MAC80211(priv, "Set: %pM\n", conf->mac_addr);
Tomas Winkler864792e2007-11-27 21:00:52 +02003759 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
3760 }
3761
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003762 if (iwl_is_ready(priv))
Zhu Yi5a669262008-01-14 17:46:18 -08003763 iwl3945_set_mode(priv, conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07003764
Zhu Yib481de92007-09-25 17:54:57 -07003765 mutex_unlock(&priv->mutex);
3766
Tomas Winklere1623442009-01-27 14:27:56 -08003767 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003768 return 0;
3769}
3770
3771/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003772 * iwl3945_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07003773 *
3774 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
3775 * be set inappropriately and the driver currently sets the hardware up to
3776 * use it whenever needed.
3777 */
Johannes Berge8975582008-10-09 12:18:51 +02003778static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed)
Zhu Yib481de92007-09-25 17:54:57 -07003779{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003780 struct iwl_priv *priv = hw->priv;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08003781 const struct iwl_channel_info *ch_info;
Johannes Berge8975582008-10-09 12:18:51 +02003782 struct ieee80211_conf *conf = &hw->conf;
Zhu Yib481de92007-09-25 17:54:57 -07003783 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08003784 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003785
3786 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08003787 IWL_DEBUG_MAC80211(priv, "enter to channel %d\n",
3788 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07003789
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003790 if (!iwl_is_ready(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003791 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08003792 ret = -EIO;
3793 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003794 }
3795
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08003796 if (unlikely(!iwl3945_mod_params.disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07003797 test_bit(STATUS_SCANNING, &priv->status))) {
Tomas Winklere1623442009-01-27 14:27:56 -08003798 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
Zhu Yia0646472007-12-20 14:10:01 +08003799 set_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003800 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08003801 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07003802 }
3803
3804 spin_lock_irqsave(&priv->lock, flags);
3805
Samuel Ortize6148912009-01-23 13:45:15 -08003806 ch_info = iwl_get_channel_info(priv, conf->channel->band,
3807 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07003808 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003809 IWL_DEBUG_SCAN(priv,
3810 "Channel %d [%d] is INVALID for this band.\n",
3811 conf->channel->hw_value, conf->channel->band);
3812 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
Zhu Yib481de92007-09-25 17:54:57 -07003813 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003814 ret = -EINVAL;
3815 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003816 }
3817
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003818 iwl_set_rxon_channel(priv, conf->channel);
Zhu Yib481de92007-09-25 17:54:57 -07003819
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003820 iwl_set_flags_for_band(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07003821
3822 /* The list of supported rates and rate mask can be different
3823 * for each phymode; since the phymode may have changed, reset
3824 * the rate mask to what mac80211 lists */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003825 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003826
3827 spin_unlock_irqrestore(&priv->lock, flags);
3828
3829#ifdef IEEE80211_CONF_CHANNEL_SWITCH
3830 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003831 iwl3945_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003832 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003833 }
3834#endif
3835
Mohamed Abbas37fec382009-03-17 21:51:42 -07003836 if (changed & IEEE80211_CONF_CHANGE_RADIO_ENABLED) {
3837 if (conf->radio_enabled &&
3838 iwl_radio_kill_sw_enable_radio(priv)) {
3839 IWL_DEBUG_MAC80211(priv, "leave - RF-KILL - "
3840 "waiting for uCode\n");
3841 goto out;
3842 }
Zhu Yib481de92007-09-25 17:54:57 -07003843
Mohamed Abbas37fec382009-03-17 21:51:42 -07003844 if (!conf->radio_enabled) {
3845 iwl_radio_kill_sw_disable_radio(priv);
3846 IWL_DEBUG_MAC80211(priv, "leave - radio disabled\n");
3847 goto out;
3848 }
Zhu Yib481de92007-09-25 17:54:57 -07003849 }
3850
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003851 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003852 IWL_DEBUG_MAC80211(priv, "leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08003853 ret = -EIO;
3854 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003855 }
3856
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003857 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003858
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003859 if (memcmp(&priv->active_rxon,
3860 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003861 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003862 else
Tomas Winklere1623442009-01-27 14:27:56 -08003863 IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration\n");
Zhu Yib481de92007-09-25 17:54:57 -07003864
Tomas Winklere1623442009-01-27 14:27:56 -08003865 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003866
Zhu Yi76bb77e2007-11-22 10:53:22 +08003867out:
Zhu Yia0646472007-12-20 14:10:01 +08003868 clear_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003869 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003870 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003871}
3872
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003873static void iwl3945_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003874{
3875 int rc = 0;
3876
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08003877 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07003878 return;
3879
3880 /* The following should be done only at AP bring up */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003881 if (!(iwl_is_associated(priv))) {
Zhu Yib481de92007-09-25 17:54:57 -07003882
3883 /* RXON - unassoc (to set timing command) */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003884 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003885 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003886
3887 /* RXON Timing */
Tomas Winkler28afaf92008-12-19 10:37:06 +08003888 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003889 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003890 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
3891 sizeof(priv->rxon_timing),
3892 &priv->rxon_timing);
Zhu Yib481de92007-09-25 17:54:57 -07003893 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003894 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003895 "Attempting to continue.\n");
3896
3897 /* FIXME: what should be the assoc_id for AP? */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003898 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003899 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003900 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003901 RXON_FLG_SHORT_PREAMBLE_MSK;
3902 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003903 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003904 ~RXON_FLG_SHORT_PREAMBLE_MSK;
3905
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003906 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003907 if (priv->assoc_capability &
3908 WLAN_CAPABILITY_SHORT_SLOT_TIME)
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 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003912 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003913 ~RXON_FLG_SHORT_SLOT_MSK;
3914
Johannes Berg05c914f2008-09-11 00:01:58 +02003915 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003916 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003917 ~RXON_FLG_SHORT_SLOT_MSK;
3918 }
3919 /* restore RXON assoc */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003920 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003921 iwl3945_commit_rxon(priv);
Kolekar, Abhijeetb5323d32008-12-19 10:37:22 +08003922 iwl3945_add_station(priv, iwl_bcast_addr, 0, 0);
Zhu Yi556f8db2007-09-27 11:27:33 +08003923 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003924 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003925
3926 /* FIXME - we need to add code here to detect a totally new
3927 * configuration, reset the AP, unassoc, rxon timing, assoc,
3928 * clear sta table, add BCAST sta... */
3929}
3930
Johannes Berg32bfd352007-12-19 01:31:26 +01003931static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
3932 struct ieee80211_vif *vif,
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003933 struct ieee80211_if_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07003934{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003935 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003936 int rc;
3937
3938 if (conf == NULL)
3939 return -EIO;
3940
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08003941 if (priv->vif != vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08003942 IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08003943 return 0;
3944 }
3945
Johannes Berg9d139c82008-07-09 14:40:37 +02003946 /* handle this temporarily here */
Johannes Berg05c914f2008-09-11 00:01:58 +02003947 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Johannes Berg9d139c82008-07-09 14:40:37 +02003948 conf->changed & IEEE80211_IFCC_BEACON) {
3949 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
3950 if (!beacon)
3951 return -ENOMEM;
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003952 mutex_lock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02003953 rc = iwl3945_mac_beacon_update(hw, beacon);
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003954 mutex_unlock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02003955 if (rc)
3956 return rc;
3957 }
3958
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003959 if (!iwl_is_alive(priv))
Zhu Yi5a669262008-01-14 17:46:18 -08003960 return -EAGAIN;
3961
Zhu Yib481de92007-09-25 17:54:57 -07003962 mutex_lock(&priv->mutex);
3963
Zhu Yib481de92007-09-25 17:54:57 -07003964 if (conf->bssid)
Tomas Winklere1623442009-01-27 14:27:56 -08003965 IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07003966
Johannes Berg4150c572007-09-17 01:29:23 -04003967/*
3968 * very dubious code was here; the probe filtering flag is never set:
3969 *
Zhu Yib481de92007-09-25 17:54:57 -07003970 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
3971 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04003972 */
Zhu Yib481de92007-09-25 17:54:57 -07003973
Johannes Berg05c914f2008-09-11 00:01:58 +02003974 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07003975 if (!conf->bssid) {
3976 conf->bssid = priv->mac_addr;
3977 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08003978 IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07003979 conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07003980 }
3981 if (priv->ibss_beacon)
3982 dev_kfree_skb(priv->ibss_beacon);
3983
Johannes Berg9d139c82008-07-09 14:40:37 +02003984 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
Zhu Yib481de92007-09-25 17:54:57 -07003985 }
3986
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003987 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08003988 goto done;
3989
Zhu Yib481de92007-09-25 17:54:57 -07003990 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
3991 !is_multicast_ether_addr(conf->bssid)) {
3992 /* If there is currently a HW scan going on in the background
3993 * then we need to cancel it else the RXON below will fail. */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003994 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003995 IWL_WARN(priv, "Aborted scan still in progress "
Zhu Yib481de92007-09-25 17:54:57 -07003996 "after 100ms\n");
Tomas Winklere1623442009-01-27 14:27:56 -08003997 IWL_DEBUG_MAC80211(priv, "leaving:scan abort failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07003998 mutex_unlock(&priv->mutex);
3999 return -EAGAIN;
4000 }
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004001 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07004002
4003 /* TODO: Audit driver for usage of these members and see
4004 * if mac80211 deprecates them (priv->bssid looks like it
4005 * shouldn't be there, but I haven't scanned the IBSS code
4006 * to verify) - jpk */
4007 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
4008
Johannes Berg05c914f2008-09-11 00:01:58 +02004009 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004010 iwl3945_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004011 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004012 rc = iwl3945_commit_rxon(priv);
Johannes Berg05c914f2008-09-11 00:01:58 +02004013 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004014 iwl3945_add_station(priv,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004015 priv->active_rxon.bssid_addr, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004016 }
4017
4018 } else {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004019 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004020 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004021 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004022 }
4023
Mohamed Abbasfde35712007-11-29 11:10:15 +08004024 done:
Tomas Winklere1623442009-01-27 14:27:56 -08004025 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004026 mutex_unlock(&priv->mutex);
4027
4028 return 0;
4029}
4030
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004031static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004032 struct ieee80211_if_init_conf *conf)
4033{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004034 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004035
Tomas Winklere1623442009-01-27 14:27:56 -08004036 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004037
4038 mutex_lock(&priv->mutex);
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004039
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004040 if (iwl_is_ready_rf(priv)) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004041 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004042 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Mohamed Abbasfde35712007-11-29 11:10:15 +08004043 iwl3945_commit_rxon(priv);
4044 }
Johannes Berg32bfd352007-12-19 01:31:26 +01004045 if (priv->vif == conf->vif) {
4046 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07004047 memset(priv->bssid, 0, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07004048 }
4049 mutex_unlock(&priv->mutex);
4050
Tomas Winklere1623442009-01-27 14:27:56 -08004051 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004052}
4053
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004054#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
4055
4056static void iwl3945_bss_info_changed(struct ieee80211_hw *hw,
4057 struct ieee80211_vif *vif,
4058 struct ieee80211_bss_conf *bss_conf,
4059 u32 changes)
4060{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004061 struct iwl_priv *priv = hw->priv;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004062
Tomas Winklere1623442009-01-27 14:27:56 -08004063 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004064
4065 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
Tomas Winklere1623442009-01-27 14:27:56 -08004066 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004067 bss_conf->use_short_preamble);
4068 if (bss_conf->use_short_preamble)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004069 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004070 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004071 priv->staging_rxon.flags &=
4072 ~RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004073 }
4074
4075 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
Tomas Winklere1623442009-01-27 14:27:56 -08004076 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n",
4077 bss_conf->use_cts_prot);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004078 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004079 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004080 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004081 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004082 }
4083
4084 if (changes & BSS_CHANGED_ASSOC) {
Tomas Winklere1623442009-01-27 14:27:56 -08004085 IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004086 /* This should never happen as this function should
4087 * never be called from interrupt context. */
4088 if (WARN_ON_ONCE(in_interrupt()))
4089 return;
4090 if (bss_conf->assoc) {
4091 priv->assoc_id = bss_conf->aid;
4092 priv->beacon_int = bss_conf->beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08004093 priv->timestamp = bss_conf->timestamp;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004094 priv->assoc_capability = bss_conf->assoc_capability;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08004095 priv->power_data.dtim_period = bss_conf->dtim_period;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004096 priv->next_scan_jiffies = jiffies +
4097 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
4098 mutex_lock(&priv->mutex);
4099 iwl3945_post_associate(priv);
4100 mutex_unlock(&priv->mutex);
4101 } else {
4102 priv->assoc_id = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08004103 IWL_DEBUG_MAC80211(priv,
4104 "DISASSOC %d\n", bss_conf->assoc);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004105 }
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004106 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
Tomas Winklere1623442009-01-27 14:27:56 -08004107 IWL_DEBUG_MAC80211(priv,
4108 "Associated Changes %d\n", changes);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004109 iwl3945_send_rxon_assoc(priv);
4110 }
4111
4112}
4113
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004114static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01004115 struct ieee80211_vif *vif,
4116 struct ieee80211_sta *sta,
4117 struct ieee80211_key_conf *key)
Zhu Yib481de92007-09-25 17:54:57 -07004118{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004119 struct iwl_priv *priv = hw->priv;
Johannes Bergdc822b52008-12-29 12:55:09 +01004120 const u8 *addr;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08004121 int ret = 0;
4122 u8 sta_id = IWL_INVALID_STATION;
4123 u8 static_key;
Zhu Yib481de92007-09-25 17:54:57 -07004124
Tomas Winklere1623442009-01-27 14:27:56 -08004125 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004126
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004127 if (iwl3945_mod_params.sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08004128 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07004129 return -EOPNOTSUPP;
4130 }
4131
Winkler, Tomas42986792009-01-19 15:30:22 -08004132 addr = sta ? sta->addr : iwl_bcast_addr;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08004133 static_key = !iwl_is_associated(priv);
4134
4135 if (!static_key) {
4136 sta_id = iwl3945_hw_find_station(priv, addr);
4137 if (sta_id == IWL_INVALID_STATION) {
Joe Perches12514392009-04-16 16:23:26 -07004138 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08004139 addr);
4140 return -EINVAL;
4141 }
Zhu Yib481de92007-09-25 17:54:57 -07004142 }
4143
4144 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004145 iwl_scan_cancel_timeout(priv, 100);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08004146 mutex_unlock(&priv->mutex);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004147
Zhu Yib481de92007-09-25 17:54:57 -07004148 switch (cmd) {
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08004149 case SET_KEY:
4150 if (static_key)
4151 ret = iwl3945_set_static_key(priv, key);
4152 else
4153 ret = iwl3945_set_dynamic_key(priv, key, sta_id);
4154 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07004155 break;
4156 case DISABLE_KEY:
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08004157 if (static_key)
4158 ret = iwl3945_remove_static_key(priv);
4159 else
4160 ret = iwl3945_clear_sta_key_info(priv, sta_id);
4161 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07004162 break;
4163 default:
Winkler, Tomas42986792009-01-19 15:30:22 -08004164 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07004165 }
4166
Tomas Winklere1623442009-01-27 14:27:56 -08004167 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004168
Winkler, Tomas42986792009-01-19 15:30:22 -08004169 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004170}
4171
Johannes Berge100bb62008-04-30 18:51:21 +02004172static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
Zhu Yib481de92007-09-25 17:54:57 -07004173 const struct ieee80211_tx_queue_params *params)
4174{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004175 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004176 unsigned long flags;
4177 int q;
Zhu Yib481de92007-09-25 17:54:57 -07004178
Tomas Winklere1623442009-01-27 14:27:56 -08004179 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004180
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004181 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004182 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004183 return -EIO;
4184 }
4185
4186 if (queue >= AC_NUM) {
Tomas Winklere1623442009-01-27 14:27:56 -08004187 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
Zhu Yib481de92007-09-25 17:54:57 -07004188 return 0;
4189 }
4190
Zhu Yib481de92007-09-25 17:54:57 -07004191 q = AC_NUM - 1 - queue;
4192
4193 spin_lock_irqsave(&priv->lock, flags);
4194
4195 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
4196 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
4197 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
4198 priv->qos_data.def_qos_parm.ac[q].edca_txop =
Johannes Berg3330d7b2008-02-10 16:49:38 +01004199 cpu_to_le16((params->txop * 32));
Zhu Yib481de92007-09-25 17:54:57 -07004200
4201 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
4202 priv->qos_data.qos_active = 1;
4203
4204 spin_unlock_irqrestore(&priv->lock, flags);
4205
4206 mutex_lock(&priv->mutex);
Johannes Berg05c914f2008-09-11 00:01:58 +02004207 if (priv->iw_mode == NL80211_IFTYPE_AP)
Abhijeet Kolekar14d2aac2009-02-27 16:21:24 -08004208 iwl_activate_qos(priv, 1);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004209 else if (priv->assoc_id && iwl_is_associated(priv))
Abhijeet Kolekar14d2aac2009-02-27 16:21:24 -08004210 iwl_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004211
4212 mutex_unlock(&priv->mutex);
4213
Tomas Winklere1623442009-01-27 14:27:56 -08004214 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004215 return 0;
4216}
4217
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004218static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004219 struct ieee80211_tx_queue_stats *stats)
4220{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004221 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004222 int i, avail;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08004223 struct iwl_tx_queue *txq;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004224 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07004225 unsigned long flags;
4226
Tomas Winklere1623442009-01-27 14:27:56 -08004227 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004228
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004229 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004230 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004231 return -EIO;
4232 }
4233
4234 spin_lock_irqsave(&priv->lock, flags);
4235
4236 for (i = 0; i < AC_NUM; i++) {
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08004237 txq = &priv->txq[i];
Zhu Yib481de92007-09-25 17:54:57 -07004238 q = &txq->q;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004239 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07004240
Johannes Berg57ffc582008-04-29 17:18:59 +02004241 stats[i].len = q->n_window - avail;
4242 stats[i].limit = q->n_window - q->high_mark;
4243 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07004244
4245 }
4246 spin_unlock_irqrestore(&priv->lock, flags);
4247
Tomas Winklere1623442009-01-27 14:27:56 -08004248 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004249
4250 return 0;
4251}
4252
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004253static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07004254{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004255 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004256 unsigned long flags;
4257
4258 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08004259 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004260
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004261 iwl_reset_qos(priv);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08004262
Zhu Yib481de92007-09-25 17:54:57 -07004263 spin_lock_irqsave(&priv->lock, flags);
4264 priv->assoc_id = 0;
4265 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004266
4267 /* new association get rid of ibss beacon skb */
4268 if (priv->ibss_beacon)
4269 dev_kfree_skb(priv->ibss_beacon);
4270
4271 priv->ibss_beacon = NULL;
4272
4273 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08004274 priv->timestamp = 0;
Johannes Berg05c914f2008-09-11 00:01:58 +02004275 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
Zhu Yib481de92007-09-25 17:54:57 -07004276 priv->beacon_int = 0;
4277
4278 spin_unlock_irqrestore(&priv->lock, flags);
4279
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004280 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004281 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +08004282 mutex_unlock(&priv->mutex);
4283 return;
4284 }
4285
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004286 /* we are restarting association process
4287 * clear RXON_FILTER_ASSOC_MSK bit
4288 */
Johannes Berg05c914f2008-09-11 00:01:58 +02004289 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004290 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004291 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004292 iwl3945_commit_rxon(priv);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004293 }
4294
Zhu Yib481de92007-09-25 17:54:57 -07004295 /* Per mac80211.h: This is only used in IBSS mode... */
Johannes Berg05c914f2008-09-11 00:01:58 +02004296 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004297
Tomas Winklere1623442009-01-27 14:27:56 -08004298 IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07004299 mutex_unlock(&priv->mutex);
4300 return;
4301 }
4302
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004303 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004304
4305 mutex_unlock(&priv->mutex);
4306
Tomas Winklere1623442009-01-27 14:27:56 -08004307 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004308
4309}
4310
Johannes Berge039fa42008-05-15 12:55:29 +02004311static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07004312{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004313 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004314 unsigned long flags;
Abhijeet Kolekar7c4cbb62009-02-27 16:21:20 -08004315 __le64 timestamp;
Zhu Yib481de92007-09-25 17:54:57 -07004316
Tomas Winklere1623442009-01-27 14:27:56 -08004317 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004318
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004319 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004320 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004321 return -EIO;
4322 }
4323
Johannes Berg05c914f2008-09-11 00:01:58 +02004324 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Tomas Winklere1623442009-01-27 14:27:56 -08004325 IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07004326 return -EIO;
4327 }
4328
4329 spin_lock_irqsave(&priv->lock, flags);
4330
4331 if (priv->ibss_beacon)
4332 dev_kfree_skb(priv->ibss_beacon);
4333
4334 priv->ibss_beacon = skb;
4335
4336 priv->assoc_id = 0;
Abhijeet Kolekar7c4cbb62009-02-27 16:21:20 -08004337 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
4338 priv->timestamp = le64_to_cpu(timestamp);
Zhu Yib481de92007-09-25 17:54:57 -07004339
Tomas Winklere1623442009-01-27 14:27:56 -08004340 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004341 spin_unlock_irqrestore(&priv->lock, flags);
4342
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004343 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004344
Abhijeet Kolekardc4b1e72008-09-03 11:26:30 +08004345 iwl3945_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004346
Zhu Yib481de92007-09-25 17:54:57 -07004347
4348 return 0;
4349}
4350
4351/*****************************************************************************
4352 *
4353 * sysfs attributes
4354 *
4355 *****************************************************************************/
4356
Samuel Ortizd08853a2009-01-23 13:45:17 -08004357#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07004358
4359/*
4360 * The following adds a new attribute to the sysfs representation
4361 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
4362 * used for controlling the debug level.
4363 *
4364 * See the level definitions in iwl for details.
4365 */
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004366static ssize_t show_debug_level(struct device *d,
4367 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07004368{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004369 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004370
4371 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07004372}
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004373static ssize_t store_debug_level(struct device *d,
4374 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07004375 const char *buf, size_t count)
4376{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004377 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004378 unsigned long val;
4379 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07004380
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004381 ret = strict_strtoul(buf, 0, &val);
4382 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08004383 IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07004384 else
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004385 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07004386
4387 return strnlen(buf, count);
4388}
4389
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004390static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
4391 show_debug_level, store_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07004392
Samuel Ortizd08853a2009-01-23 13:45:17 -08004393#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07004394
Zhu Yib481de92007-09-25 17:54:57 -07004395static ssize_t show_temperature(struct device *d,
4396 struct device_attribute *attr, char *buf)
4397{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004398 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004399
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004400 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004401 return -EAGAIN;
4402
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004403 return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
Zhu Yib481de92007-09-25 17:54:57 -07004404}
4405
4406static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
4407
Zhu Yib481de92007-09-25 17:54:57 -07004408static ssize_t show_tx_power(struct device *d,
4409 struct device_attribute *attr, char *buf)
4410{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004411 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08004412 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07004413}
4414
4415static ssize_t store_tx_power(struct device *d,
4416 struct device_attribute *attr,
4417 const char *buf, size_t count)
4418{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004419 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004420 char *p = (char *)buf;
4421 u32 val;
4422
4423 val = simple_strtoul(p, &p, 10);
4424 if (p == buf)
Tomas Winkler978785a2008-12-19 10:37:31 +08004425 IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07004426 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004427 iwl3945_hw_reg_set_txpower(priv, val);
Zhu Yib481de92007-09-25 17:54:57 -07004428
4429 return count;
4430}
4431
4432static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
4433
4434static ssize_t show_flags(struct device *d,
4435 struct device_attribute *attr, char *buf)
4436{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004437 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004438
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004439 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
Zhu Yib481de92007-09-25 17:54:57 -07004440}
4441
4442static ssize_t store_flags(struct device *d,
4443 struct device_attribute *attr,
4444 const char *buf, size_t count)
4445{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004446 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004447 u32 flags = simple_strtoul(buf, NULL, 0);
4448
4449 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004450 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
Zhu Yib481de92007-09-25 17:54:57 -07004451 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004452 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004453 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004454 else {
Tomas Winklere1623442009-01-27 14:27:56 -08004455 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
Zhu Yib481de92007-09-25 17:54:57 -07004456 flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004457 priv->staging_rxon.flags = cpu_to_le32(flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004458 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004459 }
4460 }
4461 mutex_unlock(&priv->mutex);
4462
4463 return count;
4464}
4465
4466static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
4467
4468static ssize_t show_filter_flags(struct device *d,
4469 struct device_attribute *attr, char *buf)
4470{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004471 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004472
4473 return sprintf(buf, "0x%04X\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004474 le32_to_cpu(priv->active_rxon.filter_flags));
Zhu Yib481de92007-09-25 17:54:57 -07004475}
4476
4477static ssize_t store_filter_flags(struct device *d,
4478 struct device_attribute *attr,
4479 const char *buf, size_t count)
4480{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004481 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004482 u32 filter_flags = simple_strtoul(buf, NULL, 0);
4483
4484 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004485 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
Zhu Yib481de92007-09-25 17:54:57 -07004486 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004487 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004488 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004489 else {
Tomas Winklere1623442009-01-27 14:27:56 -08004490 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
Zhu Yib481de92007-09-25 17:54:57 -07004491 "0x%04X\n", filter_flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004492 priv->staging_rxon.filter_flags =
Zhu Yib481de92007-09-25 17:54:57 -07004493 cpu_to_le32(filter_flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004494 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004495 }
4496 }
4497 mutex_unlock(&priv->mutex);
4498
4499 return count;
4500}
4501
4502static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
4503 store_filter_flags);
4504
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004505#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004506
4507static ssize_t show_measurement(struct device *d,
4508 struct device_attribute *attr, char *buf)
4509{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004510 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler600c0e12008-12-19 10:37:04 +08004511 struct iwl_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004512 u32 size = sizeof(measure_report), len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03004513 u8 *data = (u8 *)&measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004514 unsigned long flags;
4515
4516 spin_lock_irqsave(&priv->lock, flags);
4517 if (!(priv->measurement_status & MEASUREMENT_READY)) {
4518 spin_unlock_irqrestore(&priv->lock, flags);
4519 return 0;
4520 }
4521 memcpy(&measure_report, &priv->measure_report, size);
4522 priv->measurement_status = 0;
4523 spin_unlock_irqrestore(&priv->lock, flags);
4524
4525 while (size && (PAGE_SIZE - len)) {
4526 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4527 PAGE_SIZE - len, 1);
4528 len = strlen(buf);
4529 if (PAGE_SIZE - len)
4530 buf[len++] = '\n';
4531
4532 ofs += 16;
4533 size -= min(size, 16U);
4534 }
4535
4536 return len;
4537}
4538
4539static ssize_t store_measurement(struct device *d,
4540 struct device_attribute *attr,
4541 const char *buf, size_t count)
4542{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004543 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004544 struct ieee80211_measurement_params params = {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004545 .channel = le16_to_cpu(priv->active_rxon.channel),
Zhu Yib481de92007-09-25 17:54:57 -07004546 .start_time = cpu_to_le64(priv->last_tsf),
4547 .duration = cpu_to_le16(1),
4548 };
4549 u8 type = IWL_MEASURE_BASIC;
4550 u8 buffer[32];
4551 u8 channel;
4552
4553 if (count) {
4554 char *p = buffer;
4555 strncpy(buffer, buf, min(sizeof(buffer), count));
4556 channel = simple_strtoul(p, NULL, 0);
4557 if (channel)
4558 params.channel = channel;
4559
4560 p = buffer;
4561 while (*p && *p != ' ')
4562 p++;
4563 if (*p)
4564 type = simple_strtoul(p + 1, NULL, 0);
4565 }
4566
Tomas Winklere1623442009-01-27 14:27:56 -08004567 IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on "
Zhu Yib481de92007-09-25 17:54:57 -07004568 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004569 iwl3945_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07004570
4571 return count;
4572}
4573
4574static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
4575 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004576#endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07004577
Zhu Yib481de92007-09-25 17:54:57 -07004578static ssize_t store_retry_rate(struct device *d,
4579 struct device_attribute *attr,
4580 const char *buf, size_t count)
4581{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004582 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004583
4584 priv->retry_rate = simple_strtoul(buf, NULL, 0);
4585 if (priv->retry_rate <= 0)
4586 priv->retry_rate = 1;
4587
4588 return count;
4589}
4590
4591static ssize_t show_retry_rate(struct device *d,
4592 struct device_attribute *attr, char *buf)
4593{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004594 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004595 return sprintf(buf, "%d", priv->retry_rate);
4596}
4597
4598static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
4599 store_retry_rate);
4600
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004601
Zhu Yib481de92007-09-25 17:54:57 -07004602static ssize_t store_power_level(struct device *d,
4603 struct device_attribute *attr,
4604 const char *buf, size_t count)
4605{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004606 struct iwl_priv *priv = dev_get_drvdata(d);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004607 int ret;
4608 unsigned long mode;
Zhu Yib481de92007-09-25 17:54:57 -07004609
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004610
Zhu Yib481de92007-09-25 17:54:57 -07004611 mutex_lock(&priv->mutex);
4612
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004613 ret = strict_strtoul(buf, 10, &mode);
4614 if (ret)
4615 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004616
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004617 ret = iwl_power_set_user_mode(priv, mode);
4618 if (ret) {
4619 IWL_DEBUG_MAC80211(priv, "failed setting power mode.\n");
4620 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004621 }
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004622 ret = count;
Zhu Yib481de92007-09-25 17:54:57 -07004623
4624 out:
4625 mutex_unlock(&priv->mutex);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004626 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004627}
4628
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004629static ssize_t show_power_level(struct device *d,
4630 struct device_attribute *attr, char *buf)
4631{
4632 struct iwl_priv *priv = dev_get_drvdata(d);
4633 int mode = priv->power_data.user_power_setting;
4634 int system = priv->power_data.system_power_setting;
4635 int level = priv->power_data.power_mode;
4636 char *p = buf;
4637
4638 switch (system) {
4639 case IWL_POWER_SYS_AUTO:
4640 p += sprintf(p, "SYSTEM:auto");
4641 break;
4642 case IWL_POWER_SYS_AC:
4643 p += sprintf(p, "SYSTEM:ac");
4644 break;
4645 case IWL_POWER_SYS_BATTERY:
4646 p += sprintf(p, "SYSTEM:battery");
4647 break;
4648 }
4649
4650 p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
4651 "fixed" : "auto");
4652 p += sprintf(p, "\tINDEX:%d", level);
4653 p += sprintf(p, "\n");
4654 return p - buf + 1;
4655}
4656
4657static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR,
4658 show_power_level, store_power_level);
4659
Zhu Yib481de92007-09-25 17:54:57 -07004660#define MAX_WX_STRING 80
4661
4662/* Values are in microsecond */
4663static const s32 timeout_duration[] = {
4664 350000,
4665 250000,
4666 75000,
4667 37000,
4668 25000,
4669};
4670static const s32 period_duration[] = {
4671 400000,
4672 700000,
4673 1000000,
4674 1000000,
4675 1000000
4676};
4677
Zhu Yib481de92007-09-25 17:54:57 -07004678static ssize_t show_channels(struct device *d,
4679 struct device_attribute *attr, char *buf)
4680{
Johannes Berg8318d782008-01-24 19:38:38 +01004681 /* all this shit doesn't belong into sysfs anyway */
4682 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07004683}
4684
4685static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
4686
4687static ssize_t show_statistics(struct device *d,
4688 struct device_attribute *attr, char *buf)
4689{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004690 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004691 u32 size = sizeof(struct iwl3945_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07004692 u32 len = 0, ofs = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004693 u8 *data = (u8 *)&priv->statistics_39;
Zhu Yib481de92007-09-25 17:54:57 -07004694 int rc = 0;
4695
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004696 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004697 return -EAGAIN;
4698
4699 mutex_lock(&priv->mutex);
Samuel Ortiz17f841c2009-01-23 13:45:20 -08004700 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004701 mutex_unlock(&priv->mutex);
4702
4703 if (rc) {
4704 len = sprintf(buf,
4705 "Error sending statistics request: 0x%08X\n", rc);
4706 return len;
4707 }
4708
4709 while (size && (PAGE_SIZE - len)) {
4710 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4711 PAGE_SIZE - len, 1);
4712 len = strlen(buf);
4713 if (PAGE_SIZE - len)
4714 buf[len++] = '\n';
4715
4716 ofs += 16;
4717 size -= min(size, 16U);
4718 }
4719
4720 return len;
4721}
4722
4723static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
4724
4725static ssize_t show_antenna(struct device *d,
4726 struct device_attribute *attr, char *buf)
4727{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004728 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004729
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004730 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004731 return -EAGAIN;
4732
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08004733 return sprintf(buf, "%d\n", iwl3945_mod_params.antenna);
Zhu Yib481de92007-09-25 17:54:57 -07004734}
4735
4736static ssize_t store_antenna(struct device *d,
4737 struct device_attribute *attr,
4738 const char *buf, size_t count)
4739{
Winkler, Tomas7530f852009-01-27 14:27:53 -08004740 struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004741 int ant;
Zhu Yib481de92007-09-25 17:54:57 -07004742
4743 if (count == 0)
4744 return 0;
4745
4746 if (sscanf(buf, "%1i", &ant) != 1) {
Tomas Winklere1623442009-01-27 14:27:56 -08004747 IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004748 return count;
4749 }
4750
4751 if ((ant >= 0) && (ant <= 2)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004752 IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant);
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08004753 iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant;
Zhu Yib481de92007-09-25 17:54:57 -07004754 } else
Tomas Winklere1623442009-01-27 14:27:56 -08004755 IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant);
Zhu Yib481de92007-09-25 17:54:57 -07004756
4757
4758 return count;
4759}
4760
4761static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
4762
4763static ssize_t show_status(struct device *d,
4764 struct device_attribute *attr, char *buf)
4765{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004766 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004767 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004768 return -EAGAIN;
4769 return sprintf(buf, "0x%08x\n", (int)priv->status);
4770}
4771
4772static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
4773
4774static ssize_t dump_error_log(struct device *d,
4775 struct device_attribute *attr,
4776 const char *buf, size_t count)
4777{
4778 char *p = (char *)buf;
4779
4780 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004781 iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07004782
4783 return strnlen(buf, count);
4784}
4785
4786static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
4787
4788static ssize_t dump_event_log(struct device *d,
4789 struct device_attribute *attr,
4790 const char *buf, size_t count)
4791{
4792 char *p = (char *)buf;
4793
4794 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004795 iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07004796
4797 return strnlen(buf, count);
4798}
4799
4800static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
4801
4802/*****************************************************************************
4803 *
Tomas Winklera96a27f2008-10-23 23:48:56 -07004804 * driver setup and tear down
Zhu Yib481de92007-09-25 17:54:57 -07004805 *
4806 *****************************************************************************/
4807
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004808static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004809{
Reinette Chatred21050c2009-02-13 11:51:18 -08004810 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07004811
4812 init_waitqueue_head(&priv->wait_command_queue);
4813
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004814 INIT_WORK(&priv->up, iwl3945_bg_up);
4815 INIT_WORK(&priv->restart, iwl3945_bg_restart);
4816 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01004817 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004818 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004819 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
4820 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
Helmut Schaa26635162009-01-15 09:38:44 +01004821 INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll);
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08004822 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
4823 INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
4824 INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
4825 INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
Zhu Yib481de92007-09-25 17:54:57 -07004826
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004827 iwl3945_hw_setup_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004828
4829 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004830 iwl3945_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07004831}
4832
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004833static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004834{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004835 iwl3945_hw_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004836
Joonwoo Parke47eb6a2007-11-29 10:42:49 +09004837 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004838 cancel_delayed_work(&priv->scan_check);
4839 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004840 cancel_work_sync(&priv->beacon_update);
4841}
4842
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004843static struct attribute *iwl3945_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07004844 &dev_attr_antenna.attr,
4845 &dev_attr_channels.attr,
4846 &dev_attr_dump_errors.attr,
4847 &dev_attr_dump_events.attr,
4848 &dev_attr_flags.attr,
4849 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004850#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004851 &dev_attr_measurement.attr,
4852#endif
4853 &dev_attr_power_level.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004854 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004855 &dev_attr_statistics.attr,
4856 &dev_attr_status.attr,
4857 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004858 &dev_attr_tx_power.attr,
Samuel Ortizd08853a2009-01-23 13:45:17 -08004859#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004860 &dev_attr_debug_level.attr,
4861#endif
Zhu Yib481de92007-09-25 17:54:57 -07004862 NULL
4863};
4864
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004865static struct attribute_group iwl3945_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07004866 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004867 .attrs = iwl3945_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07004868};
4869
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004870static struct ieee80211_ops iwl3945_hw_ops = {
4871 .tx = iwl3945_mac_tx,
4872 .start = iwl3945_mac_start,
4873 .stop = iwl3945_mac_stop,
4874 .add_interface = iwl3945_mac_add_interface,
4875 .remove_interface = iwl3945_mac_remove_interface,
4876 .config = iwl3945_mac_config,
4877 .config_interface = iwl3945_mac_config_interface,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004878 .configure_filter = iwl_configure_filter,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004879 .set_key = iwl3945_mac_set_key,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004880 .get_tx_stats = iwl3945_mac_get_tx_stats,
4881 .conf_tx = iwl3945_mac_conf_tx,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004882 .reset_tsf = iwl3945_mac_reset_tsf,
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004883 .bss_info_changed = iwl3945_bss_info_changed,
Abhijeet Kolekare9dde6f62009-02-18 15:54:27 -08004884 .hw_scan = iwl_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07004885};
4886
Winkler, Tomase52119c2008-12-22 11:31:19 +08004887static int iwl3945_init_drv(struct iwl_priv *priv)
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004888{
4889 int ret;
Samuel Ortize6148912009-01-23 13:45:15 -08004890 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004891
4892 priv->retry_rate = 1;
4893 priv->ibss_beacon = NULL;
4894
4895 spin_lock_init(&priv->lock);
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08004896 spin_lock_init(&priv->power_data.lock);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004897 spin_lock_init(&priv->sta_lock);
4898 spin_lock_init(&priv->hcmd_lock);
4899
4900 INIT_LIST_HEAD(&priv->free_frames);
4901
4902 mutex_init(&priv->mutex);
4903
4904 /* Clear the driver's (not device's) station table */
4905 iwl3945_clear_stations_table(priv);
4906
4907 priv->data_retry_limit = -1;
4908 priv->ieee_channels = NULL;
4909 priv->ieee_rates = NULL;
4910 priv->band = IEEE80211_BAND_2GHZ;
4911
4912 priv->iw_mode = NL80211_IFTYPE_STATION;
4913
4914 iwl_reset_qos(priv);
4915
4916 priv->qos_data.qos_active = 0;
4917 priv->qos_data.qos_cap.val = 0;
4918
4919 priv->rates_mask = IWL_RATES_MASK;
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004920 /* If power management is turned on, default to CAM mode */
4921 priv->power_mode = IWL_POWER_MODE_CAM;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08004922 priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004923
Samuel Ortize6148912009-01-23 13:45:15 -08004924 if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
4925 IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
4926 eeprom->version);
4927 ret = -EINVAL;
4928 goto err;
4929 }
4930 ret = iwl_init_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004931 if (ret) {
4932 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
4933 goto err;
4934 }
4935
Samuel Ortize6148912009-01-23 13:45:15 -08004936 /* Set up txpower settings in driver for all channels */
4937 if (iwl3945_txpower_set_from_eeprom(priv)) {
4938 ret = -EIO;
4939 goto err_free_channel_map;
4940 }
4941
Samuel Ortiz534166d2009-01-23 13:45:16 -08004942 ret = iwlcore_init_geos(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004943 if (ret) {
4944 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
4945 goto err_free_channel_map;
4946 }
Samuel Ortiz534166d2009-01-23 13:45:16 -08004947 iwl3945_init_hw_rates(priv, priv->ieee_rates);
4948
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004949 return 0;
4950
4951err_free_channel_map:
Samuel Ortize6148912009-01-23 13:45:15 -08004952 iwl_free_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004953err:
4954 return ret;
4955}
4956
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004957static int iwl3945_setup_mac(struct iwl_priv *priv)
4958{
4959 int ret;
4960 struct ieee80211_hw *hw = priv->hw;
4961
4962 hw->rate_control_algorithm = "iwl-3945-rs";
4963 hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
4964
4965 /* Tell mac80211 our characteristics */
4966 hw->flags = IEEE80211_HW_SIGNAL_DBM |
Mohamed Abbasb1c60192009-03-17 21:51:47 -07004967 IEEE80211_HW_NOISE_DBM |
4968 IEEE80211_HW_SPECTRUM_MGMT;
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004969
4970 hw->wiphy->interface_modes =
4971 BIT(NL80211_IFTYPE_STATION) |
4972 BIT(NL80211_IFTYPE_ADHOC);
4973
4974 hw->wiphy->custom_regulatory = true;
4975
Johannes Bergd60cc912009-04-09 09:56:02 +02004976 hw->wiphy->max_scan_ssids = 1; /* WILL FIX */
4977
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004978 /* Default value; 4 EDCA QOS priorities */
4979 hw->queues = 4;
4980
4981 hw->conf.beacon_int = 100;
4982
4983 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
4984 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
4985 &priv->bands[IEEE80211_BAND_2GHZ];
4986
4987 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
4988 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
4989 &priv->bands[IEEE80211_BAND_5GHZ];
4990
4991 ret = ieee80211_register_hw(priv->hw);
4992 if (ret) {
4993 IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
4994 return ret;
4995 }
4996 priv->mac80211_registered = 1;
4997
4998 return 0;
4999}
5000
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005001static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07005002{
5003 int err = 0;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005004 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07005005 struct ieee80211_hw *hw;
Kolekar, Abhijeetc0f20d92008-12-19 10:37:19 +08005006 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Samuel Ortize6148912009-01-23 13:45:15 -08005007 struct iwl3945_eeprom *eeprom;
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005008 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07005009
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005010 /***********************
5011 * 1. Allocating HW data
5012 * ********************/
5013
Zhu Yib481de92007-09-25 17:54:57 -07005014 /* mac80211 allocates memory for this device instance, including
5015 * space for this driver's private structure */
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005016 hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
Zhu Yib481de92007-09-25 17:54:57 -07005017 if (hw == NULL) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005018 printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
Zhu Yib481de92007-09-25 17:54:57 -07005019 err = -ENOMEM;
5020 goto out;
5021 }
Zhu Yib481de92007-09-25 17:54:57 -07005022 priv = hw->priv;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005023 SET_IEEE80211_DEV(hw, &pdev->dev);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005024
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005025 if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) ||
5026 (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005027 IWL_ERR(priv,
5028 "invalid queues_num, should be between %d and %d\n",
5029 IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES);
Samuel Ortiza3139c52008-12-19 10:37:09 +08005030 err = -EINVAL;
Reinette Chatrec8f16132009-02-27 16:21:22 -08005031 goto out_ieee80211_free_hw;
Samuel Ortiza3139c52008-12-19 10:37:09 +08005032 }
5033
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005034 /*
5035 * Disabling hardware scan means that mac80211 will perform scans
5036 * "the hard way", rather than using device's scan.
5037 */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005038 if (iwl3945_mod_params.disable_hw_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08005039 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005040 iwl3945_hw_ops.hw_scan = NULL;
5041 }
5042
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005043
Tomas Winklere1623442009-01-27 14:27:56 -08005044 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005045 priv->cfg = cfg;
5046 priv->pci_dev = pdev;
5047
Samuel Ortizd08853a2009-01-23 13:45:17 -08005048#ifdef CONFIG_IWLWIFI_DEBUG
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005049 priv->debug_level = iwl3945_mod_params.debug;
5050 atomic_set(&priv->restrict_refcnt, 0);
5051#endif
Zhu Yib481de92007-09-25 17:54:57 -07005052
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005053 /***************************
5054 * 2. Initializing PCI bus
5055 * *************************/
Zhu Yib481de92007-09-25 17:54:57 -07005056 if (pci_enable_device(pdev)) {
5057 err = -ENODEV;
5058 goto out_ieee80211_free_hw;
5059 }
5060
5061 pci_set_master(pdev);
5062
Yang Hongyang284901a2009-04-06 19:01:15 -07005063 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Zhu Yib481de92007-09-25 17:54:57 -07005064 if (!err)
Yang Hongyang284901a2009-04-06 19:01:15 -07005065 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Zhu Yib481de92007-09-25 17:54:57 -07005066 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08005067 IWL_WARN(priv, "No suitable DMA available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07005068 goto out_pci_disable_device;
5069 }
5070
5071 pci_set_drvdata(pdev, priv);
5072 err = pci_request_regions(pdev, DRV_NAME);
5073 if (err)
5074 goto out_pci_disable_device;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005075
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005076 /***********************
5077 * 3. Read REV Register
5078 * ********************/
Zhu Yib481de92007-09-25 17:54:57 -07005079 priv->hw_base = pci_iomap(pdev, 0, 0);
5080 if (!priv->hw_base) {
5081 err = -ENODEV;
5082 goto out_pci_release_regions;
5083 }
5084
Tomas Winklere1623442009-01-27 14:27:56 -08005085 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Zhu Yib481de92007-09-25 17:54:57 -07005086 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08005087 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Zhu Yib481de92007-09-25 17:54:57 -07005088
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005089 /* We disable the RETRY_TIMEOUT register (0x41) to keep
5090 * PCI Tx retries from interfering with C3 CPU state */
5091 pci_write_config_byte(pdev, 0x41, 0x00);
Zhu Yib481de92007-09-25 17:54:57 -07005092
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005093 /* amp init */
5094 err = priv->cfg->ops->lib->apm_ops.init(priv);
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005095 if (err < 0) {
David S. Millerd5df2a12009-03-10 05:04:16 -07005096 IWL_DEBUG_INFO(priv, "Failed to init the card\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005097 goto out_iounmap;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005098 }
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005099
5100 /***********************
5101 * 4. Read EEPROM
5102 * ********************/
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005103
Zhu Yi5a669262008-01-14 17:46:18 -08005104 /* Read the EEPROM */
Samuel Ortize6148912009-01-23 13:45:15 -08005105 err = iwl_eeprom_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005106 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005107 IWL_ERR(priv, "Unable to init EEPROM\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08005108 goto out_iounmap;
Zhu Yi5a669262008-01-14 17:46:18 -08005109 }
5110 /* MAC Address location in EEPROM same for 3945/4965 */
Samuel Ortize6148912009-01-23 13:45:15 -08005111 eeprom = (struct iwl3945_eeprom *)priv->eeprom;
5112 memcpy(priv->mac_addr, eeprom->mac_address, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08005113 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
Zhu Yi5a669262008-01-14 17:46:18 -08005114 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
5115
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005116 /***********************
5117 * 5. Setup HW Constants
5118 * ********************/
5119 /* Device-specific setup */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005120 if (iwl3945_hw_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005121 IWL_ERR(priv, "failed to set hw settings\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08005122 goto out_eeprom_free;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005123 }
5124
5125 /***********************
5126 * 6. Setup priv
5127 * ********************/
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005128
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005129 err = iwl3945_init_drv(priv);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005130 if (err) {
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005131 IWL_ERR(priv, "initializing driver failed\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08005132 goto out_unset_hw_params;
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005133 }
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005134
Tomas Winkler978785a2008-12-19 10:37:31 +08005135 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
5136 priv->cfg->name);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005137
5138 /***********************************
5139 * 7. Initialize Module Parameters
5140 * **********************************/
5141
5142 /* Initialize module parameter values here */
5143 /* Disable radio (SW RF KILL) via parameter when loading driver */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005144 if (iwl3945_mod_params.disable) {
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005145 set_bit(STATUS_RF_KILL_SW, &priv->status);
Tomas Winklere1623442009-01-27 14:27:56 -08005146 IWL_DEBUG_INFO(priv, "Radio disabled.\n");
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005147 }
5148
5149
5150 /***********************
5151 * 8. Setup Services
5152 * ********************/
5153
5154 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08005155 iwl_disable_interrupts(priv);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005156 spin_unlock_irqrestore(&priv->lock, flags);
5157
Helmut Schaa26635162009-01-15 09:38:44 +01005158 pci_enable_msi(priv->pci_dev);
5159
Abhijeet Kolekarf17d08a2009-02-18 15:54:31 -08005160 err = request_irq(priv->pci_dev->irq, iwl_isr, IRQF_SHARED,
Helmut Schaa26635162009-01-15 09:38:44 +01005161 DRV_NAME, priv);
5162 if (err) {
5163 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
5164 goto out_disable_msi;
5165 }
5166
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005167 err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
5168 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005169 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005170 goto out_release_irq;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005171 }
5172
Samuel Ortiz8ccde882009-01-27 14:27:52 -08005173 iwl_set_rxon_channel(priv,
5174 &priv->bands[IEEE80211_BAND_2GHZ].channels[5]);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005175 iwl3945_setup_deferred_work(priv);
5176 iwl3945_setup_rx_handlers(priv);
5177
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005178 /*********************************
Helmut Schaa26635162009-01-15 09:38:44 +01005179 * 9. Setup and Register mac80211
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005180 * *******************************/
5181
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08005182 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005183
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08005184 err = iwl3945_setup_mac(priv);
5185 if (err)
5186 goto out_remove_sysfs;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005187
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005188 err = iwl_rfkill_init(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005189 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08005190 IWL_ERR(priv, "Unable to initialize RFKILL system. "
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005191 "Ignoring error: %d\n", err);
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08005192 else
5193 iwl_rfkill_set_hw_state(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005194
Helmut Schaa26635162009-01-15 09:38:44 +01005195 /* Start monitoring the killswitch */
5196 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
5197 2 * HZ);
5198
Zhu Yib481de92007-09-25 17:54:57 -07005199 return 0;
5200
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005201 out_remove_sysfs:
Zhu Yib481de92007-09-25 17:54:57 -07005202 destroy_workqueue(priv->workqueue);
5203 priv->workqueue = NULL;
Reinette Chatrec8f16132009-02-27 16:21:22 -08005204 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
5205 out_release_irq:
5206 free_irq(priv->pci_dev->irq, priv);
Helmut Schaa26635162009-01-15 09:38:44 +01005207 out_disable_msi:
5208 pci_disable_msi(priv->pci_dev);
Reinette Chatrec8f16132009-02-27 16:21:22 -08005209 iwlcore_free_geos(priv);
5210 iwl_free_channel_map(priv);
5211 out_unset_hw_params:
5212 iwl3945_unset_hw_params(priv);
5213 out_eeprom_free:
5214 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005215 out_iounmap:
5216 pci_iounmap(pdev, priv->hw_base);
5217 out_pci_release_regions:
5218 pci_release_regions(pdev);
5219 out_pci_disable_device:
Zhu Yib481de92007-09-25 17:54:57 -07005220 pci_set_drvdata(pdev, NULL);
Reinette Chatre623d5632009-03-03 11:37:04 -08005221 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005222 out_ieee80211_free_hw:
5223 ieee80211_free_hw(priv->hw);
5224 out:
5225 return err;
5226}
5227
Reinette Chatrec83dbf62008-03-21 13:53:41 -07005228static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07005229{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005230 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005231 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07005232
5233 if (!priv)
5234 return;
5235
Tomas Winklere1623442009-01-27 14:27:56 -08005236 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07005237
Zhu Yib481de92007-09-25 17:54:57 -07005238 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08005239
Kolekar, Abhijeetd552bfb2008-12-19 10:37:41 +08005240 if (priv->mac80211_registered) {
5241 ieee80211_unregister_hw(priv->hw);
5242 priv->mac80211_registered = 0;
5243 } else {
5244 iwl3945_down(priv);
5245 }
Zhu Yib481de92007-09-25 17:54:57 -07005246
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005247 /* make sure we flush any pending irq or
5248 * tasklet for the driver
5249 */
5250 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08005251 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005252 spin_unlock_irqrestore(&priv->lock, flags);
5253
5254 iwl_synchronize_irq(priv);
5255
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005256 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07005257
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005258 iwl_rfkill_unregister(priv);
Reinette Chatre71d449b2009-04-20 14:37:01 -07005259 cancel_delayed_work_sync(&priv->rfkill_poll);
Helmut Schaa26635162009-01-15 09:38:44 +01005260
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005261 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005262
5263 if (priv->rxq.bd)
Reinette Chatredf833b12009-04-21 10:55:48 -07005264 iwl3945_rx_queue_free(priv, &priv->rxq);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005265 iwl3945_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005266
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005267 iwl3945_unset_hw_params(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005268 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005269
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08005270 /*netif_stop_queue(dev); */
5271 flush_workqueue(priv->workqueue);
5272
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005273 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07005274 * priv->workqueue... so we can't take down the workqueue
5275 * until now... */
5276 destroy_workqueue(priv->workqueue);
5277 priv->workqueue = NULL;
5278
Helmut Schaa26635162009-01-15 09:38:44 +01005279 free_irq(pdev->irq, priv);
5280 pci_disable_msi(pdev);
5281
Zhu Yib481de92007-09-25 17:54:57 -07005282 pci_iounmap(pdev, priv->hw_base);
5283 pci_release_regions(pdev);
5284 pci_disable_device(pdev);
5285 pci_set_drvdata(pdev, NULL);
5286
Samuel Ortize6148912009-01-23 13:45:15 -08005287 iwl_free_channel_map(priv);
Samuel Ortiz534166d2009-01-23 13:45:16 -08005288 iwlcore_free_geos(priv);
Winkler, Tomas805cee52009-01-19 15:30:28 -08005289 kfree(priv->scan);
Zhu Yib481de92007-09-25 17:54:57 -07005290 if (priv->ibss_beacon)
5291 dev_kfree_skb(priv->ibss_beacon);
5292
5293 ieee80211_free_hw(priv->hw);
5294}
5295
5296#ifdef CONFIG_PM
5297
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005298static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07005299{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005300 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005301
Zhu Yie655b9f2008-01-24 02:19:38 -08005302 if (priv->is_open) {
5303 set_bit(STATUS_IN_SUSPEND, &priv->status);
5304 iwl3945_mac_stop(priv->hw);
5305 priv->is_open = 1;
5306 }
Helmut Schaa26635162009-01-15 09:38:44 +01005307 pci_save_state(pdev);
5308 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005309 pci_set_power_state(pdev, PCI_D3hot);
5310
Zhu Yib481de92007-09-25 17:54:57 -07005311 return 0;
5312}
5313
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005314static int iwl3945_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07005315{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005316 struct iwl_priv *priv = pci_get_drvdata(pdev);
Winkler, Tomas450154e2009-01-27 14:27:55 -08005317 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07005318
Zhu Yib481de92007-09-25 17:54:57 -07005319 pci_set_power_state(pdev, PCI_D0);
Winkler, Tomas450154e2009-01-27 14:27:55 -08005320 ret = pci_enable_device(pdev);
5321 if (ret)
5322 return ret;
Helmut Schaa26635162009-01-15 09:38:44 +01005323 pci_restore_state(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005324
Zhu Yie655b9f2008-01-24 02:19:38 -08005325 if (priv->is_open)
5326 iwl3945_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07005327
Zhu Yie655b9f2008-01-24 02:19:38 -08005328 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07005329 return 0;
5330}
5331
5332#endif /* CONFIG_PM */
5333
5334/*****************************************************************************
5335 *
5336 * driver and module entry point
5337 *
5338 *****************************************************************************/
5339
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005340static struct pci_driver iwl3945_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07005341 .name = DRV_NAME,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005342 .id_table = iwl3945_hw_card_ids,
5343 .probe = iwl3945_pci_probe,
5344 .remove = __devexit_p(iwl3945_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07005345#ifdef CONFIG_PM
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005346 .suspend = iwl3945_pci_suspend,
5347 .resume = iwl3945_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07005348#endif
5349};
5350
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005351static int __init iwl3945_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07005352{
5353
5354 int ret;
5355 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
5356 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005357
5358 ret = iwl3945_rate_control_register();
5359 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005360 printk(KERN_ERR DRV_NAME
5361 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005362 return ret;
5363 }
5364
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005365 ret = pci_register_driver(&iwl3945_driver);
Zhu Yib481de92007-09-25 17:54:57 -07005366 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005367 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005368 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07005369 }
Zhu Yib481de92007-09-25 17:54:57 -07005370
5371 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005372
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005373error_register:
5374 iwl3945_rate_control_unregister();
5375 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07005376}
5377
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005378static void __exit iwl3945_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07005379{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005380 pci_unregister_driver(&iwl3945_driver);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005381 iwl3945_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07005382}
5383
Reinette Chatrea0987a82008-12-02 12:14:06 -08005384MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
Zhu Yi25cb6ca2008-09-11 11:45:22 +08005385
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005386module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005387MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005388module_param_named(disable, iwl3945_mod_params.disable, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005389MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -08005390module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
5391MODULE_PARM_DESC(swcrypto,
5392 "using software crypto (default 1 [software])\n");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005393module_param_named(debug, iwl3945_mod_params.debug, uint, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005394MODULE_PARM_DESC(debug, "debug output mask");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005395module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005396MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
5397
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005398module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005399MODULE_PARM_DESC(queues_num, "number of hw queues.");
5400
Samuel Ortizaf48d042009-01-23 13:45:19 -08005401module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, 0444);
5402MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error");
5403
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005404module_exit(iwl3945_exit);
5405module_init(iwl3945_init);