blob: da020c3568981ad53bd71551e546b564e6ee756f [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Reinette Chatre01f81622009-01-08 10:20:02 -08003 * Copyright(c) 2003 - 2009 Intel Corporation. All rights reserved.
Zhu Yib481de92007-09-25 17:54:57 -07004 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
Winkler, Tomas759ef892008-12-09 11:28:58 -080025 * Intel Linux Wireless <ilw@linux.intel.com>
Zhu Yib481de92007-09-25 17:54:57 -070026 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
Zhu Yib481de92007-09-25 17:54:57 -070030#include <linux/kernel.h>
31#include <linux/module.h>
Zhu Yib481de92007-09-25 17:54:57 -070032#include <linux/init.h>
33#include <linux/pci.h>
34#include <linux/dma-mapping.h>
35#include <linux/delay.h>
36#include <linux/skbuff.h>
37#include <linux/netdevice.h>
38#include <linux/wireless.h>
39#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070040#include <linux/etherdevice.h>
41#include <linux/if_arp.h>
42
43#include <net/ieee80211_radiotap.h>
John W. Linville7e272fc2008-09-24 18:13:14 -040044#include <net/lib80211.h>
Zhu Yib481de92007-09-25 17:54:57 -070045#include <net/mac80211.h>
46
47#include <asm/div64.h>
48
Samuel Ortiza3139c52008-12-19 10:37:09 +080049#define DRV_NAME "iwl3945"
50
Winkler, Tomasdbb66542008-12-22 11:31:14 +080051#include "iwl-fh.h"
52#include "iwl-3945-fh.h"
Tomas Winkler600c0e12008-12-19 10:37:04 +080053#include "iwl-commands.h"
Samuel Ortiz17f841c2009-01-23 13:45:20 -080054#include "iwl-sta.h"
Zhu Yib481de92007-09-25 17:54:57 -070055#include "iwl-3945.h"
56#include "iwl-helpers.h"
Kolekar, Abhijeet5747d472008-12-19 10:37:18 +080057#include "iwl-core.h"
Samuel Ortizd20b3c62008-12-19 10:37:15 +080058#include "iwl-dev.h"
Zhu Yib481de92007-09-25 17:54:57 -070059
Zhu Yib481de92007-09-25 17:54:57 -070060/*
61 * module name, copyright, version, etc.
Zhu Yib481de92007-09-25 17:54:57 -070062 */
63
64#define DRV_DESCRIPTION \
65"Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
66
Samuel Ortizd08853a2009-01-23 13:45:17 -080067#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070068#define VD "d"
69#else
70#define VD
71#endif
72
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080073#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -070074#define VS "s"
75#else
76#define VS
77#endif
78
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080079#define IWL39_VERSION "1.2.26k" VD VS
Reinette Chatre01f81622009-01-08 10:20:02 -080080#define DRV_COPYRIGHT "Copyright(c) 2003-2009 Intel Corporation"
Tomas Winklera7b75202008-12-11 10:33:41 -080081#define DRV_AUTHOR "<ilw@linux.intel.com>"
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080082#define DRV_VERSION IWL39_VERSION
Zhu Yib481de92007-09-25 17:54:57 -070083
Zhu Yib481de92007-09-25 17:54:57 -070084
85MODULE_DESCRIPTION(DRV_DESCRIPTION);
86MODULE_VERSION(DRV_VERSION);
Tomas Winklera7b75202008-12-11 10:33:41 -080087MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
Zhu Yib481de92007-09-25 17:54:57 -070088MODULE_LICENSE("GPL");
89
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080090 /* module parameters */
91struct iwl_mod_params iwl3945_mod_params = {
92 .num_of_queues = IWL39_MAX_NUM_QUEUES,
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -080093 .sw_crypto = 1,
Samuel Ortizaf48d042009-01-23 13:45:19 -080094 .restart_fw = 1,
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080095 /* the rest are 0 by default */
96};
97
Zhu Yib481de92007-09-25 17:54:57 -070098/*************** STATION TABLE MANAGEMENT ****
Ben Cahill9fbab512007-11-29 11:09:47 +080099 * mac80211 should be examined to determine if sta_info is duplicating
Zhu Yib481de92007-09-25 17:54:57 -0700100 * the functionality provided here
101 */
102
103/**************************************************************/
Ian Schram01ebd062007-10-25 17:15:22 +0800104#if 0 /* temporary disable till we add real remove station */
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800105/**
106 * iwl3945_remove_station - Remove driver's knowledge of station.
107 *
108 * NOTE: This does not remove station from device's station table.
109 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800110static u8 iwl3945_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
Zhu Yib481de92007-09-25 17:54:57 -0700111{
112 int index = IWL_INVALID_STATION;
113 int i;
114 unsigned long flags;
115
116 spin_lock_irqsave(&priv->sta_lock, flags);
117
118 if (is_ap)
119 index = IWL_AP_ID;
120 else if (is_broadcast_ether_addr(addr))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800121 index = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700122 else
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800123 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800124 if (priv->stations_39[i].used &&
125 !compare_ether_addr(priv->stations_39[i].sta.sta.addr,
Zhu Yib481de92007-09-25 17:54:57 -0700126 addr)) {
127 index = i;
128 break;
129 }
130
131 if (unlikely(index == IWL_INVALID_STATION))
132 goto out;
133
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800134 if (priv->stations_39[index].used) {
135 priv->stations_39[index].used = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700136 priv->num_stations--;
137 }
138
139 BUG_ON(priv->num_stations < 0);
140
141out:
142 spin_unlock_irqrestore(&priv->sta_lock, flags);
143 return 0;
144}
Zhu Yi556f8db2007-09-27 11:27:33 +0800145#endif
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800146
147/**
148 * iwl3945_clear_stations_table - Clear the driver's station table
149 *
150 * NOTE: This does not clear or otherwise alter the device's station table.
151 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800152static void iwl3945_clear_stations_table(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700153{
154 unsigned long flags;
155
156 spin_lock_irqsave(&priv->sta_lock, flags);
157
158 priv->num_stations = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800159 memset(priv->stations_39, 0, sizeof(priv->stations_39));
Zhu Yib481de92007-09-25 17:54:57 -0700160
161 spin_unlock_irqrestore(&priv->sta_lock, flags);
162}
163
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800164/**
165 * iwl3945_add_station - Add station to station tables in driver and device
166 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800167u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags)
Zhu Yib481de92007-09-25 17:54:57 -0700168{
169 int i;
170 int index = IWL_INVALID_STATION;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800171 struct iwl3945_station_entry *station;
Zhu Yib481de92007-09-25 17:54:57 -0700172 unsigned long flags_spin;
Zhu Yic14c5212007-09-27 11:27:35 +0800173 u8 rate;
Zhu Yib481de92007-09-25 17:54:57 -0700174
175 spin_lock_irqsave(&priv->sta_lock, flags_spin);
176 if (is_ap)
177 index = IWL_AP_ID;
178 else if (is_broadcast_ether_addr(addr))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800179 index = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700180 else
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800181 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800182 if (!compare_ether_addr(priv->stations_39[i].sta.sta.addr,
Zhu Yib481de92007-09-25 17:54:57 -0700183 addr)) {
184 index = i;
185 break;
186 }
187
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800188 if (!priv->stations_39[i].used &&
Zhu Yib481de92007-09-25 17:54:57 -0700189 index == IWL_INVALID_STATION)
190 index = i;
191 }
192
Ian Schram01ebd062007-10-25 17:15:22 +0800193 /* These two conditions has the same outcome but keep them separate
Zhu Yib481de92007-09-25 17:54:57 -0700194 since they have different meaning */
195 if (unlikely(index == IWL_INVALID_STATION)) {
196 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
197 return index;
198 }
199
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800200 if (priv->stations_39[index].used &&
201 !compare_ether_addr(priv->stations_39[index].sta.sta.addr, addr)) {
Zhu Yib481de92007-09-25 17:54:57 -0700202 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
203 return index;
204 }
205
Tomas Winklere1623442009-01-27 14:27:56 -0800206 IWL_DEBUG_ASSOC(priv, "Add STA ID %d: %pM\n", index, addr);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800207 station = &priv->stations_39[index];
Zhu Yib481de92007-09-25 17:54:57 -0700208 station->used = 1;
209 priv->num_stations++;
210
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800211 /* Set up the REPLY_ADD_STA command to send to device */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800212 memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd));
Zhu Yib481de92007-09-25 17:54:57 -0700213 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
214 station->sta.mode = 0;
215 station->sta.sta.sta_id = index;
216 station->sta.station_flags = 0;
217
Johannes Berg8318d782008-01-24 19:38:38 +0100218 if (priv->band == IEEE80211_BAND_5GHZ)
Tomas Winkler69946332007-10-25 17:15:27 +0800219 rate = IWL_RATE_6M_PLCP;
220 else
221 rate = IWL_RATE_1M_PLCP;
Zhu Yic14c5212007-09-27 11:27:35 +0800222
223 /* Turn on both antennas for the station... */
224 station->sta.rate_n_flags =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800225 iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK);
Zhu Yic14c5212007-09-27 11:27:35 +0800226
Zhu Yib481de92007-09-25 17:54:57 -0700227 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800228
229 /* Add station to device's station table */
Samuel Ortiz17f841c2009-01-23 13:45:20 -0800230 iwl_send_add_sta(priv,
231 (struct iwl_addsta_cmd *)&station->sta, flags);
Zhu Yib481de92007-09-25 17:54:57 -0700232 return index;
233
234}
235
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800236static int iwl3945_send_rxon_assoc(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700237{
238 int rc = 0;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800239 struct iwl_rx_packet *res = NULL;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800240 struct iwl3945_rxon_assoc_cmd rxon_assoc;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800241 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700242 .id = REPLY_RXON_ASSOC,
243 .len = sizeof(rxon_assoc),
244 .meta.flags = CMD_WANT_SKB,
245 .data = &rxon_assoc,
246 };
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800247 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
248 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
Zhu Yib481de92007-09-25 17:54:57 -0700249
250 if ((rxon1->flags == rxon2->flags) &&
251 (rxon1->filter_flags == rxon2->filter_flags) &&
252 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
253 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800254 IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700255 return 0;
256 }
257
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800258 rxon_assoc.flags = priv->staging_rxon.flags;
259 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
260 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
261 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
Zhu Yib481de92007-09-25 17:54:57 -0700262 rxon_assoc.reserved = 0;
263
Samuel Ortiz518099a2009-01-19 15:30:27 -0800264 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700265 if (rc)
266 return rc;
267
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800268 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700269 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800270 IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -0700271 rc = -EIO;
272 }
273
274 priv->alloc_rxb_skb--;
275 dev_kfree_skb_any(cmd.meta.u.skb);
276
277 return rc;
278}
279
280/**
Samuel Ortiz7e4bca52009-01-23 13:45:18 -0800281 * iwl3945_get_antenna_flags - Get antenna flags for RXON command
282 * @priv: eeprom and antenna fields are used to determine antenna flags
283 *
284 * priv->eeprom39 is used to determine if antenna AUX/MAIN are reversed
285 * iwl3945_mod_params.antenna specifies the antenna diversity mode:
286 *
287 * IWL_ANTENNA_DIVERSITY - NIC selects best antenna by itself
288 * IWL_ANTENNA_MAIN - Force MAIN antenna
289 * IWL_ANTENNA_AUX - Force AUX antenna
290 */
291__le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv)
292{
293 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
294
295 switch (iwl3945_mod_params.antenna) {
296 case IWL_ANTENNA_DIVERSITY:
297 return 0;
298
299 case IWL_ANTENNA_MAIN:
300 if (eeprom->antenna_switch_type)
301 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
302 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
303
304 case IWL_ANTENNA_AUX:
305 if (eeprom->antenna_switch_type)
306 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
307 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
308 }
309
310 /* bad antenna selector value */
311 IWL_ERR(priv, "Bad antenna selector value (0x%x)\n",
312 iwl3945_mod_params.antenna);
313
314 return 0; /* "diversity" is default if error */
315}
316
317/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800318 * iwl3945_commit_rxon - commit staging_rxon to hardware
Zhu Yib481de92007-09-25 17:54:57 -0700319 *
Ian Schram01ebd062007-10-25 17:15:22 +0800320 * The RXON command in staging_rxon is committed to the hardware and
Zhu Yib481de92007-09-25 17:54:57 -0700321 * the active_rxon structure is updated with the new data. This
322 * function correctly transitions out of the RXON_ASSOC_MSK state if
323 * a HW tune is required based on the RXON structure changes.
324 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800325static int iwl3945_commit_rxon(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700326{
327 /* cast away the const for active_rxon in this function */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800328 struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
329 struct iwl3945_rxon_cmd *staging_rxon = (void *)&priv->staging_rxon;
Zhu Yib481de92007-09-25 17:54:57 -0700330 int rc = 0;
331
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800332 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700333 return -1;
334
335 /* always get timestamp with Rx frame */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800336 staging_rxon->flags |= RXON_FLG_TSF2HOST_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700337
338 /* select antenna */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800339 staging_rxon->flags &=
Zhu Yib481de92007-09-25 17:54:57 -0700340 ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800341 staging_rxon->flags |= iwl3945_get_antenna_flags(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700342
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800343 rc = iwl_check_rxon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700344 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800345 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700346 return -EINVAL;
347 }
348
349 /* If we don't need to send a full RXON, we can use
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800350 * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -0700351 * and other flags for the current radio configuration. */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800352 if (!iwl_full_rxon_required(priv)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800353 rc = iwl3945_send_rxon_assoc(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700354 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800355 IWL_ERR(priv, "Error setting RXON_ASSOC "
Zhu Yib481de92007-09-25 17:54:57 -0700356 "configuration (%d).\n", rc);
357 return rc;
358 }
359
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800360 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700361
362 return 0;
363 }
364
365 /* If we are currently associated and the new config requires
366 * an RXON_ASSOC and the new config wants the associated mask enabled,
367 * we must clear the associated from the active configuration
368 * before we apply the new config */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800369 if (iwl_is_associated(priv) &&
370 (staging_rxon->filter_flags & RXON_FILTER_ASSOC_MSK)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800371 IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
Zhu Yib481de92007-09-25 17:54:57 -0700372 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
373
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800374 /*
375 * reserved4 and 5 could have been filled by the iwlcore code.
376 * Let's clear them before pushing to the 3945.
377 */
378 active_rxon->reserved4 = 0;
379 active_rxon->reserved5 = 0;
Samuel Ortiz518099a2009-01-19 15:30:27 -0800380 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800381 sizeof(struct iwl3945_rxon_cmd),
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800382 &priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -0700383
384 /* If the mask clearing failed then we set
385 * active_rxon back to what it was previously */
386 if (rc) {
387 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
Winkler, Tomas15b16872008-12-19 10:37:33 +0800388 IWL_ERR(priv, "Error clearing ASSOC_MSK on current "
Zhu Yib481de92007-09-25 17:54:57 -0700389 "configuration (%d).\n", rc);
390 return rc;
391 }
Zhu Yib481de92007-09-25 17:54:57 -0700392 }
393
Tomas Winklere1623442009-01-27 14:27:56 -0800394 IWL_DEBUG_INFO(priv, "Sending RXON\n"
Zhu Yib481de92007-09-25 17:54:57 -0700395 "* with%s RXON_FILTER_ASSOC_MSK\n"
396 "* channel = %d\n"
Johannes Berge1749612008-10-27 15:59:26 -0700397 "* bssid = %pM\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800398 ((priv->staging_rxon.filter_flags &
Zhu Yib481de92007-09-25 17:54:57 -0700399 RXON_FILTER_ASSOC_MSK) ? "" : "out"),
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800400 le16_to_cpu(staging_rxon->channel),
401 staging_rxon->bssid_addr);
402
403 /*
404 * reserved4 and 5 could have been filled by the iwlcore code.
405 * Let's clear them before pushing to the 3945.
406 */
407 staging_rxon->reserved4 = 0;
408 staging_rxon->reserved5 = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700409
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
488 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
489 == STA_KEY_FLG_NO_ENC)
490 priv->stations[sta_id].sta.key.key_offset =
491 iwl_get_free_ucode_key_index(priv);
492 /* else, we are overriding an existing key => no need to allocated room
493 * in uCode. */
494
495 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
496 "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 Kolekar6e21f152009-02-27 16:21:21 -0800545int iwl3945_set_dynamic_key(struct iwl_priv *priv,
546 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:
563 IWL_ERR(priv,"Unknown alg: %s alg = %d\n", __func__, keyconf->alg);
564 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/*
693 * QoS support
694*/
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800695static int iwl3945_send_qos_params_command(struct iwl_priv *priv,
Tomas Winkler4c897252008-12-19 10:37:05 +0800696 struct iwl_qosparam_cmd *qos)
Zhu Yib481de92007-09-25 17:54:57 -0700697{
698
Samuel Ortiz518099a2009-01-19 15:30:27 -0800699 return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM,
Tomas Winkler4c897252008-12-19 10:37:05 +0800700 sizeof(struct iwl_qosparam_cmd), qos);
Zhu Yib481de92007-09-25 17:54:57 -0700701}
702
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800703static void iwl3945_activate_qos(struct iwl_priv *priv, u8 force)
Zhu Yib481de92007-09-25 17:54:57 -0700704{
705 unsigned long flags;
706
Zhu Yib481de92007-09-25 17:54:57 -0700707 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
708 return;
709
Zhu Yib481de92007-09-25 17:54:57 -0700710 spin_lock_irqsave(&priv->lock, flags);
711 priv->qos_data.def_qos_parm.qos_flags = 0;
712
713 if (priv->qos_data.qos_cap.q_AP.queue_request &&
714 !priv->qos_data.qos_cap.q_AP.txop_request)
715 priv->qos_data.def_qos_parm.qos_flags |=
716 QOS_PARAM_FLG_TXOP_TYPE_MSK;
717
718 if (priv->qos_data.qos_active)
719 priv->qos_data.def_qos_parm.qos_flags |=
720 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
721
722 spin_unlock_irqrestore(&priv->lock, flags);
723
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800724 if (force || iwl_is_associated(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800725 IWL_DEBUG_QOS(priv, "send QoS cmd with QoS active %d \n",
Zhu Yib481de92007-09-25 17:54:57 -0700726 priv->qos_data.qos_active);
727
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800728 iwl3945_send_qos_params_command(priv,
Zhu Yib481de92007-09-25 17:54:57 -0700729 &(priv->qos_data.def_qos_parm));
730 }
731}
732
Zhu Yib481de92007-09-25 17:54:57 -0700733
Zhu Yib481de92007-09-25 17:54:57 -0700734#define MAX_UCODE_BEACON_INTERVAL 1024
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -0800735#define INTEL_CONN_LISTEN_INTERVAL cpu_to_le16(0xA)
Zhu Yib481de92007-09-25 17:54:57 -0700736
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800737static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -0700738{
739 u16 new_val = 0;
740 u16 beacon_factor = 0;
741
742 beacon_factor =
743 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
744 / MAX_UCODE_BEACON_INTERVAL;
745 new_val = beacon_val / beacon_factor;
746
747 return cpu_to_le16(new_val);
748}
749
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800750static void iwl3945_setup_rxon_timing(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700751{
752 u64 interval_tm_unit;
753 u64 tsf, result;
754 unsigned long flags;
755 struct ieee80211_conf *conf = NULL;
756 u16 beacon_int = 0;
757
758 conf = ieee80211_get_hw_conf(priv->hw);
759
760 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler28afaf92008-12-19 10:37:06 +0800761 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
Zhu Yib481de92007-09-25 17:54:57 -0700762 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
763
Tomas Winkler28afaf92008-12-19 10:37:06 +0800764 tsf = priv->timestamp;
Zhu Yib481de92007-09-25 17:54:57 -0700765
766 beacon_int = priv->beacon_int;
767 spin_unlock_irqrestore(&priv->lock, flags);
768
Johannes Berg05c914f2008-09-11 00:01:58 +0200769 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Zhu Yib481de92007-09-25 17:54:57 -0700770 if (beacon_int == 0) {
771 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
772 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
773 } else {
774 priv->rxon_timing.beacon_interval =
775 cpu_to_le16(beacon_int);
776 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800777 iwl3945_adjust_beacon_interval(
Zhu Yib481de92007-09-25 17:54:57 -0700778 le16_to_cpu(priv->rxon_timing.beacon_interval));
779 }
780
781 priv->rxon_timing.atim_window = 0;
782 } else {
783 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800784 iwl3945_adjust_beacon_interval(conf->beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -0700785 /* TODO: we need to get atim_window from upper stack
786 * for now we set to 0 */
787 priv->rxon_timing.atim_window = 0;
788 }
789
790 interval_tm_unit =
791 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
792 result = do_div(tsf, interval_tm_unit);
793 priv->rxon_timing.beacon_init_val =
794 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
795
Tomas Winklere1623442009-01-27 14:27:56 -0800796 IWL_DEBUG_ASSOC(priv,
797 "beacon interval %d beacon timer %d beacon tim %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700798 le16_to_cpu(priv->rxon_timing.beacon_interval),
799 le32_to_cpu(priv->rxon_timing.beacon_init_val),
800 le16_to_cpu(priv->rxon_timing.atim_window));
801}
802
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800803static int iwl3945_set_mode(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -0700804{
Johannes Berg05c914f2008-09-11 00:01:58 +0200805 if (mode == NL80211_IFTYPE_ADHOC) {
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800806 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -0700807
Samuel Ortize6148912009-01-23 13:45:15 -0800808 ch_info = iwl_get_channel_info(priv,
Johannes Berg8318d782008-01-24 19:38:38 +0100809 priv->band,
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800810 le16_to_cpu(priv->staging_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700811
812 if (!ch_info || !is_channel_ibss(ch_info)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800813 IWL_ERR(priv, "channel %d not IBSS channel\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800814 le16_to_cpu(priv->staging_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700815 return -EINVAL;
816 }
817 }
818
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800819 iwl_connection_init_rx_config(priv, mode);
Zhu Yib481de92007-09-25 17:54:57 -0700820
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800821 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700822
Tomas Winklera96a27f2008-10-23 23:48:56 -0700823 /* don't commit rxon if rf-kill is on*/
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800824 if (!iwl_is_ready_rf(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +0800825 return -EAGAIN;
826
827 cancel_delayed_work(&priv->scan_check);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -0800828 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800829 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
Tomas Winklere1623442009-01-27 14:27:56 -0800830 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +0800831 return -EAGAIN;
832 }
833
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800834 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700835
836 return 0;
837}
838
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800839static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
Johannes Berge039fa42008-05-15 12:55:29 +0200840 struct ieee80211_tx_info *info,
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800841 struct iwl_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -0700842 struct sk_buff *skb_frag,
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800843 int sta_id)
Zhu Yib481de92007-09-25 17:54:57 -0700844{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800845 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
Ivo van Doorn1c014422008-04-17 19:41:02 +0200846 struct iwl3945_hw_key *keyinfo =
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800847 &priv->stations_39[sta_id].keyinfo;
Zhu Yib481de92007-09-25 17:54:57 -0700848
849 switch (keyinfo->alg) {
850 case ALG_CCMP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800851 tx->sec_ctl = TX_CMD_SEC_CCM;
852 memcpy(tx->key, keyinfo->key, keyinfo->keylen);
Tomas Winklere1623442009-01-27 14:27:56 -0800853 IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
Zhu Yib481de92007-09-25 17:54:57 -0700854 break;
855
856 case ALG_TKIP:
Zhu Yib481de92007-09-25 17:54:57 -0700857 break;
858
859 case ALG_WEP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800860 tx->sec_ctl = TX_CMD_SEC_WEP |
Johannes Berge039fa42008-05-15 12:55:29 +0200861 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
Zhu Yib481de92007-09-25 17:54:57 -0700862
863 if (keyinfo->keylen == 13)
Winkler, Tomase52119c2008-12-22 11:31:19 +0800864 tx->sec_ctl |= TX_CMD_SEC_KEY128;
Zhu Yib481de92007-09-25 17:54:57 -0700865
Winkler, Tomase52119c2008-12-22 11:31:19 +0800866 memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen);
Zhu Yib481de92007-09-25 17:54:57 -0700867
Tomas Winklere1623442009-01-27 14:27:56 -0800868 IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
Johannes Berge039fa42008-05-15 12:55:29 +0200869 "with key %d\n", info->control.hw_key->hw_key_idx);
Zhu Yib481de92007-09-25 17:54:57 -0700870 break;
871
Zhu Yib481de92007-09-25 17:54:57 -0700872 default:
Tomas Winkler978785a2008-12-19 10:37:31 +0800873 IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg);
Zhu Yib481de92007-09-25 17:54:57 -0700874 break;
875 }
876}
877
878/*
879 * handle build REPLY_TX command notification.
880 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800881static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800882 struct iwl_cmd *cmd,
Johannes Berge039fa42008-05-15 12:55:29 +0200883 struct ieee80211_tx_info *info,
Winkler, Tomase52119c2008-12-22 11:31:19 +0800884 struct ieee80211_hdr *hdr, u8 std_id)
Zhu Yib481de92007-09-25 17:54:57 -0700885{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800886 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
887 __le32 tx_flags = tx->tx_flags;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700888 __le16 fc = hdr->frame_control;
Johannes Berge6a98542008-10-21 12:40:02 +0200889 u8 rc_flags = info->control.rates[0].flags;
Zhu Yib481de92007-09-25 17:54:57 -0700890
Winkler, Tomase52119c2008-12-22 11:31:19 +0800891 tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Johannes Berge039fa42008-05-15 12:55:29 +0200892 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
Zhu Yib481de92007-09-25 17:54:57 -0700893 tx_flags |= TX_CMD_FLG_ACK_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700894 if (ieee80211_is_mgmt(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700895 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700896 if (ieee80211_is_probe_resp(fc) &&
Zhu Yib481de92007-09-25 17:54:57 -0700897 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
898 tx_flags |= TX_CMD_FLG_TSF_MSK;
899 } else {
900 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
901 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
902 }
903
Winkler, Tomase52119c2008-12-22 11:31:19 +0800904 tx->sta_id = std_id;
Harvey Harrison8b7b1e02008-06-11 14:21:56 -0700905 if (ieee80211_has_morefrags(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700906 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
907
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700908 if (ieee80211_is_data_qos(fc)) {
909 u8 *qc = ieee80211_get_qos_ctl(hdr);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800910 tx->tid_tspec = qc[0] & 0xf;
Zhu Yib481de92007-09-25 17:54:57 -0700911 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800912 } else {
Zhu Yib481de92007-09-25 17:54:57 -0700913 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800914 }
Zhu Yib481de92007-09-25 17:54:57 -0700915
Johannes Berge6a98542008-10-21 12:40:02 +0200916 if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
Zhu Yib481de92007-09-25 17:54:57 -0700917 tx_flags |= TX_CMD_FLG_RTS_MSK;
918 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
Johannes Berge6a98542008-10-21 12:40:02 +0200919 } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
Zhu Yib481de92007-09-25 17:54:57 -0700920 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
921 tx_flags |= TX_CMD_FLG_CTS_MSK;
922 }
923
924 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
925 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
926
927 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700928 if (ieee80211_is_mgmt(fc)) {
929 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
Winkler, Tomase52119c2008-12-22 11:31:19 +0800930 tx->timeout.pm_frame_timeout = cpu_to_le16(3);
Zhu Yib481de92007-09-25 17:54:57 -0700931 else
Winkler, Tomase52119c2008-12-22 11:31:19 +0800932 tx->timeout.pm_frame_timeout = cpu_to_le16(2);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700933 } else {
Winkler, Tomase52119c2008-12-22 11:31:19 +0800934 tx->timeout.pm_frame_timeout = 0;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700935#ifdef CONFIG_IWL3945_LEDS
936 priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
937#endif
938 }
Zhu Yib481de92007-09-25 17:54:57 -0700939
Winkler, Tomase52119c2008-12-22 11:31:19 +0800940 tx->driver_txop = 0;
941 tx->tx_flags = tx_flags;
942 tx->next_frame_len = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700943}
944
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800945/**
946 * iwl3945_get_sta_id - Find station's index within station table
947 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800948static int iwl3945_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
Zhu Yib481de92007-09-25 17:54:57 -0700949{
950 int sta_id;
951 u16 fc = le16_to_cpu(hdr->frame_control);
952
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800953 /* If this frame is broadcast or management, use broadcast station id */
Zhu Yib481de92007-09-25 17:54:57 -0700954 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
955 is_multicast_ether_addr(hdr->addr1))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800956 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700957
958 switch (priv->iw_mode) {
959
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800960 /* If we are a client station in a BSS network, use the special
961 * AP station entry (that's the only station we communicate with) */
Johannes Berg05c914f2008-09-11 00:01:58 +0200962 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -0700963 return IWL_AP_ID;
964
965 /* If we are an AP, then find the station, or use BCAST */
Johannes Berg05c914f2008-09-11 00:01:58 +0200966 case NL80211_IFTYPE_AP:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800967 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700968 if (sta_id != IWL_INVALID_STATION)
969 return sta_id;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800970 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700971
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800972 /* If this frame is going out to an IBSS network, find the station,
973 * or create a new station table entry */
Johannes Berg05c914f2008-09-11 00:01:58 +0200974 case NL80211_IFTYPE_ADHOC: {
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800975 /* Create new station table entry */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800976 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700977 if (sta_id != IWL_INVALID_STATION)
978 return sta_id;
979
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800980 sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
Zhu Yib481de92007-09-25 17:54:57 -0700981
982 if (sta_id != IWL_INVALID_STATION)
983 return sta_id;
984
Tomas Winklere1623442009-01-27 14:27:56 -0800985 IWL_DEBUG_DROP(priv, "Station %pM not in station map. "
Zhu Yib481de92007-09-25 17:54:57 -0700986 "Defaulting to broadcast...\n",
Johannes Berge1749612008-10-27 15:59:26 -0700987 hdr->addr1);
Samuel Ortiz40b8ec02008-12-19 10:37:08 +0800988 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800989 return priv->hw_params.bcast_sta_id;
Joe Perches0795af52007-10-03 17:59:30 -0700990 }
Stefanik Gábor914233d2008-06-30 17:23:30 +0800991 /* If we are in monitor mode, use BCAST. This is required for
992 * packet injection. */
Johannes Berg05c914f2008-09-11 00:01:58 +0200993 case NL80211_IFTYPE_MONITOR:
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800994 return priv->hw_params.bcast_sta_id;
Stefanik Gábor914233d2008-06-30 17:23:30 +0800995
Zhu Yib481de92007-09-25 17:54:57 -0700996 default:
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800997 IWL_WARN(priv, "Unknown mode of operation: %d\n",
998 priv->iw_mode);
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800999 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07001000 }
1001}
1002
1003/*
1004 * start REPLY_TX command process
1005 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001006static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07001007{
1008 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berge039fa42008-05-15 12:55:29 +02001009 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Winkler, Tomase52119c2008-12-22 11:31:19 +08001010 struct iwl3945_tx_cmd *tx;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001011 struct iwl_tx_queue *txq = NULL;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001012 struct iwl_queue *q = NULL;
Winkler, Tomase52119c2008-12-22 11:31:19 +08001013 struct iwl_cmd *out_cmd = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07001014 dma_addr_t phys_addr;
1015 dma_addr_t txcmd_phys;
Winkler, Tomase52119c2008-12-22 11:31:19 +08001016 int txq_id = skb_get_queue_mapping(skb);
Tomas Winkler54dbb522008-05-15 13:54:06 +08001017 u16 len, idx, len_org, hdr_len;
1018 u8 id;
1019 u8 unicast;
Zhu Yib481de92007-09-25 17:54:57 -07001020 u8 sta_id;
Tomas Winkler54dbb522008-05-15 13:54:06 +08001021 u8 tid = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001022 u16 seq_number = 0;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001023 __le16 fc;
Zhu Yib481de92007-09-25 17:54:57 -07001024 u8 wait_write_ptr = 0;
Tomas Winkler54dbb522008-05-15 13:54:06 +08001025 u8 *qc = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07001026 unsigned long flags;
1027 int rc;
1028
1029 spin_lock_irqsave(&priv->lock, flags);
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08001030 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08001031 IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
Zhu Yib481de92007-09-25 17:54:57 -07001032 goto drop_unlock;
1033 }
1034
Johannes Berge039fa42008-05-15 12:55:29 +02001035 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001036 IWL_ERR(priv, "ERROR: No TX rate available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001037 goto drop_unlock;
1038 }
1039
1040 unicast = !is_multicast_ether_addr(hdr->addr1);
1041 id = 0;
1042
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001043 fc = hdr->frame_control;
Zhu Yib481de92007-09-25 17:54:57 -07001044
Samuel Ortizd08853a2009-01-23 13:45:17 -08001045#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001046 if (ieee80211_is_auth(fc))
Tomas Winklere1623442009-01-27 14:27:56 -08001047 IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001048 else if (ieee80211_is_assoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -08001049 IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001050 else if (ieee80211_is_reassoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -08001051 IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
Zhu Yib481de92007-09-25 17:54:57 -07001052#endif
1053
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08001054 /* drop all data frame if we are not associated */
Stefanik Gábor914233d2008-06-30 17:23:30 +08001055 if (ieee80211_is_data(fc) &&
Johannes Berg05c914f2008-09-11 00:01:58 +02001056 (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001057 (!iwl_is_associated(priv) ||
Johannes Berg05c914f2008-09-11 00:01:58 +02001058 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
Tomas Winklere1623442009-01-27 14:27:56 -08001059 IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n");
Zhu Yib481de92007-09-25 17:54:57 -07001060 goto drop_unlock;
1061 }
1062
1063 spin_unlock_irqrestore(&priv->lock, flags);
1064
Harvey Harrison7294ec92008-07-15 18:43:59 -07001065 hdr_len = ieee80211_hdrlen(fc);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001066
1067 /* Find (or create) index into station table for destination station */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001068 sta_id = iwl3945_get_sta_id(priv, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07001069 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -08001070 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07001071 hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07001072 goto drop;
1073 }
1074
Tomas Winklere1623442009-01-27 14:27:56 -08001075 IWL_DEBUG_RATE(priv, "station Id %d\n", sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07001076
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001077 if (ieee80211_is_data_qos(fc)) {
1078 qc = ieee80211_get_qos_ctl(hdr);
Harvey Harrison7294ec92008-07-15 18:43:59 -07001079 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001080 seq_number = priv->stations_39[sta_id].tid[tid].seq_number &
Zhu Yib481de92007-09-25 17:54:57 -07001081 IEEE80211_SCTL_SEQ;
1082 hdr->seq_ctrl = cpu_to_le16(seq_number) |
1083 (hdr->seq_ctrl &
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -08001084 cpu_to_le16(IEEE80211_SCTL_FRAG));
Zhu Yib481de92007-09-25 17:54:57 -07001085 seq_number += 0x10;
1086 }
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001087
1088 /* Descriptor for chosen Tx queue */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001089 txq = &priv->txq[txq_id];
Zhu Yib481de92007-09-25 17:54:57 -07001090 q = &txq->q;
1091
1092 spin_lock_irqsave(&priv->lock, flags);
1093
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001094 idx = get_cmd_index(q, q->write_ptr, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001095
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001096 /* Set up driver data for this TFD */
Winkler, Tomasdbb66542008-12-22 11:31:14 +08001097 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001098 txq->txb[q->write_ptr].skb[0] = skb;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001099
1100 /* Init first empty entry in queue's array of Tx/cmd buffers */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001101 out_cmd = txq->cmd[idx];
Winkler, Tomase52119c2008-12-22 11:31:19 +08001102 tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
Zhu Yib481de92007-09-25 17:54:57 -07001103 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
Winkler, Tomase52119c2008-12-22 11:31:19 +08001104 memset(tx, 0, sizeof(*tx));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001105
1106 /*
1107 * Set up the Tx-command (not MAC!) header.
1108 * Store the chosen Tx queue and TFD index within the sequence field;
1109 * after Tx, uCode's Tx response will return this value so driver can
1110 * locate the frame within the tx queue and do post-tx processing.
1111 */
Zhu Yib481de92007-09-25 17:54:57 -07001112 out_cmd->hdr.cmd = REPLY_TX;
1113 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001114 INDEX_TO_SEQ(q->write_ptr)));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001115
1116 /* Copy MAC header from skb into command buffer */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001117 memcpy(tx->hdr, hdr, hdr_len);
Zhu Yib481de92007-09-25 17:54:57 -07001118
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001119 /*
1120 * Use the first empty entry in this queue's command buffer array
1121 * to contain the Tx command and MAC header concatenated together
1122 * (payload data will be in another buffer).
1123 * Size of this varies, due to varying MAC header length.
1124 * If end is not dword aligned, we'll have 2 extra bytes at the end
1125 * of the MAC header (device reads on dword boundaries).
1126 * We'll tell device about this padding later.
1127 */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001128 len = sizeof(struct iwl3945_tx_cmd) +
Tomas Winkler4c897252008-12-19 10:37:05 +08001129 sizeof(struct iwl_cmd_header) + hdr_len;
Zhu Yib481de92007-09-25 17:54:57 -07001130
1131 len_org = len;
1132 len = (len + 3) & ~3;
1133
1134 if (len_org != len)
1135 len_org = 1;
1136 else
1137 len_org = 0;
1138
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001139 /* Physical address of this Tx command's header (not MAC header!),
1140 * within command buffer array. */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001141 txcmd_phys = pci_map_single(priv->pci_dev,
1142 out_cmd, sizeof(struct iwl_cmd),
1143 PCI_DMA_TODEVICE);
1144 pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys);
1145 pci_unmap_len_set(&out_cmd->meta, len, sizeof(struct iwl_cmd));
1146 /* Add buffer containing Tx command and MAC(!) header to TFD's
1147 * first entry */
1148 txcmd_phys += offsetof(struct iwl_cmd, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07001149
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001150 /* Add buffer containing Tx command and MAC(!) header to TFD's
1151 * first entry */
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001152 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1153 txcmd_phys, len, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001154
Johannes Bergd0f09802008-07-29 11:32:07 +02001155 if (info->control.hw_key)
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08001156 iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07001157
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001158 /* Set up TFD's 2nd entry to point directly to remainder of skb,
1159 * if any (802.11 null frames have no payload). */
Zhu Yib481de92007-09-25 17:54:57 -07001160 len = skb->len - hdr_len;
1161 if (len) {
1162 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
1163 len, PCI_DMA_TODEVICE);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001164 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1165 phys_addr, len,
1166 0, U32_PAD(len));
Zhu Yib481de92007-09-25 17:54:57 -07001167 }
1168
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001169 /* Total # bytes to be transmitted */
Zhu Yib481de92007-09-25 17:54:57 -07001170 len = (u16)skb->len;
Winkler, Tomase52119c2008-12-22 11:31:19 +08001171 tx->len = cpu_to_le16(len);
Zhu Yib481de92007-09-25 17:54:57 -07001172
1173 /* TODO need this for burst mode later on */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001174 iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07001175
1176 /* set is_hcca to 0; it probably will never be implemented */
Johannes Berge039fa42008-05-15 12:55:29 +02001177 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001178
Winkler, Tomase52119c2008-12-22 11:31:19 +08001179 tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
1180 tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001181
Harvey Harrison8b7b1e02008-06-11 14:21:56 -07001182 if (!ieee80211_has_morefrags(hdr->frame_control)) {
Zhu Yib481de92007-09-25 17:54:57 -07001183 txq->need_update = 1;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001184 if (qc)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001185 priv->stations_39[sta_id].tid[tid].seq_number = seq_number;
Zhu Yib481de92007-09-25 17:54:57 -07001186 } else {
1187 wait_write_ptr = 1;
1188 txq->need_update = 0;
1189 }
1190
Winkler, Tomase52119c2008-12-22 11:31:19 +08001191 iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx));
Zhu Yib481de92007-09-25 17:54:57 -07001192
Winkler, Tomase52119c2008-12-22 11:31:19 +08001193 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr,
Harvey Harrison7294ec92008-07-15 18:43:59 -07001194 ieee80211_hdrlen(fc));
Zhu Yib481de92007-09-25 17:54:57 -07001195
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001196 /* Tell device the write index *just past* this latest filled TFD */
Tomas Winklerc54b6792008-03-06 17:36:53 -08001197 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001198 rc = iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001199 spin_unlock_irqrestore(&priv->lock, flags);
1200
1201 if (rc)
1202 return rc;
1203
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001204 if ((iwl_queue_space(q) < q->high_mark)
Zhu Yib481de92007-09-25 17:54:57 -07001205 && priv->mac80211_registered) {
1206 if (wait_write_ptr) {
1207 spin_lock_irqsave(&priv->lock, flags);
1208 txq->need_update = 1;
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001209 iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001210 spin_unlock_irqrestore(&priv->lock, flags);
1211 }
1212
Johannes Berge2530082008-05-17 00:57:14 +02001213 ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb));
Zhu Yib481de92007-09-25 17:54:57 -07001214 }
1215
1216 return 0;
1217
1218drop_unlock:
1219 spin_unlock_irqrestore(&priv->lock, flags);
1220drop:
1221 return -1;
1222}
1223
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001224#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07001225
1226#include "iwl-spectrum.h"
1227
1228#define BEACON_TIME_MASK_LOW 0x00FFFFFF
1229#define BEACON_TIME_MASK_HIGH 0xFF000000
1230#define TIME_UNIT 1024
1231
1232/*
1233 * extended beacon time format
1234 * time in usec will be changed into a 32-bit value in 8:24 format
1235 * the high 1 byte is the beacon counts
1236 * the lower 3 bytes is the time in usec within one beacon interval
1237 */
1238
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001239static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001240{
1241 u32 quot;
1242 u32 rem;
1243 u32 interval = beacon_interval * 1024;
1244
1245 if (!interval || !usec)
1246 return 0;
1247
1248 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
1249 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
1250
1251 return (quot << 24) + rem;
1252}
1253
1254/* base is usually what we get from ucode with each received frame,
1255 * the same as HW timer counter counting down
1256 */
1257
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001258static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001259{
1260 u32 base_low = base & BEACON_TIME_MASK_LOW;
1261 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
1262 u32 interval = beacon_interval * TIME_UNIT;
1263 u32 res = (base & BEACON_TIME_MASK_HIGH) +
1264 (addon & BEACON_TIME_MASK_HIGH);
1265
1266 if (base_low > addon_low)
1267 res += base_low - addon_low;
1268 else if (base_low < addon_low) {
1269 res += interval + base_low - addon_low;
1270 res += (1 << 24);
1271 } else
1272 res += (1 << 24);
1273
1274 return cpu_to_le32(res);
1275}
1276
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001277static int iwl3945_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001278 struct ieee80211_measurement_params *params,
1279 u8 type)
1280{
Tomas Winkler600c0e12008-12-19 10:37:04 +08001281 struct iwl_spectrum_cmd spectrum;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001282 struct iwl_rx_packet *res;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08001283 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001284 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
1285 .data = (void *)&spectrum,
1286 .meta.flags = CMD_WANT_SKB,
1287 };
1288 u32 add_time = le64_to_cpu(params->start_time);
1289 int rc;
1290 int spectrum_resp_status;
1291 int duration = le16_to_cpu(params->duration);
1292
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001293 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001294 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001295 iwl3945_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -07001296 le64_to_cpu(params->start_time) - priv->last_tsf,
1297 le16_to_cpu(priv->rxon_timing.beacon_interval));
1298
1299 memset(&spectrum, 0, sizeof(spectrum));
1300
1301 spectrum.channel_count = cpu_to_le16(1);
1302 spectrum.flags =
1303 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
1304 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
1305 cmd.len = sizeof(spectrum);
1306 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
1307
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001308 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001309 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001310 iwl3945_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -07001311 add_time,
1312 le16_to_cpu(priv->rxon_timing.beacon_interval));
1313 else
1314 spectrum.start_time = 0;
1315
1316 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
1317 spectrum.channels[0].channel = params->channel;
1318 spectrum.channels[0].type = type;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001319 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
Zhu Yib481de92007-09-25 17:54:57 -07001320 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
1321 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
1322
Samuel Ortiz518099a2009-01-19 15:30:27 -08001323 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001324 if (rc)
1325 return rc;
1326
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001327 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001328 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001329 IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -07001330 rc = -EIO;
1331 }
1332
1333 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
1334 switch (spectrum_resp_status) {
1335 case 0: /* Command will be handled */
1336 if (res->u.spectrum.id != 0xff) {
Tomas Winklere1623442009-01-27 14:27:56 -08001337 IWL_DEBUG_INFO(priv, "Replaced existing measurement: %d\n",
Ian Schrambc434dd2007-10-25 17:15:29 +08001338 res->u.spectrum.id);
Zhu Yib481de92007-09-25 17:54:57 -07001339 priv->measurement_status &= ~MEASUREMENT_READY;
1340 }
1341 priv->measurement_status |= MEASUREMENT_ACTIVE;
1342 rc = 0;
1343 break;
1344
1345 case 1: /* Command will not be handled */
1346 rc = -EAGAIN;
1347 break;
1348 }
1349
1350 dev_kfree_skb_any(cmd.meta.u.skb);
1351
1352 return rc;
1353}
1354#endif
1355
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001356static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001357 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001358{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001359 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
1360 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -07001361 struct delayed_work *pwork;
1362
1363 palive = &pkt->u.alive_frame;
1364
Tomas Winklere1623442009-01-27 14:27:56 -08001365 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
Zhu Yib481de92007-09-25 17:54:57 -07001366 "0x%01X 0x%01X\n",
1367 palive->is_valid, palive->ver_type,
1368 palive->ver_subtype);
1369
1370 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
Tomas Winklere1623442009-01-27 14:27:56 -08001371 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001372 memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
1373 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001374 pwork = &priv->init_alive_start;
1375 } else {
Tomas Winklere1623442009-01-27 14:27:56 -08001376 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001377 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001378 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001379 pwork = &priv->alive_start;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001380 iwl3945_disable_events(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001381 }
1382
1383 /* We delay the ALIVE response by 5ms to
1384 * give the HW RF Kill time to activate... */
1385 if (palive->is_valid == UCODE_VALID_OK)
1386 queue_delayed_work(priv->workqueue, pwork,
1387 msecs_to_jiffies(5));
1388 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001389 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001390}
1391
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001392static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001393 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001394{
Helmut Schaac7e035a2009-01-19 13:02:15 +01001395#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001396 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Helmut Schaac7e035a2009-01-19 13:02:15 +01001397#endif
Zhu Yib481de92007-09-25 17:54:57 -07001398
Tomas Winklere1623442009-01-27 14:27:56 -08001399 IWL_DEBUG_RX(priv, "Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
Zhu Yib481de92007-09-25 17:54:57 -07001400 return;
1401}
1402
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001403static void iwl3945_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07001404{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001405 struct iwl_priv *priv =
1406 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07001407 struct sk_buff *beacon;
1408
1409 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02001410 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07001411
1412 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001413 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07001414 return;
1415 }
1416
1417 mutex_lock(&priv->mutex);
1418 /* new beacon skb is allocated every time; dispose previous.*/
1419 if (priv->ibss_beacon)
1420 dev_kfree_skb(priv->ibss_beacon);
1421
1422 priv->ibss_beacon = beacon;
1423 mutex_unlock(&priv->mutex);
1424
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001425 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001426}
1427
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001428static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001429 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001430{
Samuel Ortizd08853a2009-01-23 13:45:17 -08001431#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001432 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001433 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
Zhu Yib481de92007-09-25 17:54:57 -07001434 u8 rate = beacon->beacon_notify_hdr.rate;
1435
Tomas Winklere1623442009-01-27 14:27:56 -08001436 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
Zhu Yib481de92007-09-25 17:54:57 -07001437 "tsf %d %d rate %d\n",
1438 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
1439 beacon->beacon_notify_hdr.failure_frame,
1440 le32_to_cpu(beacon->ibss_mgr_status),
1441 le32_to_cpu(beacon->high_tsf),
1442 le32_to_cpu(beacon->low_tsf), rate);
1443#endif
1444
Johannes Berg05c914f2008-09-11 00:01:58 +02001445 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -07001446 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1447 queue_work(priv->workqueue, &priv->beacon_update);
1448}
1449
Zhu Yib481de92007-09-25 17:54:57 -07001450/* Handle notification from uCode that card's power state is changing
1451 * due to software, hardware, or critical temperature RFKILL */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001452static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001453 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001454{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001455 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001456 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1457 unsigned long status = priv->status;
1458
Tomas Winklere1623442009-01-27 14:27:56 -08001459 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n",
Zhu Yib481de92007-09-25 17:54:57 -07001460 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1461 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1462
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001463 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001464 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1465
1466 if (flags & HW_CARD_DISABLED)
1467 set_bit(STATUS_RF_KILL_HW, &priv->status);
1468 else
1469 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1470
1471
1472 if (flags & SW_CARD_DISABLED)
1473 set_bit(STATUS_RF_KILL_SW, &priv->status);
1474 else
1475 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1476
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08001477 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001478
1479 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1480 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1481 (test_bit(STATUS_RF_KILL_SW, &status) !=
1482 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1483 queue_work(priv->workqueue, &priv->rf_kill);
1484 else
1485 wake_up_interruptible(&priv->wait_command_queue);
1486}
1487
1488/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001489 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07001490 *
1491 * Setup the RX handlers for each of the reply types sent from the uCode
1492 * to the host.
1493 *
1494 * This function chains into the hardware specific files for them to setup
1495 * any hardware specific handlers as well.
1496 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001497static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001498{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001499 priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
1500 priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
Abhijeet Kolekar261b9c32009-02-18 15:54:29 -08001501 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001502 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -08001503 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001504 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -08001505 iwl_rx_pm_debug_statistics_notif;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001506 priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001507
Ben Cahill9fbab512007-11-29 11:09:47 +08001508 /*
1509 * The same handler is used for both the REPLY to a discrete
1510 * statistics request from the host as well as for the periodic
1511 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07001512 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001513 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
1514 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
Zhu Yib481de92007-09-25 17:54:57 -07001515
Abhijeet Kolekar261b9c32009-02-18 15:54:29 -08001516 iwl_setup_spectrum_handlers(priv);
Abhijeet Kolekarcade0eb2009-02-18 15:54:26 -08001517 iwl_setup_rx_scan_handlers(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001518 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001519
Ben Cahill9fbab512007-11-29 11:09:47 +08001520 /* Set up hardware specific Rx handlers */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001521 iwl3945_hw_rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001522}
1523
1524/**
Tomas Winkler91c066f2008-03-06 17:36:55 -08001525 * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries
1526 * When FW advances 'R' index, all entries between old and new 'R' index
1527 * need to be reclaimed.
1528 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001529static void iwl3945_cmd_queue_reclaim(struct iwl_priv *priv,
Tomas Winkler91c066f2008-03-06 17:36:55 -08001530 int txq_id, int index)
1531{
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001532 struct iwl_tx_queue *txq = &priv->txq[txq_id];
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001533 struct iwl_queue *q = &txq->q;
Tomas Winkler91c066f2008-03-06 17:36:55 -08001534 int nfreed = 0;
1535
Winkler, Tomas625a3812009-01-08 10:19:55 -08001536 if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001537 IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, "
Tomas Winkler91c066f2008-03-06 17:36:55 -08001538 "is out of range [0-%d] %d %d.\n", txq_id,
1539 index, q->n_bd, q->write_ptr, q->read_ptr);
1540 return;
1541 }
1542
1543 for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
1544 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
1545 if (nfreed > 1) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001546 IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", index,
Tomas Winkler91c066f2008-03-06 17:36:55 -08001547 q->write_ptr, q->read_ptr);
1548 queue_work(priv->workqueue, &priv->restart);
1549 break;
1550 }
1551 nfreed++;
1552 }
1553}
1554
1555
1556/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001557 * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
Zhu Yib481de92007-09-25 17:54:57 -07001558 * @rxb: Rx buffer to reclaim
1559 *
1560 * If an Rx buffer has an async callback associated with it the callback
1561 * will be executed. The attached skb (if present) will only be freed
1562 * if the callback returns 1
1563 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001564static void iwl3945_tx_cmd_complete(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001565 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001566{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001567 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001568 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
1569 int txq_id = SEQ_TO_QUEUE(sequence);
1570 int index = SEQ_TO_INDEX(sequence);
Tomas Winkler600c0e12008-12-19 10:37:04 +08001571 int huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
Zhu Yib481de92007-09-25 17:54:57 -07001572 int cmd_index;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08001573 struct iwl_cmd *cmd;
Zhu Yib481de92007-09-25 17:54:57 -07001574
Chatre, Reinette638d0eb2009-01-19 15:30:24 -08001575 if (WARN(txq_id != IWL_CMD_QUEUE_NUM,
1576 "wrong command queue %d, sequence 0x%X readp=%d writep=%d\n",
1577 txq_id, sequence,
1578 priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr,
1579 priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) {
1580 iwl_print_hex_dump(priv, IWL_DL_INFO , rxb, 32);
1581 return;
1582 }
Zhu Yib481de92007-09-25 17:54:57 -07001583
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001584 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
1585 cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
Zhu Yib481de92007-09-25 17:54:57 -07001586
1587 /* Input error checking is done when commands are added to queue. */
1588 if (cmd->meta.flags & CMD_WANT_SKB) {
1589 cmd->meta.source->u.skb = rxb->skb;
1590 rxb->skb = NULL;
1591 } else if (cmd->meta.u.callback &&
1592 !cmd->meta.u.callback(priv, cmd, rxb->skb))
1593 rxb->skb = NULL;
1594
Tomas Winkler91c066f2008-03-06 17:36:55 -08001595 iwl3945_cmd_queue_reclaim(priv, txq_id, index);
Zhu Yib481de92007-09-25 17:54:57 -07001596
1597 if (!(cmd->meta.flags & CMD_ASYNC)) {
1598 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1599 wake_up_interruptible(&priv->wait_command_queue);
1600 }
1601}
1602
1603/************************** RX-FUNCTIONS ****************************/
1604/*
1605 * Rx theory of operation
1606 *
1607 * The host allocates 32 DMA target addresses and passes the host address
1608 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
1609 * 0 to 31
1610 *
1611 * Rx Queue Indexes
1612 * The host/firmware share two index registers for managing the Rx buffers.
1613 *
1614 * The READ index maps to the first position that the firmware may be writing
1615 * to -- the driver can read up to (but not including) this position and get
1616 * good data.
1617 * The READ index is managed by the firmware once the card is enabled.
1618 *
1619 * The WRITE index maps to the last position the driver has read from -- the
1620 * position preceding WRITE is the last slot the firmware can place a packet.
1621 *
1622 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
1623 * WRITE = READ.
1624 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001625 * During initialization, the host sets up the READ queue position to the first
Zhu Yib481de92007-09-25 17:54:57 -07001626 * INDEX position, and WRITE to the last (READ - 1 wrapped)
1627 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001628 * When the firmware places a packet in a buffer, it will advance the READ index
Zhu Yib481de92007-09-25 17:54:57 -07001629 * and fire the RX interrupt. The driver can then query the READ index and
1630 * process as many packets as possible, moving the WRITE index forward as it
1631 * resets the Rx queue buffers with new memory.
1632 *
1633 * The management in the driver is as follows:
1634 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
1635 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Ian Schram01ebd062007-10-25 17:15:22 +08001636 * to replenish the iwl->rxq->rx_free.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001637 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
Zhu Yib481de92007-09-25 17:54:57 -07001638 * iwl->rxq is replenished and the READ INDEX is updated (updating the
1639 * 'processed' and 'read' driver indexes as well)
1640 * + A received packet is processed and handed to the kernel network stack,
1641 * detached from the iwl->rxq. The driver 'processed' index is updated.
1642 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
1643 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
1644 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
1645 * were enough free buffers and RX_STALLED is set it is cleared.
1646 *
1647 *
1648 * Driver sequence:
1649 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001650 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001651 * iwl3945_rx_queue_restock
Ben Cahill9fbab512007-11-29 11:09:47 +08001652 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
Zhu Yib481de92007-09-25 17:54:57 -07001653 * queue, updates firmware pointers, and updates
1654 * the WRITE index. If insufficient rx_free buffers
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001655 * are available, schedules iwl3945_rx_replenish
Zhu Yib481de92007-09-25 17:54:57 -07001656 *
1657 * -- enable interrupts --
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001658 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
Zhu Yib481de92007-09-25 17:54:57 -07001659 * READ INDEX, detaching the SKB from the pool.
1660 * Moves the packet buffer from queue to rx_used.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001661 * Calls iwl3945_rx_queue_restock to refill any empty
Zhu Yib481de92007-09-25 17:54:57 -07001662 * slots.
1663 * ...
1664 *
1665 */
1666
1667/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001668 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
Zhu Yib481de92007-09-25 17:54:57 -07001669 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001670static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001671 dma_addr_t dma_addr)
1672{
1673 return cpu_to_le32((u32)dma_addr);
1674}
1675
1676/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001677 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
Zhu Yib481de92007-09-25 17:54:57 -07001678 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001679 * If there are slots in the RX queue that need to be restocked,
Zhu Yib481de92007-09-25 17:54:57 -07001680 * and we have free pre-allocated buffers, fill the ranks as much
Ben Cahill9fbab512007-11-29 11:09:47 +08001681 * as we can, pulling from rx_free.
Zhu Yib481de92007-09-25 17:54:57 -07001682 *
1683 * This moves the 'write' index forward to catch up with 'processed', and
1684 * also updates the memory address in the firmware to reference the new
1685 * target buffer.
1686 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001687static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001688{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001689 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001690 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001691 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001692 unsigned long flags;
1693 int write, rc;
1694
1695 spin_lock_irqsave(&rxq->lock, flags);
1696 write = rxq->write & ~0x7;
Winkler, Tomas37d68312009-01-08 10:19:54 -08001697 while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001698 /* Get next free Rx buffer, remove from free list */
Zhu Yib481de92007-09-25 17:54:57 -07001699 element = rxq->rx_free.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001700 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Zhu Yib481de92007-09-25 17:54:57 -07001701 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001702
1703 /* Point to Rx buffer via next RBD in circular buffer */
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001704 rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
Zhu Yib481de92007-09-25 17:54:57 -07001705 rxq->queue[rxq->write] = rxb;
1706 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
1707 rxq->free_count--;
1708 }
1709 spin_unlock_irqrestore(&rxq->lock, flags);
1710 /* If the pre-allocated buffer pool is dropping low, schedule to
1711 * refill it */
1712 if (rxq->free_count <= RX_LOW_WATERMARK)
1713 queue_work(priv->workqueue, &priv->rx_replenish);
1714
1715
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001716 /* If we've added more space for the firmware to place data, tell it.
1717 * Increment device's write pointer in multiples of 8. */
Zhu Yib481de92007-09-25 17:54:57 -07001718 if ((write != (rxq->write & ~0x7))
1719 || (abs(rxq->write - rxq->read) > 7)) {
1720 spin_lock_irqsave(&rxq->lock, flags);
1721 rxq->need_update = 1;
1722 spin_unlock_irqrestore(&rxq->lock, flags);
Winkler, Tomas141c43a2009-01-08 10:19:53 -08001723 rc = iwl_rx_queue_update_write_ptr(priv, rxq);
Zhu Yib481de92007-09-25 17:54:57 -07001724 if (rc)
1725 return rc;
1726 }
1727
1728 return 0;
1729}
1730
1731/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001732 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
Zhu Yib481de92007-09-25 17:54:57 -07001733 *
1734 * When moving to rx_free an SKB is allocated for the slot.
1735 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001736 * Also restock the Rx queue via iwl3945_rx_queue_restock.
Ian Schram01ebd062007-10-25 17:15:22 +08001737 * This is called as a scheduled work item (except for during initialization)
Zhu Yib481de92007-09-25 17:54:57 -07001738 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001739static void iwl3945_rx_allocate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001740{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001741 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001742 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001743 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001744 unsigned long flags;
1745 spin_lock_irqsave(&rxq->lock, flags);
1746 while (!list_empty(&rxq->rx_used)) {
1747 element = rxq->rx_used.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001748 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001749
1750 /* Alloc a new receive buffer */
Zhu Yib481de92007-09-25 17:54:57 -07001751 rxb->skb =
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001752 alloc_skb(priv->hw_params.rx_buf_size,
1753 __GFP_NOWARN | GFP_ATOMIC);
Zhu Yib481de92007-09-25 17:54:57 -07001754 if (!rxb->skb) {
1755 if (net_ratelimit())
Tomas Winkler978785a2008-12-19 10:37:31 +08001756 IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
Zhu Yib481de92007-09-25 17:54:57 -07001757 /* We don't reschedule replenish work here -- we will
1758 * call the restock method and if it still needs
1759 * more buffers it will schedule replenish */
1760 break;
1761 }
Zhu Yi12342c42007-12-20 11:27:32 +08001762
1763 /* If radiotap head is required, reserve some headroom here.
1764 * The physical head count is a variable rx_stats->phy_count.
1765 * We reserve 4 bytes here. Plus these extra bytes, the
1766 * headroom of the physical head should be enough for the
1767 * radiotap head that iwl3945 supported. See iwl3945_rt.
1768 */
1769 skb_reserve(rxb->skb, 4);
1770
Zhu Yib481de92007-09-25 17:54:57 -07001771 priv->alloc_rxb_skb++;
1772 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001773
1774 /* Get physical address of RB/SKB */
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001775 rxb->real_dma_addr = pci_map_single(priv->pci_dev,
1776 rxb->skb->data,
1777 priv->hw_params.rx_buf_size,
1778 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001779 list_add_tail(&rxb->list, &rxq->rx_free);
1780 rxq->free_count++;
1781 }
1782 spin_unlock_irqrestore(&rxq->lock, flags);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001783}
1784
1785/*
1786 * this should be called while priv->lock is locked
1787 */
Tomas Winkler4fd1f842007-12-05 20:59:58 +02001788static void __iwl3945_rx_replenish(void *data)
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001789{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001790 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001791
1792 iwl3945_rx_allocate(priv);
1793 iwl3945_rx_queue_restock(priv);
1794}
1795
1796
1797void iwl3945_rx_replenish(void *data)
1798{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001799 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001800 unsigned long flags;
1801
1802 iwl3945_rx_allocate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001803
1804 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001805 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001806 spin_unlock_irqrestore(&priv->lock, flags);
1807}
1808
Zhu Yib481de92007-09-25 17:54:57 -07001809/* Convert linear signal-to-noise ratio into dB */
1810static u8 ratio2dB[100] = {
1811/* 0 1 2 3 4 5 6 7 8 9 */
1812 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
1813 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
1814 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
1815 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
1816 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
1817 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
1818 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
1819 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
1820 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
1821 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
1822};
1823
1824/* Calculates a relative dB value from a ratio of linear
1825 * (i.e. not dB) signal levels.
1826 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001827int iwl3945_calc_db_from_ratio(int sig_ratio)
Zhu Yib481de92007-09-25 17:54:57 -07001828{
Adrian Bunk221c80c2008-02-02 23:19:01 +02001829 /* 1000:1 or higher just report as 60 dB */
1830 if (sig_ratio >= 1000)
Zhu Yib481de92007-09-25 17:54:57 -07001831 return 60;
1832
Adrian Bunk221c80c2008-02-02 23:19:01 +02001833 /* 100:1 or higher, divide by 10 and use table,
Zhu Yib481de92007-09-25 17:54:57 -07001834 * add 20 dB to make up for divide by 10 */
Adrian Bunk221c80c2008-02-02 23:19:01 +02001835 if (sig_ratio >= 100)
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001836 return 20 + (int)ratio2dB[sig_ratio/10];
Zhu Yib481de92007-09-25 17:54:57 -07001837
1838 /* We shouldn't see this */
1839 if (sig_ratio < 1)
1840 return 0;
1841
1842 /* Use table for ratios 1:1 - 99:1 */
1843 return (int)ratio2dB[sig_ratio];
1844}
1845
1846#define PERFECT_RSSI (-20) /* dBm */
1847#define WORST_RSSI (-95) /* dBm */
1848#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
1849
1850/* Calculate an indication of rx signal quality (a percentage, not dBm!).
1851 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
1852 * about formulas used below. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001853int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
Zhu Yib481de92007-09-25 17:54:57 -07001854{
1855 int sig_qual;
1856 int degradation = PERFECT_RSSI - rssi_dbm;
1857
1858 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
1859 * as indicator; formula is (signal dbm - noise dbm).
1860 * SNR at or above 40 is a great signal (100%).
1861 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
1862 * Weakest usable signal is usually 10 - 15 dB SNR. */
1863 if (noise_dbm) {
1864 if (rssi_dbm - noise_dbm >= 40)
1865 return 100;
1866 else if (rssi_dbm < noise_dbm)
1867 return 0;
1868 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
1869
1870 /* Else use just the signal level.
1871 * This formula is a least squares fit of data points collected and
1872 * compared with a reference system that had a percentage (%) display
1873 * for signal quality. */
1874 } else
1875 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
1876 (15 * RSSI_RANGE + 62 * degradation)) /
1877 (RSSI_RANGE * RSSI_RANGE);
1878
1879 if (sig_qual > 100)
1880 sig_qual = 100;
1881 else if (sig_qual < 1)
1882 sig_qual = 0;
1883
1884 return sig_qual;
1885}
1886
1887/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001888 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001889 *
1890 * Uses the priv->rx_handlers callback function array to invoke
1891 * the appropriate handlers, including command responses,
1892 * frame-received notifications, and other notifications.
1893 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001894static void iwl3945_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001895{
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001896 struct iwl_rx_mem_buffer *rxb;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001897 struct iwl_rx_packet *pkt;
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001898 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001899 u32 r, i;
1900 int reclaim;
1901 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001902 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001903 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07001904
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001905 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1906 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8cd812b2008-12-19 10:37:43 +08001907 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07001908 i = rxq->read;
1909
Winkler, Tomas37d68312009-01-08 10:19:54 -08001910 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001911 fill_rx = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001912 /* Rx interrupt, but nothing sent from uCode */
1913 if (i == r)
Tomas Winklere1623442009-01-27 14:27:56 -08001914 IWL_DEBUG(priv, IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001915
1916 while (i != r) {
1917 rxb = rxq->queue[i];
1918
Ben Cahill9fbab512007-11-29 11:09:47 +08001919 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001920 * then a bug has been introduced in the queue refilling
1921 * routines -- catch it here */
1922 BUG_ON(rxb == NULL);
1923
1924 rxq->queue[i] = NULL;
1925
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001926 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001927 priv->hw_params.rx_buf_size,
Zhu Yib481de92007-09-25 17:54:57 -07001928 PCI_DMA_FROMDEVICE);
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001929 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001930
1931 /* Reclaim a command buffer only if this packet is a response
1932 * to a (driver-originated) command.
1933 * If the packet (e.g. Rx frame) originated from uCode,
1934 * there is no command buffer to reclaim.
1935 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1936 * but apparently a few don't get set; catch them here. */
1937 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1938 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1939 (pkt->hdr.cmd != REPLY_TX);
1940
1941 /* Based on type of command response or notification,
1942 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001943 * rx_handlers table. See iwl3945_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001944 if (priv->rx_handlers[pkt->hdr.cmd]) {
Tomas Winklere1623442009-01-27 14:27:56 -08001945 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07001946 "r = %d, i = %d, %s, 0x%02x\n", r, i,
1947 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
1948 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1949 } else {
1950 /* No handling needed */
Tomas Winklere1623442009-01-27 14:27:56 -08001951 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07001952 "r %d i %d No handler needed for %s, 0x%02x\n",
1953 r, i, get_cmd_string(pkt->hdr.cmd),
1954 pkt->hdr.cmd);
1955 }
1956
1957 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001958 /* Invoke any callbacks, transfer the skb to caller, and
Samuel Ortiz518099a2009-01-19 15:30:27 -08001959 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001960 * as we reclaim the driver command queue */
1961 if (rxb && rxb->skb)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001962 iwl3945_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001963 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001964 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07001965 }
1966
1967 /* For now we just don't re-use anything. We can tweak this
1968 * later to try and re-use notification packets and SKBs that
1969 * fail to Rx correctly */
1970 if (rxb->skb != NULL) {
1971 priv->alloc_rxb_skb--;
1972 dev_kfree_skb_any(rxb->skb);
1973 rxb->skb = NULL;
1974 }
1975
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001976 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001977 priv->hw_params.rx_buf_size,
1978 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001979 spin_lock_irqsave(&rxq->lock, flags);
1980 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1981 spin_unlock_irqrestore(&rxq->lock, flags);
1982 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001983 /* If there are a lot of unused frames,
1984 * restock the Rx queue so ucode won't assert. */
1985 if (fill_rx) {
1986 count++;
1987 if (count >= 8) {
1988 priv->rxq.read = i;
1989 __iwl3945_rx_replenish(priv);
1990 count = 0;
1991 }
1992 }
Zhu Yib481de92007-09-25 17:54:57 -07001993 }
1994
1995 /* Backtrack one entry */
1996 priv->rxq.read = i;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001997 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001998}
1999
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002000/* call this function to flush any scheduled tasklet */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002001static inline void iwl_synchronize_irq(struct iwl_priv *priv)
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002002{
Tomas Winklera96a27f2008-10-23 23:48:56 -07002003 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002004 synchronize_irq(priv->pci_dev->irq);
2005 tasklet_kill(&priv->irq_tasklet);
2006}
2007
Zhu Yib481de92007-09-25 17:54:57 -07002008static const char *desc_lookup(int i)
2009{
2010 switch (i) {
2011 case 1:
2012 return "FAIL";
2013 case 2:
2014 return "BAD_PARAM";
2015 case 3:
2016 return "BAD_CHECKSUM";
2017 case 4:
2018 return "NMI_INTERRUPT";
2019 case 5:
2020 return "SYSASSERT";
2021 case 6:
2022 return "FATAL_ERROR";
2023 }
2024
2025 return "UNKNOWN";
2026}
2027
2028#define ERROR_START_OFFSET (1 * sizeof(u32))
2029#define ERROR_ELEM_SIZE (7 * sizeof(u32))
2030
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002031static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002032{
2033 u32 i;
2034 u32 desc, time, count, base, data1;
2035 u32 blink1, blink2, ilink1, ilink2;
2036 int rc;
2037
2038 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
2039
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002040 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002041 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07002042 return;
2043 }
2044
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002045 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002046 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002047 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002048 return;
2049 }
2050
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002051 count = iwl_read_targ_mem(priv, base);
Zhu Yib481de92007-09-25 17:54:57 -07002052
2053 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002054 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
2055 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
2056 priv->status, count);
Zhu Yib481de92007-09-25 17:54:57 -07002057 }
2058
Winkler, Tomas15b16872008-12-19 10:37:33 +08002059 IWL_ERR(priv, "Desc Time asrtPC blink2 "
Zhu Yib481de92007-09-25 17:54:57 -07002060 "ilink1 nmiPC Line\n");
2061 for (i = ERROR_START_OFFSET;
2062 i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
2063 i += ERROR_ELEM_SIZE) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002064 desc = iwl_read_targ_mem(priv, base + i);
Zhu Yib481de92007-09-25 17:54:57 -07002065 time =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002066 iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002067 blink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002068 iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002069 blink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002070 iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002071 ilink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002072 iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002073 ilink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002074 iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002075 data1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002076 iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002077
Winkler, Tomas15b16872008-12-19 10:37:33 +08002078 IWL_ERR(priv,
2079 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
2080 desc_lookup(desc), desc, time, blink1, blink2,
2081 ilink1, ilink2, data1);
Zhu Yib481de92007-09-25 17:54:57 -07002082 }
2083
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002084 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002085
2086}
2087
Ben Cahillf58177b2007-11-29 11:09:43 +08002088#define EVENT_START_OFFSET (6 * sizeof(u32))
Zhu Yib481de92007-09-25 17:54:57 -07002089
2090/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002091 * iwl3945_print_event_log - Dump error event log to syslog
Zhu Yib481de92007-09-25 17:54:57 -07002092 *
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002093 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
Zhu Yib481de92007-09-25 17:54:57 -07002094 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002095static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
Zhu Yib481de92007-09-25 17:54:57 -07002096 u32 num_events, u32 mode)
2097{
2098 u32 i;
2099 u32 base; /* SRAM byte address of event log header */
2100 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
2101 u32 ptr; /* SRAM byte address of log data */
2102 u32 ev, time, data; /* event log data */
2103
2104 if (num_events == 0)
2105 return;
2106
2107 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
2108
2109 if (mode == 0)
2110 event_size = 2 * sizeof(u32);
2111 else
2112 event_size = 3 * sizeof(u32);
2113
2114 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
2115
2116 /* "time" is actually "data" for mode 0 (no timestamp).
2117 * place event id # at far right for easier visual parsing. */
2118 for (i = 0; i < num_events; i++) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002119 ev = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002120 ptr += sizeof(u32);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002121 time = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002122 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002123 if (mode == 0) {
2124 /* data, ev */
2125 IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
2126 } else {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002127 data = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002128 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002129 IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
Zhu Yib481de92007-09-25 17:54:57 -07002130 }
2131 }
2132}
2133
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002134static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002135{
2136 int rc;
2137 u32 base; /* SRAM byte address of event log header */
2138 u32 capacity; /* event log capacity in # entries */
2139 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
2140 u32 num_wraps; /* # times uCode wrapped to top of log */
2141 u32 next_entry; /* index of next entry to be written by uCode */
2142 u32 size; /* # entries that we'll print */
2143
2144 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002145 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002146 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07002147 return;
2148 }
2149
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002150 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002151 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002152 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002153 return;
2154 }
2155
2156 /* event log header */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002157 capacity = iwl_read_targ_mem(priv, base);
2158 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
2159 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
2160 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
Zhu Yib481de92007-09-25 17:54:57 -07002161
2162 size = num_wraps ? capacity : next_entry;
2163
2164 /* bail out if nothing in log */
2165 if (size == 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002166 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002167 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002168 return;
2169 }
2170
Winkler, Tomas15b16872008-12-19 10:37:33 +08002171 IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07002172 size, num_wraps);
2173
2174 /* if uCode has wrapped back to top of log, start at the oldest entry,
2175 * i.e the next one that uCode would fill. */
2176 if (num_wraps)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002177 iwl3945_print_event_log(priv, next_entry,
Zhu Yib481de92007-09-25 17:54:57 -07002178 capacity - next_entry, mode);
2179
2180 /* (then/else) start at top of log */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002181 iwl3945_print_event_log(priv, 0, next_entry, mode);
Zhu Yib481de92007-09-25 17:54:57 -07002182
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002183 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002184}
2185
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002186static void iwl3945_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002187{
2188 unsigned long flags;
2189
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002190 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
2191 sizeof(priv->staging_rxon));
2192 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002193 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002194
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002195 iwl3945_add_station(priv, priv->bssid, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002196
2197 spin_lock_irqsave(&priv->lock, flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002198 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07002199 priv->error_recovering = 0;
2200 spin_unlock_irqrestore(&priv->lock, flags);
2201}
2202
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002203static void iwl3945_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002204{
2205 u32 inta, handled = 0;
2206 u32 inta_fh;
2207 unsigned long flags;
Samuel Ortizd08853a2009-01-23 13:45:17 -08002208#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07002209 u32 inta_mask;
2210#endif
2211
2212 spin_lock_irqsave(&priv->lock, flags);
2213
2214 /* Ack/clear/reset pending uCode interrupts.
2215 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
2216 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002217 inta = iwl_read32(priv, CSR_INT);
2218 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07002219
2220 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
2221 * Any new interrupts that happen after this, either while we're
2222 * in this tasklet, or later, will show up in next ISR/tasklet. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002223 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
2224 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07002225
Samuel Ortizd08853a2009-01-23 13:45:17 -08002226#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002227 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08002228 /* just for debug */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002229 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Tomas Winklere1623442009-01-27 14:27:56 -08002230 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002231 inta, inta_mask, inta_fh);
2232 }
2233#endif
2234
2235 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
2236 * atomic, make sure that inta covers all the interrupts that
2237 * we've discovered, even if FH interrupt came in just after
2238 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002239 if (inta_fh & CSR39_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002240 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002241 if (inta_fh & CSR39_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002242 inta |= CSR_INT_BIT_FH_TX;
2243
2244 /* Now service all interrupt bits discovered above. */
2245 if (inta & CSR_INT_BIT_HW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002246 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002247
2248 /* Tell the device to stop sending interrupts */
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002249 iwl_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002250
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002251 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002252
2253 handled |= CSR_INT_BIT_HW_ERR;
2254
2255 spin_unlock_irqrestore(&priv->lock, flags);
2256
2257 return;
2258 }
2259
Samuel Ortizd08853a2009-01-23 13:45:17 -08002260#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002261 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07002262 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002263 if (inta & CSR_INT_BIT_SCD)
Tomas Winklere1623442009-01-27 14:27:56 -08002264 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
Joonwoo Park25c03d82008-01-23 10:15:20 -08002265 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002266
2267 /* Alive notification via Rx interrupt will do the real work */
2268 if (inta & CSR_INT_BIT_ALIVE)
Tomas Winklere1623442009-01-27 14:27:56 -08002269 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002270 }
2271#endif
2272 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002273 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07002274
Zhu Yib481de92007-09-25 17:54:57 -07002275 /* Error detected by uCode */
2276 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002277 IWL_ERR(priv, "Microcode SW error detected. "
2278 "Restarting 0x%X.\n", inta);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002279 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002280 handled |= CSR_INT_BIT_SW_ERR;
2281 }
2282
2283 /* uCode wakes up after power-down sleep */
2284 if (inta & CSR_INT_BIT_WAKEUP) {
Tomas Winklere1623442009-01-27 14:27:56 -08002285 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
Winkler, Tomas141c43a2009-01-08 10:19:53 -08002286 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08002287 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
2288 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
2289 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
2290 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
2291 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
2292 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07002293
2294 handled |= CSR_INT_BIT_WAKEUP;
2295 }
2296
2297 /* All uCode command responses, including Tx command responses,
2298 * Rx "responses" (frame-received notification), and other
2299 * notifications from uCode come through here*/
2300 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002301 iwl3945_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002302 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
2303 }
2304
2305 if (inta & CSR_INT_BIT_FH_TX) {
Tomas Winklere1623442009-01-27 14:27:56 -08002306 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002307
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002308 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
2309 if (!iwl_grab_nic_access(priv)) {
2310 iwl_write_direct32(priv, FH39_TCSR_CREDIT
Tomas Winklerbddadf82008-12-19 10:37:01 +08002311 (FH39_SRVC_CHNL), 0x0);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002312 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002313 }
2314 handled |= CSR_INT_BIT_FH_TX;
2315 }
2316
2317 if (inta & ~handled)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002318 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Zhu Yib481de92007-09-25 17:54:57 -07002319
2320 if (inta & ~CSR_INI_SET_MASK) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002321 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Zhu Yib481de92007-09-25 17:54:57 -07002322 inta & ~CSR_INI_SET_MASK);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002323 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07002324 }
2325
2326 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002327 /* only Re-enable if disabled by irq */
2328 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002329 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002330
Samuel Ortizd08853a2009-01-23 13:45:17 -08002331#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002332 if (priv->debug_level & (IWL_DL_ISR)) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002333 inta = iwl_read32(priv, CSR_INT);
2334 inta_mask = iwl_read32(priv, CSR_INT_MASK);
2335 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Tomas Winklere1623442009-01-27 14:27:56 -08002336 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
Zhu Yib481de92007-09-25 17:54:57 -07002337 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
2338 }
2339#endif
2340 spin_unlock_irqrestore(&priv->lock, flags);
2341}
2342
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002343static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01002344 enum ieee80211_band band,
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08002345 u8 is_active, u8 n_probes,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002346 struct iwl3945_scan_channel *scan_ch)
Zhu Yib481de92007-09-25 17:54:57 -07002347{
2348 const struct ieee80211_channel *channels = NULL;
Johannes Berg8318d782008-01-24 19:38:38 +01002349 const struct ieee80211_supported_band *sband;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08002350 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07002351 u16 passive_dwell = 0;
2352 u16 active_dwell = 0;
2353 int added, i;
2354
Kolekar, Abhijeetcbba18c2008-12-19 10:37:42 +08002355 sband = iwl_get_hw_mode(priv, band);
Johannes Berg8318d782008-01-24 19:38:38 +01002356 if (!sband)
Zhu Yib481de92007-09-25 17:54:57 -07002357 return 0;
2358
Johannes Berg8318d782008-01-24 19:38:38 +01002359 channels = sband->channels;
Zhu Yib481de92007-09-25 17:54:57 -07002360
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08002361 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
2362 passive_dwell = iwl_get_passive_dwell_time(priv, band);
Zhu Yib481de92007-09-25 17:54:57 -07002363
Abhijeet Kolekar8f4807a2008-09-03 11:26:31 +08002364 if (passive_dwell <= active_dwell)
2365 passive_dwell = active_dwell + 1;
2366
Johannes Berg8318d782008-01-24 19:38:38 +01002367 for (i = 0, added = 0; i < sband->n_channels; i++) {
Johannes Berg182e2e62008-04-04 10:41:56 +02002368 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
2369 continue;
2370
Johannes Berg8318d782008-01-24 19:38:38 +01002371 scan_ch->channel = channels[i].hw_value;
Zhu Yib481de92007-09-25 17:54:57 -07002372
Samuel Ortize6148912009-01-23 13:45:15 -08002373 ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
Zhu Yib481de92007-09-25 17:54:57 -07002374 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002375 IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
Zhu Yib481de92007-09-25 17:54:57 -07002376 scan_ch->channel);
2377 continue;
2378 }
2379
Zhu Yib481de92007-09-25 17:54:57 -07002380 scan_ch->active_dwell = cpu_to_le16(active_dwell);
2381 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002382 /* If passive , set up for auto-switch
2383 * and use long active_dwell time.
2384 */
2385 if (!is_active || is_channel_passive(ch_info) ||
2386 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
2387 scan_ch->type = 0; /* passive */
2388 if (IWL_UCODE_API(priv->ucode_ver) == 1)
2389 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
2390 } else {
2391 scan_ch->type = 1; /* active */
2392 }
2393
2394 /* Set direct probe bits. These may be used both for active
2395 * scan channels (probes gets sent right away),
2396 * or for passive channels (probes get se sent only after
2397 * hearing clear Rx packet).*/
2398 if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
2399 if (n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002400 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002401 } else {
2402 /* uCode v1 does not allow setting direct probe bits on
2403 * passive channel. */
2404 if ((scan_ch->type & 1) && n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002405 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002406 }
Zhu Yib481de92007-09-25 17:54:57 -07002407
Ben Cahill9fbab512007-11-29 11:09:47 +08002408 /* Set txpower levels to defaults */
Zhu Yib481de92007-09-25 17:54:57 -07002409 scan_ch->tpc.dsp_atten = 110;
2410 /* scan_pwr_info->tpc.dsp_atten; */
2411
2412 /*scan_pwr_info->tpc.tx_gain; */
Johannes Berg8318d782008-01-24 19:38:38 +01002413 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -07002414 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
2415 else {
2416 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
2417 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
Ben Cahill9fbab512007-11-29 11:09:47 +08002418 * power level:
Reinette Chatre8a1b0242008-01-14 17:46:25 -08002419 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
Zhu Yib481de92007-09-25 17:54:57 -07002420 */
2421 }
2422
Tomas Winklere1623442009-01-27 14:27:56 -08002423 IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n",
Zhu Yib481de92007-09-25 17:54:57 -07002424 scan_ch->channel,
2425 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
2426 (scan_ch->type & 1) ?
2427 active_dwell : passive_dwell);
2428
2429 scan_ch++;
2430 added++;
2431 }
2432
Tomas Winklere1623442009-01-27 14:27:56 -08002433 IWL_DEBUG_SCAN(priv, "total channels to scan %d \n", added);
Zhu Yib481de92007-09-25 17:54:57 -07002434 return added;
2435}
2436
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002437static void iwl3945_init_hw_rates(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002438 struct ieee80211_rate *rates)
2439{
2440 int i;
2441
2442 for (i = 0; i < IWL_RATE_COUNT; i++) {
Johannes Berg8318d782008-01-24 19:38:38 +01002443 rates[i].bitrate = iwl3945_rates[i].ieee * 5;
2444 rates[i].hw_value = i; /* Rate scaling will work on indexes */
2445 rates[i].hw_value_short = i;
2446 rates[i].flags = 0;
Samuel Ortizd9829a62008-12-19 10:37:12 +08002447 if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
Zhu Yib481de92007-09-25 17:54:57 -07002448 /*
Johannes Berg8318d782008-01-24 19:38:38 +01002449 * If CCK != 1M then set short preamble rate flag.
Zhu Yib481de92007-09-25 17:54:57 -07002450 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002451 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
Johannes Berg8318d782008-01-24 19:38:38 +01002452 0 : IEEE80211_RATE_SHORT_PREAMBLE;
Zhu Yib481de92007-09-25 17:54:57 -07002453 }
Zhu Yib481de92007-09-25 17:54:57 -07002454 }
2455}
2456
Zhu Yib481de92007-09-25 17:54:57 -07002457/******************************************************************************
2458 *
2459 * uCode download functions
2460 *
2461 ******************************************************************************/
2462
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002463static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002464{
Tomas Winkler98c92212008-01-14 17:46:20 -08002465 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
2466 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
2467 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
2468 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
2469 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
2470 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07002471}
2472
2473/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002474 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002475 * looking at all data.
2476 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002477static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002478{
2479 u32 val;
2480 u32 save_len = len;
2481 int rc = 0;
2482 u32 errcnt;
2483
Tomas Winklere1623442009-01-27 14:27:56 -08002484 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002485
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002486 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002487 if (rc)
2488 return rc;
2489
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002490 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002491 IWL39_RTC_INST_LOWER_BOUND);
Zhu Yib481de92007-09-25 17:54:57 -07002492
2493 errcnt = 0;
2494 for (; len > 0; len -= sizeof(u32), image++) {
2495 /* read data comes through single port, auto-incr addr */
2496 /* NOTE: Use the debugless read so we don't flood kernel log
2497 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002498 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002499 if (val != le32_to_cpu(*image)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002500 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002501 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2502 save_len - len, val, le32_to_cpu(*image));
2503 rc = -EIO;
2504 errcnt++;
2505 if (errcnt >= 20)
2506 break;
2507 }
2508 }
2509
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002510 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002511
2512 if (!errcnt)
Tomas Winklere1623442009-01-27 14:27:56 -08002513 IWL_DEBUG_INFO(priv,
2514 "ucode image in INSTRUCTION memory is good\n");
Zhu Yib481de92007-09-25 17:54:57 -07002515
2516 return rc;
2517}
2518
2519
2520/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002521 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002522 * using sample data 100 bytes apart. If these sample points are good,
2523 * it's a pretty good bet that everything between them is good, too.
2524 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002525static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002526{
2527 u32 val;
2528 int rc = 0;
2529 u32 errcnt = 0;
2530 u32 i;
2531
Tomas Winklere1623442009-01-27 14:27:56 -08002532 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002533
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002534 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002535 if (rc)
2536 return rc;
2537
2538 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
2539 /* read data comes through single port, auto-incr addr */
2540 /* NOTE: Use the debugless read so we don't flood kernel log
2541 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002542 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002543 i + IWL39_RTC_INST_LOWER_BOUND);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002544 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002545 if (val != le32_to_cpu(*image)) {
2546#if 0 /* Enable this if you want to see details */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002547 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002548 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2549 i, val, *image);
2550#endif
2551 rc = -EIO;
2552 errcnt++;
2553 if (errcnt >= 3)
2554 break;
2555 }
2556 }
2557
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002558 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002559
2560 return rc;
2561}
2562
2563
2564/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002565 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
Zhu Yib481de92007-09-25 17:54:57 -07002566 * and verify its contents
2567 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002568static int iwl3945_verify_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002569{
2570 __le32 *image;
2571 u32 len;
2572 int rc = 0;
2573
2574 /* Try bootstrap */
2575 image = (__le32 *)priv->ucode_boot.v_addr;
2576 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002577 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002578 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002579 IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002580 return 0;
2581 }
2582
2583 /* Try initialize */
2584 image = (__le32 *)priv->ucode_init.v_addr;
2585 len = priv->ucode_init.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002586 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002587 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002588 IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002589 return 0;
2590 }
2591
2592 /* Try runtime/protocol */
2593 image = (__le32 *)priv->ucode_code.v_addr;
2594 len = priv->ucode_code.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002595 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002596 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002597 IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002598 return 0;
2599 }
2600
Winkler, Tomas15b16872008-12-19 10:37:33 +08002601 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
Zhu Yib481de92007-09-25 17:54:57 -07002602
Ben Cahill9fbab512007-11-29 11:09:47 +08002603 /* Since nothing seems to match, show first several data entries in
2604 * instruction SRAM, so maybe visual inspection will give a clue.
2605 * Selection of bootstrap image (vs. other images) is arbitrary. */
Zhu Yib481de92007-09-25 17:54:57 -07002606 image = (__le32 *)priv->ucode_boot.v_addr;
2607 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002608 rc = iwl3945_verify_inst_full(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002609
2610 return rc;
2611}
2612
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002613static void iwl3945_nic_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002614{
2615 /* Remove all resets to allow NIC to operate */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002616 iwl_write32(priv, CSR_RESET, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002617}
2618
2619/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002620 * iwl3945_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07002621 *
2622 * Copy into buffers for card to fetch via bus-mastering
2623 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002624static int iwl3945_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002625{
Kolekar, Abhijeeta78fe752008-12-19 10:37:21 +08002626 struct iwl_ucode *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002627 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07002628 const struct firmware *ucode_raw;
2629 /* firmware file name contains uCode/driver compatibility version */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002630 const char *name_pre = priv->cfg->fw_name_pre;
2631 const unsigned int api_max = priv->cfg->ucode_api_max;
2632 const unsigned int api_min = priv->cfg->ucode_api_min;
2633 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07002634 u8 *src;
2635 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002636 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07002637
2638 /* Ask kernel firmware_class module to get the boot firmware off disk.
2639 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002640 for (index = api_max; index >= api_min; index--) {
2641 sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
2642 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
2643 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002644 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002645 buf, ret);
2646 if (ret == -ENOENT)
2647 continue;
2648 else
2649 goto error;
2650 } else {
2651 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002652 IWL_ERR(priv, "Loaded firmware %s, "
2653 "which is deprecated. "
2654 " Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002655 buf, api_max);
Tomas Winklere1623442009-01-27 14:27:56 -08002656 IWL_DEBUG_INFO(priv, "Got firmware '%s' file "
2657 "(%zd bytes) from disk\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002658 buf, ucode_raw->size);
2659 break;
2660 }
Zhu Yib481de92007-09-25 17:54:57 -07002661 }
2662
Reinette Chatrea0987a82008-12-02 12:14:06 -08002663 if (ret < 0)
2664 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07002665
2666 /* Make sure that we got at least our header! */
2667 if (ucode_raw->size < sizeof(*ucode)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002668 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002669 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002670 goto err_release;
2671 }
2672
2673 /* Data from ucode file: header followed by uCode images */
2674 ucode = (void *)ucode_raw->data;
2675
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08002676 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08002677 api_ver = IWL_UCODE_API(priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07002678 inst_size = le32_to_cpu(ucode->inst_size);
2679 data_size = le32_to_cpu(ucode->data_size);
2680 init_size = le32_to_cpu(ucode->init_size);
2681 init_data_size = le32_to_cpu(ucode->init_data_size);
2682 boot_size = le32_to_cpu(ucode->boot_size);
2683
Reinette Chatrea0987a82008-12-02 12:14:06 -08002684 /* api_ver should match the api version forming part of the
2685 * firmware filename ... but we don't check for that and only rely
2686 * on the API version read from firware header from here on forward */
2687
2688 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002689 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002690 "Driver supports v%u, firmware is v%u.\n",
2691 api_max, api_ver);
2692 priv->ucode_ver = 0;
2693 ret = -EINVAL;
2694 goto err_release;
2695 }
2696 if (api_ver != api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002697 IWL_ERR(priv, "Firmware has old API version. Expected %u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002698 "got %u. New firmware can be obtained "
2699 "from http://www.intellinuxwireless.org.\n",
2700 api_max, api_ver);
2701
Tomas Winkler978785a2008-12-19 10:37:31 +08002702 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
2703 IWL_UCODE_MAJOR(priv->ucode_ver),
2704 IWL_UCODE_MINOR(priv->ucode_ver),
2705 IWL_UCODE_API(priv->ucode_ver),
2706 IWL_UCODE_SERIAL(priv->ucode_ver));
2707
Tomas Winklere1623442009-01-27 14:27:56 -08002708 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002709 priv->ucode_ver);
Tomas Winklere1623442009-01-27 14:27:56 -08002710 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
2711 inst_size);
2712 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
2713 data_size);
2714 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
2715 init_size);
2716 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
2717 init_data_size);
2718 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
2719 boot_size);
Zhu Yib481de92007-09-25 17:54:57 -07002720
Reinette Chatrea0987a82008-12-02 12:14:06 -08002721
Zhu Yib481de92007-09-25 17:54:57 -07002722 /* Verify size of file vs. image size info in file's header */
2723 if (ucode_raw->size < sizeof(*ucode) +
2724 inst_size + data_size + init_size +
2725 init_data_size + boot_size) {
2726
Tomas Winklere1623442009-01-27 14:27:56 -08002727 IWL_DEBUG_INFO(priv, "uCode file size %zd too small\n",
2728 ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002729 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002730 goto err_release;
2731 }
2732
2733 /* Verify that uCode images will fit in card's SRAM */
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002734 if (inst_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002735 IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002736 inst_size);
2737 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002738 goto err_release;
2739 }
2740
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002741 if (data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002742 IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002743 data_size);
2744 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002745 goto err_release;
2746 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002747 if (init_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002748 IWL_DEBUG_INFO(priv,
2749 "uCode init instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002750 init_size);
2751 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002752 goto err_release;
2753 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002754 if (init_data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002755 IWL_DEBUG_INFO(priv,
2756 "uCode init data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002757 init_data_size);
2758 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002759 goto err_release;
2760 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002761 if (boot_size > IWL39_MAX_BSM_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002762 IWL_DEBUG_INFO(priv,
2763 "uCode boot instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002764 boot_size);
2765 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002766 goto err_release;
2767 }
2768
2769 /* Allocate ucode buffers for card's bus-master loading ... */
2770
2771 /* Runtime instructions and 2 copies of data:
2772 * 1) unmodified from disk
2773 * 2) backup cache for save/restore during power-downs */
2774 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002775 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07002776
2777 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002778 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07002779
2780 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002781 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07002782
2783 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
Tomas Winkler90e759d2007-11-29 11:09:41 +08002784 !priv->ucode_data_backup.v_addr)
Zhu Yib481de92007-09-25 17:54:57 -07002785 goto err_pci_alloc;
2786
Tomas Winkler90e759d2007-11-29 11:09:41 +08002787 /* Initialization instructions and data */
2788 if (init_size && init_data_size) {
2789 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002790 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002791
2792 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002793 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002794
2795 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
2796 goto err_pci_alloc;
2797 }
2798
2799 /* Bootstrap (instructions only, no data) */
2800 if (boot_size) {
2801 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002802 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002803
2804 if (!priv->ucode_boot.v_addr)
2805 goto err_pci_alloc;
2806 }
2807
Zhu Yib481de92007-09-25 17:54:57 -07002808 /* Copy images into buffers for card's bus-master reads ... */
2809
2810 /* Runtime instructions (first block of data in file) */
2811 src = &ucode->data[0];
2812 len = priv->ucode_code.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002813 IWL_DEBUG_INFO(priv,
2814 "Copying (but not loading) uCode instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002815 memcpy(priv->ucode_code.v_addr, src, len);
Tomas Winklere1623442009-01-27 14:27:56 -08002816 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002817 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
2818
2819 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002820 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
Zhu Yib481de92007-09-25 17:54:57 -07002821 src = &ucode->data[inst_size];
2822 len = priv->ucode_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002823 IWL_DEBUG_INFO(priv,
2824 "Copying (but not loading) uCode data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002825 memcpy(priv->ucode_data.v_addr, src, len);
2826 memcpy(priv->ucode_data_backup.v_addr, src, len);
2827
2828 /* Initialization instructions (3rd block) */
2829 if (init_size) {
2830 src = &ucode->data[inst_size + data_size];
2831 len = priv->ucode_init.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002832 IWL_DEBUG_INFO(priv,
2833 "Copying (but not loading) init instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002834 memcpy(priv->ucode_init.v_addr, src, len);
2835 }
2836
2837 /* Initialization data (4th block) */
2838 if (init_data_size) {
2839 src = &ucode->data[inst_size + data_size + init_size];
2840 len = priv->ucode_init_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002841 IWL_DEBUG_INFO(priv,
2842 "Copying (but not loading) init data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002843 memcpy(priv->ucode_init_data.v_addr, src, len);
2844 }
2845
2846 /* Bootstrap instructions (5th block) */
2847 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
2848 len = priv->ucode_boot.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002849 IWL_DEBUG_INFO(priv,
2850 "Copying (but not loading) boot instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002851 memcpy(priv->ucode_boot.v_addr, src, len);
2852
2853 /* We have our copies now, allow OS release its copies */
2854 release_firmware(ucode_raw);
2855 return 0;
2856
2857 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08002858 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002859 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002860 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002861
2862 err_release:
2863 release_firmware(ucode_raw);
2864
2865 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08002866 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002867}
2868
2869
2870/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002871 * iwl3945_set_ucode_ptrs - Set uCode address location
Zhu Yib481de92007-09-25 17:54:57 -07002872 *
2873 * Tell initialization uCode where to find runtime uCode.
2874 *
2875 * BSM registers initially contain pointers to initialization uCode.
2876 * We need to replace them to load runtime uCode inst and data,
2877 * and to save runtime data when powering down.
2878 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002879static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002880{
2881 dma_addr_t pinst;
2882 dma_addr_t pdata;
2883 int rc = 0;
2884 unsigned long flags;
2885
2886 /* bits 31:0 for 3945 */
2887 pinst = priv->ucode_code.p_addr;
2888 pdata = priv->ucode_data_backup.p_addr;
2889
2890 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002891 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002892 if (rc) {
2893 spin_unlock_irqrestore(&priv->lock, flags);
2894 return rc;
2895 }
2896
2897 /* Tell bootstrap uCode where to find image to load */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002898 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
2899 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
2900 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002901 priv->ucode_data.len);
2902
Tomas Winklera96a27f2008-10-23 23:48:56 -07002903 /* Inst byte count must be last to set up, bit 31 signals uCode
Zhu Yib481de92007-09-25 17:54:57 -07002904 * that all new ptr/size info is in place */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002905 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002906 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
2907
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002908 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002909
2910 spin_unlock_irqrestore(&priv->lock, flags);
2911
Tomas Winklere1623442009-01-27 14:27:56 -08002912 IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002913
2914 return rc;
2915}
2916
2917/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002918 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002919 *
2920 * Called after REPLY_ALIVE notification received from "initialize" uCode.
2921 *
Zhu Yib481de92007-09-25 17:54:57 -07002922 * Tell "initialize" uCode to go ahead and load the runtime uCode.
Ben Cahill9fbab512007-11-29 11:09:47 +08002923 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002924static void iwl3945_init_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002925{
2926 /* Check alive response for "valid" sign from uCode */
2927 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
2928 /* We had an error bringing up the hardware, so take it
2929 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002930 IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002931 goto restart;
2932 }
2933
2934 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
2935 * This is a paranoid check, because we would not have gotten the
2936 * "initialize" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002937 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002938 /* Runtime instruction load was bad;
2939 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002940 IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002941 goto restart;
2942 }
2943
2944 /* Send pointers to protocol/runtime uCode image ... init code will
2945 * load and launch runtime uCode, which will send us another "Alive"
2946 * notification. */
Tomas Winklere1623442009-01-27 14:27:56 -08002947 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002948 if (iwl3945_set_ucode_ptrs(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002949 /* Runtime instruction load won't happen;
2950 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002951 IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002952 goto restart;
2953 }
2954 return;
2955
2956 restart:
2957 queue_work(priv->workqueue, &priv->restart);
2958}
2959
2960
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08002961/* temporary */
2962static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw,
2963 struct sk_buff *skb);
2964
Zhu Yib481de92007-09-25 17:54:57 -07002965/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002966 * iwl3945_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002967 * from protocol/runtime uCode (initialization uCode's
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002968 * Alive gets handled by iwl3945_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07002969 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002970static void iwl3945_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002971{
2972 int rc = 0;
2973 int thermal_spin = 0;
2974 u32 rfkill;
2975
Tomas Winklere1623442009-01-27 14:27:56 -08002976 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002977
2978 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
2979 /* We had an error bringing up the hardware, so take it
2980 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002981 IWL_DEBUG_INFO(priv, "Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002982 goto restart;
2983 }
2984
2985 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
2986 * This is a paranoid check, because we would not have gotten the
2987 * "runtime" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002988 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002989 /* Runtime instruction load was bad;
2990 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002991 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002992 goto restart;
2993 }
2994
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002995 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002996
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002997 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002998 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002999 IWL_WARN(priv, "Can not read RFKILL status from adapter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003000 return;
3001 }
3002
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003003 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
Tomas Winklere1623442009-01-27 14:27:56 -08003004 IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003005 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003006
3007 if (rfkill & 0x1) {
3008 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winklera96a27f2008-10-23 23:48:56 -07003009 /* if RFKILL is not on, then wait for thermal
Zhu Yib481de92007-09-25 17:54:57 -07003010 * sensor in adapter to kick in */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003011 while (iwl3945_hw_get_temperature(priv) == 0) {
Zhu Yib481de92007-09-25 17:54:57 -07003012 thermal_spin++;
3013 udelay(10);
3014 }
3015
3016 if (thermal_spin)
Tomas Winklere1623442009-01-27 14:27:56 -08003017 IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n",
Zhu Yib481de92007-09-25 17:54:57 -07003018 thermal_spin * 10);
3019 } else
3020 set_bit(STATUS_RF_KILL_HW, &priv->status);
3021
Ben Cahill9fbab512007-11-29 11:09:47 +08003022 /* After the ALIVE response, we can send commands to 3945 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07003023 set_bit(STATUS_ALIVE, &priv->status);
3024
3025 /* Clear out the uCode error bit if it is set */
3026 clear_bit(STATUS_FW_ERROR, &priv->status);
3027
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003028 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003029 return;
3030
Johannes Berg36d68252008-05-15 12:55:26 +02003031 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07003032
3033 priv->active_rate = priv->rates_mask;
3034 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
3035
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08003036 iwl_power_update_mode(priv, false);
Zhu Yib481de92007-09-25 17:54:57 -07003037
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003038 if (iwl_is_associated(priv)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003039 struct iwl3945_rxon_cmd *active_rxon =
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003040 (struct iwl3945_rxon_cmd *)(&priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07003041
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003042 memcpy(&priv->staging_rxon, &priv->active_rxon,
3043 sizeof(priv->staging_rxon));
Zhu Yib481de92007-09-25 17:54:57 -07003044 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3045 } else {
3046 /* Initialize our rx_config data */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003047 iwl_connection_init_rx_config(priv, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003048 }
3049
Ben Cahill9fbab512007-11-29 11:09:47 +08003050 /* Configure Bluetooth device coexistence support */
Samuel Ortiz17f841c2009-01-23 13:45:20 -08003051 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003052
3053 /* Configure the adapter for unassociated operation */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003054 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003055
Zhu Yib481de92007-09-25 17:54:57 -07003056 iwl3945_reg_txpower_periodic(priv);
3057
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07003058 iwl3945_led_register(priv);
3059
Tomas Winklere1623442009-01-27 14:27:56 -08003060 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07003061 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a669262008-01-14 17:46:18 -08003062 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07003063
3064 if (priv->error_recovering)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003065 iwl3945_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003066
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003067 /* reassociate for ADHOC mode */
3068 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
3069 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
3070 priv->vif);
3071 if (beacon)
3072 iwl3945_mac_beacon_update(priv->hw, beacon);
3073 }
3074
Zhu Yib481de92007-09-25 17:54:57 -07003075 return;
3076
3077 restart:
3078 queue_work(priv->workqueue, &priv->restart);
3079}
3080
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003081static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07003082
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003083static void __iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003084{
3085 unsigned long flags;
3086 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
3087 struct ieee80211_conf *conf = NULL;
3088
Tomas Winklere1623442009-01-27 14:27:56 -08003089 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07003090
3091 conf = ieee80211_get_hw_conf(priv->hw);
3092
3093 if (!exit_pending)
3094 set_bit(STATUS_EXIT_PENDING, &priv->status);
3095
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07003096 iwl3945_led_unregister(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003097 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003098
3099 /* Unblock any waiting calls */
3100 wake_up_interruptible_all(&priv->wait_command_queue);
3101
Zhu Yib481de92007-09-25 17:54:57 -07003102 /* Wipe out the EXIT_PENDING status bit if we are not actually
3103 * exiting the module */
3104 if (!exit_pending)
3105 clear_bit(STATUS_EXIT_PENDING, &priv->status);
3106
3107 /* stop and reset the on-board processor */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003108 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07003109
3110 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003111 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08003112 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003113 spin_unlock_irqrestore(&priv->lock, flags);
3114 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003115
3116 if (priv->mac80211_registered)
3117 ieee80211_stop_queues(priv->hw);
3118
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003119 /* If we have not previously called iwl3945_init() then
Zhu Yib481de92007-09-25 17:54:57 -07003120 * clear all bits but the RF Kill and SUSPEND bits and return */
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003121 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003122 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3123 STATUS_RF_KILL_HW |
3124 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3125 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08003126 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3127 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07003128 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003129 STATUS_IN_SUSPEND |
3130 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3131 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07003132 goto exit;
3133 }
3134
3135 /* ...otherwise clear out all the status bits but the RF Kill and
3136 * SUSPEND bits and continue taking the NIC down. */
3137 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3138 STATUS_RF_KILL_HW |
3139 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3140 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08003141 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3142 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07003143 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
3144 STATUS_IN_SUSPEND |
3145 test_bit(STATUS_FW_ERROR, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003146 STATUS_FW_ERROR |
3147 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3148 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07003149
Abbas, Mohamede9414b62009-01-20 21:33:55 -08003150 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003151 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003152 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07003153 spin_unlock_irqrestore(&priv->lock, flags);
3154
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003155 iwl3945_hw_txq_ctx_stop(priv);
3156 iwl3945_hw_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003157
3158 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003159 if (!iwl_grab_nic_access(priv)) {
3160 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07003161 APMG_CLK_VAL_DMA_CLK_RQT);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003162 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003163 }
3164 spin_unlock_irqrestore(&priv->lock, flags);
3165
3166 udelay(5);
3167
Abbas, Mohamede9414b62009-01-20 21:33:55 -08003168 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
3169 priv->cfg->ops->lib->apm_ops.stop(priv);
3170 else
3171 priv->cfg->ops->lib->apm_ops.reset(priv);
3172
Zhu Yib481de92007-09-25 17:54:57 -07003173 exit:
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08003174 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07003175
3176 if (priv->ibss_beacon)
3177 dev_kfree_skb(priv->ibss_beacon);
3178 priv->ibss_beacon = NULL;
3179
3180 /* clear out any free frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003181 iwl3945_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003182}
3183
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003184static void iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003185{
3186 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003187 __iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003188 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08003189
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003190 iwl3945_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003191}
3192
3193#define MAX_HW_RESTARTS 5
3194
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003195static int __iwl3945_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003196{
3197 int rc, i;
3198
3199 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003200 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003201 return -EIO;
3202 }
3203
3204 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003205 IWL_WARN(priv, "Radio disabled by SW RF kill (module "
Zhu Yib481de92007-09-25 17:54:57 -07003206 "parameter)\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003207 return -ENODEV;
3208 }
3209
Reinette Chatree903fbd2008-01-30 22:05:15 -08003210 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003211 IWL_ERR(priv, "ucode not available for device bring up\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08003212 return -EIO;
3213 }
3214
Zhu Yie655b9f2008-01-24 02:19:38 -08003215 /* If platform's RF_KILL switch is NOT set to KILL */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003216 if (iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yie655b9f2008-01-24 02:19:38 -08003217 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3218 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3219 else {
3220 set_bit(STATUS_RF_KILL_HW, &priv->status);
3221 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003222 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003223 return -ENODEV;
3224 }
Zhu Yib481de92007-09-25 17:54:57 -07003225 }
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02003226
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003227 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07003228
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003229 rc = iwl3945_hw_nic_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003230 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003231 IWL_ERR(priv, "Unable to int nic\n");
Zhu Yib481de92007-09-25 17:54:57 -07003232 return rc;
3233 }
3234
3235 /* make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003236 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3237 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07003238 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
3239
3240 /* clear (again), then enable host interrupts */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003241 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08003242 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003243
3244 /* really make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003245 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3246 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07003247
3248 /* Copy original ucode data image from disk into backup cache.
3249 * This will be used to initialize the on-board processor's
3250 * data SRAM for a clean start when the runtime program first loads. */
3251 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a669262008-01-14 17:46:18 -08003252 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07003253
Zhu Yie655b9f2008-01-24 02:19:38 -08003254 /* We return success when we resume from suspend and rf_kill is on. */
3255 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
3256 return 0;
3257
Zhu Yib481de92007-09-25 17:54:57 -07003258 for (i = 0; i < MAX_HW_RESTARTS; i++) {
3259
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003260 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003261
3262 /* load bootstrap state machine,
3263 * load bootstrap program into processor's memory,
3264 * prepare to load the "initialize" uCode */
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08003265 priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003266
3267 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003268 IWL_ERR(priv,
3269 "Unable to set up bootstrap uCode: %d\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -07003270 continue;
3271 }
3272
3273 /* start card; "initialize" will load runtime ucode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003274 iwl3945_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003275
Tomas Winklere1623442009-01-27 14:27:56 -08003276 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003277
3278 return 0;
3279 }
3280
3281 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003282 __iwl3945_down(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003283 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003284
3285 /* tried to restart and config the device for as long as our
3286 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08003287 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07003288 return -EIO;
3289}
3290
3291
3292/*****************************************************************************
3293 *
3294 * Workqueue callbacks
3295 *
3296 *****************************************************************************/
3297
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003298static void iwl3945_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003299{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003300 struct iwl_priv *priv =
3301 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003302
3303 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3304 return;
3305
3306 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003307 iwl3945_init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003308 mutex_unlock(&priv->mutex);
3309}
3310
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003311static void iwl3945_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003312{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003313 struct iwl_priv *priv =
3314 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003315
3316 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3317 return;
3318
3319 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003320 iwl3945_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003321 mutex_unlock(&priv->mutex);
3322}
3323
Helmut Schaa26635162009-01-15 09:38:44 +01003324static void iwl3945_rfkill_poll(struct work_struct *data)
3325{
3326 struct iwl_priv *priv =
3327 container_of(data, struct iwl_priv, rfkill_poll.work);
3328 unsigned long status = priv->status;
3329
3330 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3331 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3332 else
3333 set_bit(STATUS_RF_KILL_HW, &priv->status);
3334
3335 if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status))
3336 queue_work(priv->workqueue, &priv->rf_kill);
3337
3338 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3339 round_jiffies_relative(2 * HZ));
3340
3341}
3342
Zhu Yib481de92007-09-25 17:54:57 -07003343#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003344static void iwl3945_bg_request_scan(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003345{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003346 struct iwl_priv *priv =
3347 container_of(data, struct iwl_priv, request_scan);
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08003348 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07003349 .id = REPLY_SCAN_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003350 .len = sizeof(struct iwl3945_scan_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07003351 .meta.flags = CMD_SIZE_HUGE,
3352 };
3353 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003354 struct iwl3945_scan_cmd *scan;
Zhu Yib481de92007-09-25 17:54:57 -07003355 struct ieee80211_conf *conf = NULL;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003356 u8 n_probes = 2;
Johannes Berg8318d782008-01-24 19:38:38 +01003357 enum ieee80211_band band;
John W. Linville9387b7c2008-09-30 20:59:05 -04003358 DECLARE_SSID_BUF(ssid);
Zhu Yib481de92007-09-25 17:54:57 -07003359
3360 conf = ieee80211_get_hw_conf(priv->hw);
3361
3362 mutex_lock(&priv->mutex);
3363
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003364 if (!iwl_is_ready(priv)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003365 IWL_WARN(priv, "request scan called when driver not ready.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003366 goto done;
3367 }
3368
Tomas Winklera96a27f2008-10-23 23:48:56 -07003369 /* Make sure the scan wasn't canceled before this queued work
Zhu Yib481de92007-09-25 17:54:57 -07003370 * was given the chance to run... */
3371 if (!test_bit(STATUS_SCANNING, &priv->status))
3372 goto done;
3373
3374 /* This should never be called or scheduled if there is currently
3375 * a scan active in the hardware. */
3376 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003377 IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests "
3378 "Ignoring second request.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003379 rc = -EIO;
3380 goto done;
3381 }
3382
3383 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003384 IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n");
Zhu Yib481de92007-09-25 17:54:57 -07003385 goto done;
3386 }
3387
3388 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003389 IWL_DEBUG_HC(priv,
3390 "Scan request while abort pending. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003391 goto done;
3392 }
3393
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003394 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003395 IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n");
Zhu Yib481de92007-09-25 17:54:57 -07003396 goto done;
3397 }
3398
3399 if (!test_bit(STATUS_READY, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003400 IWL_DEBUG_HC(priv,
3401 "Scan request while uninitialized. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003402 goto done;
3403 }
3404
3405 if (!priv->scan_bands) {
Tomas Winklere1623442009-01-27 14:27:56 -08003406 IWL_DEBUG_HC(priv, "Aborting scan due to no requested bands\n");
Zhu Yib481de92007-09-25 17:54:57 -07003407 goto done;
3408 }
3409
Winkler, Tomas805cee52009-01-19 15:30:28 -08003410 if (!priv->scan) {
3411 priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
Zhu Yib481de92007-09-25 17:54:57 -07003412 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
Winkler, Tomas805cee52009-01-19 15:30:28 -08003413 if (!priv->scan) {
Zhu Yib481de92007-09-25 17:54:57 -07003414 rc = -ENOMEM;
3415 goto done;
3416 }
3417 }
Winkler, Tomas805cee52009-01-19 15:30:28 -08003418 scan = priv->scan;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003419 memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07003420
3421 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
3422 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
3423
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003424 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003425 u16 interval = 0;
3426 u32 extra;
3427 u32 suspend_time = 100;
3428 u32 scan_suspend_time = 100;
3429 unsigned long flags;
3430
Tomas Winklere1623442009-01-27 14:27:56 -08003431 IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
Zhu Yib481de92007-09-25 17:54:57 -07003432
3433 spin_lock_irqsave(&priv->lock, flags);
3434 interval = priv->beacon_int;
3435 spin_unlock_irqrestore(&priv->lock, flags);
3436
3437 scan->suspend_time = 0;
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003438 scan->max_out_time = cpu_to_le32(200 * 1024);
Zhu Yib481de92007-09-25 17:54:57 -07003439 if (!interval)
3440 interval = suspend_time;
3441 /*
3442 * suspend time format:
3443 * 0-19: beacon interval in usec (time before exec.)
3444 * 20-23: 0
3445 * 24-31: number of beacons (suspend between channels)
3446 */
3447
3448 extra = (suspend_time / interval) << 24;
3449 scan_suspend_time = 0xFF0FFFFF &
3450 (extra | ((suspend_time % interval) * 1024));
3451
3452 scan->suspend_time = cpu_to_le32(scan_suspend_time);
Tomas Winklere1623442009-01-27 14:27:56 -08003453 IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003454 scan_suspend_time, interval);
3455 }
3456
3457 /* We should add the ability for user to lock to PASSIVE ONLY */
3458 if (priv->one_direct_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08003459 IWL_DEBUG_SCAN(priv, "Kicking off one direct scan for '%s'\n",
3460 print_ssid(ssid, priv->direct_ssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04003461 priv->direct_ssid_len));
Zhu Yib481de92007-09-25 17:54:57 -07003462 scan->direct_scan[0].id = WLAN_EID_SSID;
3463 scan->direct_scan[0].len = priv->direct_ssid_len;
3464 memcpy(scan->direct_scan[0].ssid,
3465 priv->direct_ssid, priv->direct_ssid_len);
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003466 n_probes++;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003467 } else
Tomas Winklere1623442009-01-27 14:27:56 -08003468 IWL_DEBUG_SCAN(priv, "Kicking off one indirect scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003469
3470 /* We don't build a direct scan probe request; the uCode will do
3471 * that based on the direct_mask added to each channel entry */
Zhu Yib481de92007-09-25 17:54:57 -07003472 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08003473 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07003474 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
3475
3476 /* flags + rate selection */
3477
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003478 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003479 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
3480 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
3481 scan->good_CRC_th = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01003482 band = IEEE80211_BAND_2GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003483 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003484 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
3485 scan->good_CRC_th = IWL_GOOD_CRC_TH;
Johannes Berg8318d782008-01-24 19:38:38 +01003486 band = IEEE80211_BAND_5GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003487 } else {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003488 IWL_WARN(priv, "Invalid scan band count\n");
Zhu Yib481de92007-09-25 17:54:57 -07003489 goto done;
3490 }
3491
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08003492 scan->tx_cmd.len = cpu_to_le16(
3493 iwl_fill_probe_req(priv, band,
3494 (struct ieee80211_mgmt *)scan->data,
3495 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
3496
Zhu Yib481de92007-09-25 17:54:57 -07003497 /* select Rx antennas */
3498 scan->flags |= iwl3945_get_antenna_flags(priv);
3499
Johannes Berg05c914f2008-09-11 00:01:58 +02003500 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
Zhu Yib481de92007-09-25 17:54:57 -07003501 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
3502
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003503 scan->channel_count =
3504 iwl3945_get_channels_for_scan(priv, band, 1, /* active */
3505 n_probes,
3506 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
Zhu Yib481de92007-09-25 17:54:57 -07003507
Reinette Chatre14b54332008-11-04 12:21:35 -08003508 if (scan->channel_count == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08003509 IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
Reinette Chatre14b54332008-11-04 12:21:35 -08003510 goto done;
3511 }
3512
Zhu Yib481de92007-09-25 17:54:57 -07003513 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003514 scan->channel_count * sizeof(struct iwl3945_scan_channel);
Zhu Yib481de92007-09-25 17:54:57 -07003515 cmd.data = scan;
3516 scan->len = cpu_to_le16(cmd.len);
3517
3518 set_bit(STATUS_SCAN_HW, &priv->status);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003519 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07003520 if (rc)
3521 goto done;
3522
3523 queue_delayed_work(priv->workqueue, &priv->scan_check,
3524 IWL_SCAN_CHECK_WATCHDOG);
3525
3526 mutex_unlock(&priv->mutex);
3527 return;
3528
3529 done:
Mohamed Abbas2420ebc2008-11-04 12:21:34 -08003530 /* can not perform scan make sure we clear scanning
3531 * bits from status so next scan request can be performed.
3532 * if we dont clear scanning status bit here all next scan
3533 * will fail
3534 */
3535 clear_bit(STATUS_SCAN_HW, &priv->status);
3536 clear_bit(STATUS_SCANNING, &priv->status);
3537
Ian Schram01ebd062007-10-25 17:15:22 +08003538 /* inform mac80211 scan aborted */
Zhu Yib481de92007-09-25 17:54:57 -07003539 queue_work(priv->workqueue, &priv->scan_completed);
3540 mutex_unlock(&priv->mutex);
3541}
3542
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003543static void iwl3945_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003544{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003545 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07003546
3547 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3548 return;
3549
3550 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003551 __iwl3945_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003552 mutex_unlock(&priv->mutex);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003553 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003554}
3555
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003556static void iwl3945_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003557{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003558 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07003559
3560 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3561 return;
3562
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003563 iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003564 queue_work(priv->workqueue, &priv->up);
3565}
3566
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003567static void iwl3945_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003568{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003569 struct iwl_priv *priv =
3570 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07003571
3572 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3573 return;
3574
3575 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003576 iwl3945_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003577 mutex_unlock(&priv->mutex);
3578}
3579
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003580#define IWL_DELAY_NEXT_SCAN (HZ*2)
3581
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003582static void iwl3945_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003583{
Zhu Yib481de92007-09-25 17:54:57 -07003584 int rc = 0;
3585 struct ieee80211_conf *conf = NULL;
3586
Johannes Berg05c914f2008-09-11 00:01:58 +02003587 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003588 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07003589 return;
3590 }
3591
3592
Tomas Winklere1623442009-01-27 14:27:56 -08003593 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003594 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07003595
3596 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3597 return;
3598
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003599 if (!priv->vif || !priv->is_open)
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003600 return;
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003601
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003602 iwl_scan_cancel_timeout(priv, 200);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003603
Zhu Yib481de92007-09-25 17:54:57 -07003604 conf = ieee80211_get_hw_conf(priv->hw);
3605
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003606 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003607 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003608
Tomas Winkler28afaf92008-12-19 10:37:06 +08003609 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003610 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003611 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07003612 sizeof(priv->rxon_timing), &priv->rxon_timing);
3613 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003614 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003615 "Attempting to continue.\n");
3616
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003617 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003618
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003619 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003620
Tomas Winklere1623442009-01-27 14:27:56 -08003621 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003622 priv->assoc_id, priv->beacon_int);
3623
3624 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003625 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003626 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003627 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003628
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003629 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003630 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003631 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003632 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003633 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003634
Johannes Berg05c914f2008-09-11 00:01:58 +02003635 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003636 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003637
3638 }
3639
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003640 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003641
3642 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02003643 case NL80211_IFTYPE_STATION:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003644 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07003645 break;
3646
Johannes Berg05c914f2008-09-11 00:01:58 +02003647 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07003648
Abhijeet Kolekarce546fd2008-11-19 15:32:22 -08003649 priv->assoc_id = 1;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003650 iwl3945_add_station(priv, priv->bssid, 0, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003651 iwl3945_sync_sta(priv, IWL_STA_ID,
Johannes Berg8318d782008-01-24 19:38:38 +01003652 (priv->band == IEEE80211_BAND_5GHZ) ?
Zhu Yib481de92007-09-25 17:54:57 -07003653 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
3654 CMD_ASYNC);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003655 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
3656 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003657
3658 break;
3659
3660 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08003661 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003662 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003663 break;
3664 }
3665
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003666 iwl3945_activate_qos(priv, 0);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08003667
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003668 /* we have just associated, don't start scan too early */
3669 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08003670}
3671
Johannes Berge8975582008-10-09 12:18:51 +02003672static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003673
Zhu Yib481de92007-09-25 17:54:57 -07003674/*****************************************************************************
3675 *
3676 * mac80211 entry point functions
3677 *
3678 *****************************************************************************/
3679
Zhu Yi5a669262008-01-14 17:46:18 -08003680#define UCODE_READY_TIMEOUT (2 * HZ)
3681
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003682static int iwl3945_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003683{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003684 struct iwl_priv *priv = hw->priv;
Zhu Yi5a669262008-01-14 17:46:18 -08003685 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003686
Tomas Winklere1623442009-01-27 14:27:56 -08003687 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003688
3689 /* we should be verifying the device is ready to be opened */
3690 mutex_lock(&priv->mutex);
3691
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003692 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
Zhu Yi5a669262008-01-14 17:46:18 -08003693 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
3694 * ucode filename and max sizes are card-specific. */
3695
3696 if (!priv->ucode_code.len) {
3697 ret = iwl3945_read_ucode(priv);
3698 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003699 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a669262008-01-14 17:46:18 -08003700 mutex_unlock(&priv->mutex);
3701 goto out_release_irq;
3702 }
3703 }
3704
Zhu Yie655b9f2008-01-24 02:19:38 -08003705 ret = __iwl3945_up(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08003706
Zhu Yib481de92007-09-25 17:54:57 -07003707 mutex_unlock(&priv->mutex);
Zhu Yi5a669262008-01-14 17:46:18 -08003708
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003709 iwl_rfkill_set_hw_state(priv);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02003710
Zhu Yie655b9f2008-01-24 02:19:38 -08003711 if (ret)
3712 goto out_release_irq;
3713
Tomas Winklere1623442009-01-27 14:27:56 -08003714 IWL_DEBUG_INFO(priv, "Start UP work.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003715
3716 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
3717 return 0;
3718
Zhu Yi5a669262008-01-14 17:46:18 -08003719 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
3720 * mac80211 will not be run successfully. */
3721 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
3722 test_bit(STATUS_READY, &priv->status),
3723 UCODE_READY_TIMEOUT);
3724 if (!ret) {
3725 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003726 IWL_ERR(priv,
3727 "Wait for START_ALIVE timeout after %dms.\n",
3728 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Zhu Yi5a669262008-01-14 17:46:18 -08003729 ret = -ETIMEDOUT;
3730 goto out_release_irq;
3731 }
3732 }
3733
Helmut Schaa26635162009-01-15 09:38:44 +01003734 /* ucode is running and will send rfkill notifications,
3735 * no need to poll the killswitch state anymore */
3736 cancel_delayed_work(&priv->rfkill_poll);
3737
Zhu Yie655b9f2008-01-24 02:19:38 -08003738 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08003739 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003740 return 0;
Zhu Yi5a669262008-01-14 17:46:18 -08003741
3742out_release_irq:
Zhu Yie655b9f2008-01-24 02:19:38 -08003743 priv->is_open = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08003744 IWL_DEBUG_MAC80211(priv, "leave - failed\n");
Zhu Yi5a669262008-01-14 17:46:18 -08003745 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003746}
3747
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003748static void iwl3945_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003749{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003750 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003751
Tomas Winklere1623442009-01-27 14:27:56 -08003752 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003753
Zhu Yie655b9f2008-01-24 02:19:38 -08003754 if (!priv->is_open) {
Tomas Winklere1623442009-01-27 14:27:56 -08003755 IWL_DEBUG_MAC80211(priv, "leave - skip\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003756 return;
3757 }
3758
Zhu Yib481de92007-09-25 17:54:57 -07003759 priv->is_open = 0;
Zhu Yi5a669262008-01-14 17:46:18 -08003760
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003761 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08003762 /* stop mac, cancel any scan request and clear
3763 * RXON_FILTER_ASSOC_MSK BIT
3764 */
Zhu Yi5a669262008-01-14 17:46:18 -08003765 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003766 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003767 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003768 }
3769
Zhu Yi5a669262008-01-14 17:46:18 -08003770 iwl3945_down(priv);
3771
3772 flush_workqueue(priv->workqueue);
Helmut Schaa26635162009-01-15 09:38:44 +01003773
3774 /* start polling the killswitch state again */
3775 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3776 round_jiffies_relative(2 * HZ));
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003777
Tomas Winklere1623442009-01-27 14:27:56 -08003778 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003779}
3780
Johannes Berge039fa42008-05-15 12:55:29 +02003781static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003782{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003783 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003784
Tomas Winklere1623442009-01-27 14:27:56 -08003785 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003786
Tomas Winklere1623442009-01-27 14:27:56 -08003787 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02003788 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07003789
Johannes Berge039fa42008-05-15 12:55:29 +02003790 if (iwl3945_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07003791 dev_kfree_skb_any(skb);
3792
Tomas Winklere1623442009-01-27 14:27:56 -08003793 IWL_DEBUG_MAC80211(priv, "leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08003794 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07003795}
3796
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003797static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003798 struct ieee80211_if_init_conf *conf)
3799{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003800 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003801 unsigned long flags;
3802
Tomas Winklere1623442009-01-27 14:27:56 -08003803 IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07003804
Johannes Berg32bfd352007-12-19 01:31:26 +01003805 if (priv->vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08003806 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
Tomas Winkler864792e2007-11-27 21:00:52 +02003807 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07003808 }
3809
3810 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01003811 priv->vif = conf->vif;
Zhu, Yi60294de2008-10-29 14:05:45 -07003812 priv->iw_mode = conf->type;
Zhu Yib481de92007-09-25 17:54:57 -07003813
3814 spin_unlock_irqrestore(&priv->lock, flags);
3815
3816 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02003817
3818 if (conf->mac_addr) {
Tomas Winklere1623442009-01-27 14:27:56 -08003819 IWL_DEBUG_MAC80211(priv, "Set: %pM\n", conf->mac_addr);
Tomas Winkler864792e2007-11-27 21:00:52 +02003820 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
3821 }
3822
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003823 if (iwl_is_ready(priv))
Zhu Yi5a669262008-01-14 17:46:18 -08003824 iwl3945_set_mode(priv, conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07003825
Zhu Yib481de92007-09-25 17:54:57 -07003826 mutex_unlock(&priv->mutex);
3827
Tomas Winklere1623442009-01-27 14:27:56 -08003828 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003829 return 0;
3830}
3831
3832/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003833 * iwl3945_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07003834 *
3835 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
3836 * be set inappropriately and the driver currently sets the hardware up to
3837 * use it whenever needed.
3838 */
Johannes Berge8975582008-10-09 12:18:51 +02003839static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed)
Zhu Yib481de92007-09-25 17:54:57 -07003840{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003841 struct iwl_priv *priv = hw->priv;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08003842 const struct iwl_channel_info *ch_info;
Johannes Berge8975582008-10-09 12:18:51 +02003843 struct ieee80211_conf *conf = &hw->conf;
Zhu Yib481de92007-09-25 17:54:57 -07003844 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08003845 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003846
3847 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08003848 IWL_DEBUG_MAC80211(priv, "enter to channel %d\n",
3849 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07003850
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003851 if (!iwl_is_ready(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003852 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08003853 ret = -EIO;
3854 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003855 }
3856
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08003857 if (unlikely(!iwl3945_mod_params.disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07003858 test_bit(STATUS_SCANNING, &priv->status))) {
Tomas Winklere1623442009-01-27 14:27:56 -08003859 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
Zhu Yia0646472007-12-20 14:10:01 +08003860 set_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003861 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08003862 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07003863 }
3864
3865 spin_lock_irqsave(&priv->lock, flags);
3866
Samuel Ortize6148912009-01-23 13:45:15 -08003867 ch_info = iwl_get_channel_info(priv, conf->channel->band,
3868 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07003869 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003870 IWL_DEBUG_SCAN(priv,
3871 "Channel %d [%d] is INVALID for this band.\n",
3872 conf->channel->hw_value, conf->channel->band);
3873 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
Zhu Yib481de92007-09-25 17:54:57 -07003874 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003875 ret = -EINVAL;
3876 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003877 }
3878
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003879 iwl_set_rxon_channel(priv, conf->channel);
Zhu Yib481de92007-09-25 17:54:57 -07003880
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003881 iwl_set_flags_for_band(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07003882
3883 /* The list of supported rates and rate mask can be different
3884 * for each phymode; since the phymode may have changed, reset
3885 * the rate mask to what mac80211 lists */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003886 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003887
3888 spin_unlock_irqrestore(&priv->lock, flags);
3889
3890#ifdef IEEE80211_CONF_CHANNEL_SWITCH
3891 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003892 iwl3945_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003893 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003894 }
3895#endif
3896
Abhijeet Kolekar7dc45f22009-02-18 15:54:32 -08003897 if (conf->radio_enabled && iwl_radio_kill_sw_enable_radio(priv)) {
3898 IWL_DEBUG_MAC80211(priv, "leave - RF-KILL - waiting for uCode\n");
3899 goto out;
3900 }
Zhu Yib481de92007-09-25 17:54:57 -07003901
3902 if (!conf->radio_enabled) {
Abhijeet Kolekar7dc45f22009-02-18 15:54:32 -08003903 iwl_radio_kill_sw_disable_radio(priv);
Tomas Winklere1623442009-01-27 14:27:56 -08003904 IWL_DEBUG_MAC80211(priv, "leave - radio disabled\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08003905 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003906 }
3907
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003908 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003909 IWL_DEBUG_MAC80211(priv, "leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08003910 ret = -EIO;
3911 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003912 }
3913
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003914 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003915
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003916 if (memcmp(&priv->active_rxon,
3917 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003918 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003919 else
Tomas Winklere1623442009-01-27 14:27:56 -08003920 IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration\n");
Zhu Yib481de92007-09-25 17:54:57 -07003921
Tomas Winklere1623442009-01-27 14:27:56 -08003922 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003923
Zhu Yi76bb77e2007-11-22 10:53:22 +08003924out:
Zhu Yia0646472007-12-20 14:10:01 +08003925 clear_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003926 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003927 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003928}
3929
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003930static void iwl3945_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003931{
3932 int rc = 0;
3933
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08003934 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07003935 return;
3936
3937 /* The following should be done only at AP bring up */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003938 if (!(iwl_is_associated(priv))) {
Zhu Yib481de92007-09-25 17:54:57 -07003939
3940 /* RXON - unassoc (to set timing command) */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003941 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003942 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003943
3944 /* RXON Timing */
Tomas Winkler28afaf92008-12-19 10:37:06 +08003945 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003946 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003947 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
3948 sizeof(priv->rxon_timing),
3949 &priv->rxon_timing);
Zhu Yib481de92007-09-25 17:54:57 -07003950 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003951 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003952 "Attempting to continue.\n");
3953
3954 /* FIXME: what should be the assoc_id for AP? */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003955 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003956 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003957 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003958 RXON_FLG_SHORT_PREAMBLE_MSK;
3959 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003960 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003961 ~RXON_FLG_SHORT_PREAMBLE_MSK;
3962
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003963 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003964 if (priv->assoc_capability &
3965 WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003966 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003967 RXON_FLG_SHORT_SLOT_MSK;
3968 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003969 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003970 ~RXON_FLG_SHORT_SLOT_MSK;
3971
Johannes Berg05c914f2008-09-11 00:01:58 +02003972 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003973 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003974 ~RXON_FLG_SHORT_SLOT_MSK;
3975 }
3976 /* restore RXON assoc */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003977 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003978 iwl3945_commit_rxon(priv);
Kolekar, Abhijeetb5323d32008-12-19 10:37:22 +08003979 iwl3945_add_station(priv, iwl_bcast_addr, 0, 0);
Zhu Yi556f8db2007-09-27 11:27:33 +08003980 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003981 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003982
3983 /* FIXME - we need to add code here to detect a totally new
3984 * configuration, reset the AP, unassoc, rxon timing, assoc,
3985 * clear sta table, add BCAST sta... */
3986}
3987
Johannes Berg32bfd352007-12-19 01:31:26 +01003988static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
3989 struct ieee80211_vif *vif,
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003990 struct ieee80211_if_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07003991{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003992 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003993 int rc;
3994
3995 if (conf == NULL)
3996 return -EIO;
3997
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08003998 if (priv->vif != vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08003999 IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08004000 return 0;
4001 }
4002
Johannes Berg9d139c82008-07-09 14:40:37 +02004003 /* handle this temporarily here */
Johannes Berg05c914f2008-09-11 00:01:58 +02004004 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Johannes Berg9d139c82008-07-09 14:40:37 +02004005 conf->changed & IEEE80211_IFCC_BEACON) {
4006 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
4007 if (!beacon)
4008 return -ENOMEM;
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08004009 mutex_lock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02004010 rc = iwl3945_mac_beacon_update(hw, beacon);
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08004011 mutex_unlock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02004012 if (rc)
4013 return rc;
4014 }
4015
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004016 if (!iwl_is_alive(priv))
Zhu Yi5a669262008-01-14 17:46:18 -08004017 return -EAGAIN;
4018
Zhu Yib481de92007-09-25 17:54:57 -07004019 mutex_lock(&priv->mutex);
4020
Zhu Yib481de92007-09-25 17:54:57 -07004021 if (conf->bssid)
Tomas Winklere1623442009-01-27 14:27:56 -08004022 IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07004023
Johannes Berg4150c572007-09-17 01:29:23 -04004024/*
4025 * very dubious code was here; the probe filtering flag is never set:
4026 *
Zhu Yib481de92007-09-25 17:54:57 -07004027 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
4028 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04004029 */
Zhu Yib481de92007-09-25 17:54:57 -07004030
Johannes Berg05c914f2008-09-11 00:01:58 +02004031 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07004032 if (!conf->bssid) {
4033 conf->bssid = priv->mac_addr;
4034 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08004035 IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07004036 conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07004037 }
4038 if (priv->ibss_beacon)
4039 dev_kfree_skb(priv->ibss_beacon);
4040
Johannes Berg9d139c82008-07-09 14:40:37 +02004041 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
Zhu Yib481de92007-09-25 17:54:57 -07004042 }
4043
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004044 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08004045 goto done;
4046
Zhu Yib481de92007-09-25 17:54:57 -07004047 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
4048 !is_multicast_ether_addr(conf->bssid)) {
4049 /* If there is currently a HW scan going on in the background
4050 * then we need to cancel it else the RXON below will fail. */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004051 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004052 IWL_WARN(priv, "Aborted scan still in progress "
Zhu Yib481de92007-09-25 17:54:57 -07004053 "after 100ms\n");
Tomas Winklere1623442009-01-27 14:27:56 -08004054 IWL_DEBUG_MAC80211(priv, "leaving:scan abort failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07004055 mutex_unlock(&priv->mutex);
4056 return -EAGAIN;
4057 }
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004058 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07004059
4060 /* TODO: Audit driver for usage of these members and see
4061 * if mac80211 deprecates them (priv->bssid looks like it
4062 * shouldn't be there, but I haven't scanned the IBSS code
4063 * to verify) - jpk */
4064 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
4065
Johannes Berg05c914f2008-09-11 00:01:58 +02004066 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004067 iwl3945_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004068 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004069 rc = iwl3945_commit_rxon(priv);
Johannes Berg05c914f2008-09-11 00:01:58 +02004070 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004071 iwl3945_add_station(priv,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004072 priv->active_rxon.bssid_addr, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004073 }
4074
4075 } else {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004076 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004077 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004078 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004079 }
4080
Mohamed Abbasfde35712007-11-29 11:10:15 +08004081 done:
Tomas Winklere1623442009-01-27 14:27:56 -08004082 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004083 mutex_unlock(&priv->mutex);
4084
4085 return 0;
4086}
4087
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004088static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004089 struct ieee80211_if_init_conf *conf)
4090{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004091 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004092
Tomas Winklere1623442009-01-27 14:27:56 -08004093 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004094
4095 mutex_lock(&priv->mutex);
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004096
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004097 if (iwl_is_ready_rf(priv)) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004098 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004099 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Mohamed Abbasfde35712007-11-29 11:10:15 +08004100 iwl3945_commit_rxon(priv);
4101 }
Johannes Berg32bfd352007-12-19 01:31:26 +01004102 if (priv->vif == conf->vif) {
4103 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07004104 memset(priv->bssid, 0, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07004105 }
4106 mutex_unlock(&priv->mutex);
4107
Tomas Winklere1623442009-01-27 14:27:56 -08004108 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004109}
4110
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004111#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
4112
4113static void iwl3945_bss_info_changed(struct ieee80211_hw *hw,
4114 struct ieee80211_vif *vif,
4115 struct ieee80211_bss_conf *bss_conf,
4116 u32 changes)
4117{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004118 struct iwl_priv *priv = hw->priv;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004119
Tomas Winklere1623442009-01-27 14:27:56 -08004120 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004121
4122 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
Tomas Winklere1623442009-01-27 14:27:56 -08004123 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004124 bss_conf->use_short_preamble);
4125 if (bss_conf->use_short_preamble)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004126 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004127 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004128 priv->staging_rxon.flags &=
4129 ~RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004130 }
4131
4132 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
Tomas Winklere1623442009-01-27 14:27:56 -08004133 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n",
4134 bss_conf->use_cts_prot);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004135 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004136 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004137 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004138 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004139 }
4140
4141 if (changes & BSS_CHANGED_ASSOC) {
Tomas Winklere1623442009-01-27 14:27:56 -08004142 IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004143 /* This should never happen as this function should
4144 * never be called from interrupt context. */
4145 if (WARN_ON_ONCE(in_interrupt()))
4146 return;
4147 if (bss_conf->assoc) {
4148 priv->assoc_id = bss_conf->aid;
4149 priv->beacon_int = bss_conf->beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08004150 priv->timestamp = bss_conf->timestamp;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004151 priv->assoc_capability = bss_conf->assoc_capability;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08004152 priv->power_data.dtim_period = bss_conf->dtim_period;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004153 priv->next_scan_jiffies = jiffies +
4154 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
4155 mutex_lock(&priv->mutex);
4156 iwl3945_post_associate(priv);
4157 mutex_unlock(&priv->mutex);
4158 } else {
4159 priv->assoc_id = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08004160 IWL_DEBUG_MAC80211(priv,
4161 "DISASSOC %d\n", bss_conf->assoc);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004162 }
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004163 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
Tomas Winklere1623442009-01-27 14:27:56 -08004164 IWL_DEBUG_MAC80211(priv,
4165 "Associated Changes %d\n", changes);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004166 iwl3945_send_rxon_assoc(priv);
4167 }
4168
4169}
4170
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004171static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01004172 struct ieee80211_vif *vif,
4173 struct ieee80211_sta *sta,
4174 struct ieee80211_key_conf *key)
Zhu Yib481de92007-09-25 17:54:57 -07004175{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004176 struct iwl_priv *priv = hw->priv;
Johannes Bergdc822b52008-12-29 12:55:09 +01004177 const u8 *addr;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08004178 int ret = 0;
4179 u8 sta_id = IWL_INVALID_STATION;
4180 u8 static_key;
Zhu Yib481de92007-09-25 17:54:57 -07004181
Tomas Winklere1623442009-01-27 14:27:56 -08004182 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004183
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004184 if (iwl3945_mod_params.sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08004185 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07004186 return -EOPNOTSUPP;
4187 }
4188
Winkler, Tomas42986792009-01-19 15:30:22 -08004189 addr = sta ? sta->addr : iwl_bcast_addr;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08004190 static_key = !iwl_is_associated(priv);
4191
4192 if (!static_key) {
4193 sta_id = iwl3945_hw_find_station(priv, addr);
4194 if (sta_id == IWL_INVALID_STATION) {
4195 IWL_DEBUG_MAC80211(priv, "leave - %pMnot in station map.\n",
4196 addr);
4197 return -EINVAL;
4198 }
Zhu Yib481de92007-09-25 17:54:57 -07004199 }
4200
4201 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004202 iwl_scan_cancel_timeout(priv, 100);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08004203 mutex_unlock(&priv->mutex);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004204
Zhu Yib481de92007-09-25 17:54:57 -07004205 switch (cmd) {
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08004206 case SET_KEY:
4207 if (static_key)
4208 ret = iwl3945_set_static_key(priv, key);
4209 else
4210 ret = iwl3945_set_dynamic_key(priv, key, sta_id);
4211 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07004212 break;
4213 case DISABLE_KEY:
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08004214 if (static_key)
4215 ret = iwl3945_remove_static_key(priv);
4216 else
4217 ret = iwl3945_clear_sta_key_info(priv, sta_id);
4218 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07004219 break;
4220 default:
Winkler, Tomas42986792009-01-19 15:30:22 -08004221 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07004222 }
4223
Tomas Winklere1623442009-01-27 14:27:56 -08004224 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004225
Winkler, Tomas42986792009-01-19 15:30:22 -08004226 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004227}
4228
Johannes Berge100bb62008-04-30 18:51:21 +02004229static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
Zhu Yib481de92007-09-25 17:54:57 -07004230 const struct ieee80211_tx_queue_params *params)
4231{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004232 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004233 unsigned long flags;
4234 int q;
Zhu Yib481de92007-09-25 17:54:57 -07004235
Tomas Winklere1623442009-01-27 14:27:56 -08004236 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004237
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004238 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004239 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004240 return -EIO;
4241 }
4242
4243 if (queue >= AC_NUM) {
Tomas Winklere1623442009-01-27 14:27:56 -08004244 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
Zhu Yib481de92007-09-25 17:54:57 -07004245 return 0;
4246 }
4247
Zhu Yib481de92007-09-25 17:54:57 -07004248 q = AC_NUM - 1 - queue;
4249
4250 spin_lock_irqsave(&priv->lock, flags);
4251
4252 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
4253 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
4254 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
4255 priv->qos_data.def_qos_parm.ac[q].edca_txop =
Johannes Berg3330d7b2008-02-10 16:49:38 +01004256 cpu_to_le16((params->txop * 32));
Zhu Yib481de92007-09-25 17:54:57 -07004257
4258 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
4259 priv->qos_data.qos_active = 1;
4260
4261 spin_unlock_irqrestore(&priv->lock, flags);
4262
4263 mutex_lock(&priv->mutex);
Johannes Berg05c914f2008-09-11 00:01:58 +02004264 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004265 iwl3945_activate_qos(priv, 1);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004266 else if (priv->assoc_id && iwl_is_associated(priv))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004267 iwl3945_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004268
4269 mutex_unlock(&priv->mutex);
4270
Tomas Winklere1623442009-01-27 14:27:56 -08004271 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004272 return 0;
4273}
4274
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004275static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004276 struct ieee80211_tx_queue_stats *stats)
4277{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004278 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004279 int i, avail;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08004280 struct iwl_tx_queue *txq;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004281 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07004282 unsigned long flags;
4283
Tomas Winklere1623442009-01-27 14:27:56 -08004284 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004285
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004286 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004287 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004288 return -EIO;
4289 }
4290
4291 spin_lock_irqsave(&priv->lock, flags);
4292
4293 for (i = 0; i < AC_NUM; i++) {
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08004294 txq = &priv->txq[i];
Zhu Yib481de92007-09-25 17:54:57 -07004295 q = &txq->q;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004296 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07004297
Johannes Berg57ffc582008-04-29 17:18:59 +02004298 stats[i].len = q->n_window - avail;
4299 stats[i].limit = q->n_window - q->high_mark;
4300 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07004301
4302 }
4303 spin_unlock_irqrestore(&priv->lock, flags);
4304
Tomas Winklere1623442009-01-27 14:27:56 -08004305 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004306
4307 return 0;
4308}
4309
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004310static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07004311{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004312 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004313 unsigned long flags;
4314
4315 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08004316 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004317
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004318 iwl_reset_qos(priv);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08004319
Zhu Yib481de92007-09-25 17:54:57 -07004320 spin_lock_irqsave(&priv->lock, flags);
4321 priv->assoc_id = 0;
4322 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004323
4324 /* new association get rid of ibss beacon skb */
4325 if (priv->ibss_beacon)
4326 dev_kfree_skb(priv->ibss_beacon);
4327
4328 priv->ibss_beacon = NULL;
4329
4330 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08004331 priv->timestamp = 0;
Johannes Berg05c914f2008-09-11 00:01:58 +02004332 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
Zhu Yib481de92007-09-25 17:54:57 -07004333 priv->beacon_int = 0;
4334
4335 spin_unlock_irqrestore(&priv->lock, flags);
4336
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004337 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004338 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +08004339 mutex_unlock(&priv->mutex);
4340 return;
4341 }
4342
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004343 /* we are restarting association process
4344 * clear RXON_FILTER_ASSOC_MSK bit
4345 */
Johannes Berg05c914f2008-09-11 00:01:58 +02004346 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004347 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004348 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004349 iwl3945_commit_rxon(priv);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004350 }
4351
Zhu Yib481de92007-09-25 17:54:57 -07004352 /* Per mac80211.h: This is only used in IBSS mode... */
Johannes Berg05c914f2008-09-11 00:01:58 +02004353 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004354
Tomas Winklere1623442009-01-27 14:27:56 -08004355 IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07004356 mutex_unlock(&priv->mutex);
4357 return;
4358 }
4359
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004360 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004361
4362 mutex_unlock(&priv->mutex);
4363
Tomas Winklere1623442009-01-27 14:27:56 -08004364 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004365
4366}
4367
Johannes Berge039fa42008-05-15 12:55:29 +02004368static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07004369{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004370 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004371 unsigned long flags;
Abhijeet Kolekar7c4cbb62009-02-27 16:21:20 -08004372 __le64 timestamp;
Zhu Yib481de92007-09-25 17:54:57 -07004373
Tomas Winklere1623442009-01-27 14:27:56 -08004374 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004375
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004376 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004377 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004378 return -EIO;
4379 }
4380
Johannes Berg05c914f2008-09-11 00:01:58 +02004381 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Tomas Winklere1623442009-01-27 14:27:56 -08004382 IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07004383 return -EIO;
4384 }
4385
4386 spin_lock_irqsave(&priv->lock, flags);
4387
4388 if (priv->ibss_beacon)
4389 dev_kfree_skb(priv->ibss_beacon);
4390
4391 priv->ibss_beacon = skb;
4392
4393 priv->assoc_id = 0;
Abhijeet Kolekar7c4cbb62009-02-27 16:21:20 -08004394 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
4395 priv->timestamp = le64_to_cpu(timestamp);
Zhu Yib481de92007-09-25 17:54:57 -07004396
Tomas Winklere1623442009-01-27 14:27:56 -08004397 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004398 spin_unlock_irqrestore(&priv->lock, flags);
4399
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004400 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004401
Abhijeet Kolekardc4b1e72008-09-03 11:26:30 +08004402 iwl3945_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004403
Zhu Yib481de92007-09-25 17:54:57 -07004404
4405 return 0;
4406}
4407
4408/*****************************************************************************
4409 *
4410 * sysfs attributes
4411 *
4412 *****************************************************************************/
4413
Samuel Ortizd08853a2009-01-23 13:45:17 -08004414#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07004415
4416/*
4417 * The following adds a new attribute to the sysfs representation
4418 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
4419 * used for controlling the debug level.
4420 *
4421 * See the level definitions in iwl for details.
4422 */
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004423static ssize_t show_debug_level(struct device *d,
4424 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07004425{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004426 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004427
4428 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07004429}
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004430static ssize_t store_debug_level(struct device *d,
4431 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07004432 const char *buf, size_t count)
4433{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004434 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004435 unsigned long val;
4436 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07004437
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004438 ret = strict_strtoul(buf, 0, &val);
4439 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08004440 IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07004441 else
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004442 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07004443
4444 return strnlen(buf, count);
4445}
4446
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004447static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
4448 show_debug_level, store_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07004449
Samuel Ortizd08853a2009-01-23 13:45:17 -08004450#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07004451
Zhu Yib481de92007-09-25 17:54:57 -07004452static ssize_t show_temperature(struct device *d,
4453 struct device_attribute *attr, char *buf)
4454{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004455 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004456
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004457 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004458 return -EAGAIN;
4459
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004460 return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
Zhu Yib481de92007-09-25 17:54:57 -07004461}
4462
4463static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
4464
Zhu Yib481de92007-09-25 17:54:57 -07004465static ssize_t show_tx_power(struct device *d,
4466 struct device_attribute *attr, char *buf)
4467{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004468 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08004469 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07004470}
4471
4472static ssize_t store_tx_power(struct device *d,
4473 struct device_attribute *attr,
4474 const char *buf, size_t count)
4475{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004476 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004477 char *p = (char *)buf;
4478 u32 val;
4479
4480 val = simple_strtoul(p, &p, 10);
4481 if (p == buf)
Tomas Winkler978785a2008-12-19 10:37:31 +08004482 IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07004483 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004484 iwl3945_hw_reg_set_txpower(priv, val);
Zhu Yib481de92007-09-25 17:54:57 -07004485
4486 return count;
4487}
4488
4489static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
4490
4491static ssize_t show_flags(struct device *d,
4492 struct device_attribute *attr, char *buf)
4493{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004494 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004495
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004496 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
Zhu Yib481de92007-09-25 17:54:57 -07004497}
4498
4499static ssize_t store_flags(struct device *d,
4500 struct device_attribute *attr,
4501 const char *buf, size_t count)
4502{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004503 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004504 u32 flags = simple_strtoul(buf, NULL, 0);
4505
4506 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004507 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
Zhu Yib481de92007-09-25 17:54:57 -07004508 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004509 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004510 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004511 else {
Tomas Winklere1623442009-01-27 14:27:56 -08004512 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
Zhu Yib481de92007-09-25 17:54:57 -07004513 flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004514 priv->staging_rxon.flags = cpu_to_le32(flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004515 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004516 }
4517 }
4518 mutex_unlock(&priv->mutex);
4519
4520 return count;
4521}
4522
4523static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
4524
4525static ssize_t show_filter_flags(struct device *d,
4526 struct device_attribute *attr, char *buf)
4527{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004528 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004529
4530 return sprintf(buf, "0x%04X\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004531 le32_to_cpu(priv->active_rxon.filter_flags));
Zhu Yib481de92007-09-25 17:54:57 -07004532}
4533
4534static ssize_t store_filter_flags(struct device *d,
4535 struct device_attribute *attr,
4536 const char *buf, size_t count)
4537{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004538 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004539 u32 filter_flags = simple_strtoul(buf, NULL, 0);
4540
4541 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004542 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
Zhu Yib481de92007-09-25 17:54:57 -07004543 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004544 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004545 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004546 else {
Tomas Winklere1623442009-01-27 14:27:56 -08004547 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
Zhu Yib481de92007-09-25 17:54:57 -07004548 "0x%04X\n", filter_flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004549 priv->staging_rxon.filter_flags =
Zhu Yib481de92007-09-25 17:54:57 -07004550 cpu_to_le32(filter_flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004551 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004552 }
4553 }
4554 mutex_unlock(&priv->mutex);
4555
4556 return count;
4557}
4558
4559static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
4560 store_filter_flags);
4561
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004562#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004563
4564static ssize_t show_measurement(struct device *d,
4565 struct device_attribute *attr, char *buf)
4566{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004567 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler600c0e12008-12-19 10:37:04 +08004568 struct iwl_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004569 u32 size = sizeof(measure_report), len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03004570 u8 *data = (u8 *)&measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004571 unsigned long flags;
4572
4573 spin_lock_irqsave(&priv->lock, flags);
4574 if (!(priv->measurement_status & MEASUREMENT_READY)) {
4575 spin_unlock_irqrestore(&priv->lock, flags);
4576 return 0;
4577 }
4578 memcpy(&measure_report, &priv->measure_report, size);
4579 priv->measurement_status = 0;
4580 spin_unlock_irqrestore(&priv->lock, flags);
4581
4582 while (size && (PAGE_SIZE - len)) {
4583 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4584 PAGE_SIZE - len, 1);
4585 len = strlen(buf);
4586 if (PAGE_SIZE - len)
4587 buf[len++] = '\n';
4588
4589 ofs += 16;
4590 size -= min(size, 16U);
4591 }
4592
4593 return len;
4594}
4595
4596static ssize_t store_measurement(struct device *d,
4597 struct device_attribute *attr,
4598 const char *buf, size_t count)
4599{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004600 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004601 struct ieee80211_measurement_params params = {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004602 .channel = le16_to_cpu(priv->active_rxon.channel),
Zhu Yib481de92007-09-25 17:54:57 -07004603 .start_time = cpu_to_le64(priv->last_tsf),
4604 .duration = cpu_to_le16(1),
4605 };
4606 u8 type = IWL_MEASURE_BASIC;
4607 u8 buffer[32];
4608 u8 channel;
4609
4610 if (count) {
4611 char *p = buffer;
4612 strncpy(buffer, buf, min(sizeof(buffer), count));
4613 channel = simple_strtoul(p, NULL, 0);
4614 if (channel)
4615 params.channel = channel;
4616
4617 p = buffer;
4618 while (*p && *p != ' ')
4619 p++;
4620 if (*p)
4621 type = simple_strtoul(p + 1, NULL, 0);
4622 }
4623
Tomas Winklere1623442009-01-27 14:27:56 -08004624 IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on "
Zhu Yib481de92007-09-25 17:54:57 -07004625 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004626 iwl3945_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07004627
4628 return count;
4629}
4630
4631static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
4632 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004633#endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07004634
Zhu Yib481de92007-09-25 17:54:57 -07004635static ssize_t store_retry_rate(struct device *d,
4636 struct device_attribute *attr,
4637 const char *buf, size_t count)
4638{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004639 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004640
4641 priv->retry_rate = simple_strtoul(buf, NULL, 0);
4642 if (priv->retry_rate <= 0)
4643 priv->retry_rate = 1;
4644
4645 return count;
4646}
4647
4648static ssize_t show_retry_rate(struct device *d,
4649 struct device_attribute *attr, char *buf)
4650{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004651 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004652 return sprintf(buf, "%d", priv->retry_rate);
4653}
4654
4655static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
4656 store_retry_rate);
4657
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004658
Zhu Yib481de92007-09-25 17:54:57 -07004659static ssize_t store_power_level(struct device *d,
4660 struct device_attribute *attr,
4661 const char *buf, size_t count)
4662{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004663 struct iwl_priv *priv = dev_get_drvdata(d);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004664 int ret;
4665 unsigned long mode;
Zhu Yib481de92007-09-25 17:54:57 -07004666
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004667
Zhu Yib481de92007-09-25 17:54:57 -07004668 mutex_lock(&priv->mutex);
4669
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004670 if (!iwl_is_ready(priv)) {
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004671 ret = -EAGAIN;
Zhu Yib481de92007-09-25 17:54:57 -07004672 goto out;
4673 }
4674
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004675 ret = strict_strtoul(buf, 10, &mode);
4676 if (ret)
4677 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004678
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004679 ret = iwl_power_set_user_mode(priv, mode);
4680 if (ret) {
4681 IWL_DEBUG_MAC80211(priv, "failed setting power mode.\n");
4682 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004683 }
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004684 ret = count;
Zhu Yib481de92007-09-25 17:54:57 -07004685
4686 out:
4687 mutex_unlock(&priv->mutex);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004688 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004689}
4690
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004691static ssize_t show_power_level(struct device *d,
4692 struct device_attribute *attr, char *buf)
4693{
4694 struct iwl_priv *priv = dev_get_drvdata(d);
4695 int mode = priv->power_data.user_power_setting;
4696 int system = priv->power_data.system_power_setting;
4697 int level = priv->power_data.power_mode;
4698 char *p = buf;
4699
4700 switch (system) {
4701 case IWL_POWER_SYS_AUTO:
4702 p += sprintf(p, "SYSTEM:auto");
4703 break;
4704 case IWL_POWER_SYS_AC:
4705 p += sprintf(p, "SYSTEM:ac");
4706 break;
4707 case IWL_POWER_SYS_BATTERY:
4708 p += sprintf(p, "SYSTEM:battery");
4709 break;
4710 }
4711
4712 p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
4713 "fixed" : "auto");
4714 p += sprintf(p, "\tINDEX:%d", level);
4715 p += sprintf(p, "\n");
4716 return p - buf + 1;
4717}
4718
4719static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR,
4720 show_power_level, store_power_level);
4721
Zhu Yib481de92007-09-25 17:54:57 -07004722#define MAX_WX_STRING 80
4723
4724/* Values are in microsecond */
4725static const s32 timeout_duration[] = {
4726 350000,
4727 250000,
4728 75000,
4729 37000,
4730 25000,
4731};
4732static const s32 period_duration[] = {
4733 400000,
4734 700000,
4735 1000000,
4736 1000000,
4737 1000000
4738};
4739
Zhu Yib481de92007-09-25 17:54:57 -07004740static ssize_t show_channels(struct device *d,
4741 struct device_attribute *attr, char *buf)
4742{
Johannes Berg8318d782008-01-24 19:38:38 +01004743 /* all this shit doesn't belong into sysfs anyway */
4744 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07004745}
4746
4747static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
4748
4749static ssize_t show_statistics(struct device *d,
4750 struct device_attribute *attr, char *buf)
4751{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004752 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004753 u32 size = sizeof(struct iwl3945_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07004754 u32 len = 0, ofs = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004755 u8 *data = (u8 *)&priv->statistics_39;
Zhu Yib481de92007-09-25 17:54:57 -07004756 int rc = 0;
4757
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004758 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004759 return -EAGAIN;
4760
4761 mutex_lock(&priv->mutex);
Samuel Ortiz17f841c2009-01-23 13:45:20 -08004762 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004763 mutex_unlock(&priv->mutex);
4764
4765 if (rc) {
4766 len = sprintf(buf,
4767 "Error sending statistics request: 0x%08X\n", rc);
4768 return len;
4769 }
4770
4771 while (size && (PAGE_SIZE - len)) {
4772 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4773 PAGE_SIZE - len, 1);
4774 len = strlen(buf);
4775 if (PAGE_SIZE - len)
4776 buf[len++] = '\n';
4777
4778 ofs += 16;
4779 size -= min(size, 16U);
4780 }
4781
4782 return len;
4783}
4784
4785static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
4786
4787static ssize_t show_antenna(struct device *d,
4788 struct device_attribute *attr, char *buf)
4789{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004790 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004791
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004792 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004793 return -EAGAIN;
4794
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08004795 return sprintf(buf, "%d\n", iwl3945_mod_params.antenna);
Zhu Yib481de92007-09-25 17:54:57 -07004796}
4797
4798static ssize_t store_antenna(struct device *d,
4799 struct device_attribute *attr,
4800 const char *buf, size_t count)
4801{
Winkler, Tomas7530f852009-01-27 14:27:53 -08004802 struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004803 int ant;
Zhu Yib481de92007-09-25 17:54:57 -07004804
4805 if (count == 0)
4806 return 0;
4807
4808 if (sscanf(buf, "%1i", &ant) != 1) {
Tomas Winklere1623442009-01-27 14:27:56 -08004809 IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004810 return count;
4811 }
4812
4813 if ((ant >= 0) && (ant <= 2)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004814 IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant);
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08004815 iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant;
Zhu Yib481de92007-09-25 17:54:57 -07004816 } else
Tomas Winklere1623442009-01-27 14:27:56 -08004817 IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant);
Zhu Yib481de92007-09-25 17:54:57 -07004818
4819
4820 return count;
4821}
4822
4823static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
4824
4825static ssize_t show_status(struct device *d,
4826 struct device_attribute *attr, char *buf)
4827{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004828 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004829 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004830 return -EAGAIN;
4831 return sprintf(buf, "0x%08x\n", (int)priv->status);
4832}
4833
4834static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
4835
4836static ssize_t dump_error_log(struct device *d,
4837 struct device_attribute *attr,
4838 const char *buf, size_t count)
4839{
4840 char *p = (char *)buf;
4841
4842 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004843 iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07004844
4845 return strnlen(buf, count);
4846}
4847
4848static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
4849
4850static ssize_t dump_event_log(struct device *d,
4851 struct device_attribute *attr,
4852 const char *buf, size_t count)
4853{
4854 char *p = (char *)buf;
4855
4856 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004857 iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07004858
4859 return strnlen(buf, count);
4860}
4861
4862static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
4863
4864/*****************************************************************************
4865 *
Tomas Winklera96a27f2008-10-23 23:48:56 -07004866 * driver setup and tear down
Zhu Yib481de92007-09-25 17:54:57 -07004867 *
4868 *****************************************************************************/
4869
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004870static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004871{
Reinette Chatred21050c2009-02-13 11:51:18 -08004872 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07004873
4874 init_waitqueue_head(&priv->wait_command_queue);
4875
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004876 INIT_WORK(&priv->up, iwl3945_bg_up);
4877 INIT_WORK(&priv->restart, iwl3945_bg_restart);
4878 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01004879 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004880 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004881 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
4882 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
Helmut Schaa26635162009-01-15 09:38:44 +01004883 INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll);
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08004884 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
4885 INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
4886 INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
4887 INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
Zhu Yib481de92007-09-25 17:54:57 -07004888
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004889 iwl3945_hw_setup_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004890
4891 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004892 iwl3945_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07004893}
4894
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004895static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004896{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004897 iwl3945_hw_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004898
Joonwoo Parke47eb6a2007-11-29 10:42:49 +09004899 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004900 cancel_delayed_work(&priv->scan_check);
4901 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004902 cancel_work_sync(&priv->beacon_update);
4903}
4904
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004905static struct attribute *iwl3945_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07004906 &dev_attr_antenna.attr,
4907 &dev_attr_channels.attr,
4908 &dev_attr_dump_errors.attr,
4909 &dev_attr_dump_events.attr,
4910 &dev_attr_flags.attr,
4911 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004912#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004913 &dev_attr_measurement.attr,
4914#endif
4915 &dev_attr_power_level.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004916 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004917 &dev_attr_statistics.attr,
4918 &dev_attr_status.attr,
4919 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004920 &dev_attr_tx_power.attr,
Samuel Ortizd08853a2009-01-23 13:45:17 -08004921#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004922 &dev_attr_debug_level.attr,
4923#endif
Zhu Yib481de92007-09-25 17:54:57 -07004924 NULL
4925};
4926
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004927static struct attribute_group iwl3945_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07004928 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004929 .attrs = iwl3945_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07004930};
4931
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004932static struct ieee80211_ops iwl3945_hw_ops = {
4933 .tx = iwl3945_mac_tx,
4934 .start = iwl3945_mac_start,
4935 .stop = iwl3945_mac_stop,
4936 .add_interface = iwl3945_mac_add_interface,
4937 .remove_interface = iwl3945_mac_remove_interface,
4938 .config = iwl3945_mac_config,
4939 .config_interface = iwl3945_mac_config_interface,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004940 .configure_filter = iwl_configure_filter,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004941 .set_key = iwl3945_mac_set_key,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004942 .get_tx_stats = iwl3945_mac_get_tx_stats,
4943 .conf_tx = iwl3945_mac_conf_tx,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004944 .reset_tsf = iwl3945_mac_reset_tsf,
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004945 .bss_info_changed = iwl3945_bss_info_changed,
Abhijeet Kolekare9dde6f62009-02-18 15:54:27 -08004946 .hw_scan = iwl_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07004947};
4948
Winkler, Tomase52119c2008-12-22 11:31:19 +08004949static int iwl3945_init_drv(struct iwl_priv *priv)
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004950{
4951 int ret;
Samuel Ortize6148912009-01-23 13:45:15 -08004952 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004953
4954 priv->retry_rate = 1;
4955 priv->ibss_beacon = NULL;
4956
4957 spin_lock_init(&priv->lock);
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08004958 spin_lock_init(&priv->power_data.lock);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004959 spin_lock_init(&priv->sta_lock);
4960 spin_lock_init(&priv->hcmd_lock);
4961
4962 INIT_LIST_HEAD(&priv->free_frames);
4963
4964 mutex_init(&priv->mutex);
4965
4966 /* Clear the driver's (not device's) station table */
4967 iwl3945_clear_stations_table(priv);
4968
4969 priv->data_retry_limit = -1;
4970 priv->ieee_channels = NULL;
4971 priv->ieee_rates = NULL;
4972 priv->band = IEEE80211_BAND_2GHZ;
4973
4974 priv->iw_mode = NL80211_IFTYPE_STATION;
4975
4976 iwl_reset_qos(priv);
4977
4978 priv->qos_data.qos_active = 0;
4979 priv->qos_data.qos_cap.val = 0;
4980
4981 priv->rates_mask = IWL_RATES_MASK;
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004982 /* If power management is turned on, default to CAM mode */
4983 priv->power_mode = IWL_POWER_MODE_CAM;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08004984 priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004985
Samuel Ortize6148912009-01-23 13:45:15 -08004986 if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
4987 IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
4988 eeprom->version);
4989 ret = -EINVAL;
4990 goto err;
4991 }
4992 ret = iwl_init_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004993 if (ret) {
4994 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
4995 goto err;
4996 }
4997
Samuel Ortize6148912009-01-23 13:45:15 -08004998 /* Set up txpower settings in driver for all channels */
4999 if (iwl3945_txpower_set_from_eeprom(priv)) {
5000 ret = -EIO;
5001 goto err_free_channel_map;
5002 }
5003
Samuel Ortiz534166d2009-01-23 13:45:16 -08005004 ret = iwlcore_init_geos(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005005 if (ret) {
5006 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
5007 goto err_free_channel_map;
5008 }
Samuel Ortiz534166d2009-01-23 13:45:16 -08005009 iwl3945_init_hw_rates(priv, priv->ieee_rates);
5010
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005011 return 0;
5012
5013err_free_channel_map:
Samuel Ortize6148912009-01-23 13:45:15 -08005014 iwl_free_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005015err:
5016 return ret;
5017}
5018
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08005019static int iwl3945_setup_mac(struct iwl_priv *priv)
5020{
5021 int ret;
5022 struct ieee80211_hw *hw = priv->hw;
5023
5024 hw->rate_control_algorithm = "iwl-3945-rs";
5025 hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
5026
5027 /* Tell mac80211 our characteristics */
5028 hw->flags = IEEE80211_HW_SIGNAL_DBM |
5029 IEEE80211_HW_NOISE_DBM;
5030
5031 hw->wiphy->interface_modes =
5032 BIT(NL80211_IFTYPE_STATION) |
5033 BIT(NL80211_IFTYPE_ADHOC);
5034
5035 hw->wiphy->custom_regulatory = true;
5036
5037 /* Default value; 4 EDCA QOS priorities */
5038 hw->queues = 4;
5039
5040 hw->conf.beacon_int = 100;
5041
5042 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
5043 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
5044 &priv->bands[IEEE80211_BAND_2GHZ];
5045
5046 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
5047 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
5048 &priv->bands[IEEE80211_BAND_5GHZ];
5049
5050 ret = ieee80211_register_hw(priv->hw);
5051 if (ret) {
5052 IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
5053 return ret;
5054 }
5055 priv->mac80211_registered = 1;
5056
5057 return 0;
5058}
5059
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005060static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07005061{
5062 int err = 0;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005063 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07005064 struct ieee80211_hw *hw;
Kolekar, Abhijeetc0f20d92008-12-19 10:37:19 +08005065 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Samuel Ortize6148912009-01-23 13:45:15 -08005066 struct iwl3945_eeprom *eeprom;
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005067 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07005068
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005069 /***********************
5070 * 1. Allocating HW data
5071 * ********************/
5072
Zhu Yib481de92007-09-25 17:54:57 -07005073 /* mac80211 allocates memory for this device instance, including
5074 * space for this driver's private structure */
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005075 hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
Zhu Yib481de92007-09-25 17:54:57 -07005076 if (hw == NULL) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005077 printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
Zhu Yib481de92007-09-25 17:54:57 -07005078 err = -ENOMEM;
5079 goto out;
5080 }
Zhu Yib481de92007-09-25 17:54:57 -07005081 priv = hw->priv;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005082 SET_IEEE80211_DEV(hw, &pdev->dev);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005083
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005084 if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) ||
5085 (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005086 IWL_ERR(priv,
5087 "invalid queues_num, should be between %d and %d\n",
5088 IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES);
Samuel Ortiza3139c52008-12-19 10:37:09 +08005089 err = -EINVAL;
Reinette Chatrec8f16132009-02-27 16:21:22 -08005090 goto out_ieee80211_free_hw;
Samuel Ortiza3139c52008-12-19 10:37:09 +08005091 }
5092
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005093 /*
5094 * Disabling hardware scan means that mac80211 will perform scans
5095 * "the hard way", rather than using device's scan.
5096 */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005097 if (iwl3945_mod_params.disable_hw_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08005098 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005099 iwl3945_hw_ops.hw_scan = NULL;
5100 }
5101
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005102
Tomas Winklere1623442009-01-27 14:27:56 -08005103 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005104 priv->cfg = cfg;
5105 priv->pci_dev = pdev;
5106
Samuel Ortizd08853a2009-01-23 13:45:17 -08005107#ifdef CONFIG_IWLWIFI_DEBUG
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005108 priv->debug_level = iwl3945_mod_params.debug;
5109 atomic_set(&priv->restrict_refcnt, 0);
5110#endif
Zhu Yib481de92007-09-25 17:54:57 -07005111
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005112 /***************************
5113 * 2. Initializing PCI bus
5114 * *************************/
Zhu Yib481de92007-09-25 17:54:57 -07005115 if (pci_enable_device(pdev)) {
5116 err = -ENODEV;
5117 goto out_ieee80211_free_hw;
5118 }
5119
5120 pci_set_master(pdev);
5121
Zhu Yib481de92007-09-25 17:54:57 -07005122 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
5123 if (!err)
5124 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
5125 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08005126 IWL_WARN(priv, "No suitable DMA available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07005127 goto out_pci_disable_device;
5128 }
5129
5130 pci_set_drvdata(pdev, priv);
5131 err = pci_request_regions(pdev, DRV_NAME);
5132 if (err)
5133 goto out_pci_disable_device;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005134
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005135 /***********************
5136 * 3. Read REV Register
5137 * ********************/
Zhu Yib481de92007-09-25 17:54:57 -07005138 priv->hw_base = pci_iomap(pdev, 0, 0);
5139 if (!priv->hw_base) {
5140 err = -ENODEV;
5141 goto out_pci_release_regions;
5142 }
5143
Tomas Winklere1623442009-01-27 14:27:56 -08005144 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Zhu Yib481de92007-09-25 17:54:57 -07005145 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08005146 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Zhu Yib481de92007-09-25 17:54:57 -07005147
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005148 /* We disable the RETRY_TIMEOUT register (0x41) to keep
5149 * PCI Tx retries from interfering with C3 CPU state */
5150 pci_write_config_byte(pdev, 0x41, 0x00);
Zhu Yib481de92007-09-25 17:54:57 -07005151
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005152 /* amp init */
5153 err = priv->cfg->ops->lib->apm_ops.init(priv);
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005154 if (err < 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08005155 IWL_DEBUG_INFO(priv, "Failed to init APMG\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005156 goto out_iounmap;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005157 }
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005158
5159 /***********************
5160 * 4. Read EEPROM
5161 * ********************/
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005162
Zhu Yi5a669262008-01-14 17:46:18 -08005163 /* Read the EEPROM */
Samuel Ortize6148912009-01-23 13:45:15 -08005164 err = iwl_eeprom_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005165 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005166 IWL_ERR(priv, "Unable to init EEPROM\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08005167 goto out_iounmap;
Zhu Yi5a669262008-01-14 17:46:18 -08005168 }
5169 /* MAC Address location in EEPROM same for 3945/4965 */
Samuel Ortize6148912009-01-23 13:45:15 -08005170 eeprom = (struct iwl3945_eeprom *)priv->eeprom;
5171 memcpy(priv->mac_addr, eeprom->mac_address, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08005172 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
Zhu Yi5a669262008-01-14 17:46:18 -08005173 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
5174
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005175 /***********************
5176 * 5. Setup HW Constants
5177 * ********************/
5178 /* Device-specific setup */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005179 if (iwl3945_hw_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005180 IWL_ERR(priv, "failed to set hw settings\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08005181 goto out_eeprom_free;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005182 }
5183
5184 /***********************
5185 * 6. Setup priv
5186 * ********************/
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005187
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005188 err = iwl3945_init_drv(priv);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005189 if (err) {
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005190 IWL_ERR(priv, "initializing driver failed\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08005191 goto out_unset_hw_params;
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005192 }
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005193
Tomas Winkler978785a2008-12-19 10:37:31 +08005194 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
5195 priv->cfg->name);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005196
5197 /***********************************
5198 * 7. Initialize Module Parameters
5199 * **********************************/
5200
5201 /* Initialize module parameter values here */
5202 /* Disable radio (SW RF KILL) via parameter when loading driver */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005203 if (iwl3945_mod_params.disable) {
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005204 set_bit(STATUS_RF_KILL_SW, &priv->status);
Tomas Winklere1623442009-01-27 14:27:56 -08005205 IWL_DEBUG_INFO(priv, "Radio disabled.\n");
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005206 }
5207
5208
5209 /***********************
5210 * 8. Setup Services
5211 * ********************/
5212
5213 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08005214 iwl_disable_interrupts(priv);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005215 spin_unlock_irqrestore(&priv->lock, flags);
5216
Helmut Schaa26635162009-01-15 09:38:44 +01005217 pci_enable_msi(priv->pci_dev);
5218
Abhijeet Kolekarf17d08a2009-02-18 15:54:31 -08005219 err = request_irq(priv->pci_dev->irq, iwl_isr, IRQF_SHARED,
Helmut Schaa26635162009-01-15 09:38:44 +01005220 DRV_NAME, priv);
5221 if (err) {
5222 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
5223 goto out_disable_msi;
5224 }
5225
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005226 err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
5227 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005228 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005229 goto out_release_irq;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005230 }
5231
Samuel Ortiz8ccde882009-01-27 14:27:52 -08005232 iwl_set_rxon_channel(priv,
5233 &priv->bands[IEEE80211_BAND_2GHZ].channels[5]);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005234 iwl3945_setup_deferred_work(priv);
5235 iwl3945_setup_rx_handlers(priv);
5236
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005237 /*********************************
Helmut Schaa26635162009-01-15 09:38:44 +01005238 * 9. Setup and Register mac80211
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005239 * *******************************/
5240
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08005241 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005242
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08005243 err = iwl3945_setup_mac(priv);
5244 if (err)
5245 goto out_remove_sysfs;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005246
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005247 err = iwl_rfkill_init(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005248 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08005249 IWL_ERR(priv, "Unable to initialize RFKILL system. "
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005250 "Ignoring error: %d\n", err);
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08005251 else
5252 iwl_rfkill_set_hw_state(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005253
Helmut Schaa26635162009-01-15 09:38:44 +01005254 /* Start monitoring the killswitch */
5255 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
5256 2 * HZ);
5257
Zhu Yib481de92007-09-25 17:54:57 -07005258 return 0;
5259
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005260 out_remove_sysfs:
Zhu Yib481de92007-09-25 17:54:57 -07005261 destroy_workqueue(priv->workqueue);
5262 priv->workqueue = NULL;
Reinette Chatrec8f16132009-02-27 16:21:22 -08005263 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
5264 out_release_irq:
5265 free_irq(priv->pci_dev->irq, priv);
Helmut Schaa26635162009-01-15 09:38:44 +01005266 out_disable_msi:
5267 pci_disable_msi(priv->pci_dev);
Reinette Chatrec8f16132009-02-27 16:21:22 -08005268 iwlcore_free_geos(priv);
5269 iwl_free_channel_map(priv);
5270 out_unset_hw_params:
5271 iwl3945_unset_hw_params(priv);
5272 out_eeprom_free:
5273 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005274 out_iounmap:
5275 pci_iounmap(pdev, priv->hw_base);
5276 out_pci_release_regions:
5277 pci_release_regions(pdev);
5278 out_pci_disable_device:
5279 pci_disable_device(pdev);
5280 pci_set_drvdata(pdev, NULL);
5281 out_ieee80211_free_hw:
5282 ieee80211_free_hw(priv->hw);
5283 out:
5284 return err;
5285}
5286
Reinette Chatrec83dbf62008-03-21 13:53:41 -07005287static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07005288{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005289 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005290 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07005291
5292 if (!priv)
5293 return;
5294
Tomas Winklere1623442009-01-27 14:27:56 -08005295 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07005296
Zhu Yib481de92007-09-25 17:54:57 -07005297 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08005298
Kolekar, Abhijeetd552bfb2008-12-19 10:37:41 +08005299 if (priv->mac80211_registered) {
5300 ieee80211_unregister_hw(priv->hw);
5301 priv->mac80211_registered = 0;
5302 } else {
5303 iwl3945_down(priv);
5304 }
Zhu Yib481de92007-09-25 17:54:57 -07005305
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005306 /* make sure we flush any pending irq or
5307 * tasklet for the driver
5308 */
5309 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08005310 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005311 spin_unlock_irqrestore(&priv->lock, flags);
5312
5313 iwl_synchronize_irq(priv);
5314
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005315 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07005316
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005317 iwl_rfkill_unregister(priv);
Helmut Schaa26635162009-01-15 09:38:44 +01005318 cancel_delayed_work(&priv->rfkill_poll);
5319
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005320 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005321
5322 if (priv->rxq.bd)
Winkler, Tomas51af3d32008-12-22 11:31:23 +08005323 iwl_rx_queue_free(priv, &priv->rxq);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005324 iwl3945_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005325
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005326 iwl3945_unset_hw_params(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005327 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005328
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08005329 /*netif_stop_queue(dev); */
5330 flush_workqueue(priv->workqueue);
5331
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005332 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07005333 * priv->workqueue... so we can't take down the workqueue
5334 * until now... */
5335 destroy_workqueue(priv->workqueue);
5336 priv->workqueue = NULL;
5337
Helmut Schaa26635162009-01-15 09:38:44 +01005338 free_irq(pdev->irq, priv);
5339 pci_disable_msi(pdev);
5340
Zhu Yib481de92007-09-25 17:54:57 -07005341 pci_iounmap(pdev, priv->hw_base);
5342 pci_release_regions(pdev);
5343 pci_disable_device(pdev);
5344 pci_set_drvdata(pdev, NULL);
5345
Samuel Ortize6148912009-01-23 13:45:15 -08005346 iwl_free_channel_map(priv);
Samuel Ortiz534166d2009-01-23 13:45:16 -08005347 iwlcore_free_geos(priv);
Winkler, Tomas805cee52009-01-19 15:30:28 -08005348 kfree(priv->scan);
Zhu Yib481de92007-09-25 17:54:57 -07005349 if (priv->ibss_beacon)
5350 dev_kfree_skb(priv->ibss_beacon);
5351
5352 ieee80211_free_hw(priv->hw);
5353}
5354
5355#ifdef CONFIG_PM
5356
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005357static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07005358{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005359 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005360
Zhu Yie655b9f2008-01-24 02:19:38 -08005361 if (priv->is_open) {
5362 set_bit(STATUS_IN_SUSPEND, &priv->status);
5363 iwl3945_mac_stop(priv->hw);
5364 priv->is_open = 1;
5365 }
Helmut Schaa26635162009-01-15 09:38:44 +01005366 pci_save_state(pdev);
5367 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005368 pci_set_power_state(pdev, PCI_D3hot);
5369
Zhu Yib481de92007-09-25 17:54:57 -07005370 return 0;
5371}
5372
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005373static int iwl3945_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07005374{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005375 struct iwl_priv *priv = pci_get_drvdata(pdev);
Winkler, Tomas450154e2009-01-27 14:27:55 -08005376 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07005377
Zhu Yib481de92007-09-25 17:54:57 -07005378 pci_set_power_state(pdev, PCI_D0);
Winkler, Tomas450154e2009-01-27 14:27:55 -08005379 ret = pci_enable_device(pdev);
5380 if (ret)
5381 return ret;
Helmut Schaa26635162009-01-15 09:38:44 +01005382 pci_restore_state(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005383
Zhu Yie655b9f2008-01-24 02:19:38 -08005384 if (priv->is_open)
5385 iwl3945_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07005386
Zhu Yie655b9f2008-01-24 02:19:38 -08005387 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07005388 return 0;
5389}
5390
5391#endif /* CONFIG_PM */
5392
5393/*****************************************************************************
5394 *
5395 * driver and module entry point
5396 *
5397 *****************************************************************************/
5398
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005399static struct pci_driver iwl3945_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07005400 .name = DRV_NAME,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005401 .id_table = iwl3945_hw_card_ids,
5402 .probe = iwl3945_pci_probe,
5403 .remove = __devexit_p(iwl3945_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07005404#ifdef CONFIG_PM
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005405 .suspend = iwl3945_pci_suspend,
5406 .resume = iwl3945_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07005407#endif
5408};
5409
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005410static int __init iwl3945_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07005411{
5412
5413 int ret;
5414 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
5415 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005416
5417 ret = iwl3945_rate_control_register();
5418 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005419 printk(KERN_ERR DRV_NAME
5420 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005421 return ret;
5422 }
5423
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005424 ret = pci_register_driver(&iwl3945_driver);
Zhu Yib481de92007-09-25 17:54:57 -07005425 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005426 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005427 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07005428 }
Zhu Yib481de92007-09-25 17:54:57 -07005429
5430 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005431
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005432error_register:
5433 iwl3945_rate_control_unregister();
5434 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07005435}
5436
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005437static void __exit iwl3945_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07005438{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005439 pci_unregister_driver(&iwl3945_driver);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005440 iwl3945_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07005441}
5442
Reinette Chatrea0987a82008-12-02 12:14:06 -08005443MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
Zhu Yi25cb6ca2008-09-11 11:45:22 +08005444
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005445module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005446MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005447module_param_named(disable, iwl3945_mod_params.disable, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005448MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -08005449module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
5450MODULE_PARM_DESC(swcrypto,
5451 "using software crypto (default 1 [software])\n");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005452module_param_named(debug, iwl3945_mod_params.debug, uint, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005453MODULE_PARM_DESC(debug, "debug output mask");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005454module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005455MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
5456
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005457module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005458MODULE_PARM_DESC(queues_num, "number of hw queues.");
5459
Samuel Ortizaf48d042009-01-23 13:45:19 -08005460module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, 0444);
5461MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error");
5462
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005463module_exit(iwl3945_exit);
5464module_init(iwl3945_init);