blob: 6d816ebd7cea47570f24f335fd72a86145e21c3b [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Reinette Chatre01f81622009-01-08 10:20:02 -08003 * Copyright(c) 2003 - 2009 Intel Corporation. All rights reserved.
Zhu Yib481de92007-09-25 17:54:57 -07004 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
Winkler, Tomas759ef892008-12-09 11:28:58 -080025 * Intel Linux Wireless <ilw@linux.intel.com>
Zhu Yib481de92007-09-25 17:54:57 -070026 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
Zhu Yib481de92007-09-25 17:54:57 -070030#include <linux/kernel.h>
31#include <linux/module.h>
Zhu Yib481de92007-09-25 17:54:57 -070032#include <linux/init.h>
33#include <linux/pci.h>
34#include <linux/dma-mapping.h>
35#include <linux/delay.h>
36#include <linux/skbuff.h>
37#include <linux/netdevice.h>
38#include <linux/wireless.h>
39#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070040#include <linux/etherdevice.h>
41#include <linux/if_arp.h>
42
43#include <net/ieee80211_radiotap.h>
John W. Linville7e272fc2008-09-24 18:13:14 -040044#include <net/lib80211.h>
Zhu Yib481de92007-09-25 17:54:57 -070045#include <net/mac80211.h>
46
47#include <asm/div64.h>
48
Samuel Ortiza3139c52008-12-19 10:37:09 +080049#define DRV_NAME "iwl3945"
50
Winkler, Tomasdbb66542008-12-22 11:31:14 +080051#include "iwl-fh.h"
52#include "iwl-3945-fh.h"
Tomas Winkler600c0e12008-12-19 10:37:04 +080053#include "iwl-commands.h"
Samuel Ortiz17f841c2009-01-23 13:45:20 -080054#include "iwl-sta.h"
Zhu Yib481de92007-09-25 17:54:57 -070055#include "iwl-3945.h"
56#include "iwl-helpers.h"
Kolekar, Abhijeet5747d472008-12-19 10:37:18 +080057#include "iwl-core.h"
Samuel Ortizd20b3c62008-12-19 10:37:15 +080058#include "iwl-dev.h"
Zhu Yib481de92007-09-25 17:54:57 -070059
Zhu Yib481de92007-09-25 17:54:57 -070060/*
61 * module name, copyright, version, etc.
Zhu Yib481de92007-09-25 17:54:57 -070062 */
63
64#define DRV_DESCRIPTION \
65"Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
66
Samuel Ortizd08853a2009-01-23 13:45:17 -080067#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070068#define VD "d"
69#else
70#define VD
71#endif
72
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080073#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -070074#define VS "s"
75#else
76#define VS
77#endif
78
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080079#define IWL39_VERSION "1.2.26k" VD VS
Reinette Chatre01f81622009-01-08 10:20:02 -080080#define DRV_COPYRIGHT "Copyright(c) 2003-2009 Intel Corporation"
Tomas Winklera7b75202008-12-11 10:33:41 -080081#define DRV_AUTHOR "<ilw@linux.intel.com>"
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080082#define DRV_VERSION IWL39_VERSION
Zhu Yib481de92007-09-25 17:54:57 -070083
Zhu Yib481de92007-09-25 17:54:57 -070084
85MODULE_DESCRIPTION(DRV_DESCRIPTION);
86MODULE_VERSION(DRV_VERSION);
Tomas Winklera7b75202008-12-11 10:33:41 -080087MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
Zhu Yib481de92007-09-25 17:54:57 -070088MODULE_LICENSE("GPL");
89
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080090 /* module parameters */
91struct iwl_mod_params iwl3945_mod_params = {
92 .num_of_queues = IWL39_MAX_NUM_QUEUES,
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -080093 .sw_crypto = 1,
Samuel Ortizaf48d042009-01-23 13:45:19 -080094 .restart_fw = 1,
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080095 /* the rest are 0 by default */
96};
97
Zhu Yib481de92007-09-25 17:54:57 -070098/*************** STATION TABLE MANAGEMENT ****
Ben Cahill9fbab512007-11-29 11:09:47 +080099 * mac80211 should be examined to determine if sta_info is duplicating
Zhu Yib481de92007-09-25 17:54:57 -0700100 * the functionality provided here
101 */
102
103/**************************************************************/
Ian Schram01ebd062007-10-25 17:15:22 +0800104#if 0 /* temporary disable till we add real remove station */
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800105/**
106 * iwl3945_remove_station - Remove driver's knowledge of station.
107 *
108 * NOTE: This does not remove station from device's station table.
109 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800110static u8 iwl3945_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
Zhu Yib481de92007-09-25 17:54:57 -0700111{
112 int index = IWL_INVALID_STATION;
113 int i;
114 unsigned long flags;
115
116 spin_lock_irqsave(&priv->sta_lock, flags);
117
118 if (is_ap)
119 index = IWL_AP_ID;
120 else if (is_broadcast_ether_addr(addr))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800121 index = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700122 else
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800123 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800124 if (priv->stations_39[i].used &&
125 !compare_ether_addr(priv->stations_39[i].sta.sta.addr,
Zhu Yib481de92007-09-25 17:54:57 -0700126 addr)) {
127 index = i;
128 break;
129 }
130
131 if (unlikely(index == IWL_INVALID_STATION))
132 goto out;
133
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800134 if (priv->stations_39[index].used) {
135 priv->stations_39[index].used = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700136 priv->num_stations--;
137 }
138
139 BUG_ON(priv->num_stations < 0);
140
141out:
142 spin_unlock_irqrestore(&priv->sta_lock, flags);
143 return 0;
144}
Zhu Yi556f8db2007-09-27 11:27:33 +0800145#endif
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800146
147/**
148 * iwl3945_clear_stations_table - Clear the driver's station table
149 *
150 * NOTE: This does not clear or otherwise alter the device's station table.
151 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800152static void iwl3945_clear_stations_table(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700153{
154 unsigned long flags;
155
156 spin_lock_irqsave(&priv->sta_lock, flags);
157
158 priv->num_stations = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800159 memset(priv->stations_39, 0, sizeof(priv->stations_39));
Zhu Yib481de92007-09-25 17:54:57 -0700160
161 spin_unlock_irqrestore(&priv->sta_lock, flags);
162}
163
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800164/**
165 * iwl3945_add_station - Add station to station tables in driver and device
166 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800167u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags)
Zhu Yib481de92007-09-25 17:54:57 -0700168{
169 int i;
170 int index = IWL_INVALID_STATION;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800171 struct iwl3945_station_entry *station;
Zhu Yib481de92007-09-25 17:54:57 -0700172 unsigned long flags_spin;
Zhu Yic14c5212007-09-27 11:27:35 +0800173 u8 rate;
Zhu Yib481de92007-09-25 17:54:57 -0700174
175 spin_lock_irqsave(&priv->sta_lock, flags_spin);
176 if (is_ap)
177 index = IWL_AP_ID;
178 else if (is_broadcast_ether_addr(addr))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800179 index = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700180 else
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800181 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800182 if (!compare_ether_addr(priv->stations_39[i].sta.sta.addr,
Zhu Yib481de92007-09-25 17:54:57 -0700183 addr)) {
184 index = i;
185 break;
186 }
187
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800188 if (!priv->stations_39[i].used &&
Zhu Yib481de92007-09-25 17:54:57 -0700189 index == IWL_INVALID_STATION)
190 index = i;
191 }
192
Ian Schram01ebd062007-10-25 17:15:22 +0800193 /* These two conditions has the same outcome but keep them separate
Zhu Yib481de92007-09-25 17:54:57 -0700194 since they have different meaning */
195 if (unlikely(index == IWL_INVALID_STATION)) {
196 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
197 return index;
198 }
199
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800200 if (priv->stations_39[index].used &&
201 !compare_ether_addr(priv->stations_39[index].sta.sta.addr, addr)) {
Zhu Yib481de92007-09-25 17:54:57 -0700202 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
203 return index;
204 }
205
Tomas Winklere1623442009-01-27 14:27:56 -0800206 IWL_DEBUG_ASSOC(priv, "Add STA ID %d: %pM\n", index, addr);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800207 station = &priv->stations_39[index];
Zhu Yib481de92007-09-25 17:54:57 -0700208 station->used = 1;
209 priv->num_stations++;
210
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800211 /* Set up the REPLY_ADD_STA command to send to device */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800212 memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd));
Zhu Yib481de92007-09-25 17:54:57 -0700213 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
214 station->sta.mode = 0;
215 station->sta.sta.sta_id = index;
216 station->sta.station_flags = 0;
217
Johannes Berg8318d782008-01-24 19:38:38 +0100218 if (priv->band == IEEE80211_BAND_5GHZ)
Tomas Winkler69946332007-10-25 17:15:27 +0800219 rate = IWL_RATE_6M_PLCP;
220 else
221 rate = IWL_RATE_1M_PLCP;
Zhu Yic14c5212007-09-27 11:27:35 +0800222
223 /* Turn on both antennas for the station... */
224 station->sta.rate_n_flags =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800225 iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK);
Zhu Yic14c5212007-09-27 11:27:35 +0800226
Zhu Yib481de92007-09-25 17:54:57 -0700227 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800228
229 /* Add station to device's station table */
Samuel Ortiz17f841c2009-01-23 13:45:20 -0800230 iwl_send_add_sta(priv,
231 (struct iwl_addsta_cmd *)&station->sta, flags);
Zhu Yib481de92007-09-25 17:54:57 -0700232 return index;
233
234}
235
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800236static int iwl3945_send_rxon_assoc(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700237{
238 int rc = 0;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800239 struct iwl_rx_packet *res = NULL;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800240 struct iwl3945_rxon_assoc_cmd rxon_assoc;
Winkler, Tomasc2d79b482008-12-19 10:37:34 +0800241 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700242 .id = REPLY_RXON_ASSOC,
243 .len = sizeof(rxon_assoc),
244 .meta.flags = CMD_WANT_SKB,
245 .data = &rxon_assoc,
246 };
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800247 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
248 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
Zhu Yib481de92007-09-25 17:54:57 -0700249
250 if ((rxon1->flags == rxon2->flags) &&
251 (rxon1->filter_flags == rxon2->filter_flags) &&
252 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
253 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800254 IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700255 return 0;
256 }
257
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800258 rxon_assoc.flags = priv->staging_rxon.flags;
259 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
260 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
261 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
Zhu Yib481de92007-09-25 17:54:57 -0700262 rxon_assoc.reserved = 0;
263
Samuel Ortiz518099a2009-01-19 15:30:27 -0800264 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700265 if (rc)
266 return rc;
267
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800268 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700269 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800270 IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -0700271 rc = -EIO;
272 }
273
274 priv->alloc_rxb_skb--;
275 dev_kfree_skb_any(cmd.meta.u.skb);
276
277 return rc;
278}
279
280/**
Samuel Ortiz7e4bca52009-01-23 13:45:18 -0800281 * iwl3945_get_antenna_flags - Get antenna flags for RXON command
282 * @priv: eeprom and antenna fields are used to determine antenna flags
283 *
284 * priv->eeprom39 is used to determine if antenna AUX/MAIN are reversed
285 * iwl3945_mod_params.antenna specifies the antenna diversity mode:
286 *
287 * IWL_ANTENNA_DIVERSITY - NIC selects best antenna by itself
288 * IWL_ANTENNA_MAIN - Force MAIN antenna
289 * IWL_ANTENNA_AUX - Force AUX antenna
290 */
291__le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv)
292{
293 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
294
295 switch (iwl3945_mod_params.antenna) {
296 case IWL_ANTENNA_DIVERSITY:
297 return 0;
298
299 case IWL_ANTENNA_MAIN:
300 if (eeprom->antenna_switch_type)
301 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
302 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
303
304 case IWL_ANTENNA_AUX:
305 if (eeprom->antenna_switch_type)
306 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
307 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
308 }
309
310 /* bad antenna selector value */
311 IWL_ERR(priv, "Bad antenna selector value (0x%x)\n",
312 iwl3945_mod_params.antenna);
313
314 return 0; /* "diversity" is default if error */
315}
316
317/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800318 * iwl3945_commit_rxon - commit staging_rxon to hardware
Zhu Yib481de92007-09-25 17:54:57 -0700319 *
Ian Schram01ebd062007-10-25 17:15:22 +0800320 * The RXON command in staging_rxon is committed to the hardware and
Zhu Yib481de92007-09-25 17:54:57 -0700321 * the active_rxon structure is updated with the new data. This
322 * function correctly transitions out of the RXON_ASSOC_MSK state if
323 * a HW tune is required based on the RXON structure changes.
324 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800325static int iwl3945_commit_rxon(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700326{
327 /* cast away the const for active_rxon in this function */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800328 struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
329 struct iwl3945_rxon_cmd *staging_rxon = (void *)&priv->staging_rxon;
Zhu Yib481de92007-09-25 17:54:57 -0700330 int rc = 0;
331
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800332 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700333 return -1;
334
335 /* always get timestamp with Rx frame */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800336 staging_rxon->flags |= RXON_FLG_TSF2HOST_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700337
338 /* select antenna */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800339 staging_rxon->flags &=
Zhu Yib481de92007-09-25 17:54:57 -0700340 ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800341 staging_rxon->flags |= iwl3945_get_antenna_flags(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700342
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800343 rc = iwl_check_rxon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700344 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800345 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700346 return -EINVAL;
347 }
348
349 /* If we don't need to send a full RXON, we can use
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800350 * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -0700351 * and other flags for the current radio configuration. */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800352 if (!iwl_full_rxon_required(priv)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800353 rc = iwl3945_send_rxon_assoc(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700354 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800355 IWL_ERR(priv, "Error setting RXON_ASSOC "
Zhu Yib481de92007-09-25 17:54:57 -0700356 "configuration (%d).\n", rc);
357 return rc;
358 }
359
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800360 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700361
362 return 0;
363 }
364
365 /* If we are currently associated and the new config requires
366 * an RXON_ASSOC and the new config wants the associated mask enabled,
367 * we must clear the associated from the active configuration
368 * before we apply the new config */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800369 if (iwl_is_associated(priv) &&
370 (staging_rxon->filter_flags & RXON_FILTER_ASSOC_MSK)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800371 IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
Zhu Yib481de92007-09-25 17:54:57 -0700372 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
373
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800374 /*
375 * reserved4 and 5 could have been filled by the iwlcore code.
376 * Let's clear them before pushing to the 3945.
377 */
378 active_rxon->reserved4 = 0;
379 active_rxon->reserved5 = 0;
Samuel Ortiz518099a2009-01-19 15:30:27 -0800380 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800381 sizeof(struct iwl3945_rxon_cmd),
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800382 &priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -0700383
384 /* If the mask clearing failed then we set
385 * active_rxon back to what it was previously */
386 if (rc) {
387 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
Winkler, Tomas15b16872008-12-19 10:37:33 +0800388 IWL_ERR(priv, "Error clearing ASSOC_MSK on current "
Zhu Yib481de92007-09-25 17:54:57 -0700389 "configuration (%d).\n", rc);
390 return rc;
391 }
Zhu Yib481de92007-09-25 17:54:57 -0700392 }
393
Tomas Winklere1623442009-01-27 14:27:56 -0800394 IWL_DEBUG_INFO(priv, "Sending RXON\n"
Zhu Yib481de92007-09-25 17:54:57 -0700395 "* with%s RXON_FILTER_ASSOC_MSK\n"
396 "* channel = %d\n"
Johannes Berge1749612008-10-27 15:59:26 -0700397 "* bssid = %pM\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800398 ((priv->staging_rxon.filter_flags &
Zhu Yib481de92007-09-25 17:54:57 -0700399 RXON_FILTER_ASSOC_MSK) ? "" : "out"),
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800400 le16_to_cpu(staging_rxon->channel),
401 staging_rxon->bssid_addr);
402
403 /*
404 * reserved4 and 5 could have been filled by the iwlcore code.
405 * Let's clear them before pushing to the 3945.
406 */
407 staging_rxon->reserved4 = 0;
408 staging_rxon->reserved5 = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700409
410 /* Apply the new configuration */
Samuel Ortiz518099a2009-01-19 15:30:27 -0800411 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800412 sizeof(struct iwl3945_rxon_cmd),
413 staging_rxon);
Zhu Yib481de92007-09-25 17:54:57 -0700414 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800415 IWL_ERR(priv, "Error setting new configuration (%d).\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700416 return rc;
417 }
418
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800419 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700420
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800421 iwl3945_clear_stations_table(priv);
Zhu Yi556f8db2007-09-27 11:27:33 +0800422
Zhu Yib481de92007-09-25 17:54:57 -0700423 /* If we issue a new RXON command which required a tune then we must
424 * send a new TXPOWER command or we won't be able to Tx any frames */
Samuel Ortiz75bcfae2009-01-23 13:45:11 -0800425 rc = priv->cfg->ops->lib->send_tx_power(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700426 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800427 IWL_ERR(priv, "Error setting Tx power (%d).\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700428 return rc;
429 }
430
431 /* Add the broadcast address so we can send broadcast frames */
Kolekar, Abhijeetb5323d32008-12-19 10:37:22 +0800432 if (iwl3945_add_station(priv, iwl_bcast_addr, 0, 0) ==
Zhu Yib481de92007-09-25 17:54:57 -0700433 IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800434 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700435 return -EIO;
436 }
437
438 /* If we have set the ASSOC_MSK and we are in BSS mode then
439 * add the IWL_AP_ID to the station rate table */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800440 if (iwl_is_associated(priv) &&
Johannes Berg05c914f2008-09-11 00:01:58 +0200441 (priv->iw_mode == NL80211_IFTYPE_STATION))
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800442 if (iwl3945_add_station(priv, priv->active_rxon.bssid_addr,
443 1, 0)
Zhu Yib481de92007-09-25 17:54:57 -0700444 == IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800445 IWL_ERR(priv, "Error adding AP address for transmit\n");
Zhu Yib481de92007-09-25 17:54:57 -0700446 return -EIO;
447 }
448
Johannes Berg8318d782008-01-24 19:38:38 +0100449 /* Init the hardware's rate fallback order based on the band */
Zhu Yib481de92007-09-25 17:54:57 -0700450 rc = iwl3945_init_hw_rate_table(priv);
451 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800452 IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700453 return -EIO;
454 }
455
456 return 0;
457}
458
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800459static int iwl3945_update_sta_key_info(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700460 struct ieee80211_key_conf *keyconf,
461 u8 sta_id)
462{
463 unsigned long flags;
464 __le16 key_flags = 0;
465
466 switch (keyconf->alg) {
467 case ALG_CCMP:
468 key_flags |= STA_KEY_FLG_CCMP;
469 key_flags |= cpu_to_le16(
470 keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
471 key_flags &= ~STA_KEY_FLG_INVALID;
472 break;
473 case ALG_TKIP:
474 case ALG_WEP:
Zhu Yib481de92007-09-25 17:54:57 -0700475 default:
476 return -EINVAL;
477 }
478 spin_lock_irqsave(&priv->sta_lock, flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800479 priv->stations_39[sta_id].keyinfo.alg = keyconf->alg;
480 priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen;
481 memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700482 keyconf->keylen);
483
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800484 memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700485 keyconf->keylen);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800486 priv->stations_39[sta_id].sta.key.key_flags = key_flags;
487 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
488 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700489
490 spin_unlock_irqrestore(&priv->sta_lock, flags);
491
Tomas Winklere1623442009-01-27 14:27:56 -0800492 IWL_DEBUG_INFO(priv, "hwcrypto: modify ucode station key info\n");
Samuel Ortiz17f841c2009-01-23 13:45:20 -0800493 iwl_send_add_sta(priv,
494 (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700495 return 0;
496}
497
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800498static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
Zhu Yib481de92007-09-25 17:54:57 -0700499{
500 unsigned long flags;
501
502 spin_lock_irqsave(&priv->sta_lock, flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800503 memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key));
504 memset(&priv->stations_39[sta_id].sta.key, 0,
Tomas Winkler4c897252008-12-19 10:37:05 +0800505 sizeof(struct iwl4965_keyinfo));
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800506 priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
507 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
508 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700509 spin_unlock_irqrestore(&priv->sta_lock, flags);
510
Tomas Winklere1623442009-01-27 14:27:56 -0800511 IWL_DEBUG_INFO(priv, "hwcrypto: clear ucode station key info\n");
Samuel Ortiz17f841c2009-01-23 13:45:20 -0800512 iwl_send_add_sta(priv,
513 (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700514 return 0;
515}
516
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800517static void iwl3945_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700518{
519 struct list_head *element;
520
Tomas Winklere1623442009-01-27 14:27:56 -0800521 IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
Zhu Yib481de92007-09-25 17:54:57 -0700522 priv->frames_count);
523
524 while (!list_empty(&priv->free_frames)) {
525 element = priv->free_frames.next;
526 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800527 kfree(list_entry(element, struct iwl3945_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700528 priv->frames_count--;
529 }
530
531 if (priv->frames_count) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800532 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
Zhu Yib481de92007-09-25 17:54:57 -0700533 priv->frames_count);
534 priv->frames_count = 0;
535 }
536}
537
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800538static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700539{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800540 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700541 struct list_head *element;
542 if (list_empty(&priv->free_frames)) {
543 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
544 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800545 IWL_ERR(priv, "Could not allocate frame!\n");
Zhu Yib481de92007-09-25 17:54:57 -0700546 return NULL;
547 }
548
549 priv->frames_count++;
550 return frame;
551 }
552
553 element = priv->free_frames.next;
554 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800555 return list_entry(element, struct iwl3945_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700556}
557
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800558static void iwl3945_free_frame(struct iwl_priv *priv, struct iwl3945_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700559{
560 memset(frame, 0, sizeof(*frame));
561 list_add(&frame->list, &priv->free_frames);
562}
563
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800564unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700565 struct ieee80211_hdr *hdr,
Rami Rosen73ec1cc2008-12-16 09:37:07 +0200566 int left)
Zhu Yib481de92007-09-25 17:54:57 -0700567{
568
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800569 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200570 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
571 (priv->iw_mode != NL80211_IFTYPE_AP)))
Zhu Yib481de92007-09-25 17:54:57 -0700572 return 0;
573
574 if (priv->ibss_beacon->len > left)
575 return 0;
576
577 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
578
579 return priv->ibss_beacon->len;
580}
581
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800582static int iwl3945_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700583{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800584 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700585 unsigned int frame_size;
586 int rc;
587 u8 rate;
588
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800589 frame = iwl3945_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700590
591 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800592 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
Zhu Yib481de92007-09-25 17:54:57 -0700593 "command.\n");
594 return -ENOMEM;
595 }
596
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800597 rate = iwl_rate_get_lowest_plcp(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700598
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800599 frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -0700600
Samuel Ortiz518099a2009-01-19 15:30:27 -0800601 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700602 &frame->u.cmd[0]);
603
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800604 iwl3945_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700605
606 return rc;
607}
608
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800609static void iwl3945_unset_hw_params(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700610{
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800611 if (priv->shared_virt)
Zhu Yib481de92007-09-25 17:54:57 -0700612 pci_free_consistent(priv->pci_dev,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800613 sizeof(struct iwl3945_shared),
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800614 priv->shared_virt,
615 priv->shared_phys);
Zhu Yib481de92007-09-25 17:54:57 -0700616}
617
Zhu Yib481de92007-09-25 17:54:57 -0700618/*
619 * QoS support
620*/
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800621static int iwl3945_send_qos_params_command(struct iwl_priv *priv,
Tomas Winkler4c897252008-12-19 10:37:05 +0800622 struct iwl_qosparam_cmd *qos)
Zhu Yib481de92007-09-25 17:54:57 -0700623{
624
Samuel Ortiz518099a2009-01-19 15:30:27 -0800625 return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM,
Tomas Winkler4c897252008-12-19 10:37:05 +0800626 sizeof(struct iwl_qosparam_cmd), qos);
Zhu Yib481de92007-09-25 17:54:57 -0700627}
628
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800629static void iwl3945_activate_qos(struct iwl_priv *priv, u8 force)
Zhu Yib481de92007-09-25 17:54:57 -0700630{
631 unsigned long flags;
632
Zhu Yib481de92007-09-25 17:54:57 -0700633 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
634 return;
635
Zhu Yib481de92007-09-25 17:54:57 -0700636 spin_lock_irqsave(&priv->lock, flags);
637 priv->qos_data.def_qos_parm.qos_flags = 0;
638
639 if (priv->qos_data.qos_cap.q_AP.queue_request &&
640 !priv->qos_data.qos_cap.q_AP.txop_request)
641 priv->qos_data.def_qos_parm.qos_flags |=
642 QOS_PARAM_FLG_TXOP_TYPE_MSK;
643
644 if (priv->qos_data.qos_active)
645 priv->qos_data.def_qos_parm.qos_flags |=
646 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
647
648 spin_unlock_irqrestore(&priv->lock, flags);
649
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800650 if (force || iwl_is_associated(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800651 IWL_DEBUG_QOS(priv, "send QoS cmd with QoS active %d \n",
Zhu Yib481de92007-09-25 17:54:57 -0700652 priv->qos_data.qos_active);
653
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800654 iwl3945_send_qos_params_command(priv,
Zhu Yib481de92007-09-25 17:54:57 -0700655 &(priv->qos_data.def_qos_parm));
656 }
657}
658
Zhu Yib481de92007-09-25 17:54:57 -0700659
Zhu Yib481de92007-09-25 17:54:57 -0700660#define MAX_UCODE_BEACON_INTERVAL 1024
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -0800661#define INTEL_CONN_LISTEN_INTERVAL cpu_to_le16(0xA)
Zhu Yib481de92007-09-25 17:54:57 -0700662
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800663static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -0700664{
665 u16 new_val = 0;
666 u16 beacon_factor = 0;
667
668 beacon_factor =
669 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
670 / MAX_UCODE_BEACON_INTERVAL;
671 new_val = beacon_val / beacon_factor;
672
673 return cpu_to_le16(new_val);
674}
675
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800676static void iwl3945_setup_rxon_timing(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700677{
678 u64 interval_tm_unit;
679 u64 tsf, result;
680 unsigned long flags;
681 struct ieee80211_conf *conf = NULL;
682 u16 beacon_int = 0;
683
684 conf = ieee80211_get_hw_conf(priv->hw);
685
686 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler28afaf92008-12-19 10:37:06 +0800687 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
Zhu Yib481de92007-09-25 17:54:57 -0700688 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
689
Tomas Winkler28afaf92008-12-19 10:37:06 +0800690 tsf = priv->timestamp;
Zhu Yib481de92007-09-25 17:54:57 -0700691
692 beacon_int = priv->beacon_int;
693 spin_unlock_irqrestore(&priv->lock, flags);
694
Johannes Berg05c914f2008-09-11 00:01:58 +0200695 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Zhu Yib481de92007-09-25 17:54:57 -0700696 if (beacon_int == 0) {
697 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
698 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
699 } else {
700 priv->rxon_timing.beacon_interval =
701 cpu_to_le16(beacon_int);
702 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800703 iwl3945_adjust_beacon_interval(
Zhu Yib481de92007-09-25 17:54:57 -0700704 le16_to_cpu(priv->rxon_timing.beacon_interval));
705 }
706
707 priv->rxon_timing.atim_window = 0;
708 } else {
709 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800710 iwl3945_adjust_beacon_interval(conf->beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -0700711 /* TODO: we need to get atim_window from upper stack
712 * for now we set to 0 */
713 priv->rxon_timing.atim_window = 0;
714 }
715
716 interval_tm_unit =
717 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
718 result = do_div(tsf, interval_tm_unit);
719 priv->rxon_timing.beacon_init_val =
720 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
721
Tomas Winklere1623442009-01-27 14:27:56 -0800722 IWL_DEBUG_ASSOC(priv,
723 "beacon interval %d beacon timer %d beacon tim %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700724 le16_to_cpu(priv->rxon_timing.beacon_interval),
725 le32_to_cpu(priv->rxon_timing.beacon_init_val),
726 le16_to_cpu(priv->rxon_timing.atim_window));
727}
728
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800729static int iwl3945_set_mode(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -0700730{
Johannes Berg05c914f2008-09-11 00:01:58 +0200731 if (mode == NL80211_IFTYPE_ADHOC) {
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800732 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -0700733
Samuel Ortize6148912009-01-23 13:45:15 -0800734 ch_info = iwl_get_channel_info(priv,
Johannes Berg8318d782008-01-24 19:38:38 +0100735 priv->band,
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800736 le16_to_cpu(priv->staging_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700737
738 if (!ch_info || !is_channel_ibss(ch_info)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800739 IWL_ERR(priv, "channel %d not IBSS channel\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800740 le16_to_cpu(priv->staging_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700741 return -EINVAL;
742 }
743 }
744
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800745 iwl_connection_init_rx_config(priv, mode);
Zhu Yib481de92007-09-25 17:54:57 -0700746
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800747 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700748
Tomas Winklera96a27f2008-10-23 23:48:56 -0700749 /* don't commit rxon if rf-kill is on*/
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800750 if (!iwl_is_ready_rf(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +0800751 return -EAGAIN;
752
753 cancel_delayed_work(&priv->scan_check);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -0800754 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800755 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
Tomas Winklere1623442009-01-27 14:27:56 -0800756 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +0800757 return -EAGAIN;
758 }
759
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800760 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700761
762 return 0;
763}
764
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800765static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
Johannes Berge039fa42008-05-15 12:55:29 +0200766 struct ieee80211_tx_info *info,
Winkler, Tomasc2d79b482008-12-19 10:37:34 +0800767 struct iwl_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -0700768 struct sk_buff *skb_frag,
769 int last_frag)
770{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800771 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
Ivo van Doorn1c014422008-04-17 19:41:02 +0200772 struct iwl3945_hw_key *keyinfo =
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800773 &priv->stations_39[info->control.hw_key->hw_key_idx].keyinfo;
Zhu Yib481de92007-09-25 17:54:57 -0700774
775 switch (keyinfo->alg) {
776 case ALG_CCMP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800777 tx->sec_ctl = TX_CMD_SEC_CCM;
778 memcpy(tx->key, keyinfo->key, keyinfo->keylen);
Tomas Winklere1623442009-01-27 14:27:56 -0800779 IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
Zhu Yib481de92007-09-25 17:54:57 -0700780 break;
781
782 case ALG_TKIP:
783#if 0
Winkler, Tomase52119c2008-12-22 11:31:19 +0800784 tx->sec_ctl = TX_CMD_SEC_TKIP;
Zhu Yib481de92007-09-25 17:54:57 -0700785
786 if (last_frag)
Winkler, Tomase52119c2008-12-22 11:31:19 +0800787 memcpy(tx->tkip_mic.byte, skb_frag->tail - 8,
Zhu Yib481de92007-09-25 17:54:57 -0700788 8);
789 else
Winkler, Tomase52119c2008-12-22 11:31:19 +0800790 memset(tx->tkip_mic.byte, 0, 8);
Zhu Yib481de92007-09-25 17:54:57 -0700791#endif
792 break;
793
794 case ALG_WEP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800795 tx->sec_ctl = TX_CMD_SEC_WEP |
Johannes Berge039fa42008-05-15 12:55:29 +0200796 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
Zhu Yib481de92007-09-25 17:54:57 -0700797
798 if (keyinfo->keylen == 13)
Winkler, Tomase52119c2008-12-22 11:31:19 +0800799 tx->sec_ctl |= TX_CMD_SEC_KEY128;
Zhu Yib481de92007-09-25 17:54:57 -0700800
Winkler, Tomase52119c2008-12-22 11:31:19 +0800801 memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen);
Zhu Yib481de92007-09-25 17:54:57 -0700802
Tomas Winklere1623442009-01-27 14:27:56 -0800803 IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
Johannes Berge039fa42008-05-15 12:55:29 +0200804 "with key %d\n", info->control.hw_key->hw_key_idx);
Zhu Yib481de92007-09-25 17:54:57 -0700805 break;
806
Zhu Yib481de92007-09-25 17:54:57 -0700807 default:
Tomas Winkler978785a2008-12-19 10:37:31 +0800808 IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg);
Zhu Yib481de92007-09-25 17:54:57 -0700809 break;
810 }
811}
812
813/*
814 * handle build REPLY_TX command notification.
815 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800816static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
Winkler, Tomasc2d79b482008-12-19 10:37:34 +0800817 struct iwl_cmd *cmd,
Johannes Berge039fa42008-05-15 12:55:29 +0200818 struct ieee80211_tx_info *info,
Winkler, Tomase52119c2008-12-22 11:31:19 +0800819 struct ieee80211_hdr *hdr, u8 std_id)
Zhu Yib481de92007-09-25 17:54:57 -0700820{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800821 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
822 __le32 tx_flags = tx->tx_flags;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700823 __le16 fc = hdr->frame_control;
Johannes Berge6a98542008-10-21 12:40:02 +0200824 u8 rc_flags = info->control.rates[0].flags;
Zhu Yib481de92007-09-25 17:54:57 -0700825
Winkler, Tomase52119c2008-12-22 11:31:19 +0800826 tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Johannes Berge039fa42008-05-15 12:55:29 +0200827 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
Zhu Yib481de92007-09-25 17:54:57 -0700828 tx_flags |= TX_CMD_FLG_ACK_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700829 if (ieee80211_is_mgmt(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700830 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700831 if (ieee80211_is_probe_resp(fc) &&
Zhu Yib481de92007-09-25 17:54:57 -0700832 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
833 tx_flags |= TX_CMD_FLG_TSF_MSK;
834 } else {
835 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
836 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
837 }
838
Winkler, Tomase52119c2008-12-22 11:31:19 +0800839 tx->sta_id = std_id;
Harvey Harrison8b7b1e02008-06-11 14:21:56 -0700840 if (ieee80211_has_morefrags(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700841 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
842
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700843 if (ieee80211_is_data_qos(fc)) {
844 u8 *qc = ieee80211_get_qos_ctl(hdr);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800845 tx->tid_tspec = qc[0] & 0xf;
Zhu Yib481de92007-09-25 17:54:57 -0700846 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800847 } else {
Zhu Yib481de92007-09-25 17:54:57 -0700848 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800849 }
Zhu Yib481de92007-09-25 17:54:57 -0700850
Johannes Berge6a98542008-10-21 12:40:02 +0200851 if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
Zhu Yib481de92007-09-25 17:54:57 -0700852 tx_flags |= TX_CMD_FLG_RTS_MSK;
853 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
Johannes Berge6a98542008-10-21 12:40:02 +0200854 } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
Zhu Yib481de92007-09-25 17:54:57 -0700855 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
856 tx_flags |= TX_CMD_FLG_CTS_MSK;
857 }
858
859 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
860 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
861
862 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700863 if (ieee80211_is_mgmt(fc)) {
864 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
Winkler, Tomase52119c2008-12-22 11:31:19 +0800865 tx->timeout.pm_frame_timeout = cpu_to_le16(3);
Zhu Yib481de92007-09-25 17:54:57 -0700866 else
Winkler, Tomase52119c2008-12-22 11:31:19 +0800867 tx->timeout.pm_frame_timeout = cpu_to_le16(2);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700868 } else {
Winkler, Tomase52119c2008-12-22 11:31:19 +0800869 tx->timeout.pm_frame_timeout = 0;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700870#ifdef CONFIG_IWL3945_LEDS
871 priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
872#endif
873 }
Zhu Yib481de92007-09-25 17:54:57 -0700874
Winkler, Tomase52119c2008-12-22 11:31:19 +0800875 tx->driver_txop = 0;
876 tx->tx_flags = tx_flags;
877 tx->next_frame_len = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700878}
879
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800880/**
881 * iwl3945_get_sta_id - Find station's index within station table
882 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800883static int iwl3945_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
Zhu Yib481de92007-09-25 17:54:57 -0700884{
885 int sta_id;
886 u16 fc = le16_to_cpu(hdr->frame_control);
887
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800888 /* If this frame is broadcast or management, use broadcast station id */
Zhu Yib481de92007-09-25 17:54:57 -0700889 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
890 is_multicast_ether_addr(hdr->addr1))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800891 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700892
893 switch (priv->iw_mode) {
894
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800895 /* If we are a client station in a BSS network, use the special
896 * AP station entry (that's the only station we communicate with) */
Johannes Berg05c914f2008-09-11 00:01:58 +0200897 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -0700898 return IWL_AP_ID;
899
900 /* If we are an AP, then find the station, or use BCAST */
Johannes Berg05c914f2008-09-11 00:01:58 +0200901 case NL80211_IFTYPE_AP:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800902 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700903 if (sta_id != IWL_INVALID_STATION)
904 return sta_id;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800905 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700906
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800907 /* If this frame is going out to an IBSS network, find the station,
908 * or create a new station table entry */
Johannes Berg05c914f2008-09-11 00:01:58 +0200909 case NL80211_IFTYPE_ADHOC: {
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800910 /* Create new station table entry */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800911 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700912 if (sta_id != IWL_INVALID_STATION)
913 return sta_id;
914
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800915 sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
Zhu Yib481de92007-09-25 17:54:57 -0700916
917 if (sta_id != IWL_INVALID_STATION)
918 return sta_id;
919
Tomas Winklere1623442009-01-27 14:27:56 -0800920 IWL_DEBUG_DROP(priv, "Station %pM not in station map. "
Zhu Yib481de92007-09-25 17:54:57 -0700921 "Defaulting to broadcast...\n",
Johannes Berge1749612008-10-27 15:59:26 -0700922 hdr->addr1);
Samuel Ortiz40b8ec02008-12-19 10:37:08 +0800923 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800924 return priv->hw_params.bcast_sta_id;
Joe Perches0795af52007-10-03 17:59:30 -0700925 }
Stefanik Gábor914233d2008-06-30 17:23:30 +0800926 /* If we are in monitor mode, use BCAST. This is required for
927 * packet injection. */
Johannes Berg05c914f2008-09-11 00:01:58 +0200928 case NL80211_IFTYPE_MONITOR:
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800929 return priv->hw_params.bcast_sta_id;
Stefanik Gábor914233d2008-06-30 17:23:30 +0800930
Zhu Yib481de92007-09-25 17:54:57 -0700931 default:
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800932 IWL_WARN(priv, "Unknown mode of operation: %d\n",
933 priv->iw_mode);
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800934 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700935 }
936}
937
938/*
939 * start REPLY_TX command process
940 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800941static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -0700942{
943 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berge039fa42008-05-15 12:55:29 +0200944 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800945 struct iwl3945_tx_cmd *tx;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800946 struct iwl_tx_queue *txq = NULL;
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800947 struct iwl_queue *q = NULL;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800948 struct iwl_cmd *out_cmd = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700949 dma_addr_t phys_addr;
950 dma_addr_t txcmd_phys;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800951 int txq_id = skb_get_queue_mapping(skb);
Tomas Winkler54dbb522008-05-15 13:54:06 +0800952 u16 len, idx, len_org, hdr_len;
953 u8 id;
954 u8 unicast;
Zhu Yib481de92007-09-25 17:54:57 -0700955 u8 sta_id;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800956 u8 tid = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700957 u16 seq_number = 0;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700958 __le16 fc;
Zhu Yib481de92007-09-25 17:54:57 -0700959 u8 wait_write_ptr = 0;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800960 u8 *qc = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700961 unsigned long flags;
962 int rc;
963
964 spin_lock_irqsave(&priv->lock, flags);
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800965 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800966 IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
Zhu Yib481de92007-09-25 17:54:57 -0700967 goto drop_unlock;
968 }
969
Johannes Berge039fa42008-05-15 12:55:29 +0200970 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800971 IWL_ERR(priv, "ERROR: No TX rate available.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700972 goto drop_unlock;
973 }
974
975 unicast = !is_multicast_ether_addr(hdr->addr1);
976 id = 0;
977
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700978 fc = hdr->frame_control;
Zhu Yib481de92007-09-25 17:54:57 -0700979
Samuel Ortizd08853a2009-01-23 13:45:17 -0800980#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -0700981 if (ieee80211_is_auth(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800982 IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700983 else if (ieee80211_is_assoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800984 IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700985 else if (ieee80211_is_reassoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800986 IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
Zhu Yib481de92007-09-25 17:54:57 -0700987#endif
988
Mohamed Abbas7878a5a2007-11-29 11:10:13 +0800989 /* drop all data frame if we are not associated */
Stefanik Gábor914233d2008-06-30 17:23:30 +0800990 if (ieee80211_is_data(fc) &&
Johannes Berg05c914f2008-09-11 00:01:58 +0200991 (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800992 (!iwl_is_associated(priv) ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200993 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
Tomas Winklere1623442009-01-27 14:27:56 -0800994 IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n");
Zhu Yib481de92007-09-25 17:54:57 -0700995 goto drop_unlock;
996 }
997
998 spin_unlock_irqrestore(&priv->lock, flags);
999
Harvey Harrison7294ec92008-07-15 18:43:59 -07001000 hdr_len = ieee80211_hdrlen(fc);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001001
1002 /* Find (or create) index into station table for destination station */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001003 sta_id = iwl3945_get_sta_id(priv, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07001004 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -08001005 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07001006 hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07001007 goto drop;
1008 }
1009
Tomas Winklere1623442009-01-27 14:27:56 -08001010 IWL_DEBUG_RATE(priv, "station Id %d\n", sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07001011
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001012 if (ieee80211_is_data_qos(fc)) {
1013 qc = ieee80211_get_qos_ctl(hdr);
Harvey Harrison7294ec92008-07-15 18:43:59 -07001014 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001015 seq_number = priv->stations_39[sta_id].tid[tid].seq_number &
Zhu Yib481de92007-09-25 17:54:57 -07001016 IEEE80211_SCTL_SEQ;
1017 hdr->seq_ctrl = cpu_to_le16(seq_number) |
1018 (hdr->seq_ctrl &
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -08001019 cpu_to_le16(IEEE80211_SCTL_FRAG));
Zhu Yib481de92007-09-25 17:54:57 -07001020 seq_number += 0x10;
1021 }
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001022
1023 /* Descriptor for chosen Tx queue */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001024 txq = &priv->txq[txq_id];
Zhu Yib481de92007-09-25 17:54:57 -07001025 q = &txq->q;
1026
1027 spin_lock_irqsave(&priv->lock, flags);
1028
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001029 idx = get_cmd_index(q, q->write_ptr, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001030
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001031 /* Set up driver data for this TFD */
Winkler, Tomasdbb66542008-12-22 11:31:14 +08001032 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001033 txq->txb[q->write_ptr].skb[0] = skb;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001034
1035 /* Init first empty entry in queue's array of Tx/cmd buffers */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001036 out_cmd = txq->cmd[idx];
Winkler, Tomase52119c2008-12-22 11:31:19 +08001037 tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
Zhu Yib481de92007-09-25 17:54:57 -07001038 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
Winkler, Tomase52119c2008-12-22 11:31:19 +08001039 memset(tx, 0, sizeof(*tx));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001040
1041 /*
1042 * Set up the Tx-command (not MAC!) header.
1043 * Store the chosen Tx queue and TFD index within the sequence field;
1044 * after Tx, uCode's Tx response will return this value so driver can
1045 * locate the frame within the tx queue and do post-tx processing.
1046 */
Zhu Yib481de92007-09-25 17:54:57 -07001047 out_cmd->hdr.cmd = REPLY_TX;
1048 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001049 INDEX_TO_SEQ(q->write_ptr)));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001050
1051 /* Copy MAC header from skb into command buffer */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001052 memcpy(tx->hdr, hdr, hdr_len);
Zhu Yib481de92007-09-25 17:54:57 -07001053
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001054 /*
1055 * Use the first empty entry in this queue's command buffer array
1056 * to contain the Tx command and MAC header concatenated together
1057 * (payload data will be in another buffer).
1058 * Size of this varies, due to varying MAC header length.
1059 * If end is not dword aligned, we'll have 2 extra bytes at the end
1060 * of the MAC header (device reads on dword boundaries).
1061 * We'll tell device about this padding later.
1062 */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001063 len = sizeof(struct iwl3945_tx_cmd) +
Tomas Winkler4c897252008-12-19 10:37:05 +08001064 sizeof(struct iwl_cmd_header) + hdr_len;
Zhu Yib481de92007-09-25 17:54:57 -07001065
1066 len_org = len;
1067 len = (len + 3) & ~3;
1068
1069 if (len_org != len)
1070 len_org = 1;
1071 else
1072 len_org = 0;
1073
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001074 /* Physical address of this Tx command's header (not MAC header!),
1075 * within command buffer array. */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001076 txcmd_phys = pci_map_single(priv->pci_dev,
1077 out_cmd, sizeof(struct iwl_cmd),
1078 PCI_DMA_TODEVICE);
1079 pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys);
1080 pci_unmap_len_set(&out_cmd->meta, len, sizeof(struct iwl_cmd));
1081 /* Add buffer containing Tx command and MAC(!) header to TFD's
1082 * first entry */
1083 txcmd_phys += offsetof(struct iwl_cmd, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07001084
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001085 /* Add buffer containing Tx command and MAC(!) header to TFD's
1086 * first entry */
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001087 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1088 txcmd_phys, len, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001089
Johannes Bergd0f09802008-07-29 11:32:07 +02001090 if (info->control.hw_key)
Johannes Berge039fa42008-05-15 12:55:29 +02001091 iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001092
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001093 /* Set up TFD's 2nd entry to point directly to remainder of skb,
1094 * if any (802.11 null frames have no payload). */
Zhu Yib481de92007-09-25 17:54:57 -07001095 len = skb->len - hdr_len;
1096 if (len) {
1097 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
1098 len, PCI_DMA_TODEVICE);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001099 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1100 phys_addr, len,
1101 0, U32_PAD(len));
Zhu Yib481de92007-09-25 17:54:57 -07001102 }
1103
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001104 /* Total # bytes to be transmitted */
Zhu Yib481de92007-09-25 17:54:57 -07001105 len = (u16)skb->len;
Winkler, Tomase52119c2008-12-22 11:31:19 +08001106 tx->len = cpu_to_le16(len);
Zhu Yib481de92007-09-25 17:54:57 -07001107
1108 /* TODO need this for burst mode later on */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001109 iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07001110
1111 /* set is_hcca to 0; it probably will never be implemented */
Johannes Berge039fa42008-05-15 12:55:29 +02001112 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001113
Winkler, Tomase52119c2008-12-22 11:31:19 +08001114 tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
1115 tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001116
Harvey Harrison8b7b1e02008-06-11 14:21:56 -07001117 if (!ieee80211_has_morefrags(hdr->frame_control)) {
Zhu Yib481de92007-09-25 17:54:57 -07001118 txq->need_update = 1;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001119 if (qc)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001120 priv->stations_39[sta_id].tid[tid].seq_number = seq_number;
Zhu Yib481de92007-09-25 17:54:57 -07001121 } else {
1122 wait_write_ptr = 1;
1123 txq->need_update = 0;
1124 }
1125
Winkler, Tomase52119c2008-12-22 11:31:19 +08001126 iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx));
Zhu Yib481de92007-09-25 17:54:57 -07001127
Winkler, Tomase52119c2008-12-22 11:31:19 +08001128 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr,
Harvey Harrison7294ec92008-07-15 18:43:59 -07001129 ieee80211_hdrlen(fc));
Zhu Yib481de92007-09-25 17:54:57 -07001130
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001131 /* Tell device the write index *just past* this latest filled TFD */
Tomas Winklerc54b6792008-03-06 17:36:53 -08001132 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001133 rc = iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001134 spin_unlock_irqrestore(&priv->lock, flags);
1135
1136 if (rc)
1137 return rc;
1138
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001139 if ((iwl_queue_space(q) < q->high_mark)
Zhu Yib481de92007-09-25 17:54:57 -07001140 && priv->mac80211_registered) {
1141 if (wait_write_ptr) {
1142 spin_lock_irqsave(&priv->lock, flags);
1143 txq->need_update = 1;
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001144 iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001145 spin_unlock_irqrestore(&priv->lock, flags);
1146 }
1147
Johannes Berge2530082008-05-17 00:57:14 +02001148 ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb));
Zhu Yib481de92007-09-25 17:54:57 -07001149 }
1150
1151 return 0;
1152
1153drop_unlock:
1154 spin_unlock_irqrestore(&priv->lock, flags);
1155drop:
1156 return -1;
1157}
1158
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001159static void iwl3945_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
Zhu Yib481de92007-09-25 17:54:57 -07001160{
1161 unsigned long flags;
1162
1163 if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
1164 return;
1165
Tomas Winklere1623442009-01-27 14:27:56 -08001166 IWL_DEBUG_RF_KILL(priv, "Manual SW RF KILL set to: RADIO %s\n",
Zhu Yib481de92007-09-25 17:54:57 -07001167 disable_radio ? "OFF" : "ON");
1168
1169 if (disable_radio) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08001170 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001171 /* FIXME: This is a workaround for AP */
Johannes Berg05c914f2008-09-11 00:01:58 +02001172 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07001173 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001174 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001175 CSR_UCODE_SW_BIT_RFKILL);
1176 spin_unlock_irqrestore(&priv->lock, flags);
Samuel Ortizc4962942008-12-22 11:31:18 +08001177 iwl_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001178 set_bit(STATUS_RF_KILL_SW, &priv->status);
1179 }
1180 return;
1181 }
1182
1183 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001184 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07001185
1186 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1187 spin_unlock_irqrestore(&priv->lock, flags);
1188
1189 /* wake up ucode */
1190 msleep(10);
1191
1192 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001193 iwl_read32(priv, CSR_UCODE_DRV_GP1);
1194 if (!iwl_grab_nic_access(priv))
1195 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001196 spin_unlock_irqrestore(&priv->lock, flags);
1197
1198 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08001199 IWL_DEBUG_RF_KILL(priv, "Can not turn radio back on - "
Zhu Yib481de92007-09-25 17:54:57 -07001200 "disabled by HW switch\n");
1201 return;
1202 }
1203
Zhu Yi808e72a2008-06-12 09:47:17 +08001204 if (priv->is_open)
1205 queue_work(priv->workqueue, &priv->restart);
Zhu Yib481de92007-09-25 17:54:57 -07001206 return;
1207}
1208
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001209#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07001210
1211#include "iwl-spectrum.h"
1212
1213#define BEACON_TIME_MASK_LOW 0x00FFFFFF
1214#define BEACON_TIME_MASK_HIGH 0xFF000000
1215#define TIME_UNIT 1024
1216
1217/*
1218 * extended beacon time format
1219 * time in usec will be changed into a 32-bit value in 8:24 format
1220 * the high 1 byte is the beacon counts
1221 * the lower 3 bytes is the time in usec within one beacon interval
1222 */
1223
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001224static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001225{
1226 u32 quot;
1227 u32 rem;
1228 u32 interval = beacon_interval * 1024;
1229
1230 if (!interval || !usec)
1231 return 0;
1232
1233 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
1234 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
1235
1236 return (quot << 24) + rem;
1237}
1238
1239/* base is usually what we get from ucode with each received frame,
1240 * the same as HW timer counter counting down
1241 */
1242
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001243static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001244{
1245 u32 base_low = base & BEACON_TIME_MASK_LOW;
1246 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
1247 u32 interval = beacon_interval * TIME_UNIT;
1248 u32 res = (base & BEACON_TIME_MASK_HIGH) +
1249 (addon & BEACON_TIME_MASK_HIGH);
1250
1251 if (base_low > addon_low)
1252 res += base_low - addon_low;
1253 else if (base_low < addon_low) {
1254 res += interval + base_low - addon_low;
1255 res += (1 << 24);
1256 } else
1257 res += (1 << 24);
1258
1259 return cpu_to_le32(res);
1260}
1261
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001262static int iwl3945_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001263 struct ieee80211_measurement_params *params,
1264 u8 type)
1265{
Tomas Winkler600c0e12008-12-19 10:37:04 +08001266 struct iwl_spectrum_cmd spectrum;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001267 struct iwl_rx_packet *res;
Winkler, Tomasc2d79b482008-12-19 10:37:34 +08001268 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001269 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
1270 .data = (void *)&spectrum,
1271 .meta.flags = CMD_WANT_SKB,
1272 };
1273 u32 add_time = le64_to_cpu(params->start_time);
1274 int rc;
1275 int spectrum_resp_status;
1276 int duration = le16_to_cpu(params->duration);
1277
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001278 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001279 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001280 iwl3945_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -07001281 le64_to_cpu(params->start_time) - priv->last_tsf,
1282 le16_to_cpu(priv->rxon_timing.beacon_interval));
1283
1284 memset(&spectrum, 0, sizeof(spectrum));
1285
1286 spectrum.channel_count = cpu_to_le16(1);
1287 spectrum.flags =
1288 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
1289 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
1290 cmd.len = sizeof(spectrum);
1291 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
1292
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001293 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001294 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001295 iwl3945_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -07001296 add_time,
1297 le16_to_cpu(priv->rxon_timing.beacon_interval));
1298 else
1299 spectrum.start_time = 0;
1300
1301 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
1302 spectrum.channels[0].channel = params->channel;
1303 spectrum.channels[0].type = type;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001304 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
Zhu Yib481de92007-09-25 17:54:57 -07001305 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
1306 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
1307
Samuel Ortiz518099a2009-01-19 15:30:27 -08001308 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001309 if (rc)
1310 return rc;
1311
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001312 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001313 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001314 IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -07001315 rc = -EIO;
1316 }
1317
1318 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
1319 switch (spectrum_resp_status) {
1320 case 0: /* Command will be handled */
1321 if (res->u.spectrum.id != 0xff) {
Tomas Winklere1623442009-01-27 14:27:56 -08001322 IWL_DEBUG_INFO(priv, "Replaced existing measurement: %d\n",
Ian Schrambc434dd2007-10-25 17:15:29 +08001323 res->u.spectrum.id);
Zhu Yib481de92007-09-25 17:54:57 -07001324 priv->measurement_status &= ~MEASUREMENT_READY;
1325 }
1326 priv->measurement_status |= MEASUREMENT_ACTIVE;
1327 rc = 0;
1328 break;
1329
1330 case 1: /* Command will not be handled */
1331 rc = -EAGAIN;
1332 break;
1333 }
1334
1335 dev_kfree_skb_any(cmd.meta.u.skb);
1336
1337 return rc;
1338}
1339#endif
1340
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001341static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001342 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001343{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001344 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
1345 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -07001346 struct delayed_work *pwork;
1347
1348 palive = &pkt->u.alive_frame;
1349
Tomas Winklere1623442009-01-27 14:27:56 -08001350 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
Zhu Yib481de92007-09-25 17:54:57 -07001351 "0x%01X 0x%01X\n",
1352 palive->is_valid, palive->ver_type,
1353 palive->ver_subtype);
1354
1355 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
Tomas Winklere1623442009-01-27 14:27:56 -08001356 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001357 memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
1358 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001359 pwork = &priv->init_alive_start;
1360 } else {
Tomas Winklere1623442009-01-27 14:27:56 -08001361 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001362 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001363 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001364 pwork = &priv->alive_start;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001365 iwl3945_disable_events(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001366 }
1367
1368 /* We delay the ALIVE response by 5ms to
1369 * give the HW RF Kill time to activate... */
1370 if (palive->is_valid == UCODE_VALID_OK)
1371 queue_delayed_work(priv->workqueue, pwork,
1372 msecs_to_jiffies(5));
1373 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001374 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001375}
1376
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001377static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001378 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001379{
Helmut Schaac7e035a2009-01-19 13:02:15 +01001380#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001381 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Helmut Schaac7e035a2009-01-19 13:02:15 +01001382#endif
Zhu Yib481de92007-09-25 17:54:57 -07001383
Tomas Winklere1623442009-01-27 14:27:56 -08001384 IWL_DEBUG_RX(priv, "Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
Zhu Yib481de92007-09-25 17:54:57 -07001385 return;
1386}
1387
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001388static void iwl3945_rx_reply_error(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001389 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001390{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001391 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001392
Winkler, Tomas15b16872008-12-19 10:37:33 +08001393 IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
Zhu Yib481de92007-09-25 17:54:57 -07001394 "seq 0x%04X ser 0x%08X\n",
1395 le32_to_cpu(pkt->u.err_resp.error_type),
1396 get_cmd_string(pkt->u.err_resp.cmd_id),
1397 pkt->u.err_resp.cmd_id,
1398 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
1399 le32_to_cpu(pkt->u.err_resp.error_info));
1400}
1401
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001402static void iwl3945_rx_spectrum_measure_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001403 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001404{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001405#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001406 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler600c0e12008-12-19 10:37:04 +08001407 struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001408
1409 if (!report->state) {
Tomas Winklere1623442009-01-27 14:27:56 -08001410 IWL_DEBUG(priv, IWL_DL_11H | IWL_DL_INFO,
Zhu Yib481de92007-09-25 17:54:57 -07001411 "Spectrum Measure Notification: Start\n");
1412 return;
1413 }
1414
1415 memcpy(&priv->measure_report, report, sizeof(*report));
1416 priv->measurement_status |= MEASUREMENT_READY;
1417#endif
1418}
1419
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001420static void iwl3945_rx_pm_sleep_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001421 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001422{
Samuel Ortizd08853a2009-01-23 13:45:17 -08001423#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001424 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler600c0e12008-12-19 10:37:04 +08001425 struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
Tomas Winklere1623442009-01-27 14:27:56 -08001426 IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07001427 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
1428#endif
1429}
1430
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001431static void iwl3945_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001432 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001433{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001434 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winklere1623442009-01-27 14:27:56 -08001435 IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
Zhu Yib481de92007-09-25 17:54:57 -07001436 "notification for %s:\n",
1437 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08001438 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw,
1439 le32_to_cpu(pkt->len));
Zhu Yib481de92007-09-25 17:54:57 -07001440}
1441
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001442static void iwl3945_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07001443{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001444 struct iwl_priv *priv =
1445 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07001446 struct sk_buff *beacon;
1447
1448 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02001449 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07001450
1451 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001452 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07001453 return;
1454 }
1455
1456 mutex_lock(&priv->mutex);
1457 /* new beacon skb is allocated every time; dispose previous.*/
1458 if (priv->ibss_beacon)
1459 dev_kfree_skb(priv->ibss_beacon);
1460
1461 priv->ibss_beacon = beacon;
1462 mutex_unlock(&priv->mutex);
1463
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001464 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001465}
1466
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001467static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001468 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001469{
Samuel Ortizd08853a2009-01-23 13:45:17 -08001470#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001471 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001472 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
Zhu Yib481de92007-09-25 17:54:57 -07001473 u8 rate = beacon->beacon_notify_hdr.rate;
1474
Tomas Winklere1623442009-01-27 14:27:56 -08001475 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
Zhu Yib481de92007-09-25 17:54:57 -07001476 "tsf %d %d rate %d\n",
1477 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
1478 beacon->beacon_notify_hdr.failure_frame,
1479 le32_to_cpu(beacon->ibss_mgr_status),
1480 le32_to_cpu(beacon->high_tsf),
1481 le32_to_cpu(beacon->low_tsf), rate);
1482#endif
1483
Johannes Berg05c914f2008-09-11 00:01:58 +02001484 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -07001485 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1486 queue_work(priv->workqueue, &priv->beacon_update);
1487}
1488
Zhu Yib481de92007-09-25 17:54:57 -07001489/* Handle notification from uCode that card's power state is changing
1490 * due to software, hardware, or critical temperature RFKILL */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001491static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001492 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001493{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001494 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001495 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1496 unsigned long status = priv->status;
1497
Tomas Winklere1623442009-01-27 14:27:56 -08001498 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n",
Zhu Yib481de92007-09-25 17:54:57 -07001499 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1500 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1501
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001502 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001503 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1504
1505 if (flags & HW_CARD_DISABLED)
1506 set_bit(STATUS_RF_KILL_HW, &priv->status);
1507 else
1508 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1509
1510
1511 if (flags & SW_CARD_DISABLED)
1512 set_bit(STATUS_RF_KILL_SW, &priv->status);
1513 else
1514 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1515
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08001516 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001517
1518 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1519 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1520 (test_bit(STATUS_RF_KILL_SW, &status) !=
1521 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1522 queue_work(priv->workqueue, &priv->rf_kill);
1523 else
1524 wake_up_interruptible(&priv->wait_command_queue);
1525}
1526
1527/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001528 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07001529 *
1530 * Setup the RX handlers for each of the reply types sent from the uCode
1531 * to the host.
1532 *
1533 * This function chains into the hardware specific files for them to setup
1534 * any hardware specific handlers as well.
1535 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001536static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001537{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001538 priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
1539 priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
1540 priv->rx_handlers[REPLY_ERROR] = iwl3945_rx_reply_error;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001541 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Zhu Yib481de92007-09-25 17:54:57 -07001542 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001543 iwl3945_rx_spectrum_measure_notif;
1544 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl3945_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001545 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001546 iwl3945_rx_pm_debug_statistics_notif;
1547 priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001548
Ben Cahill9fbab512007-11-29 11:09:47 +08001549 /*
1550 * The same handler is used for both the REPLY to a discrete
1551 * statistics request from the host as well as for the periodic
1552 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07001553 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001554 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
1555 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
Zhu Yib481de92007-09-25 17:54:57 -07001556
Abhijeet Kolekarcade0eb2009-02-18 15:54:26 -08001557 iwl_setup_rx_scan_handlers(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001558 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001559
Ben Cahill9fbab512007-11-29 11:09:47 +08001560 /* Set up hardware specific Rx handlers */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001561 iwl3945_hw_rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001562}
1563
1564/**
Tomas Winkler91c066f2008-03-06 17:36:55 -08001565 * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries
1566 * When FW advances 'R' index, all entries between old and new 'R' index
1567 * need to be reclaimed.
1568 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001569static void iwl3945_cmd_queue_reclaim(struct iwl_priv *priv,
Tomas Winkler91c066f2008-03-06 17:36:55 -08001570 int txq_id, int index)
1571{
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001572 struct iwl_tx_queue *txq = &priv->txq[txq_id];
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001573 struct iwl_queue *q = &txq->q;
Tomas Winkler91c066f2008-03-06 17:36:55 -08001574 int nfreed = 0;
1575
Winkler, Tomas625a3812009-01-08 10:19:55 -08001576 if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001577 IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, "
Tomas Winkler91c066f2008-03-06 17:36:55 -08001578 "is out of range [0-%d] %d %d.\n", txq_id,
1579 index, q->n_bd, q->write_ptr, q->read_ptr);
1580 return;
1581 }
1582
1583 for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
1584 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
1585 if (nfreed > 1) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001586 IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", index,
Tomas Winkler91c066f2008-03-06 17:36:55 -08001587 q->write_ptr, q->read_ptr);
1588 queue_work(priv->workqueue, &priv->restart);
1589 break;
1590 }
1591 nfreed++;
1592 }
1593}
1594
1595
1596/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001597 * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
Zhu Yib481de92007-09-25 17:54:57 -07001598 * @rxb: Rx buffer to reclaim
1599 *
1600 * If an Rx buffer has an async callback associated with it the callback
1601 * will be executed. The attached skb (if present) will only be freed
1602 * if the callback returns 1
1603 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001604static void iwl3945_tx_cmd_complete(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001605 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001606{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001607 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001608 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
1609 int txq_id = SEQ_TO_QUEUE(sequence);
1610 int index = SEQ_TO_INDEX(sequence);
Tomas Winkler600c0e12008-12-19 10:37:04 +08001611 int huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
Zhu Yib481de92007-09-25 17:54:57 -07001612 int cmd_index;
Winkler, Tomasc2d79b482008-12-19 10:37:34 +08001613 struct iwl_cmd *cmd;
Zhu Yib481de92007-09-25 17:54:57 -07001614
Chatre, Reinette638d0eb2009-01-19 15:30:24 -08001615 if (WARN(txq_id != IWL_CMD_QUEUE_NUM,
1616 "wrong command queue %d, sequence 0x%X readp=%d writep=%d\n",
1617 txq_id, sequence,
1618 priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr,
1619 priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) {
1620 iwl_print_hex_dump(priv, IWL_DL_INFO , rxb, 32);
1621 return;
1622 }
Zhu Yib481de92007-09-25 17:54:57 -07001623
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001624 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
1625 cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
Zhu Yib481de92007-09-25 17:54:57 -07001626
1627 /* Input error checking is done when commands are added to queue. */
1628 if (cmd->meta.flags & CMD_WANT_SKB) {
1629 cmd->meta.source->u.skb = rxb->skb;
1630 rxb->skb = NULL;
1631 } else if (cmd->meta.u.callback &&
1632 !cmd->meta.u.callback(priv, cmd, rxb->skb))
1633 rxb->skb = NULL;
1634
Tomas Winkler91c066f2008-03-06 17:36:55 -08001635 iwl3945_cmd_queue_reclaim(priv, txq_id, index);
Zhu Yib481de92007-09-25 17:54:57 -07001636
1637 if (!(cmd->meta.flags & CMD_ASYNC)) {
1638 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1639 wake_up_interruptible(&priv->wait_command_queue);
1640 }
1641}
1642
1643/************************** RX-FUNCTIONS ****************************/
1644/*
1645 * Rx theory of operation
1646 *
1647 * The host allocates 32 DMA target addresses and passes the host address
1648 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
1649 * 0 to 31
1650 *
1651 * Rx Queue Indexes
1652 * The host/firmware share two index registers for managing the Rx buffers.
1653 *
1654 * The READ index maps to the first position that the firmware may be writing
1655 * to -- the driver can read up to (but not including) this position and get
1656 * good data.
1657 * The READ index is managed by the firmware once the card is enabled.
1658 *
1659 * The WRITE index maps to the last position the driver has read from -- the
1660 * position preceding WRITE is the last slot the firmware can place a packet.
1661 *
1662 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
1663 * WRITE = READ.
1664 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001665 * During initialization, the host sets up the READ queue position to the first
Zhu Yib481de92007-09-25 17:54:57 -07001666 * INDEX position, and WRITE to the last (READ - 1 wrapped)
1667 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001668 * When the firmware places a packet in a buffer, it will advance the READ index
Zhu Yib481de92007-09-25 17:54:57 -07001669 * and fire the RX interrupt. The driver can then query the READ index and
1670 * process as many packets as possible, moving the WRITE index forward as it
1671 * resets the Rx queue buffers with new memory.
1672 *
1673 * The management in the driver is as follows:
1674 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
1675 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Ian Schram01ebd062007-10-25 17:15:22 +08001676 * to replenish the iwl->rxq->rx_free.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001677 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
Zhu Yib481de92007-09-25 17:54:57 -07001678 * iwl->rxq is replenished and the READ INDEX is updated (updating the
1679 * 'processed' and 'read' driver indexes as well)
1680 * + A received packet is processed and handed to the kernel network stack,
1681 * detached from the iwl->rxq. The driver 'processed' index is updated.
1682 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
1683 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
1684 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
1685 * were enough free buffers and RX_STALLED is set it is cleared.
1686 *
1687 *
1688 * Driver sequence:
1689 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001690 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001691 * iwl3945_rx_queue_restock
Ben Cahill9fbab512007-11-29 11:09:47 +08001692 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
Zhu Yib481de92007-09-25 17:54:57 -07001693 * queue, updates firmware pointers, and updates
1694 * the WRITE index. If insufficient rx_free buffers
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001695 * are available, schedules iwl3945_rx_replenish
Zhu Yib481de92007-09-25 17:54:57 -07001696 *
1697 * -- enable interrupts --
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001698 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
Zhu Yib481de92007-09-25 17:54:57 -07001699 * READ INDEX, detaching the SKB from the pool.
1700 * Moves the packet buffer from queue to rx_used.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001701 * Calls iwl3945_rx_queue_restock to refill any empty
Zhu Yib481de92007-09-25 17:54:57 -07001702 * slots.
1703 * ...
1704 *
1705 */
1706
1707/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001708 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
Zhu Yib481de92007-09-25 17:54:57 -07001709 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001710static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001711 dma_addr_t dma_addr)
1712{
1713 return cpu_to_le32((u32)dma_addr);
1714}
1715
1716/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001717 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
Zhu Yib481de92007-09-25 17:54:57 -07001718 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001719 * If there are slots in the RX queue that need to be restocked,
Zhu Yib481de92007-09-25 17:54:57 -07001720 * and we have free pre-allocated buffers, fill the ranks as much
Ben Cahill9fbab512007-11-29 11:09:47 +08001721 * as we can, pulling from rx_free.
Zhu Yib481de92007-09-25 17:54:57 -07001722 *
1723 * This moves the 'write' index forward to catch up with 'processed', and
1724 * also updates the memory address in the firmware to reference the new
1725 * target buffer.
1726 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001727static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001728{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001729 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001730 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001731 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001732 unsigned long flags;
1733 int write, rc;
1734
1735 spin_lock_irqsave(&rxq->lock, flags);
1736 write = rxq->write & ~0x7;
Winkler, Tomas37d68312009-01-08 10:19:54 -08001737 while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001738 /* Get next free Rx buffer, remove from free list */
Zhu Yib481de92007-09-25 17:54:57 -07001739 element = rxq->rx_free.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001740 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Zhu Yib481de92007-09-25 17:54:57 -07001741 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001742
1743 /* Point to Rx buffer via next RBD in circular buffer */
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001744 rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
Zhu Yib481de92007-09-25 17:54:57 -07001745 rxq->queue[rxq->write] = rxb;
1746 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
1747 rxq->free_count--;
1748 }
1749 spin_unlock_irqrestore(&rxq->lock, flags);
1750 /* If the pre-allocated buffer pool is dropping low, schedule to
1751 * refill it */
1752 if (rxq->free_count <= RX_LOW_WATERMARK)
1753 queue_work(priv->workqueue, &priv->rx_replenish);
1754
1755
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001756 /* If we've added more space for the firmware to place data, tell it.
1757 * Increment device's write pointer in multiples of 8. */
Zhu Yib481de92007-09-25 17:54:57 -07001758 if ((write != (rxq->write & ~0x7))
1759 || (abs(rxq->write - rxq->read) > 7)) {
1760 spin_lock_irqsave(&rxq->lock, flags);
1761 rxq->need_update = 1;
1762 spin_unlock_irqrestore(&rxq->lock, flags);
Winkler, Tomas141c43a2009-01-08 10:19:53 -08001763 rc = iwl_rx_queue_update_write_ptr(priv, rxq);
Zhu Yib481de92007-09-25 17:54:57 -07001764 if (rc)
1765 return rc;
1766 }
1767
1768 return 0;
1769}
1770
1771/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001772 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
Zhu Yib481de92007-09-25 17:54:57 -07001773 *
1774 * When moving to rx_free an SKB is allocated for the slot.
1775 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001776 * Also restock the Rx queue via iwl3945_rx_queue_restock.
Ian Schram01ebd062007-10-25 17:15:22 +08001777 * This is called as a scheduled work item (except for during initialization)
Zhu Yib481de92007-09-25 17:54:57 -07001778 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001779static void iwl3945_rx_allocate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001780{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001781 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001782 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001783 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001784 unsigned long flags;
1785 spin_lock_irqsave(&rxq->lock, flags);
1786 while (!list_empty(&rxq->rx_used)) {
1787 element = rxq->rx_used.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001788 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001789
1790 /* Alloc a new receive buffer */
Zhu Yib481de92007-09-25 17:54:57 -07001791 rxb->skb =
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001792 alloc_skb(priv->hw_params.rx_buf_size,
1793 __GFP_NOWARN | GFP_ATOMIC);
Zhu Yib481de92007-09-25 17:54:57 -07001794 if (!rxb->skb) {
1795 if (net_ratelimit())
Tomas Winkler978785a2008-12-19 10:37:31 +08001796 IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
Zhu Yib481de92007-09-25 17:54:57 -07001797 /* We don't reschedule replenish work here -- we will
1798 * call the restock method and if it still needs
1799 * more buffers it will schedule replenish */
1800 break;
1801 }
Zhu Yi12342c42007-12-20 11:27:32 +08001802
1803 /* If radiotap head is required, reserve some headroom here.
1804 * The physical head count is a variable rx_stats->phy_count.
1805 * We reserve 4 bytes here. Plus these extra bytes, the
1806 * headroom of the physical head should be enough for the
1807 * radiotap head that iwl3945 supported. See iwl3945_rt.
1808 */
1809 skb_reserve(rxb->skb, 4);
1810
Zhu Yib481de92007-09-25 17:54:57 -07001811 priv->alloc_rxb_skb++;
1812 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001813
1814 /* Get physical address of RB/SKB */
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001815 rxb->real_dma_addr = pci_map_single(priv->pci_dev,
1816 rxb->skb->data,
1817 priv->hw_params.rx_buf_size,
1818 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001819 list_add_tail(&rxb->list, &rxq->rx_free);
1820 rxq->free_count++;
1821 }
1822 spin_unlock_irqrestore(&rxq->lock, flags);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001823}
1824
1825/*
1826 * this should be called while priv->lock is locked
1827 */
Tomas Winkler4fd1f842007-12-05 20:59:58 +02001828static void __iwl3945_rx_replenish(void *data)
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001829{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001830 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001831
1832 iwl3945_rx_allocate(priv);
1833 iwl3945_rx_queue_restock(priv);
1834}
1835
1836
1837void iwl3945_rx_replenish(void *data)
1838{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001839 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001840 unsigned long flags;
1841
1842 iwl3945_rx_allocate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001843
1844 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001845 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001846 spin_unlock_irqrestore(&priv->lock, flags);
1847}
1848
Zhu Yib481de92007-09-25 17:54:57 -07001849/* Convert linear signal-to-noise ratio into dB */
1850static u8 ratio2dB[100] = {
1851/* 0 1 2 3 4 5 6 7 8 9 */
1852 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
1853 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
1854 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
1855 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
1856 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
1857 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
1858 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
1859 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
1860 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
1861 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
1862};
1863
1864/* Calculates a relative dB value from a ratio of linear
1865 * (i.e. not dB) signal levels.
1866 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001867int iwl3945_calc_db_from_ratio(int sig_ratio)
Zhu Yib481de92007-09-25 17:54:57 -07001868{
Adrian Bunk221c80c2008-02-02 23:19:01 +02001869 /* 1000:1 or higher just report as 60 dB */
1870 if (sig_ratio >= 1000)
Zhu Yib481de92007-09-25 17:54:57 -07001871 return 60;
1872
Adrian Bunk221c80c2008-02-02 23:19:01 +02001873 /* 100:1 or higher, divide by 10 and use table,
Zhu Yib481de92007-09-25 17:54:57 -07001874 * add 20 dB to make up for divide by 10 */
Adrian Bunk221c80c2008-02-02 23:19:01 +02001875 if (sig_ratio >= 100)
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001876 return 20 + (int)ratio2dB[sig_ratio/10];
Zhu Yib481de92007-09-25 17:54:57 -07001877
1878 /* We shouldn't see this */
1879 if (sig_ratio < 1)
1880 return 0;
1881
1882 /* Use table for ratios 1:1 - 99:1 */
1883 return (int)ratio2dB[sig_ratio];
1884}
1885
1886#define PERFECT_RSSI (-20) /* dBm */
1887#define WORST_RSSI (-95) /* dBm */
1888#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
1889
1890/* Calculate an indication of rx signal quality (a percentage, not dBm!).
1891 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
1892 * about formulas used below. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001893int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
Zhu Yib481de92007-09-25 17:54:57 -07001894{
1895 int sig_qual;
1896 int degradation = PERFECT_RSSI - rssi_dbm;
1897
1898 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
1899 * as indicator; formula is (signal dbm - noise dbm).
1900 * SNR at or above 40 is a great signal (100%).
1901 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
1902 * Weakest usable signal is usually 10 - 15 dB SNR. */
1903 if (noise_dbm) {
1904 if (rssi_dbm - noise_dbm >= 40)
1905 return 100;
1906 else if (rssi_dbm < noise_dbm)
1907 return 0;
1908 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
1909
1910 /* Else use just the signal level.
1911 * This formula is a least squares fit of data points collected and
1912 * compared with a reference system that had a percentage (%) display
1913 * for signal quality. */
1914 } else
1915 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
1916 (15 * RSSI_RANGE + 62 * degradation)) /
1917 (RSSI_RANGE * RSSI_RANGE);
1918
1919 if (sig_qual > 100)
1920 sig_qual = 100;
1921 else if (sig_qual < 1)
1922 sig_qual = 0;
1923
1924 return sig_qual;
1925}
1926
1927/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001928 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001929 *
1930 * Uses the priv->rx_handlers callback function array to invoke
1931 * the appropriate handlers, including command responses,
1932 * frame-received notifications, and other notifications.
1933 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001934static void iwl3945_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001935{
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001936 struct iwl_rx_mem_buffer *rxb;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001937 struct iwl_rx_packet *pkt;
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001938 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001939 u32 r, i;
1940 int reclaim;
1941 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001942 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001943 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07001944
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001945 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1946 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8cd812b2008-12-19 10:37:43 +08001947 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07001948 i = rxq->read;
1949
Winkler, Tomas37d68312009-01-08 10:19:54 -08001950 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001951 fill_rx = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001952 /* Rx interrupt, but nothing sent from uCode */
1953 if (i == r)
Tomas Winklere1623442009-01-27 14:27:56 -08001954 IWL_DEBUG(priv, IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001955
1956 while (i != r) {
1957 rxb = rxq->queue[i];
1958
Ben Cahill9fbab512007-11-29 11:09:47 +08001959 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001960 * then a bug has been introduced in the queue refilling
1961 * routines -- catch it here */
1962 BUG_ON(rxb == NULL);
1963
1964 rxq->queue[i] = NULL;
1965
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001966 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001967 priv->hw_params.rx_buf_size,
Zhu Yib481de92007-09-25 17:54:57 -07001968 PCI_DMA_FROMDEVICE);
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001969 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001970
1971 /* Reclaim a command buffer only if this packet is a response
1972 * to a (driver-originated) command.
1973 * If the packet (e.g. Rx frame) originated from uCode,
1974 * there is no command buffer to reclaim.
1975 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1976 * but apparently a few don't get set; catch them here. */
1977 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1978 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1979 (pkt->hdr.cmd != REPLY_TX);
1980
1981 /* Based on type of command response or notification,
1982 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001983 * rx_handlers table. See iwl3945_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001984 if (priv->rx_handlers[pkt->hdr.cmd]) {
Tomas Winklere1623442009-01-27 14:27:56 -08001985 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07001986 "r = %d, i = %d, %s, 0x%02x\n", r, i,
1987 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
1988 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1989 } else {
1990 /* No handling needed */
Tomas Winklere1623442009-01-27 14:27:56 -08001991 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07001992 "r %d i %d No handler needed for %s, 0x%02x\n",
1993 r, i, get_cmd_string(pkt->hdr.cmd),
1994 pkt->hdr.cmd);
1995 }
1996
1997 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001998 /* Invoke any callbacks, transfer the skb to caller, and
Samuel Ortiz518099a2009-01-19 15:30:27 -08001999 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07002000 * as we reclaim the driver command queue */
2001 if (rxb && rxb->skb)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002002 iwl3945_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07002003 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002004 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07002005 }
2006
2007 /* For now we just don't re-use anything. We can tweak this
2008 * later to try and re-use notification packets and SKBs that
2009 * fail to Rx correctly */
2010 if (rxb->skb != NULL) {
2011 priv->alloc_rxb_skb--;
2012 dev_kfree_skb_any(rxb->skb);
2013 rxb->skb = NULL;
2014 }
2015
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002016 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08002017 priv->hw_params.rx_buf_size,
2018 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07002019 spin_lock_irqsave(&rxq->lock, flags);
2020 list_add_tail(&rxb->list, &priv->rxq.rx_used);
2021 spin_unlock_irqrestore(&rxq->lock, flags);
2022 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002023 /* If there are a lot of unused frames,
2024 * restock the Rx queue so ucode won't assert. */
2025 if (fill_rx) {
2026 count++;
2027 if (count >= 8) {
2028 priv->rxq.read = i;
2029 __iwl3945_rx_replenish(priv);
2030 count = 0;
2031 }
2032 }
Zhu Yib481de92007-09-25 17:54:57 -07002033 }
2034
2035 /* Backtrack one entry */
2036 priv->rxq.read = i;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002037 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002038}
2039
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002040static void iwl3945_enable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002041{
Tomas Winklere1623442009-01-27 14:27:56 -08002042 IWL_DEBUG_ISR(priv, "Enabling interrupts\n");
Zhu Yib481de92007-09-25 17:54:57 -07002043 set_bit(STATUS_INT_ENABLED, &priv->status);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002044 iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07002045}
2046
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002047
2048/* call this function to flush any scheduled tasklet */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002049static inline void iwl_synchronize_irq(struct iwl_priv *priv)
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002050{
Tomas Winklera96a27f2008-10-23 23:48:56 -07002051 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002052 synchronize_irq(priv->pci_dev->irq);
2053 tasklet_kill(&priv->irq_tasklet);
2054}
2055
2056
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002057static inline void iwl3945_disable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002058{
2059 clear_bit(STATUS_INT_ENABLED, &priv->status);
2060
2061 /* disable interrupts from uCode/NIC to host */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002062 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07002063
2064 /* acknowledge/clear/reset any interrupts still pending
2065 * from uCode or flow handler (Rx/Tx DMA) */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002066 iwl_write32(priv, CSR_INT, 0xffffffff);
2067 iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
Tomas Winklere1623442009-01-27 14:27:56 -08002068 IWL_DEBUG_ISR(priv, "Disabled interrupts\n");
Zhu Yib481de92007-09-25 17:54:57 -07002069}
2070
2071static const char *desc_lookup(int i)
2072{
2073 switch (i) {
2074 case 1:
2075 return "FAIL";
2076 case 2:
2077 return "BAD_PARAM";
2078 case 3:
2079 return "BAD_CHECKSUM";
2080 case 4:
2081 return "NMI_INTERRUPT";
2082 case 5:
2083 return "SYSASSERT";
2084 case 6:
2085 return "FATAL_ERROR";
2086 }
2087
2088 return "UNKNOWN";
2089}
2090
2091#define ERROR_START_OFFSET (1 * sizeof(u32))
2092#define ERROR_ELEM_SIZE (7 * sizeof(u32))
2093
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002094static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002095{
2096 u32 i;
2097 u32 desc, time, count, base, data1;
2098 u32 blink1, blink2, ilink1, ilink2;
2099 int rc;
2100
2101 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
2102
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002103 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002104 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07002105 return;
2106 }
2107
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002108 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002109 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002110 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002111 return;
2112 }
2113
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002114 count = iwl_read_targ_mem(priv, base);
Zhu Yib481de92007-09-25 17:54:57 -07002115
2116 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002117 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
2118 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
2119 priv->status, count);
Zhu Yib481de92007-09-25 17:54:57 -07002120 }
2121
Winkler, Tomas15b16872008-12-19 10:37:33 +08002122 IWL_ERR(priv, "Desc Time asrtPC blink2 "
Zhu Yib481de92007-09-25 17:54:57 -07002123 "ilink1 nmiPC Line\n");
2124 for (i = ERROR_START_OFFSET;
2125 i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
2126 i += ERROR_ELEM_SIZE) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002127 desc = iwl_read_targ_mem(priv, base + i);
Zhu Yib481de92007-09-25 17:54:57 -07002128 time =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002129 iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002130 blink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002131 iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002132 blink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002133 iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002134 ilink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002135 iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002136 ilink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002137 iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002138 data1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002139 iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002140
Winkler, Tomas15b16872008-12-19 10:37:33 +08002141 IWL_ERR(priv,
2142 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
2143 desc_lookup(desc), desc, time, blink1, blink2,
2144 ilink1, ilink2, data1);
Zhu Yib481de92007-09-25 17:54:57 -07002145 }
2146
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002147 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002148
2149}
2150
Ben Cahillf58177b2007-11-29 11:09:43 +08002151#define EVENT_START_OFFSET (6 * sizeof(u32))
Zhu Yib481de92007-09-25 17:54:57 -07002152
2153/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002154 * iwl3945_print_event_log - Dump error event log to syslog
Zhu Yib481de92007-09-25 17:54:57 -07002155 *
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002156 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
Zhu Yib481de92007-09-25 17:54:57 -07002157 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002158static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
Zhu Yib481de92007-09-25 17:54:57 -07002159 u32 num_events, u32 mode)
2160{
2161 u32 i;
2162 u32 base; /* SRAM byte address of event log header */
2163 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
2164 u32 ptr; /* SRAM byte address of log data */
2165 u32 ev, time, data; /* event log data */
2166
2167 if (num_events == 0)
2168 return;
2169
2170 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
2171
2172 if (mode == 0)
2173 event_size = 2 * sizeof(u32);
2174 else
2175 event_size = 3 * sizeof(u32);
2176
2177 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
2178
2179 /* "time" is actually "data" for mode 0 (no timestamp).
2180 * place event id # at far right for easier visual parsing. */
2181 for (i = 0; i < num_events; i++) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002182 ev = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002183 ptr += sizeof(u32);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002184 time = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002185 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002186 if (mode == 0) {
2187 /* data, ev */
2188 IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
2189 } else {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002190 data = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002191 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002192 IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
Zhu Yib481de92007-09-25 17:54:57 -07002193 }
2194 }
2195}
2196
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002197static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002198{
2199 int rc;
2200 u32 base; /* SRAM byte address of event log header */
2201 u32 capacity; /* event log capacity in # entries */
2202 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
2203 u32 num_wraps; /* # times uCode wrapped to top of log */
2204 u32 next_entry; /* index of next entry to be written by uCode */
2205 u32 size; /* # entries that we'll print */
2206
2207 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002208 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002209 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07002210 return;
2211 }
2212
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002213 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002214 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002215 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002216 return;
2217 }
2218
2219 /* event log header */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002220 capacity = iwl_read_targ_mem(priv, base);
2221 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
2222 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
2223 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
Zhu Yib481de92007-09-25 17:54:57 -07002224
2225 size = num_wraps ? capacity : next_entry;
2226
2227 /* bail out if nothing in log */
2228 if (size == 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002229 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002230 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002231 return;
2232 }
2233
Winkler, Tomas15b16872008-12-19 10:37:33 +08002234 IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07002235 size, num_wraps);
2236
2237 /* if uCode has wrapped back to top of log, start at the oldest entry,
2238 * i.e the next one that uCode would fill. */
2239 if (num_wraps)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002240 iwl3945_print_event_log(priv, next_entry,
Zhu Yib481de92007-09-25 17:54:57 -07002241 capacity - next_entry, mode);
2242
2243 /* (then/else) start at top of log */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002244 iwl3945_print_event_log(priv, 0, next_entry, mode);
Zhu Yib481de92007-09-25 17:54:57 -07002245
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002246 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002247}
2248
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002249static void iwl3945_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002250{
2251 unsigned long flags;
2252
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002253 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
2254 sizeof(priv->staging_rxon));
2255 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002256 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002257
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002258 iwl3945_add_station(priv, priv->bssid, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002259
2260 spin_lock_irqsave(&priv->lock, flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002261 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07002262 priv->error_recovering = 0;
2263 spin_unlock_irqrestore(&priv->lock, flags);
2264}
2265
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002266static void iwl3945_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002267{
2268 u32 inta, handled = 0;
2269 u32 inta_fh;
2270 unsigned long flags;
Samuel Ortizd08853a2009-01-23 13:45:17 -08002271#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07002272 u32 inta_mask;
2273#endif
2274
2275 spin_lock_irqsave(&priv->lock, flags);
2276
2277 /* Ack/clear/reset pending uCode interrupts.
2278 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
2279 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002280 inta = iwl_read32(priv, CSR_INT);
2281 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07002282
2283 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
2284 * Any new interrupts that happen after this, either while we're
2285 * in this tasklet, or later, will show up in next ISR/tasklet. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002286 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
2287 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07002288
Samuel Ortizd08853a2009-01-23 13:45:17 -08002289#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002290 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08002291 /* just for debug */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002292 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Tomas Winklere1623442009-01-27 14:27:56 -08002293 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002294 inta, inta_mask, inta_fh);
2295 }
2296#endif
2297
2298 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
2299 * atomic, make sure that inta covers all the interrupts that
2300 * we've discovered, even if FH interrupt came in just after
2301 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002302 if (inta_fh & CSR39_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002303 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002304 if (inta_fh & CSR39_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002305 inta |= CSR_INT_BIT_FH_TX;
2306
2307 /* Now service all interrupt bits discovered above. */
2308 if (inta & CSR_INT_BIT_HW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002309 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002310
2311 /* Tell the device to stop sending interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002312 iwl3945_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002313
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002314 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002315
2316 handled |= CSR_INT_BIT_HW_ERR;
2317
2318 spin_unlock_irqrestore(&priv->lock, flags);
2319
2320 return;
2321 }
2322
Samuel Ortizd08853a2009-01-23 13:45:17 -08002323#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002324 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07002325 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002326 if (inta & CSR_INT_BIT_SCD)
Tomas Winklere1623442009-01-27 14:27:56 -08002327 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
Joonwoo Park25c03d82008-01-23 10:15:20 -08002328 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002329
2330 /* Alive notification via Rx interrupt will do the real work */
2331 if (inta & CSR_INT_BIT_ALIVE)
Tomas Winklere1623442009-01-27 14:27:56 -08002332 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002333 }
2334#endif
2335 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002336 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07002337
Zhu Yib481de92007-09-25 17:54:57 -07002338 /* Error detected by uCode */
2339 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002340 IWL_ERR(priv, "Microcode SW error detected. "
2341 "Restarting 0x%X.\n", inta);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002342 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002343 handled |= CSR_INT_BIT_SW_ERR;
2344 }
2345
2346 /* uCode wakes up after power-down sleep */
2347 if (inta & CSR_INT_BIT_WAKEUP) {
Tomas Winklere1623442009-01-27 14:27:56 -08002348 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
Winkler, Tomas141c43a2009-01-08 10:19:53 -08002349 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08002350 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
2351 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
2352 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
2353 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
2354 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
2355 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07002356
2357 handled |= CSR_INT_BIT_WAKEUP;
2358 }
2359
2360 /* All uCode command responses, including Tx command responses,
2361 * Rx "responses" (frame-received notification), and other
2362 * notifications from uCode come through here*/
2363 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002364 iwl3945_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002365 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
2366 }
2367
2368 if (inta & CSR_INT_BIT_FH_TX) {
Tomas Winklere1623442009-01-27 14:27:56 -08002369 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002370
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002371 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
2372 if (!iwl_grab_nic_access(priv)) {
2373 iwl_write_direct32(priv, FH39_TCSR_CREDIT
Tomas Winklerbddadf82008-12-19 10:37:01 +08002374 (FH39_SRVC_CHNL), 0x0);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002375 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002376 }
2377 handled |= CSR_INT_BIT_FH_TX;
2378 }
2379
2380 if (inta & ~handled)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002381 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Zhu Yib481de92007-09-25 17:54:57 -07002382
2383 if (inta & ~CSR_INI_SET_MASK) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002384 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Zhu Yib481de92007-09-25 17:54:57 -07002385 inta & ~CSR_INI_SET_MASK);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002386 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07002387 }
2388
2389 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002390 /* only Re-enable if disabled by irq */
2391 if (test_bit(STATUS_INT_ENABLED, &priv->status))
2392 iwl3945_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002393
Samuel Ortizd08853a2009-01-23 13:45:17 -08002394#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002395 if (priv->debug_level & (IWL_DL_ISR)) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002396 inta = iwl_read32(priv, CSR_INT);
2397 inta_mask = iwl_read32(priv, CSR_INT_MASK);
2398 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Tomas Winklere1623442009-01-27 14:27:56 -08002399 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
Zhu Yib481de92007-09-25 17:54:57 -07002400 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
2401 }
2402#endif
2403 spin_unlock_irqrestore(&priv->lock, flags);
2404}
2405
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002406static irqreturn_t iwl3945_isr(int irq, void *data)
Zhu Yib481de92007-09-25 17:54:57 -07002407{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002408 struct iwl_priv *priv = data;
Zhu Yib481de92007-09-25 17:54:57 -07002409 u32 inta, inta_mask;
2410 u32 inta_fh;
2411 if (!priv)
2412 return IRQ_NONE;
2413
2414 spin_lock(&priv->lock);
2415
2416 /* Disable (but don't clear!) interrupts here to avoid
2417 * back-to-back ISRs and sporadic interrupts from our NIC.
2418 * If we have something to service, the tasklet will re-enable ints.
2419 * If we *don't* have something, we'll re-enable before leaving here. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002420 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
2421 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07002422
2423 /* Discover which interrupts are active/pending */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002424 inta = iwl_read32(priv, CSR_INT);
2425 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07002426
2427 /* Ignore interrupt if there's nothing in NIC to service.
2428 * This may be due to IRQ shared with another device,
2429 * or due to sporadic interrupts thrown from our NIC. */
2430 if (!inta && !inta_fh) {
Tomas Winklere1623442009-01-27 14:27:56 -08002431 IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0, inta_fh == 0\n");
Zhu Yib481de92007-09-25 17:54:57 -07002432 goto none;
2433 }
2434
2435 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
2436 /* Hardware disappeared */
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002437 IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
Oliver Neukumcb4da1a2007-11-13 21:10:32 -08002438 goto unplugged;
Zhu Yib481de92007-09-25 17:54:57 -07002439 }
2440
Tomas Winklere1623442009-01-27 14:27:56 -08002441 IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002442 inta, inta_mask, inta_fh);
2443
Joonwoo Park25c03d82008-01-23 10:15:20 -08002444 inta &= ~CSR_INT_BIT_SCD;
2445
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002446 /* iwl3945_irq_tasklet() will service interrupts and re-enable them */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002447 if (likely(inta || inta_fh))
2448 tasklet_schedule(&priv->irq_tasklet);
Oliver Neukumcb4da1a2007-11-13 21:10:32 -08002449unplugged:
Zhu Yib481de92007-09-25 17:54:57 -07002450 spin_unlock(&priv->lock);
2451
2452 return IRQ_HANDLED;
2453
2454 none:
2455 /* re-enable interrupts here since we don't have anything to service. */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002456 /* only Re-enable if disabled by irq */
2457 if (test_bit(STATUS_INT_ENABLED, &priv->status))
2458 iwl3945_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002459 spin_unlock(&priv->lock);
2460 return IRQ_NONE;
2461}
2462
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002463static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01002464 enum ieee80211_band band,
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08002465 u8 is_active, u8 n_probes,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002466 struct iwl3945_scan_channel *scan_ch)
Zhu Yib481de92007-09-25 17:54:57 -07002467{
2468 const struct ieee80211_channel *channels = NULL;
Johannes Berg8318d782008-01-24 19:38:38 +01002469 const struct ieee80211_supported_band *sband;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08002470 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07002471 u16 passive_dwell = 0;
2472 u16 active_dwell = 0;
2473 int added, i;
2474
Kolekar, Abhijeetcbba18c2008-12-19 10:37:42 +08002475 sband = iwl_get_hw_mode(priv, band);
Johannes Berg8318d782008-01-24 19:38:38 +01002476 if (!sband)
Zhu Yib481de92007-09-25 17:54:57 -07002477 return 0;
2478
Johannes Berg8318d782008-01-24 19:38:38 +01002479 channels = sband->channels;
Zhu Yib481de92007-09-25 17:54:57 -07002480
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08002481 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
2482 passive_dwell = iwl_get_passive_dwell_time(priv, band);
Zhu Yib481de92007-09-25 17:54:57 -07002483
Abhijeet Kolekar8f4807a2008-09-03 11:26:31 +08002484 if (passive_dwell <= active_dwell)
2485 passive_dwell = active_dwell + 1;
2486
Johannes Berg8318d782008-01-24 19:38:38 +01002487 for (i = 0, added = 0; i < sband->n_channels; i++) {
Johannes Berg182e2e62008-04-04 10:41:56 +02002488 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
2489 continue;
2490
Johannes Berg8318d782008-01-24 19:38:38 +01002491 scan_ch->channel = channels[i].hw_value;
Zhu Yib481de92007-09-25 17:54:57 -07002492
Samuel Ortize6148912009-01-23 13:45:15 -08002493 ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
Zhu Yib481de92007-09-25 17:54:57 -07002494 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002495 IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
Zhu Yib481de92007-09-25 17:54:57 -07002496 scan_ch->channel);
2497 continue;
2498 }
2499
Zhu Yib481de92007-09-25 17:54:57 -07002500 scan_ch->active_dwell = cpu_to_le16(active_dwell);
2501 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002502 /* If passive , set up for auto-switch
2503 * and use long active_dwell time.
2504 */
2505 if (!is_active || is_channel_passive(ch_info) ||
2506 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
2507 scan_ch->type = 0; /* passive */
2508 if (IWL_UCODE_API(priv->ucode_ver) == 1)
2509 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
2510 } else {
2511 scan_ch->type = 1; /* active */
2512 }
2513
2514 /* Set direct probe bits. These may be used both for active
2515 * scan channels (probes gets sent right away),
2516 * or for passive channels (probes get se sent only after
2517 * hearing clear Rx packet).*/
2518 if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
2519 if (n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002520 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002521 } else {
2522 /* uCode v1 does not allow setting direct probe bits on
2523 * passive channel. */
2524 if ((scan_ch->type & 1) && n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002525 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002526 }
Zhu Yib481de92007-09-25 17:54:57 -07002527
Ben Cahill9fbab512007-11-29 11:09:47 +08002528 /* Set txpower levels to defaults */
Zhu Yib481de92007-09-25 17:54:57 -07002529 scan_ch->tpc.dsp_atten = 110;
2530 /* scan_pwr_info->tpc.dsp_atten; */
2531
2532 /*scan_pwr_info->tpc.tx_gain; */
Johannes Berg8318d782008-01-24 19:38:38 +01002533 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -07002534 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
2535 else {
2536 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
2537 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
Ben Cahill9fbab512007-11-29 11:09:47 +08002538 * power level:
Reinette Chatre8a1b0242008-01-14 17:46:25 -08002539 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
Zhu Yib481de92007-09-25 17:54:57 -07002540 */
2541 }
2542
Tomas Winklere1623442009-01-27 14:27:56 -08002543 IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n",
Zhu Yib481de92007-09-25 17:54:57 -07002544 scan_ch->channel,
2545 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
2546 (scan_ch->type & 1) ?
2547 active_dwell : passive_dwell);
2548
2549 scan_ch++;
2550 added++;
2551 }
2552
Tomas Winklere1623442009-01-27 14:27:56 -08002553 IWL_DEBUG_SCAN(priv, "total channels to scan %d \n", added);
Zhu Yib481de92007-09-25 17:54:57 -07002554 return added;
2555}
2556
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002557static void iwl3945_init_hw_rates(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002558 struct ieee80211_rate *rates)
2559{
2560 int i;
2561
2562 for (i = 0; i < IWL_RATE_COUNT; i++) {
Johannes Berg8318d782008-01-24 19:38:38 +01002563 rates[i].bitrate = iwl3945_rates[i].ieee * 5;
2564 rates[i].hw_value = i; /* Rate scaling will work on indexes */
2565 rates[i].hw_value_short = i;
2566 rates[i].flags = 0;
Samuel Ortizd9829a62008-12-19 10:37:12 +08002567 if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
Zhu Yib481de92007-09-25 17:54:57 -07002568 /*
Johannes Berg8318d782008-01-24 19:38:38 +01002569 * If CCK != 1M then set short preamble rate flag.
Zhu Yib481de92007-09-25 17:54:57 -07002570 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002571 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
Johannes Berg8318d782008-01-24 19:38:38 +01002572 0 : IEEE80211_RATE_SHORT_PREAMBLE;
Zhu Yib481de92007-09-25 17:54:57 -07002573 }
Zhu Yib481de92007-09-25 17:54:57 -07002574 }
2575}
2576
Zhu Yib481de92007-09-25 17:54:57 -07002577/******************************************************************************
2578 *
2579 * uCode download functions
2580 *
2581 ******************************************************************************/
2582
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002583static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002584{
Tomas Winkler98c92212008-01-14 17:46:20 -08002585 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
2586 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
2587 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
2588 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
2589 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
2590 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07002591}
2592
2593/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002594 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002595 * looking at all data.
2596 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002597static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002598{
2599 u32 val;
2600 u32 save_len = len;
2601 int rc = 0;
2602 u32 errcnt;
2603
Tomas Winklere1623442009-01-27 14:27:56 -08002604 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002605
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002606 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002607 if (rc)
2608 return rc;
2609
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002610 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002611 IWL39_RTC_INST_LOWER_BOUND);
Zhu Yib481de92007-09-25 17:54:57 -07002612
2613 errcnt = 0;
2614 for (; len > 0; len -= sizeof(u32), image++) {
2615 /* read data comes through single port, auto-incr addr */
2616 /* NOTE: Use the debugless read so we don't flood kernel log
2617 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002618 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002619 if (val != le32_to_cpu(*image)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002620 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002621 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2622 save_len - len, val, le32_to_cpu(*image));
2623 rc = -EIO;
2624 errcnt++;
2625 if (errcnt >= 20)
2626 break;
2627 }
2628 }
2629
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002630 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002631
2632 if (!errcnt)
Tomas Winklere1623442009-01-27 14:27:56 -08002633 IWL_DEBUG_INFO(priv,
2634 "ucode image in INSTRUCTION memory is good\n");
Zhu Yib481de92007-09-25 17:54:57 -07002635
2636 return rc;
2637}
2638
2639
2640/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002641 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002642 * using sample data 100 bytes apart. If these sample points are good,
2643 * it's a pretty good bet that everything between them is good, too.
2644 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002645static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002646{
2647 u32 val;
2648 int rc = 0;
2649 u32 errcnt = 0;
2650 u32 i;
2651
Tomas Winklere1623442009-01-27 14:27:56 -08002652 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002653
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002654 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002655 if (rc)
2656 return rc;
2657
2658 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
2659 /* read data comes through single port, auto-incr addr */
2660 /* NOTE: Use the debugless read so we don't flood kernel log
2661 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002662 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002663 i + IWL39_RTC_INST_LOWER_BOUND);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002664 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002665 if (val != le32_to_cpu(*image)) {
2666#if 0 /* Enable this if you want to see details */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002667 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002668 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2669 i, val, *image);
2670#endif
2671 rc = -EIO;
2672 errcnt++;
2673 if (errcnt >= 3)
2674 break;
2675 }
2676 }
2677
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002678 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002679
2680 return rc;
2681}
2682
2683
2684/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002685 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
Zhu Yib481de92007-09-25 17:54:57 -07002686 * and verify its contents
2687 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002688static int iwl3945_verify_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002689{
2690 __le32 *image;
2691 u32 len;
2692 int rc = 0;
2693
2694 /* Try bootstrap */
2695 image = (__le32 *)priv->ucode_boot.v_addr;
2696 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002697 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002698 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002699 IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002700 return 0;
2701 }
2702
2703 /* Try initialize */
2704 image = (__le32 *)priv->ucode_init.v_addr;
2705 len = priv->ucode_init.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002706 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002707 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002708 IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002709 return 0;
2710 }
2711
2712 /* Try runtime/protocol */
2713 image = (__le32 *)priv->ucode_code.v_addr;
2714 len = priv->ucode_code.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002715 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002716 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002717 IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002718 return 0;
2719 }
2720
Winkler, Tomas15b16872008-12-19 10:37:33 +08002721 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
Zhu Yib481de92007-09-25 17:54:57 -07002722
Ben Cahill9fbab512007-11-29 11:09:47 +08002723 /* Since nothing seems to match, show first several data entries in
2724 * instruction SRAM, so maybe visual inspection will give a clue.
2725 * Selection of bootstrap image (vs. other images) is arbitrary. */
Zhu Yib481de92007-09-25 17:54:57 -07002726 image = (__le32 *)priv->ucode_boot.v_addr;
2727 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002728 rc = iwl3945_verify_inst_full(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002729
2730 return rc;
2731}
2732
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002733static void iwl3945_nic_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002734{
2735 /* Remove all resets to allow NIC to operate */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002736 iwl_write32(priv, CSR_RESET, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002737}
2738
2739/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002740 * iwl3945_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07002741 *
2742 * Copy into buffers for card to fetch via bus-mastering
2743 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002744static int iwl3945_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002745{
Kolekar, Abhijeeta78fe752008-12-19 10:37:21 +08002746 struct iwl_ucode *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002747 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07002748 const struct firmware *ucode_raw;
2749 /* firmware file name contains uCode/driver compatibility version */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002750 const char *name_pre = priv->cfg->fw_name_pre;
2751 const unsigned int api_max = priv->cfg->ucode_api_max;
2752 const unsigned int api_min = priv->cfg->ucode_api_min;
2753 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07002754 u8 *src;
2755 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002756 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07002757
2758 /* Ask kernel firmware_class module to get the boot firmware off disk.
2759 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002760 for (index = api_max; index >= api_min; index--) {
2761 sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
2762 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
2763 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002764 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002765 buf, ret);
2766 if (ret == -ENOENT)
2767 continue;
2768 else
2769 goto error;
2770 } else {
2771 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002772 IWL_ERR(priv, "Loaded firmware %s, "
2773 "which is deprecated. "
2774 " Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002775 buf, api_max);
Tomas Winklere1623442009-01-27 14:27:56 -08002776 IWL_DEBUG_INFO(priv, "Got firmware '%s' file "
2777 "(%zd bytes) from disk\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002778 buf, ucode_raw->size);
2779 break;
2780 }
Zhu Yib481de92007-09-25 17:54:57 -07002781 }
2782
Reinette Chatrea0987a82008-12-02 12:14:06 -08002783 if (ret < 0)
2784 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07002785
2786 /* Make sure that we got at least our header! */
2787 if (ucode_raw->size < sizeof(*ucode)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002788 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002789 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002790 goto err_release;
2791 }
2792
2793 /* Data from ucode file: header followed by uCode images */
2794 ucode = (void *)ucode_raw->data;
2795
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08002796 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08002797 api_ver = IWL_UCODE_API(priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07002798 inst_size = le32_to_cpu(ucode->inst_size);
2799 data_size = le32_to_cpu(ucode->data_size);
2800 init_size = le32_to_cpu(ucode->init_size);
2801 init_data_size = le32_to_cpu(ucode->init_data_size);
2802 boot_size = le32_to_cpu(ucode->boot_size);
2803
Reinette Chatrea0987a82008-12-02 12:14:06 -08002804 /* api_ver should match the api version forming part of the
2805 * firmware filename ... but we don't check for that and only rely
2806 * on the API version read from firware header from here on forward */
2807
2808 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002809 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002810 "Driver supports v%u, firmware is v%u.\n",
2811 api_max, api_ver);
2812 priv->ucode_ver = 0;
2813 ret = -EINVAL;
2814 goto err_release;
2815 }
2816 if (api_ver != api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002817 IWL_ERR(priv, "Firmware has old API version. Expected %u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002818 "got %u. New firmware can be obtained "
2819 "from http://www.intellinuxwireless.org.\n",
2820 api_max, api_ver);
2821
Tomas Winkler978785a2008-12-19 10:37:31 +08002822 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
2823 IWL_UCODE_MAJOR(priv->ucode_ver),
2824 IWL_UCODE_MINOR(priv->ucode_ver),
2825 IWL_UCODE_API(priv->ucode_ver),
2826 IWL_UCODE_SERIAL(priv->ucode_ver));
2827
Tomas Winklere1623442009-01-27 14:27:56 -08002828 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002829 priv->ucode_ver);
Tomas Winklere1623442009-01-27 14:27:56 -08002830 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
2831 inst_size);
2832 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
2833 data_size);
2834 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
2835 init_size);
2836 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
2837 init_data_size);
2838 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
2839 boot_size);
Zhu Yib481de92007-09-25 17:54:57 -07002840
Reinette Chatrea0987a82008-12-02 12:14:06 -08002841
Zhu Yib481de92007-09-25 17:54:57 -07002842 /* Verify size of file vs. image size info in file's header */
2843 if (ucode_raw->size < sizeof(*ucode) +
2844 inst_size + data_size + init_size +
2845 init_data_size + boot_size) {
2846
Tomas Winklere1623442009-01-27 14:27:56 -08002847 IWL_DEBUG_INFO(priv, "uCode file size %zd too small\n",
2848 ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002849 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002850 goto err_release;
2851 }
2852
2853 /* Verify that uCode images will fit in card's SRAM */
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002854 if (inst_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002855 IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002856 inst_size);
2857 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002858 goto err_release;
2859 }
2860
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002861 if (data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002862 IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002863 data_size);
2864 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002865 goto err_release;
2866 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002867 if (init_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002868 IWL_DEBUG_INFO(priv,
2869 "uCode init instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002870 init_size);
2871 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002872 goto err_release;
2873 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002874 if (init_data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002875 IWL_DEBUG_INFO(priv,
2876 "uCode init data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002877 init_data_size);
2878 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002879 goto err_release;
2880 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002881 if (boot_size > IWL39_MAX_BSM_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002882 IWL_DEBUG_INFO(priv,
2883 "uCode boot instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002884 boot_size);
2885 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002886 goto err_release;
2887 }
2888
2889 /* Allocate ucode buffers for card's bus-master loading ... */
2890
2891 /* Runtime instructions and 2 copies of data:
2892 * 1) unmodified from disk
2893 * 2) backup cache for save/restore during power-downs */
2894 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002895 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07002896
2897 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002898 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07002899
2900 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002901 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07002902
2903 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
Tomas Winkler90e759d2007-11-29 11:09:41 +08002904 !priv->ucode_data_backup.v_addr)
Zhu Yib481de92007-09-25 17:54:57 -07002905 goto err_pci_alloc;
2906
Tomas Winkler90e759d2007-11-29 11:09:41 +08002907 /* Initialization instructions and data */
2908 if (init_size && init_data_size) {
2909 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002910 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002911
2912 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002913 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002914
2915 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
2916 goto err_pci_alloc;
2917 }
2918
2919 /* Bootstrap (instructions only, no data) */
2920 if (boot_size) {
2921 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002922 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002923
2924 if (!priv->ucode_boot.v_addr)
2925 goto err_pci_alloc;
2926 }
2927
Zhu Yib481de92007-09-25 17:54:57 -07002928 /* Copy images into buffers for card's bus-master reads ... */
2929
2930 /* Runtime instructions (first block of data in file) */
2931 src = &ucode->data[0];
2932 len = priv->ucode_code.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002933 IWL_DEBUG_INFO(priv,
2934 "Copying (but not loading) uCode instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002935 memcpy(priv->ucode_code.v_addr, src, len);
Tomas Winklere1623442009-01-27 14:27:56 -08002936 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002937 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
2938
2939 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002940 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
Zhu Yib481de92007-09-25 17:54:57 -07002941 src = &ucode->data[inst_size];
2942 len = priv->ucode_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002943 IWL_DEBUG_INFO(priv,
2944 "Copying (but not loading) uCode data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002945 memcpy(priv->ucode_data.v_addr, src, len);
2946 memcpy(priv->ucode_data_backup.v_addr, src, len);
2947
2948 /* Initialization instructions (3rd block) */
2949 if (init_size) {
2950 src = &ucode->data[inst_size + data_size];
2951 len = priv->ucode_init.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002952 IWL_DEBUG_INFO(priv,
2953 "Copying (but not loading) init instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002954 memcpy(priv->ucode_init.v_addr, src, len);
2955 }
2956
2957 /* Initialization data (4th block) */
2958 if (init_data_size) {
2959 src = &ucode->data[inst_size + data_size + init_size];
2960 len = priv->ucode_init_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002961 IWL_DEBUG_INFO(priv,
2962 "Copying (but not loading) init data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002963 memcpy(priv->ucode_init_data.v_addr, src, len);
2964 }
2965
2966 /* Bootstrap instructions (5th block) */
2967 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
2968 len = priv->ucode_boot.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002969 IWL_DEBUG_INFO(priv,
2970 "Copying (but not loading) boot instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002971 memcpy(priv->ucode_boot.v_addr, src, len);
2972
2973 /* We have our copies now, allow OS release its copies */
2974 release_firmware(ucode_raw);
2975 return 0;
2976
2977 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08002978 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002979 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002980 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002981
2982 err_release:
2983 release_firmware(ucode_raw);
2984
2985 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08002986 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002987}
2988
2989
2990/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002991 * iwl3945_set_ucode_ptrs - Set uCode address location
Zhu Yib481de92007-09-25 17:54:57 -07002992 *
2993 * Tell initialization uCode where to find runtime uCode.
2994 *
2995 * BSM registers initially contain pointers to initialization uCode.
2996 * We need to replace them to load runtime uCode inst and data,
2997 * and to save runtime data when powering down.
2998 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002999static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003000{
3001 dma_addr_t pinst;
3002 dma_addr_t pdata;
3003 int rc = 0;
3004 unsigned long flags;
3005
3006 /* bits 31:0 for 3945 */
3007 pinst = priv->ucode_code.p_addr;
3008 pdata = priv->ucode_data_backup.p_addr;
3009
3010 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003011 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003012 if (rc) {
3013 spin_unlock_irqrestore(&priv->lock, flags);
3014 return rc;
3015 }
3016
3017 /* Tell bootstrap uCode where to find image to load */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003018 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
3019 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
3020 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07003021 priv->ucode_data.len);
3022
Tomas Winklera96a27f2008-10-23 23:48:56 -07003023 /* Inst byte count must be last to set up, bit 31 signals uCode
Zhu Yib481de92007-09-25 17:54:57 -07003024 * that all new ptr/size info is in place */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003025 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07003026 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
3027
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003028 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003029
3030 spin_unlock_irqrestore(&priv->lock, flags);
3031
Tomas Winklere1623442009-01-27 14:27:56 -08003032 IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003033
3034 return rc;
3035}
3036
3037/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003038 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07003039 *
3040 * Called after REPLY_ALIVE notification received from "initialize" uCode.
3041 *
Zhu Yib481de92007-09-25 17:54:57 -07003042 * Tell "initialize" uCode to go ahead and load the runtime uCode.
Ben Cahill9fbab512007-11-29 11:09:47 +08003043 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003044static void iwl3945_init_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003045{
3046 /* Check alive response for "valid" sign from uCode */
3047 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
3048 /* We had an error bringing up the hardware, so take it
3049 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08003050 IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003051 goto restart;
3052 }
3053
3054 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
3055 * This is a paranoid check, because we would not have gotten the
3056 * "initialize" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003057 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003058 /* Runtime instruction load was bad;
3059 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08003060 IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003061 goto restart;
3062 }
3063
3064 /* Send pointers to protocol/runtime uCode image ... init code will
3065 * load and launch runtime uCode, which will send us another "Alive"
3066 * notification. */
Tomas Winklere1623442009-01-27 14:27:56 -08003067 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003068 if (iwl3945_set_ucode_ptrs(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003069 /* Runtime instruction load won't happen;
3070 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08003071 IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003072 goto restart;
3073 }
3074 return;
3075
3076 restart:
3077 queue_work(priv->workqueue, &priv->restart);
3078}
3079
3080
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003081/* temporary */
3082static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw,
3083 struct sk_buff *skb);
3084
Zhu Yib481de92007-09-25 17:54:57 -07003085/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003086 * iwl3945_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07003087 * from protocol/runtime uCode (initialization uCode's
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003088 * Alive gets handled by iwl3945_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07003089 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003090static void iwl3945_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003091{
3092 int rc = 0;
3093 int thermal_spin = 0;
3094 u32 rfkill;
3095
Tomas Winklere1623442009-01-27 14:27:56 -08003096 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003097
3098 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
3099 /* We had an error bringing up the hardware, so take it
3100 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08003101 IWL_DEBUG_INFO(priv, "Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003102 goto restart;
3103 }
3104
3105 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
3106 * This is a paranoid check, because we would not have gotten the
3107 * "runtime" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003108 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003109 /* Runtime instruction load was bad;
3110 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08003111 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003112 goto restart;
3113 }
3114
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003115 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003116
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003117 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003118 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003119 IWL_WARN(priv, "Can not read RFKILL status from adapter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003120 return;
3121 }
3122
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003123 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
Tomas Winklere1623442009-01-27 14:27:56 -08003124 IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003125 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003126
3127 if (rfkill & 0x1) {
3128 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winklera96a27f2008-10-23 23:48:56 -07003129 /* if RFKILL is not on, then wait for thermal
Zhu Yib481de92007-09-25 17:54:57 -07003130 * sensor in adapter to kick in */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003131 while (iwl3945_hw_get_temperature(priv) == 0) {
Zhu Yib481de92007-09-25 17:54:57 -07003132 thermal_spin++;
3133 udelay(10);
3134 }
3135
3136 if (thermal_spin)
Tomas Winklere1623442009-01-27 14:27:56 -08003137 IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n",
Zhu Yib481de92007-09-25 17:54:57 -07003138 thermal_spin * 10);
3139 } else
3140 set_bit(STATUS_RF_KILL_HW, &priv->status);
3141
Ben Cahill9fbab512007-11-29 11:09:47 +08003142 /* After the ALIVE response, we can send commands to 3945 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07003143 set_bit(STATUS_ALIVE, &priv->status);
3144
3145 /* Clear out the uCode error bit if it is set */
3146 clear_bit(STATUS_FW_ERROR, &priv->status);
3147
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003148 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003149 return;
3150
Johannes Berg36d68252008-05-15 12:55:26 +02003151 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07003152
3153 priv->active_rate = priv->rates_mask;
3154 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
3155
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08003156 iwl_power_update_mode(priv, false);
Zhu Yib481de92007-09-25 17:54:57 -07003157
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003158 if (iwl_is_associated(priv)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003159 struct iwl3945_rxon_cmd *active_rxon =
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003160 (struct iwl3945_rxon_cmd *)(&priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07003161
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003162 memcpy(&priv->staging_rxon, &priv->active_rxon,
3163 sizeof(priv->staging_rxon));
Zhu Yib481de92007-09-25 17:54:57 -07003164 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3165 } else {
3166 /* Initialize our rx_config data */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003167 iwl_connection_init_rx_config(priv, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003168 }
3169
Ben Cahill9fbab512007-11-29 11:09:47 +08003170 /* Configure Bluetooth device coexistence support */
Samuel Ortiz17f841c2009-01-23 13:45:20 -08003171 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003172
3173 /* Configure the adapter for unassociated operation */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003174 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003175
Zhu Yib481de92007-09-25 17:54:57 -07003176 iwl3945_reg_txpower_periodic(priv);
3177
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07003178 iwl3945_led_register(priv);
3179
Tomas Winklere1623442009-01-27 14:27:56 -08003180 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07003181 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003182 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07003183
3184 if (priv->error_recovering)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003185 iwl3945_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003186
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003187 /* reassociate for ADHOC mode */
3188 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
3189 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
3190 priv->vif);
3191 if (beacon)
3192 iwl3945_mac_beacon_update(priv->hw, beacon);
3193 }
3194
Zhu Yib481de92007-09-25 17:54:57 -07003195 return;
3196
3197 restart:
3198 queue_work(priv->workqueue, &priv->restart);
3199}
3200
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003201static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07003202
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003203static void __iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003204{
3205 unsigned long flags;
3206 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
3207 struct ieee80211_conf *conf = NULL;
3208
Tomas Winklere1623442009-01-27 14:27:56 -08003209 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07003210
3211 conf = ieee80211_get_hw_conf(priv->hw);
3212
3213 if (!exit_pending)
3214 set_bit(STATUS_EXIT_PENDING, &priv->status);
3215
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07003216 iwl3945_led_unregister(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003217 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003218
3219 /* Unblock any waiting calls */
3220 wake_up_interruptible_all(&priv->wait_command_queue);
3221
Zhu Yib481de92007-09-25 17:54:57 -07003222 /* Wipe out the EXIT_PENDING status bit if we are not actually
3223 * exiting the module */
3224 if (!exit_pending)
3225 clear_bit(STATUS_EXIT_PENDING, &priv->status);
3226
3227 /* stop and reset the on-board processor */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003228 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07003229
3230 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003231 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003232 iwl3945_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003233 spin_unlock_irqrestore(&priv->lock, flags);
3234 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003235
3236 if (priv->mac80211_registered)
3237 ieee80211_stop_queues(priv->hw);
3238
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003239 /* If we have not previously called iwl3945_init() then
Zhu Yib481de92007-09-25 17:54:57 -07003240 * clear all bits but the RF Kill and SUSPEND bits and return */
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003241 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003242 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3243 STATUS_RF_KILL_HW |
3244 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3245 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08003246 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3247 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07003248 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003249 STATUS_IN_SUSPEND |
3250 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3251 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07003252 goto exit;
3253 }
3254
3255 /* ...otherwise clear out all the status bits but the RF Kill and
3256 * SUSPEND bits and continue taking the NIC down. */
3257 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3258 STATUS_RF_KILL_HW |
3259 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3260 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08003261 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3262 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07003263 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
3264 STATUS_IN_SUSPEND |
3265 test_bit(STATUS_FW_ERROR, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003266 STATUS_FW_ERROR |
3267 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3268 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07003269
Abbas, Mohamede9414b62009-01-20 21:33:55 -08003270 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003271 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003272 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07003273 spin_unlock_irqrestore(&priv->lock, flags);
3274
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003275 iwl3945_hw_txq_ctx_stop(priv);
3276 iwl3945_hw_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003277
3278 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003279 if (!iwl_grab_nic_access(priv)) {
3280 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07003281 APMG_CLK_VAL_DMA_CLK_RQT);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003282 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003283 }
3284 spin_unlock_irqrestore(&priv->lock, flags);
3285
3286 udelay(5);
3287
Abbas, Mohamede9414b62009-01-20 21:33:55 -08003288 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
3289 priv->cfg->ops->lib->apm_ops.stop(priv);
3290 else
3291 priv->cfg->ops->lib->apm_ops.reset(priv);
3292
Zhu Yib481de92007-09-25 17:54:57 -07003293 exit:
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08003294 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07003295
3296 if (priv->ibss_beacon)
3297 dev_kfree_skb(priv->ibss_beacon);
3298 priv->ibss_beacon = NULL;
3299
3300 /* clear out any free frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003301 iwl3945_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003302}
3303
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003304static void iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003305{
3306 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003307 __iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003308 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08003309
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003310 iwl3945_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003311}
3312
3313#define MAX_HW_RESTARTS 5
3314
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003315static int __iwl3945_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003316{
3317 int rc, i;
3318
3319 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003320 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003321 return -EIO;
3322 }
3323
3324 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003325 IWL_WARN(priv, "Radio disabled by SW RF kill (module "
Zhu Yib481de92007-09-25 17:54:57 -07003326 "parameter)\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003327 return -ENODEV;
3328 }
3329
Reinette Chatree903fbd2008-01-30 22:05:15 -08003330 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003331 IWL_ERR(priv, "ucode not available for device bring up\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08003332 return -EIO;
3333 }
3334
Zhu Yie655b9f2008-01-24 02:19:38 -08003335 /* If platform's RF_KILL switch is NOT set to KILL */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003336 if (iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yie655b9f2008-01-24 02:19:38 -08003337 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3338 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3339 else {
3340 set_bit(STATUS_RF_KILL_HW, &priv->status);
3341 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003342 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003343 return -ENODEV;
3344 }
Zhu Yib481de92007-09-25 17:54:57 -07003345 }
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02003346
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003347 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07003348
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003349 rc = iwl3945_hw_nic_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003350 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003351 IWL_ERR(priv, "Unable to int nic\n");
Zhu Yib481de92007-09-25 17:54:57 -07003352 return rc;
3353 }
3354
3355 /* make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003356 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3357 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07003358 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
3359
3360 /* clear (again), then enable host interrupts */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003361 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003362 iwl3945_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003363
3364 /* really make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003365 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3366 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07003367
3368 /* Copy original ucode data image from disk into backup cache.
3369 * This will be used to initialize the on-board processor's
3370 * data SRAM for a clean start when the runtime program first loads. */
3371 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a66926a2008-01-14 17:46:18 -08003372 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07003373
Zhu Yie655b9f2008-01-24 02:19:38 -08003374 /* We return success when we resume from suspend and rf_kill is on. */
3375 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
3376 return 0;
3377
Zhu Yib481de92007-09-25 17:54:57 -07003378 for (i = 0; i < MAX_HW_RESTARTS; i++) {
3379
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003380 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003381
3382 /* load bootstrap state machine,
3383 * load bootstrap program into processor's memory,
3384 * prepare to load the "initialize" uCode */
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08003385 priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003386
3387 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003388 IWL_ERR(priv,
3389 "Unable to set up bootstrap uCode: %d\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -07003390 continue;
3391 }
3392
3393 /* start card; "initialize" will load runtime ucode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003394 iwl3945_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003395
Tomas Winklere1623442009-01-27 14:27:56 -08003396 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003397
3398 return 0;
3399 }
3400
3401 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003402 __iwl3945_down(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003403 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003404
3405 /* tried to restart and config the device for as long as our
3406 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08003407 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07003408 return -EIO;
3409}
3410
3411
3412/*****************************************************************************
3413 *
3414 * Workqueue callbacks
3415 *
3416 *****************************************************************************/
3417
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003418static void iwl3945_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003419{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003420 struct iwl_priv *priv =
3421 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003422
3423 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3424 return;
3425
3426 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003427 iwl3945_init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003428 mutex_unlock(&priv->mutex);
3429}
3430
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003431static void iwl3945_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003432{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003433 struct iwl_priv *priv =
3434 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003435
3436 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3437 return;
3438
3439 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003440 iwl3945_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003441 mutex_unlock(&priv->mutex);
3442}
3443
Helmut Schaa26635162009-01-15 09:38:44 +01003444static void iwl3945_rfkill_poll(struct work_struct *data)
3445{
3446 struct iwl_priv *priv =
3447 container_of(data, struct iwl_priv, rfkill_poll.work);
3448 unsigned long status = priv->status;
3449
3450 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3451 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3452 else
3453 set_bit(STATUS_RF_KILL_HW, &priv->status);
3454
3455 if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status))
3456 queue_work(priv->workqueue, &priv->rf_kill);
3457
3458 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3459 round_jiffies_relative(2 * HZ));
3460
3461}
3462
Zhu Yib481de92007-09-25 17:54:57 -07003463#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003464static void iwl3945_bg_request_scan(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003465{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003466 struct iwl_priv *priv =
3467 container_of(data, struct iwl_priv, request_scan);
Winkler, Tomasc2d79b482008-12-19 10:37:34 +08003468 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07003469 .id = REPLY_SCAN_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003470 .len = sizeof(struct iwl3945_scan_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07003471 .meta.flags = CMD_SIZE_HUGE,
3472 };
3473 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003474 struct iwl3945_scan_cmd *scan;
Zhu Yib481de92007-09-25 17:54:57 -07003475 struct ieee80211_conf *conf = NULL;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003476 u8 n_probes = 2;
Johannes Berg8318d782008-01-24 19:38:38 +01003477 enum ieee80211_band band;
John W. Linville9387b7c2008-09-30 20:59:05 -04003478 DECLARE_SSID_BUF(ssid);
Zhu Yib481de92007-09-25 17:54:57 -07003479
3480 conf = ieee80211_get_hw_conf(priv->hw);
3481
3482 mutex_lock(&priv->mutex);
3483
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003484 if (!iwl_is_ready(priv)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003485 IWL_WARN(priv, "request scan called when driver not ready.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003486 goto done;
3487 }
3488
Tomas Winklera96a27f2008-10-23 23:48:56 -07003489 /* Make sure the scan wasn't canceled before this queued work
Zhu Yib481de92007-09-25 17:54:57 -07003490 * was given the chance to run... */
3491 if (!test_bit(STATUS_SCANNING, &priv->status))
3492 goto done;
3493
3494 /* This should never be called or scheduled if there is currently
3495 * a scan active in the hardware. */
3496 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003497 IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests "
3498 "Ignoring second request.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003499 rc = -EIO;
3500 goto done;
3501 }
3502
3503 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003504 IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n");
Zhu Yib481de92007-09-25 17:54:57 -07003505 goto done;
3506 }
3507
3508 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003509 IWL_DEBUG_HC(priv,
3510 "Scan request while abort pending. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003511 goto done;
3512 }
3513
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003514 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003515 IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n");
Zhu Yib481de92007-09-25 17:54:57 -07003516 goto done;
3517 }
3518
3519 if (!test_bit(STATUS_READY, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003520 IWL_DEBUG_HC(priv,
3521 "Scan request while uninitialized. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003522 goto done;
3523 }
3524
3525 if (!priv->scan_bands) {
Tomas Winklere1623442009-01-27 14:27:56 -08003526 IWL_DEBUG_HC(priv, "Aborting scan due to no requested bands\n");
Zhu Yib481de92007-09-25 17:54:57 -07003527 goto done;
3528 }
3529
Winkler, Tomas805cee52009-01-19 15:30:28 -08003530 if (!priv->scan) {
3531 priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
Zhu Yib481de92007-09-25 17:54:57 -07003532 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
Winkler, Tomas805cee52009-01-19 15:30:28 -08003533 if (!priv->scan) {
Zhu Yib481de92007-09-25 17:54:57 -07003534 rc = -ENOMEM;
3535 goto done;
3536 }
3537 }
Winkler, Tomas805cee52009-01-19 15:30:28 -08003538 scan = priv->scan;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003539 memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07003540
3541 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
3542 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
3543
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003544 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003545 u16 interval = 0;
3546 u32 extra;
3547 u32 suspend_time = 100;
3548 u32 scan_suspend_time = 100;
3549 unsigned long flags;
3550
Tomas Winklere1623442009-01-27 14:27:56 -08003551 IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
Zhu Yib481de92007-09-25 17:54:57 -07003552
3553 spin_lock_irqsave(&priv->lock, flags);
3554 interval = priv->beacon_int;
3555 spin_unlock_irqrestore(&priv->lock, flags);
3556
3557 scan->suspend_time = 0;
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003558 scan->max_out_time = cpu_to_le32(200 * 1024);
Zhu Yib481de92007-09-25 17:54:57 -07003559 if (!interval)
3560 interval = suspend_time;
3561 /*
3562 * suspend time format:
3563 * 0-19: beacon interval in usec (time before exec.)
3564 * 20-23: 0
3565 * 24-31: number of beacons (suspend between channels)
3566 */
3567
3568 extra = (suspend_time / interval) << 24;
3569 scan_suspend_time = 0xFF0FFFFF &
3570 (extra | ((suspend_time % interval) * 1024));
3571
3572 scan->suspend_time = cpu_to_le32(scan_suspend_time);
Tomas Winklere1623442009-01-27 14:27:56 -08003573 IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003574 scan_suspend_time, interval);
3575 }
3576
3577 /* We should add the ability for user to lock to PASSIVE ONLY */
3578 if (priv->one_direct_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08003579 IWL_DEBUG_SCAN(priv, "Kicking off one direct scan for '%s'\n",
3580 print_ssid(ssid, priv->direct_ssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04003581 priv->direct_ssid_len));
Zhu Yib481de92007-09-25 17:54:57 -07003582 scan->direct_scan[0].id = WLAN_EID_SSID;
3583 scan->direct_scan[0].len = priv->direct_ssid_len;
3584 memcpy(scan->direct_scan[0].ssid,
3585 priv->direct_ssid, priv->direct_ssid_len);
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003586 n_probes++;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003587 } else
Tomas Winklere1623442009-01-27 14:27:56 -08003588 IWL_DEBUG_SCAN(priv, "Kicking off one indirect scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003589
3590 /* We don't build a direct scan probe request; the uCode will do
3591 * that based on the direct_mask added to each channel entry */
Zhu Yib481de92007-09-25 17:54:57 -07003592 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08003593 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07003594 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
3595
3596 /* flags + rate selection */
3597
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003598 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003599 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
3600 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
3601 scan->good_CRC_th = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01003602 band = IEEE80211_BAND_2GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003603 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003604 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
3605 scan->good_CRC_th = IWL_GOOD_CRC_TH;
Johannes Berg8318d782008-01-24 19:38:38 +01003606 band = IEEE80211_BAND_5GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003607 } else {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003608 IWL_WARN(priv, "Invalid scan band count\n");
Zhu Yib481de92007-09-25 17:54:57 -07003609 goto done;
3610 }
3611
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08003612 scan->tx_cmd.len = cpu_to_le16(
3613 iwl_fill_probe_req(priv, band,
3614 (struct ieee80211_mgmt *)scan->data,
3615 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
3616
Zhu Yib481de92007-09-25 17:54:57 -07003617 /* select Rx antennas */
3618 scan->flags |= iwl3945_get_antenna_flags(priv);
3619
Johannes Berg05c914f2008-09-11 00:01:58 +02003620 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
Zhu Yib481de92007-09-25 17:54:57 -07003621 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
3622
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003623 scan->channel_count =
3624 iwl3945_get_channels_for_scan(priv, band, 1, /* active */
3625 n_probes,
3626 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
Zhu Yib481de92007-09-25 17:54:57 -07003627
Reinette Chatre14b54332008-11-04 12:21:35 -08003628 if (scan->channel_count == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08003629 IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
Reinette Chatre14b54332008-11-04 12:21:35 -08003630 goto done;
3631 }
3632
Zhu Yib481de92007-09-25 17:54:57 -07003633 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003634 scan->channel_count * sizeof(struct iwl3945_scan_channel);
Zhu Yib481de92007-09-25 17:54:57 -07003635 cmd.data = scan;
3636 scan->len = cpu_to_le16(cmd.len);
3637
3638 set_bit(STATUS_SCAN_HW, &priv->status);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003639 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07003640 if (rc)
3641 goto done;
3642
3643 queue_delayed_work(priv->workqueue, &priv->scan_check,
3644 IWL_SCAN_CHECK_WATCHDOG);
3645
3646 mutex_unlock(&priv->mutex);
3647 return;
3648
3649 done:
Mohamed Abbas2420ebc2008-11-04 12:21:34 -08003650 /* can not perform scan make sure we clear scanning
3651 * bits from status so next scan request can be performed.
3652 * if we dont clear scanning status bit here all next scan
3653 * will fail
3654 */
3655 clear_bit(STATUS_SCAN_HW, &priv->status);
3656 clear_bit(STATUS_SCANNING, &priv->status);
3657
Ian Schram01ebd062007-10-25 17:15:22 +08003658 /* inform mac80211 scan aborted */
Zhu Yib481de92007-09-25 17:54:57 -07003659 queue_work(priv->workqueue, &priv->scan_completed);
3660 mutex_unlock(&priv->mutex);
3661}
3662
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003663static void iwl3945_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003664{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003665 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07003666
3667 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3668 return;
3669
3670 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003671 __iwl3945_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003672 mutex_unlock(&priv->mutex);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003673 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003674}
3675
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003676static void iwl3945_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003677{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003678 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07003679
3680 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3681 return;
3682
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003683 iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003684 queue_work(priv->workqueue, &priv->up);
3685}
3686
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003687static void iwl3945_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003688{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003689 struct iwl_priv *priv =
3690 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07003691
3692 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3693 return;
3694
3695 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003696 iwl3945_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003697 mutex_unlock(&priv->mutex);
3698}
3699
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003700#define IWL_DELAY_NEXT_SCAN (HZ*2)
3701
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003702static void iwl3945_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003703{
Zhu Yib481de92007-09-25 17:54:57 -07003704 int rc = 0;
3705 struct ieee80211_conf *conf = NULL;
3706
Johannes Berg05c914f2008-09-11 00:01:58 +02003707 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003708 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07003709 return;
3710 }
3711
3712
Tomas Winklere1623442009-01-27 14:27:56 -08003713 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003714 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07003715
3716 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3717 return;
3718
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003719 if (!priv->vif || !priv->is_open)
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003720 return;
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003721
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003722 iwl_scan_cancel_timeout(priv, 200);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003723
Zhu Yib481de92007-09-25 17:54:57 -07003724 conf = ieee80211_get_hw_conf(priv->hw);
3725
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003726 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003727 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003728
Tomas Winkler28afaf92008-12-19 10:37:06 +08003729 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003730 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003731 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07003732 sizeof(priv->rxon_timing), &priv->rxon_timing);
3733 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003734 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003735 "Attempting to continue.\n");
3736
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003737 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003738
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003739 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003740
Tomas Winklere1623442009-01-27 14:27:56 -08003741 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003742 priv->assoc_id, priv->beacon_int);
3743
3744 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003745 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003746 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003747 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003748
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003749 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003750 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003751 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003752 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003753 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003754
Johannes Berg05c914f2008-09-11 00:01:58 +02003755 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003756 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003757
3758 }
3759
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003760 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003761
3762 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02003763 case NL80211_IFTYPE_STATION:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003764 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07003765 break;
3766
Johannes Berg05c914f2008-09-11 00:01:58 +02003767 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07003768
Abhijeet Kolekarce546fd2008-11-19 15:32:22 -08003769 priv->assoc_id = 1;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003770 iwl3945_add_station(priv, priv->bssid, 0, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003771 iwl3945_sync_sta(priv, IWL_STA_ID,
Johannes Berg8318d782008-01-24 19:38:38 +01003772 (priv->band == IEEE80211_BAND_5GHZ) ?
Zhu Yib481de92007-09-25 17:54:57 -07003773 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
3774 CMD_ASYNC);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003775 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
3776 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003777
3778 break;
3779
3780 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08003781 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003782 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003783 break;
3784 }
3785
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003786 iwl3945_activate_qos(priv, 0);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08003787
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003788 /* we have just associated, don't start scan too early */
3789 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08003790}
3791
Johannes Berge8975582008-10-09 12:18:51 +02003792static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003793
Zhu Yib481de92007-09-25 17:54:57 -07003794/*****************************************************************************
3795 *
3796 * mac80211 entry point functions
3797 *
3798 *****************************************************************************/
3799
Zhu Yi5a66926a2008-01-14 17:46:18 -08003800#define UCODE_READY_TIMEOUT (2 * HZ)
3801
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003802static int iwl3945_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003803{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003804 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003805 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003806
Tomas Winklere1623442009-01-27 14:27:56 -08003807 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003808
3809 /* we should be verifying the device is ready to be opened */
3810 mutex_lock(&priv->mutex);
3811
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003812 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
Zhu Yi5a66926a2008-01-14 17:46:18 -08003813 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
3814 * ucode filename and max sizes are card-specific. */
3815
3816 if (!priv->ucode_code.len) {
3817 ret = iwl3945_read_ucode(priv);
3818 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003819 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003820 mutex_unlock(&priv->mutex);
3821 goto out_release_irq;
3822 }
3823 }
3824
Zhu Yie655b9f2008-01-24 02:19:38 -08003825 ret = __iwl3945_up(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003826
Zhu Yib481de92007-09-25 17:54:57 -07003827 mutex_unlock(&priv->mutex);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003828
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003829 iwl_rfkill_set_hw_state(priv);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02003830
Zhu Yie655b9f2008-01-24 02:19:38 -08003831 if (ret)
3832 goto out_release_irq;
3833
Tomas Winklere1623442009-01-27 14:27:56 -08003834 IWL_DEBUG_INFO(priv, "Start UP work.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003835
3836 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
3837 return 0;
3838
Zhu Yi5a66926a2008-01-14 17:46:18 -08003839 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
3840 * mac80211 will not be run successfully. */
3841 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
3842 test_bit(STATUS_READY, &priv->status),
3843 UCODE_READY_TIMEOUT);
3844 if (!ret) {
3845 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003846 IWL_ERR(priv,
3847 "Wait for START_ALIVE timeout after %dms.\n",
3848 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Zhu Yi5a66926a2008-01-14 17:46:18 -08003849 ret = -ETIMEDOUT;
3850 goto out_release_irq;
3851 }
3852 }
3853
Helmut Schaa26635162009-01-15 09:38:44 +01003854 /* ucode is running and will send rfkill notifications,
3855 * no need to poll the killswitch state anymore */
3856 cancel_delayed_work(&priv->rfkill_poll);
3857
Zhu Yie655b9f2008-01-24 02:19:38 -08003858 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08003859 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003860 return 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003861
3862out_release_irq:
Zhu Yie655b9f2008-01-24 02:19:38 -08003863 priv->is_open = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08003864 IWL_DEBUG_MAC80211(priv, "leave - failed\n");
Zhu Yi5a66926a2008-01-14 17:46:18 -08003865 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003866}
3867
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003868static void iwl3945_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003869{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003870 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003871
Tomas Winklere1623442009-01-27 14:27:56 -08003872 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003873
Zhu Yie655b9f2008-01-24 02:19:38 -08003874 if (!priv->is_open) {
Tomas Winklere1623442009-01-27 14:27:56 -08003875 IWL_DEBUG_MAC80211(priv, "leave - skip\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003876 return;
3877 }
3878
Zhu Yib481de92007-09-25 17:54:57 -07003879 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003880
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003881 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08003882 /* stop mac, cancel any scan request and clear
3883 * RXON_FILTER_ASSOC_MSK BIT
3884 */
Zhu Yi5a66926a2008-01-14 17:46:18 -08003885 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003886 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003887 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003888 }
3889
Zhu Yi5a66926a2008-01-14 17:46:18 -08003890 iwl3945_down(priv);
3891
3892 flush_workqueue(priv->workqueue);
Helmut Schaa26635162009-01-15 09:38:44 +01003893
3894 /* start polling the killswitch state again */
3895 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3896 round_jiffies_relative(2 * HZ));
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003897
Tomas Winklere1623442009-01-27 14:27:56 -08003898 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003899}
3900
Johannes Berge039fa42008-05-15 12:55:29 +02003901static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003902{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003903 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003904
Tomas Winklere1623442009-01-27 14:27:56 -08003905 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003906
Tomas Winklere1623442009-01-27 14:27:56 -08003907 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02003908 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07003909
Johannes Berge039fa42008-05-15 12:55:29 +02003910 if (iwl3945_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07003911 dev_kfree_skb_any(skb);
3912
Tomas Winklere1623442009-01-27 14:27:56 -08003913 IWL_DEBUG_MAC80211(priv, "leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08003914 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07003915}
3916
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003917static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003918 struct ieee80211_if_init_conf *conf)
3919{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003920 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003921 unsigned long flags;
3922
Tomas Winklere1623442009-01-27 14:27:56 -08003923 IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07003924
Johannes Berg32bfd352007-12-19 01:31:26 +01003925 if (priv->vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08003926 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
Tomas Winkler864792e2007-11-27 21:00:52 +02003927 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07003928 }
3929
3930 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01003931 priv->vif = conf->vif;
Zhu, Yi60294de2008-10-29 14:05:45 -07003932 priv->iw_mode = conf->type;
Zhu Yib481de92007-09-25 17:54:57 -07003933
3934 spin_unlock_irqrestore(&priv->lock, flags);
3935
3936 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02003937
3938 if (conf->mac_addr) {
Tomas Winklere1623442009-01-27 14:27:56 -08003939 IWL_DEBUG_MAC80211(priv, "Set: %pM\n", conf->mac_addr);
Tomas Winkler864792e2007-11-27 21:00:52 +02003940 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
3941 }
3942
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003943 if (iwl_is_ready(priv))
Zhu Yi5a66926a2008-01-14 17:46:18 -08003944 iwl3945_set_mode(priv, conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07003945
Zhu Yib481de92007-09-25 17:54:57 -07003946 mutex_unlock(&priv->mutex);
3947
Tomas Winklere1623442009-01-27 14:27:56 -08003948 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003949 return 0;
3950}
3951
3952/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003953 * iwl3945_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07003954 *
3955 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
3956 * be set inappropriately and the driver currently sets the hardware up to
3957 * use it whenever needed.
3958 */
Johannes Berge8975582008-10-09 12:18:51 +02003959static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed)
Zhu Yib481de92007-09-25 17:54:57 -07003960{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003961 struct iwl_priv *priv = hw->priv;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08003962 const struct iwl_channel_info *ch_info;
Johannes Berge8975582008-10-09 12:18:51 +02003963 struct ieee80211_conf *conf = &hw->conf;
Zhu Yib481de92007-09-25 17:54:57 -07003964 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08003965 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003966
3967 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08003968 IWL_DEBUG_MAC80211(priv, "enter to channel %d\n",
3969 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07003970
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003971 if (!iwl_is_ready(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003972 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08003973 ret = -EIO;
3974 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003975 }
3976
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08003977 if (unlikely(!iwl3945_mod_params.disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07003978 test_bit(STATUS_SCANNING, &priv->status))) {
Tomas Winklere1623442009-01-27 14:27:56 -08003979 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
Zhu Yia0646472007-12-20 14:10:01 +08003980 set_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003981 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08003982 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07003983 }
3984
3985 spin_lock_irqsave(&priv->lock, flags);
3986
Samuel Ortize6148912009-01-23 13:45:15 -08003987 ch_info = iwl_get_channel_info(priv, conf->channel->band,
3988 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07003989 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003990 IWL_DEBUG_SCAN(priv,
3991 "Channel %d [%d] is INVALID for this band.\n",
3992 conf->channel->hw_value, conf->channel->band);
3993 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
Zhu Yib481de92007-09-25 17:54:57 -07003994 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003995 ret = -EINVAL;
3996 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003997 }
3998
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003999 iwl_set_rxon_channel(priv, conf->channel);
Zhu Yib481de92007-09-25 17:54:57 -07004000
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004001 iwl_set_flags_for_band(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07004002
4003 /* The list of supported rates and rate mask can be different
4004 * for each phymode; since the phymode may have changed, reset
4005 * the rate mask to what mac80211 lists */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004006 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004007
4008 spin_unlock_irqrestore(&priv->lock, flags);
4009
4010#ifdef IEEE80211_CONF_CHANNEL_SWITCH
4011 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004012 iwl3945_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08004013 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004014 }
4015#endif
4016
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004017 iwl3945_radio_kill_sw(priv, !conf->radio_enabled);
Zhu Yib481de92007-09-25 17:54:57 -07004018
4019 if (!conf->radio_enabled) {
Tomas Winklere1623442009-01-27 14:27:56 -08004020 IWL_DEBUG_MAC80211(priv, "leave - radio disabled\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08004021 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004022 }
4023
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004024 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004025 IWL_DEBUG_MAC80211(priv, "leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08004026 ret = -EIO;
4027 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004028 }
4029
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004030 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004031
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004032 if (memcmp(&priv->active_rxon,
4033 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004034 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004035 else
Tomas Winklere1623442009-01-27 14:27:56 -08004036 IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration\n");
Zhu Yib481de92007-09-25 17:54:57 -07004037
Tomas Winklere1623442009-01-27 14:27:56 -08004038 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004039
Zhu Yi76bb77e2007-11-22 10:53:22 +08004040out:
Zhu Yia0646472007-12-20 14:10:01 +08004041 clear_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07004042 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08004043 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004044}
4045
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004046static void iwl3945_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004047{
4048 int rc = 0;
4049
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08004050 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07004051 return;
4052
4053 /* The following should be done only at AP bring up */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004054 if (!(iwl_is_associated(priv))) {
Zhu Yib481de92007-09-25 17:54:57 -07004055
4056 /* RXON - unassoc (to set timing command) */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004057 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004058 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004059
4060 /* RXON Timing */
Tomas Winkler28afaf92008-12-19 10:37:06 +08004061 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004062 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08004063 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
4064 sizeof(priv->rxon_timing),
4065 &priv->rxon_timing);
Zhu Yib481de92007-09-25 17:54:57 -07004066 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004067 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07004068 "Attempting to continue.\n");
4069
4070 /* FIXME: what should be the assoc_id for AP? */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004071 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07004072 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004073 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07004074 RXON_FLG_SHORT_PREAMBLE_MSK;
4075 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004076 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07004077 ~RXON_FLG_SHORT_PREAMBLE_MSK;
4078
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004079 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07004080 if (priv->assoc_capability &
4081 WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004082 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07004083 RXON_FLG_SHORT_SLOT_MSK;
4084 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004085 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07004086 ~RXON_FLG_SHORT_SLOT_MSK;
4087
Johannes Berg05c914f2008-09-11 00:01:58 +02004088 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004089 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07004090 ~RXON_FLG_SHORT_SLOT_MSK;
4091 }
4092 /* restore RXON assoc */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004093 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004094 iwl3945_commit_rxon(priv);
Kolekar, Abhijeetb5323d32008-12-19 10:37:22 +08004095 iwl3945_add_station(priv, iwl_bcast_addr, 0, 0);
Zhu Yi556f8db2007-09-27 11:27:33 +08004096 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004097 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004098
4099 /* FIXME - we need to add code here to detect a totally new
4100 * configuration, reset the AP, unassoc, rxon timing, assoc,
4101 * clear sta table, add BCAST sta... */
4102}
4103
Johannes Berg32bfd352007-12-19 01:31:26 +01004104static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
4105 struct ieee80211_vif *vif,
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004106 struct ieee80211_if_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07004107{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004108 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004109 int rc;
4110
4111 if (conf == NULL)
4112 return -EIO;
4113
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08004114 if (priv->vif != vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08004115 IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08004116 return 0;
4117 }
4118
Johannes Berg9d139c82008-07-09 14:40:37 +02004119 /* handle this temporarily here */
Johannes Berg05c914f2008-09-11 00:01:58 +02004120 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Johannes Berg9d139c82008-07-09 14:40:37 +02004121 conf->changed & IEEE80211_IFCC_BEACON) {
4122 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
4123 if (!beacon)
4124 return -ENOMEM;
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08004125 mutex_lock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02004126 rc = iwl3945_mac_beacon_update(hw, beacon);
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08004127 mutex_unlock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02004128 if (rc)
4129 return rc;
4130 }
4131
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004132 if (!iwl_is_alive(priv))
Zhu Yi5a66926a2008-01-14 17:46:18 -08004133 return -EAGAIN;
4134
Zhu Yib481de92007-09-25 17:54:57 -07004135 mutex_lock(&priv->mutex);
4136
Zhu Yib481de92007-09-25 17:54:57 -07004137 if (conf->bssid)
Tomas Winklere1623442009-01-27 14:27:56 -08004138 IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07004139
Johannes Berg4150c572007-09-17 01:29:23 -04004140/*
4141 * very dubious code was here; the probe filtering flag is never set:
4142 *
Zhu Yib481de92007-09-25 17:54:57 -07004143 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
4144 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04004145 */
Zhu Yib481de92007-09-25 17:54:57 -07004146
Johannes Berg05c914f2008-09-11 00:01:58 +02004147 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07004148 if (!conf->bssid) {
4149 conf->bssid = priv->mac_addr;
4150 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08004151 IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07004152 conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07004153 }
4154 if (priv->ibss_beacon)
4155 dev_kfree_skb(priv->ibss_beacon);
4156
Johannes Berg9d139c82008-07-09 14:40:37 +02004157 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
Zhu Yib481de92007-09-25 17:54:57 -07004158 }
4159
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004160 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08004161 goto done;
4162
Zhu Yib481de92007-09-25 17:54:57 -07004163 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
4164 !is_multicast_ether_addr(conf->bssid)) {
4165 /* If there is currently a HW scan going on in the background
4166 * then we need to cancel it else the RXON below will fail. */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004167 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004168 IWL_WARN(priv, "Aborted scan still in progress "
Zhu Yib481de92007-09-25 17:54:57 -07004169 "after 100ms\n");
Tomas Winklere1623442009-01-27 14:27:56 -08004170 IWL_DEBUG_MAC80211(priv, "leaving:scan abort failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07004171 mutex_unlock(&priv->mutex);
4172 return -EAGAIN;
4173 }
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004174 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07004175
4176 /* TODO: Audit driver for usage of these members and see
4177 * if mac80211 deprecates them (priv->bssid looks like it
4178 * shouldn't be there, but I haven't scanned the IBSS code
4179 * to verify) - jpk */
4180 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
4181
Johannes Berg05c914f2008-09-11 00:01:58 +02004182 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004183 iwl3945_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004184 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004185 rc = iwl3945_commit_rxon(priv);
Johannes Berg05c914f2008-09-11 00:01:58 +02004186 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004187 iwl3945_add_station(priv,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004188 priv->active_rxon.bssid_addr, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004189 }
4190
4191 } else {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004192 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004193 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004194 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004195 }
4196
Mohamed Abbasfde35712007-11-29 11:10:15 +08004197 done:
Tomas Winklere1623442009-01-27 14:27:56 -08004198 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004199 mutex_unlock(&priv->mutex);
4200
4201 return 0;
4202}
4203
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004204static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004205 struct ieee80211_if_init_conf *conf)
4206{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004207 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004208
Tomas Winklere1623442009-01-27 14:27:56 -08004209 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004210
4211 mutex_lock(&priv->mutex);
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004212
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004213 if (iwl_is_ready_rf(priv)) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004214 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004215 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Mohamed Abbasfde35712007-11-29 11:10:15 +08004216 iwl3945_commit_rxon(priv);
4217 }
Johannes Berg32bfd352007-12-19 01:31:26 +01004218 if (priv->vif == conf->vif) {
4219 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07004220 memset(priv->bssid, 0, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07004221 }
4222 mutex_unlock(&priv->mutex);
4223
Tomas Winklere1623442009-01-27 14:27:56 -08004224 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004225}
4226
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004227#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
4228
4229static void iwl3945_bss_info_changed(struct ieee80211_hw *hw,
4230 struct ieee80211_vif *vif,
4231 struct ieee80211_bss_conf *bss_conf,
4232 u32 changes)
4233{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004234 struct iwl_priv *priv = hw->priv;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004235
Tomas Winklere1623442009-01-27 14:27:56 -08004236 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004237
4238 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
Tomas Winklere1623442009-01-27 14:27:56 -08004239 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004240 bss_conf->use_short_preamble);
4241 if (bss_conf->use_short_preamble)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004242 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004243 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004244 priv->staging_rxon.flags &=
4245 ~RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004246 }
4247
4248 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
Tomas Winklere1623442009-01-27 14:27:56 -08004249 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n",
4250 bss_conf->use_cts_prot);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004251 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004252 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004253 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004254 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004255 }
4256
4257 if (changes & BSS_CHANGED_ASSOC) {
Tomas Winklere1623442009-01-27 14:27:56 -08004258 IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004259 /* This should never happen as this function should
4260 * never be called from interrupt context. */
4261 if (WARN_ON_ONCE(in_interrupt()))
4262 return;
4263 if (bss_conf->assoc) {
4264 priv->assoc_id = bss_conf->aid;
4265 priv->beacon_int = bss_conf->beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08004266 priv->timestamp = bss_conf->timestamp;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004267 priv->assoc_capability = bss_conf->assoc_capability;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08004268 priv->power_data.dtim_period = bss_conf->dtim_period;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004269 priv->next_scan_jiffies = jiffies +
4270 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
4271 mutex_lock(&priv->mutex);
4272 iwl3945_post_associate(priv);
4273 mutex_unlock(&priv->mutex);
4274 } else {
4275 priv->assoc_id = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08004276 IWL_DEBUG_MAC80211(priv,
4277 "DISASSOC %d\n", bss_conf->assoc);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004278 }
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004279 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
Tomas Winklere1623442009-01-27 14:27:56 -08004280 IWL_DEBUG_MAC80211(priv,
4281 "Associated Changes %d\n", changes);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004282 iwl3945_send_rxon_assoc(priv);
4283 }
4284
4285}
4286
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004287static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01004288 struct ieee80211_vif *vif,
4289 struct ieee80211_sta *sta,
4290 struct ieee80211_key_conf *key)
Zhu Yib481de92007-09-25 17:54:57 -07004291{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004292 struct iwl_priv *priv = hw->priv;
Johannes Bergdc822b52008-12-29 12:55:09 +01004293 const u8 *addr;
Winkler, Tomas42986792009-01-19 15:30:22 -08004294 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07004295 u8 sta_id;
4296
Tomas Winklere1623442009-01-27 14:27:56 -08004297 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004298
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004299 if (iwl3945_mod_params.sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08004300 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07004301 return -EOPNOTSUPP;
4302 }
4303
Winkler, Tomas42986792009-01-19 15:30:22 -08004304 addr = sta ? sta->addr : iwl_bcast_addr;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004305 sta_id = iwl3945_hw_find_station(priv, addr);
Zhu Yib481de92007-09-25 17:54:57 -07004306 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -08004307 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
Johannes Berge1749612008-10-27 15:59:26 -07004308 addr);
Zhu Yib481de92007-09-25 17:54:57 -07004309 return -EINVAL;
4310 }
4311
4312 mutex_lock(&priv->mutex);
4313
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004314 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004315
Zhu Yib481de92007-09-25 17:54:57 -07004316 switch (cmd) {
4317 case SET_KEY:
Winkler, Tomas42986792009-01-19 15:30:22 -08004318 ret = iwl3945_update_sta_key_info(priv, key, sta_id);
4319 if (!ret) {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004320 iwl_set_rxon_hwcrypto(priv, 1);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004321 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004322 key->hw_key_idx = sta_id;
Tomas Winklere1623442009-01-27 14:27:56 -08004323 IWL_DEBUG_MAC80211(priv,
4324 "set_key success, using hwcrypto\n");
Zhu Yib481de92007-09-25 17:54:57 -07004325 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
4326 }
4327 break;
4328 case DISABLE_KEY:
Winkler, Tomas42986792009-01-19 15:30:22 -08004329 ret = iwl3945_clear_sta_key_info(priv, sta_id);
4330 if (!ret) {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004331 iwl_set_rxon_hwcrypto(priv, 0);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004332 iwl3945_commit_rxon(priv);
Tomas Winklere1623442009-01-27 14:27:56 -08004333 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07004334 }
4335 break;
4336 default:
Winkler, Tomas42986792009-01-19 15:30:22 -08004337 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07004338 }
4339
Tomas Winklere1623442009-01-27 14:27:56 -08004340 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004341 mutex_unlock(&priv->mutex);
4342
Winkler, Tomas42986792009-01-19 15:30:22 -08004343 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004344}
4345
Johannes Berge100bb62008-04-30 18:51:21 +02004346static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
Zhu Yib481de92007-09-25 17:54:57 -07004347 const struct ieee80211_tx_queue_params *params)
4348{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004349 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004350 unsigned long flags;
4351 int q;
Zhu Yib481de92007-09-25 17:54:57 -07004352
Tomas Winklere1623442009-01-27 14:27:56 -08004353 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004354
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004355 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004356 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004357 return -EIO;
4358 }
4359
4360 if (queue >= AC_NUM) {
Tomas Winklere1623442009-01-27 14:27:56 -08004361 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
Zhu Yib481de92007-09-25 17:54:57 -07004362 return 0;
4363 }
4364
Zhu Yib481de92007-09-25 17:54:57 -07004365 q = AC_NUM - 1 - queue;
4366
4367 spin_lock_irqsave(&priv->lock, flags);
4368
4369 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
4370 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
4371 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
4372 priv->qos_data.def_qos_parm.ac[q].edca_txop =
Johannes Berg3330d7b2008-02-10 16:49:38 +01004373 cpu_to_le16((params->txop * 32));
Zhu Yib481de92007-09-25 17:54:57 -07004374
4375 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
4376 priv->qos_data.qos_active = 1;
4377
4378 spin_unlock_irqrestore(&priv->lock, flags);
4379
4380 mutex_lock(&priv->mutex);
Johannes Berg05c914f2008-09-11 00:01:58 +02004381 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004382 iwl3945_activate_qos(priv, 1);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004383 else if (priv->assoc_id && iwl_is_associated(priv))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004384 iwl3945_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004385
4386 mutex_unlock(&priv->mutex);
4387
Tomas Winklere1623442009-01-27 14:27:56 -08004388 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004389 return 0;
4390}
4391
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004392static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004393 struct ieee80211_tx_queue_stats *stats)
4394{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004395 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004396 int i, avail;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08004397 struct iwl_tx_queue *txq;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004398 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07004399 unsigned long flags;
4400
Tomas Winklere1623442009-01-27 14:27:56 -08004401 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004402
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004403 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004404 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004405 return -EIO;
4406 }
4407
4408 spin_lock_irqsave(&priv->lock, flags);
4409
4410 for (i = 0; i < AC_NUM; i++) {
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08004411 txq = &priv->txq[i];
Zhu Yib481de92007-09-25 17:54:57 -07004412 q = &txq->q;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004413 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07004414
Johannes Berg57ffc582008-04-29 17:18:59 +02004415 stats[i].len = q->n_window - avail;
4416 stats[i].limit = q->n_window - q->high_mark;
4417 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07004418
4419 }
4420 spin_unlock_irqrestore(&priv->lock, flags);
4421
Tomas Winklere1623442009-01-27 14:27:56 -08004422 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004423
4424 return 0;
4425}
4426
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004427static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07004428{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004429 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004430 unsigned long flags;
4431
4432 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08004433 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004434
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004435 iwl_reset_qos(priv);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08004436
Zhu Yib481de92007-09-25 17:54:57 -07004437 spin_lock_irqsave(&priv->lock, flags);
4438 priv->assoc_id = 0;
4439 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004440
4441 /* new association get rid of ibss beacon skb */
4442 if (priv->ibss_beacon)
4443 dev_kfree_skb(priv->ibss_beacon);
4444
4445 priv->ibss_beacon = NULL;
4446
4447 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08004448 priv->timestamp = 0;
Johannes Berg05c914f2008-09-11 00:01:58 +02004449 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
Zhu Yib481de92007-09-25 17:54:57 -07004450 priv->beacon_int = 0;
4451
4452 spin_unlock_irqrestore(&priv->lock, flags);
4453
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004454 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004455 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +08004456 mutex_unlock(&priv->mutex);
4457 return;
4458 }
4459
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004460 /* we are restarting association process
4461 * clear RXON_FILTER_ASSOC_MSK bit
4462 */
Johannes Berg05c914f2008-09-11 00:01:58 +02004463 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004464 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004465 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004466 iwl3945_commit_rxon(priv);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004467 }
4468
Zhu Yib481de92007-09-25 17:54:57 -07004469 /* Per mac80211.h: This is only used in IBSS mode... */
Johannes Berg05c914f2008-09-11 00:01:58 +02004470 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004471
Tomas Winklere1623442009-01-27 14:27:56 -08004472 IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07004473 mutex_unlock(&priv->mutex);
4474 return;
4475 }
4476
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004477 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004478
4479 mutex_unlock(&priv->mutex);
4480
Tomas Winklere1623442009-01-27 14:27:56 -08004481 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004482
4483}
4484
Johannes Berge039fa42008-05-15 12:55:29 +02004485static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07004486{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004487 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004488 unsigned long flags;
4489
Tomas Winklere1623442009-01-27 14:27:56 -08004490 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004491
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004492 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004493 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004494 return -EIO;
4495 }
4496
Johannes Berg05c914f2008-09-11 00:01:58 +02004497 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Tomas Winklere1623442009-01-27 14:27:56 -08004498 IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07004499 return -EIO;
4500 }
4501
4502 spin_lock_irqsave(&priv->lock, flags);
4503
4504 if (priv->ibss_beacon)
4505 dev_kfree_skb(priv->ibss_beacon);
4506
4507 priv->ibss_beacon = skb;
4508
4509 priv->assoc_id = 0;
4510
Tomas Winklere1623442009-01-27 14:27:56 -08004511 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004512 spin_unlock_irqrestore(&priv->lock, flags);
4513
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004514 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004515
Abhijeet Kolekardc4b1e72008-09-03 11:26:30 +08004516 iwl3945_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004517
Zhu Yib481de92007-09-25 17:54:57 -07004518
4519 return 0;
4520}
4521
4522/*****************************************************************************
4523 *
4524 * sysfs attributes
4525 *
4526 *****************************************************************************/
4527
Samuel Ortizd08853a2009-01-23 13:45:17 -08004528#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07004529
4530/*
4531 * The following adds a new attribute to the sysfs representation
4532 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
4533 * used for controlling the debug level.
4534 *
4535 * See the level definitions in iwl for details.
4536 */
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004537static ssize_t show_debug_level(struct device *d,
4538 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07004539{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004540 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004541
4542 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07004543}
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004544static ssize_t store_debug_level(struct device *d,
4545 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07004546 const char *buf, size_t count)
4547{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004548 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004549 unsigned long val;
4550 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07004551
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004552 ret = strict_strtoul(buf, 0, &val);
4553 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08004554 IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07004555 else
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004556 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07004557
4558 return strnlen(buf, count);
4559}
4560
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004561static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
4562 show_debug_level, store_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07004563
Samuel Ortizd08853a2009-01-23 13:45:17 -08004564#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07004565
Zhu Yib481de92007-09-25 17:54:57 -07004566static ssize_t show_temperature(struct device *d,
4567 struct device_attribute *attr, char *buf)
4568{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004569 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004570
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004571 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004572 return -EAGAIN;
4573
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004574 return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
Zhu Yib481de92007-09-25 17:54:57 -07004575}
4576
4577static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
4578
Zhu Yib481de92007-09-25 17:54:57 -07004579static ssize_t show_tx_power(struct device *d,
4580 struct device_attribute *attr, char *buf)
4581{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004582 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08004583 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07004584}
4585
4586static ssize_t store_tx_power(struct device *d,
4587 struct device_attribute *attr,
4588 const char *buf, size_t count)
4589{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004590 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004591 char *p = (char *)buf;
4592 u32 val;
4593
4594 val = simple_strtoul(p, &p, 10);
4595 if (p == buf)
Tomas Winkler978785a2008-12-19 10:37:31 +08004596 IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07004597 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004598 iwl3945_hw_reg_set_txpower(priv, val);
Zhu Yib481de92007-09-25 17:54:57 -07004599
4600 return count;
4601}
4602
4603static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
4604
4605static ssize_t show_flags(struct device *d,
4606 struct device_attribute *attr, char *buf)
4607{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004608 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004609
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004610 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
Zhu Yib481de92007-09-25 17:54:57 -07004611}
4612
4613static ssize_t store_flags(struct device *d,
4614 struct device_attribute *attr,
4615 const char *buf, size_t count)
4616{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004617 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004618 u32 flags = simple_strtoul(buf, NULL, 0);
4619
4620 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004621 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
Zhu Yib481de92007-09-25 17:54:57 -07004622 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004623 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004624 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004625 else {
Tomas Winklere1623442009-01-27 14:27:56 -08004626 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
Zhu Yib481de92007-09-25 17:54:57 -07004627 flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004628 priv->staging_rxon.flags = cpu_to_le32(flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004629 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004630 }
4631 }
4632 mutex_unlock(&priv->mutex);
4633
4634 return count;
4635}
4636
4637static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
4638
4639static ssize_t show_filter_flags(struct device *d,
4640 struct device_attribute *attr, char *buf)
4641{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004642 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004643
4644 return sprintf(buf, "0x%04X\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004645 le32_to_cpu(priv->active_rxon.filter_flags));
Zhu Yib481de92007-09-25 17:54:57 -07004646}
4647
4648static ssize_t store_filter_flags(struct device *d,
4649 struct device_attribute *attr,
4650 const char *buf, size_t count)
4651{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004652 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004653 u32 filter_flags = simple_strtoul(buf, NULL, 0);
4654
4655 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004656 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
Zhu Yib481de92007-09-25 17:54:57 -07004657 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004658 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004659 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004660 else {
Tomas Winklere1623442009-01-27 14:27:56 -08004661 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
Zhu Yib481de92007-09-25 17:54:57 -07004662 "0x%04X\n", filter_flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004663 priv->staging_rxon.filter_flags =
Zhu Yib481de92007-09-25 17:54:57 -07004664 cpu_to_le32(filter_flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004665 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004666 }
4667 }
4668 mutex_unlock(&priv->mutex);
4669
4670 return count;
4671}
4672
4673static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
4674 store_filter_flags);
4675
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004676#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004677
4678static ssize_t show_measurement(struct device *d,
4679 struct device_attribute *attr, char *buf)
4680{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004681 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler600c0e12008-12-19 10:37:04 +08004682 struct iwl_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004683 u32 size = sizeof(measure_report), len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03004684 u8 *data = (u8 *)&measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004685 unsigned long flags;
4686
4687 spin_lock_irqsave(&priv->lock, flags);
4688 if (!(priv->measurement_status & MEASUREMENT_READY)) {
4689 spin_unlock_irqrestore(&priv->lock, flags);
4690 return 0;
4691 }
4692 memcpy(&measure_report, &priv->measure_report, size);
4693 priv->measurement_status = 0;
4694 spin_unlock_irqrestore(&priv->lock, flags);
4695
4696 while (size && (PAGE_SIZE - len)) {
4697 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4698 PAGE_SIZE - len, 1);
4699 len = strlen(buf);
4700 if (PAGE_SIZE - len)
4701 buf[len++] = '\n';
4702
4703 ofs += 16;
4704 size -= min(size, 16U);
4705 }
4706
4707 return len;
4708}
4709
4710static ssize_t store_measurement(struct device *d,
4711 struct device_attribute *attr,
4712 const char *buf, size_t count)
4713{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004714 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004715 struct ieee80211_measurement_params params = {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004716 .channel = le16_to_cpu(priv->active_rxon.channel),
Zhu Yib481de92007-09-25 17:54:57 -07004717 .start_time = cpu_to_le64(priv->last_tsf),
4718 .duration = cpu_to_le16(1),
4719 };
4720 u8 type = IWL_MEASURE_BASIC;
4721 u8 buffer[32];
4722 u8 channel;
4723
4724 if (count) {
4725 char *p = buffer;
4726 strncpy(buffer, buf, min(sizeof(buffer), count));
4727 channel = simple_strtoul(p, NULL, 0);
4728 if (channel)
4729 params.channel = channel;
4730
4731 p = buffer;
4732 while (*p && *p != ' ')
4733 p++;
4734 if (*p)
4735 type = simple_strtoul(p + 1, NULL, 0);
4736 }
4737
Tomas Winklere1623442009-01-27 14:27:56 -08004738 IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on "
Zhu Yib481de92007-09-25 17:54:57 -07004739 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004740 iwl3945_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07004741
4742 return count;
4743}
4744
4745static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
4746 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004747#endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07004748
Zhu Yib481de92007-09-25 17:54:57 -07004749static ssize_t store_retry_rate(struct device *d,
4750 struct device_attribute *attr,
4751 const char *buf, size_t count)
4752{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004753 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004754
4755 priv->retry_rate = simple_strtoul(buf, NULL, 0);
4756 if (priv->retry_rate <= 0)
4757 priv->retry_rate = 1;
4758
4759 return count;
4760}
4761
4762static ssize_t show_retry_rate(struct device *d,
4763 struct device_attribute *attr, char *buf)
4764{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004765 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004766 return sprintf(buf, "%d", priv->retry_rate);
4767}
4768
4769static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
4770 store_retry_rate);
4771
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004772
Zhu Yib481de92007-09-25 17:54:57 -07004773static ssize_t store_power_level(struct device *d,
4774 struct device_attribute *attr,
4775 const char *buf, size_t count)
4776{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004777 struct iwl_priv *priv = dev_get_drvdata(d);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004778 int ret;
4779 unsigned long mode;
Zhu Yib481de92007-09-25 17:54:57 -07004780
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004781
Zhu Yib481de92007-09-25 17:54:57 -07004782 mutex_lock(&priv->mutex);
4783
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004784 if (!iwl_is_ready(priv)) {
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004785 ret = -EAGAIN;
Zhu Yib481de92007-09-25 17:54:57 -07004786 goto out;
4787 }
4788
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004789 ret = strict_strtoul(buf, 10, &mode);
4790 if (ret)
4791 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004792
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004793 ret = iwl_power_set_user_mode(priv, mode);
4794 if (ret) {
4795 IWL_DEBUG_MAC80211(priv, "failed setting power mode.\n");
4796 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004797 }
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004798 ret = count;
Zhu Yib481de92007-09-25 17:54:57 -07004799
4800 out:
4801 mutex_unlock(&priv->mutex);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004802 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004803}
4804
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004805static ssize_t show_power_level(struct device *d,
4806 struct device_attribute *attr, char *buf)
4807{
4808 struct iwl_priv *priv = dev_get_drvdata(d);
4809 int mode = priv->power_data.user_power_setting;
4810 int system = priv->power_data.system_power_setting;
4811 int level = priv->power_data.power_mode;
4812 char *p = buf;
4813
4814 switch (system) {
4815 case IWL_POWER_SYS_AUTO:
4816 p += sprintf(p, "SYSTEM:auto");
4817 break;
4818 case IWL_POWER_SYS_AC:
4819 p += sprintf(p, "SYSTEM:ac");
4820 break;
4821 case IWL_POWER_SYS_BATTERY:
4822 p += sprintf(p, "SYSTEM:battery");
4823 break;
4824 }
4825
4826 p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
4827 "fixed" : "auto");
4828 p += sprintf(p, "\tINDEX:%d", level);
4829 p += sprintf(p, "\n");
4830 return p - buf + 1;
4831}
4832
4833static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR,
4834 show_power_level, store_power_level);
4835
Zhu Yib481de92007-09-25 17:54:57 -07004836#define MAX_WX_STRING 80
4837
4838/* Values are in microsecond */
4839static const s32 timeout_duration[] = {
4840 350000,
4841 250000,
4842 75000,
4843 37000,
4844 25000,
4845};
4846static const s32 period_duration[] = {
4847 400000,
4848 700000,
4849 1000000,
4850 1000000,
4851 1000000
4852};
4853
Zhu Yib481de92007-09-25 17:54:57 -07004854static ssize_t show_channels(struct device *d,
4855 struct device_attribute *attr, char *buf)
4856{
Johannes Berg8318d782008-01-24 19:38:38 +01004857 /* all this shit doesn't belong into sysfs anyway */
4858 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07004859}
4860
4861static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
4862
4863static ssize_t show_statistics(struct device *d,
4864 struct device_attribute *attr, char *buf)
4865{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004866 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004867 u32 size = sizeof(struct iwl3945_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07004868 u32 len = 0, ofs = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004869 u8 *data = (u8 *)&priv->statistics_39;
Zhu Yib481de92007-09-25 17:54:57 -07004870 int rc = 0;
4871
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004872 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004873 return -EAGAIN;
4874
4875 mutex_lock(&priv->mutex);
Samuel Ortiz17f841c2009-01-23 13:45:20 -08004876 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004877 mutex_unlock(&priv->mutex);
4878
4879 if (rc) {
4880 len = sprintf(buf,
4881 "Error sending statistics request: 0x%08X\n", rc);
4882 return len;
4883 }
4884
4885 while (size && (PAGE_SIZE - len)) {
4886 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4887 PAGE_SIZE - len, 1);
4888 len = strlen(buf);
4889 if (PAGE_SIZE - len)
4890 buf[len++] = '\n';
4891
4892 ofs += 16;
4893 size -= min(size, 16U);
4894 }
4895
4896 return len;
4897}
4898
4899static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
4900
4901static ssize_t show_antenna(struct device *d,
4902 struct device_attribute *attr, char *buf)
4903{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004904 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004905
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004906 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004907 return -EAGAIN;
4908
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08004909 return sprintf(buf, "%d\n", iwl3945_mod_params.antenna);
Zhu Yib481de92007-09-25 17:54:57 -07004910}
4911
4912static ssize_t store_antenna(struct device *d,
4913 struct device_attribute *attr,
4914 const char *buf, size_t count)
4915{
Winkler, Tomas7530f852009-01-27 14:27:53 -08004916 struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004917 int ant;
Zhu Yib481de92007-09-25 17:54:57 -07004918
4919 if (count == 0)
4920 return 0;
4921
4922 if (sscanf(buf, "%1i", &ant) != 1) {
Tomas Winklere1623442009-01-27 14:27:56 -08004923 IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004924 return count;
4925 }
4926
4927 if ((ant >= 0) && (ant <= 2)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004928 IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant);
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08004929 iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant;
Zhu Yib481de92007-09-25 17:54:57 -07004930 } else
Tomas Winklere1623442009-01-27 14:27:56 -08004931 IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant);
Zhu Yib481de92007-09-25 17:54:57 -07004932
4933
4934 return count;
4935}
4936
4937static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
4938
4939static ssize_t show_status(struct device *d,
4940 struct device_attribute *attr, char *buf)
4941{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004942 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004943 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004944 return -EAGAIN;
4945 return sprintf(buf, "0x%08x\n", (int)priv->status);
4946}
4947
4948static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
4949
4950static ssize_t dump_error_log(struct device *d,
4951 struct device_attribute *attr,
4952 const char *buf, size_t count)
4953{
4954 char *p = (char *)buf;
4955
4956 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004957 iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07004958
4959 return strnlen(buf, count);
4960}
4961
4962static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
4963
4964static ssize_t dump_event_log(struct device *d,
4965 struct device_attribute *attr,
4966 const char *buf, size_t count)
4967{
4968 char *p = (char *)buf;
4969
4970 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004971 iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07004972
4973 return strnlen(buf, count);
4974}
4975
4976static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
4977
4978/*****************************************************************************
4979 *
Tomas Winklera96a27f2008-10-23 23:48:56 -07004980 * driver setup and tear down
Zhu Yib481de92007-09-25 17:54:57 -07004981 *
4982 *****************************************************************************/
4983
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004984static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004985{
Reinette Chatred21050c2009-02-13 11:51:18 -08004986 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07004987
4988 init_waitqueue_head(&priv->wait_command_queue);
4989
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004990 INIT_WORK(&priv->up, iwl3945_bg_up);
4991 INIT_WORK(&priv->restart, iwl3945_bg_restart);
4992 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01004993 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004994 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004995 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
4996 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
Helmut Schaa26635162009-01-15 09:38:44 +01004997 INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll);
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08004998 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
4999 INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
5000 INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
5001 INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
Zhu Yib481de92007-09-25 17:54:57 -07005002
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005003 iwl3945_hw_setup_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005004
5005 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005006 iwl3945_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07005007}
5008
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005009static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005010{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005011 iwl3945_hw_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005012
Joonwoo Parke47eb6a2007-11-29 10:42:49 +09005013 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07005014 cancel_delayed_work(&priv->scan_check);
5015 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07005016 cancel_work_sync(&priv->beacon_update);
5017}
5018
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005019static struct attribute *iwl3945_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07005020 &dev_attr_antenna.attr,
5021 &dev_attr_channels.attr,
5022 &dev_attr_dump_errors.attr,
5023 &dev_attr_dump_events.attr,
5024 &dev_attr_flags.attr,
5025 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08005026#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07005027 &dev_attr_measurement.attr,
5028#endif
5029 &dev_attr_power_level.attr,
Zhu Yib481de92007-09-25 17:54:57 -07005030 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07005031 &dev_attr_statistics.attr,
5032 &dev_attr_status.attr,
5033 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07005034 &dev_attr_tx_power.attr,
Samuel Ortizd08853a2009-01-23 13:45:17 -08005035#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005036 &dev_attr_debug_level.attr,
5037#endif
Zhu Yib481de92007-09-25 17:54:57 -07005038 NULL
5039};
5040
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005041static struct attribute_group iwl3945_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07005042 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005043 .attrs = iwl3945_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07005044};
5045
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005046static struct ieee80211_ops iwl3945_hw_ops = {
5047 .tx = iwl3945_mac_tx,
5048 .start = iwl3945_mac_start,
5049 .stop = iwl3945_mac_stop,
5050 .add_interface = iwl3945_mac_add_interface,
5051 .remove_interface = iwl3945_mac_remove_interface,
5052 .config = iwl3945_mac_config,
5053 .config_interface = iwl3945_mac_config_interface,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08005054 .configure_filter = iwl_configure_filter,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005055 .set_key = iwl3945_mac_set_key,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005056 .get_tx_stats = iwl3945_mac_get_tx_stats,
5057 .conf_tx = iwl3945_mac_conf_tx,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005058 .reset_tsf = iwl3945_mac_reset_tsf,
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005059 .bss_info_changed = iwl3945_bss_info_changed,
Abhijeet Kolekare9dde6f62009-02-18 15:54:27 -08005060 .hw_scan = iwl_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07005061};
5062
Winkler, Tomase52119c2008-12-22 11:31:19 +08005063static int iwl3945_init_drv(struct iwl_priv *priv)
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005064{
5065 int ret;
Samuel Ortize6148912009-01-23 13:45:15 -08005066 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005067
5068 priv->retry_rate = 1;
5069 priv->ibss_beacon = NULL;
5070
5071 spin_lock_init(&priv->lock);
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08005072 spin_lock_init(&priv->power_data.lock);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005073 spin_lock_init(&priv->sta_lock);
5074 spin_lock_init(&priv->hcmd_lock);
5075
5076 INIT_LIST_HEAD(&priv->free_frames);
5077
5078 mutex_init(&priv->mutex);
5079
5080 /* Clear the driver's (not device's) station table */
5081 iwl3945_clear_stations_table(priv);
5082
5083 priv->data_retry_limit = -1;
5084 priv->ieee_channels = NULL;
5085 priv->ieee_rates = NULL;
5086 priv->band = IEEE80211_BAND_2GHZ;
5087
5088 priv->iw_mode = NL80211_IFTYPE_STATION;
5089
5090 iwl_reset_qos(priv);
5091
5092 priv->qos_data.qos_active = 0;
5093 priv->qos_data.qos_cap.val = 0;
5094
5095 priv->rates_mask = IWL_RATES_MASK;
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08005096 /* If power management is turned on, default to CAM mode */
5097 priv->power_mode = IWL_POWER_MODE_CAM;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08005098 priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005099
Samuel Ortize6148912009-01-23 13:45:15 -08005100 if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
5101 IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
5102 eeprom->version);
5103 ret = -EINVAL;
5104 goto err;
5105 }
5106 ret = iwl_init_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005107 if (ret) {
5108 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
5109 goto err;
5110 }
5111
Samuel Ortize6148912009-01-23 13:45:15 -08005112 /* Set up txpower settings in driver for all channels */
5113 if (iwl3945_txpower_set_from_eeprom(priv)) {
5114 ret = -EIO;
5115 goto err_free_channel_map;
5116 }
5117
Samuel Ortiz534166d2009-01-23 13:45:16 -08005118 ret = iwlcore_init_geos(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005119 if (ret) {
5120 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
5121 goto err_free_channel_map;
5122 }
Samuel Ortiz534166d2009-01-23 13:45:16 -08005123 iwl3945_init_hw_rates(priv, priv->ieee_rates);
5124
5125 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
5126 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
5127 &priv->bands[IEEE80211_BAND_2GHZ];
5128 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
5129 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
5130 &priv->bands[IEEE80211_BAND_5GHZ];
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005131
5132 return 0;
5133
5134err_free_channel_map:
Samuel Ortize6148912009-01-23 13:45:15 -08005135 iwl_free_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005136err:
5137 return ret;
5138}
5139
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005140static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07005141{
5142 int err = 0;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005143 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07005144 struct ieee80211_hw *hw;
Kolekar, Abhijeetc0f20d92008-12-19 10:37:19 +08005145 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Samuel Ortize6148912009-01-23 13:45:15 -08005146 struct iwl3945_eeprom *eeprom;
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005147 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07005148
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005149 /***********************
5150 * 1. Allocating HW data
5151 * ********************/
5152
Zhu Yib481de92007-09-25 17:54:57 -07005153 /* mac80211 allocates memory for this device instance, including
5154 * space for this driver's private structure */
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005155 hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
Zhu Yib481de92007-09-25 17:54:57 -07005156 if (hw == NULL) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005157 printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
Zhu Yib481de92007-09-25 17:54:57 -07005158 err = -ENOMEM;
5159 goto out;
5160 }
Zhu Yib481de92007-09-25 17:54:57 -07005161 priv = hw->priv;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005162 SET_IEEE80211_DEV(hw, &pdev->dev);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005163
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005164 if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) ||
5165 (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005166 IWL_ERR(priv,
5167 "invalid queues_num, should be between %d and %d\n",
5168 IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES);
Samuel Ortiza3139c52008-12-19 10:37:09 +08005169 err = -EINVAL;
5170 goto out;
5171 }
5172
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005173 /*
5174 * Disabling hardware scan means that mac80211 will perform scans
5175 * "the hard way", rather than using device's scan.
5176 */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005177 if (iwl3945_mod_params.disable_hw_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08005178 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005179 iwl3945_hw_ops.hw_scan = NULL;
5180 }
5181
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005182
Tomas Winklere1623442009-01-27 14:27:56 -08005183 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005184 priv->cfg = cfg;
5185 priv->pci_dev = pdev;
5186
Samuel Ortizd08853a2009-01-23 13:45:17 -08005187#ifdef CONFIG_IWLWIFI_DEBUG
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005188 priv->debug_level = iwl3945_mod_params.debug;
5189 atomic_set(&priv->restrict_refcnt, 0);
5190#endif
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005191 hw->rate_control_algorithm = "iwl-3945-rs";
5192 hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
5193
Bruno Randolf566bfe52008-05-08 19:15:40 +02005194 /* Tell mac80211 our characteristics */
Johannes Berg605a0bd2008-07-15 10:10:01 +02005195 hw->flags = IEEE80211_HW_SIGNAL_DBM |
Bruno Randolf566bfe52008-05-08 19:15:40 +02005196 IEEE80211_HW_NOISE_DBM;
Zhu Yib481de92007-09-25 17:54:57 -07005197
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -07005198 hw->wiphy->interface_modes =
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -07005199 BIT(NL80211_IFTYPE_STATION) |
5200 BIT(NL80211_IFTYPE_ADHOC);
5201
Luis R. Rodriguez2a44f912009-01-22 15:05:49 -08005202 hw->wiphy->custom_regulatory = true;
Luis R. Rodriguezea4a82dc2008-11-12 14:22:04 -08005203
Johannes Berg2a519312009-02-10 21:25:55 +01005204 hw->wiphy->max_scan_ssids = 1;
5205
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005206 /* 4 EDCA QOS priorities */
Zhu Yib481de92007-09-25 17:54:57 -07005207 hw->queues = 4;
5208
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005209 /***************************
5210 * 2. Initializing PCI bus
5211 * *************************/
Zhu Yib481de92007-09-25 17:54:57 -07005212 if (pci_enable_device(pdev)) {
5213 err = -ENODEV;
5214 goto out_ieee80211_free_hw;
5215 }
5216
5217 pci_set_master(pdev);
5218
Zhu Yib481de92007-09-25 17:54:57 -07005219 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
5220 if (!err)
5221 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
5222 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08005223 IWL_WARN(priv, "No suitable DMA available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07005224 goto out_pci_disable_device;
5225 }
5226
5227 pci_set_drvdata(pdev, priv);
5228 err = pci_request_regions(pdev, DRV_NAME);
5229 if (err)
5230 goto out_pci_disable_device;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005231
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005232 /***********************
5233 * 3. Read REV Register
5234 * ********************/
Zhu Yib481de92007-09-25 17:54:57 -07005235 priv->hw_base = pci_iomap(pdev, 0, 0);
5236 if (!priv->hw_base) {
5237 err = -ENODEV;
5238 goto out_pci_release_regions;
5239 }
5240
Tomas Winklere1623442009-01-27 14:27:56 -08005241 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Zhu Yib481de92007-09-25 17:54:57 -07005242 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08005243 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Zhu Yib481de92007-09-25 17:54:57 -07005244
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005245 /* We disable the RETRY_TIMEOUT register (0x41) to keep
5246 * PCI Tx retries from interfering with C3 CPU state */
5247 pci_write_config_byte(pdev, 0x41, 0x00);
Zhu Yib481de92007-09-25 17:54:57 -07005248
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005249 /* amp init */
5250 err = priv->cfg->ops->lib->apm_ops.init(priv);
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005251 if (err < 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08005252 IWL_DEBUG_INFO(priv, "Failed to init APMG\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005253 goto out_iounmap;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005254 }
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005255
5256 /***********************
5257 * 4. Read EEPROM
5258 * ********************/
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005259
Zhu Yi5a66926a2008-01-14 17:46:18 -08005260 /* Read the EEPROM */
Samuel Ortize6148912009-01-23 13:45:15 -08005261 err = iwl_eeprom_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005262 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005263 IWL_ERR(priv, "Unable to init EEPROM\n");
Zhu Yi5a66926a2008-01-14 17:46:18 -08005264 goto out_remove_sysfs;
5265 }
5266 /* MAC Address location in EEPROM same for 3945/4965 */
Samuel Ortize6148912009-01-23 13:45:15 -08005267 eeprom = (struct iwl3945_eeprom *)priv->eeprom;
5268 memcpy(priv->mac_addr, eeprom->mac_address, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08005269 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
Zhu Yi5a66926a2008-01-14 17:46:18 -08005270 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
5271
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005272 /***********************
5273 * 5. Setup HW Constants
5274 * ********************/
5275 /* Device-specific setup */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005276 if (iwl3945_hw_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005277 IWL_ERR(priv, "failed to set hw settings\n");
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005278 goto out_iounmap;
5279 }
5280
5281 /***********************
5282 * 6. Setup priv
5283 * ********************/
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005284
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005285 err = iwl3945_init_drv(priv);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005286 if (err) {
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005287 IWL_ERR(priv, "initializing driver failed\n");
5288 goto out_free_geos;
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005289 }
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005290
Tomas Winkler978785a2008-12-19 10:37:31 +08005291 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
5292 priv->cfg->name);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005293
5294 /***********************************
5295 * 7. Initialize Module Parameters
5296 * **********************************/
5297
5298 /* Initialize module parameter values here */
5299 /* Disable radio (SW RF KILL) via parameter when loading driver */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005300 if (iwl3945_mod_params.disable) {
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005301 set_bit(STATUS_RF_KILL_SW, &priv->status);
Tomas Winklere1623442009-01-27 14:27:56 -08005302 IWL_DEBUG_INFO(priv, "Radio disabled.\n");
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005303 }
5304
5305
5306 /***********************
5307 * 8. Setup Services
5308 * ********************/
5309
5310 spin_lock_irqsave(&priv->lock, flags);
5311 iwl3945_disable_interrupts(priv);
5312 spin_unlock_irqrestore(&priv->lock, flags);
5313
Helmut Schaa26635162009-01-15 09:38:44 +01005314 pci_enable_msi(priv->pci_dev);
5315
5316 err = request_irq(priv->pci_dev->irq, iwl3945_isr, IRQF_SHARED,
5317 DRV_NAME, priv);
5318 if (err) {
5319 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
5320 goto out_disable_msi;
5321 }
5322
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005323 err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
5324 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005325 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005326 goto out_release_irq;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005327 }
5328
Samuel Ortiz8ccde882009-01-27 14:27:52 -08005329 iwl_set_rxon_channel(priv,
5330 &priv->bands[IEEE80211_BAND_2GHZ].channels[5]);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005331 iwl3945_setup_deferred_work(priv);
5332 iwl3945_setup_rx_handlers(priv);
5333
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005334 /*********************************
Helmut Schaa26635162009-01-15 09:38:44 +01005335 * 9. Setup and Register mac80211
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005336 * *******************************/
5337
Zhu Yi5a66926a2008-01-14 17:46:18 -08005338 err = ieee80211_register_hw(priv->hw);
5339 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005340 IWL_ERR(priv, "Failed to register network device: %d\n", err);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005341 goto out_remove_sysfs;
Zhu Yib481de92007-09-25 17:54:57 -07005342 }
5343
Zhu Yi5a66926a2008-01-14 17:46:18 -08005344 priv->hw->conf.beacon_int = 100;
5345 priv->mac80211_registered = 1;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005346
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005347 err = iwl_rfkill_init(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005348 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08005349 IWL_ERR(priv, "Unable to initialize RFKILL system. "
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005350 "Ignoring error: %d\n", err);
5351
Helmut Schaa26635162009-01-15 09:38:44 +01005352 /* Start monitoring the killswitch */
5353 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
5354 2 * HZ);
5355
Zhu Yib481de92007-09-25 17:54:57 -07005356 return 0;
5357
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005358 out_remove_sysfs:
5359 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005360 out_free_geos:
Samuel Ortiz534166d2009-01-23 13:45:16 -08005361 iwlcore_free_geos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005362
5363 out_release_irq:
Helmut Schaa26635162009-01-15 09:38:44 +01005364 free_irq(priv->pci_dev->irq, priv);
Zhu Yib481de92007-09-25 17:54:57 -07005365 destroy_workqueue(priv->workqueue);
5366 priv->workqueue = NULL;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005367 iwl3945_unset_hw_params(priv);
Helmut Schaa26635162009-01-15 09:38:44 +01005368 out_disable_msi:
5369 pci_disable_msi(priv->pci_dev);
Zhu Yib481de92007-09-25 17:54:57 -07005370 out_iounmap:
5371 pci_iounmap(pdev, priv->hw_base);
5372 out_pci_release_regions:
5373 pci_release_regions(pdev);
5374 out_pci_disable_device:
5375 pci_disable_device(pdev);
5376 pci_set_drvdata(pdev, NULL);
5377 out_ieee80211_free_hw:
5378 ieee80211_free_hw(priv->hw);
5379 out:
5380 return err;
5381}
5382
Reinette Chatrec83dbf62008-03-21 13:53:41 -07005383static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07005384{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005385 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005386 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07005387
5388 if (!priv)
5389 return;
5390
Tomas Winklere1623442009-01-27 14:27:56 -08005391 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07005392
Zhu Yib481de92007-09-25 17:54:57 -07005393 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08005394
Kolekar, Abhijeetd552bfb2008-12-19 10:37:41 +08005395 if (priv->mac80211_registered) {
5396 ieee80211_unregister_hw(priv->hw);
5397 priv->mac80211_registered = 0;
5398 } else {
5399 iwl3945_down(priv);
5400 }
Zhu Yib481de92007-09-25 17:54:57 -07005401
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005402 /* make sure we flush any pending irq or
5403 * tasklet for the driver
5404 */
5405 spin_lock_irqsave(&priv->lock, flags);
5406 iwl3945_disable_interrupts(priv);
5407 spin_unlock_irqrestore(&priv->lock, flags);
5408
5409 iwl_synchronize_irq(priv);
5410
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005411 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07005412
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005413 iwl_rfkill_unregister(priv);
Helmut Schaa26635162009-01-15 09:38:44 +01005414 cancel_delayed_work(&priv->rfkill_poll);
5415
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005416 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005417
5418 if (priv->rxq.bd)
Winkler, Tomas51af3d32008-12-22 11:31:23 +08005419 iwl_rx_queue_free(priv, &priv->rxq);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005420 iwl3945_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005421
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005422 iwl3945_unset_hw_params(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005423 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005424
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08005425 /*netif_stop_queue(dev); */
5426 flush_workqueue(priv->workqueue);
5427
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005428 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07005429 * priv->workqueue... so we can't take down the workqueue
5430 * until now... */
5431 destroy_workqueue(priv->workqueue);
5432 priv->workqueue = NULL;
5433
Helmut Schaa26635162009-01-15 09:38:44 +01005434 free_irq(pdev->irq, priv);
5435 pci_disable_msi(pdev);
5436
Zhu Yib481de92007-09-25 17:54:57 -07005437 pci_iounmap(pdev, priv->hw_base);
5438 pci_release_regions(pdev);
5439 pci_disable_device(pdev);
5440 pci_set_drvdata(pdev, NULL);
5441
Samuel Ortize6148912009-01-23 13:45:15 -08005442 iwl_free_channel_map(priv);
Samuel Ortiz534166d2009-01-23 13:45:16 -08005443 iwlcore_free_geos(priv);
Winkler, Tomas805cee52009-01-19 15:30:28 -08005444 kfree(priv->scan);
Zhu Yib481de92007-09-25 17:54:57 -07005445 if (priv->ibss_beacon)
5446 dev_kfree_skb(priv->ibss_beacon);
5447
5448 ieee80211_free_hw(priv->hw);
5449}
5450
5451#ifdef CONFIG_PM
5452
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005453static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07005454{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005455 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005456
Zhu Yie655b9f2008-01-24 02:19:38 -08005457 if (priv->is_open) {
5458 set_bit(STATUS_IN_SUSPEND, &priv->status);
5459 iwl3945_mac_stop(priv->hw);
5460 priv->is_open = 1;
5461 }
Helmut Schaa26635162009-01-15 09:38:44 +01005462 pci_save_state(pdev);
5463 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005464 pci_set_power_state(pdev, PCI_D3hot);
5465
Zhu Yib481de92007-09-25 17:54:57 -07005466 return 0;
5467}
5468
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005469static int iwl3945_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07005470{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005471 struct iwl_priv *priv = pci_get_drvdata(pdev);
Winkler, Tomas450154e2009-01-27 14:27:55 -08005472 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07005473
Zhu Yib481de92007-09-25 17:54:57 -07005474 pci_set_power_state(pdev, PCI_D0);
Winkler, Tomas450154e2009-01-27 14:27:55 -08005475 ret = pci_enable_device(pdev);
5476 if (ret)
5477 return ret;
Helmut Schaa26635162009-01-15 09:38:44 +01005478 pci_restore_state(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005479
Zhu Yie655b9f2008-01-24 02:19:38 -08005480 if (priv->is_open)
5481 iwl3945_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07005482
Zhu Yie655b9f2008-01-24 02:19:38 -08005483 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07005484 return 0;
5485}
5486
5487#endif /* CONFIG_PM */
5488
5489/*****************************************************************************
5490 *
5491 * driver and module entry point
5492 *
5493 *****************************************************************************/
5494
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005495static struct pci_driver iwl3945_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07005496 .name = DRV_NAME,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005497 .id_table = iwl3945_hw_card_ids,
5498 .probe = iwl3945_pci_probe,
5499 .remove = __devexit_p(iwl3945_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07005500#ifdef CONFIG_PM
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005501 .suspend = iwl3945_pci_suspend,
5502 .resume = iwl3945_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07005503#endif
5504};
5505
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005506static int __init iwl3945_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07005507{
5508
5509 int ret;
5510 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
5511 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005512
5513 ret = iwl3945_rate_control_register();
5514 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005515 printk(KERN_ERR DRV_NAME
5516 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005517 return ret;
5518 }
5519
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005520 ret = pci_register_driver(&iwl3945_driver);
Zhu Yib481de92007-09-25 17:54:57 -07005521 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005522 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005523 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07005524 }
Zhu Yib481de92007-09-25 17:54:57 -07005525
5526 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005527
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005528error_register:
5529 iwl3945_rate_control_unregister();
5530 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07005531}
5532
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005533static void __exit iwl3945_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07005534{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005535 pci_unregister_driver(&iwl3945_driver);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005536 iwl3945_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07005537}
5538
Reinette Chatrea0987a82008-12-02 12:14:06 -08005539MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
Zhu Yi25cb6ca2008-09-11 11:45:22 +08005540
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005541module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005542MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005543module_param_named(disable, iwl3945_mod_params.disable, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005544MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -08005545module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
5546MODULE_PARM_DESC(swcrypto,
5547 "using software crypto (default 1 [software])\n");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005548module_param_named(debug, iwl3945_mod_params.debug, uint, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005549MODULE_PARM_DESC(debug, "debug output mask");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005550module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005551MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
5552
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005553module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005554MODULE_PARM_DESC(queues_num, "number of hw queues.");
5555
Samuel Ortizaf48d042009-01-23 13:45:19 -08005556module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, 0444);
5557MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error");
5558
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005559module_exit(iwl3945_exit);
5560module_init(iwl3945_init);