blob: 800e46c9a68b36d43946904efbc7643baf66a976 [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
661#define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
662
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_scan_initiate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700730{
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800731 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800732 IWL_DEBUG_SCAN(priv, "Aborting scan due to not ready.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700733 return -EIO;
734 }
735
736 if (test_bit(STATUS_SCANNING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800737 IWL_DEBUG_SCAN(priv, "Scan already in progress.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700738 return -EAGAIN;
739 }
740
741 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800742 IWL_DEBUG_SCAN(priv, "Scan request while abort pending. "
Zhu Yib481de92007-09-25 17:54:57 -0700743 "Queuing.\n");
744 return -EAGAIN;
745 }
746
Tomas Winklere1623442009-01-27 14:27:56 -0800747 IWL_DEBUG_INFO(priv, "Starting scan...\n");
Ron Rindjunsky66b50042008-06-25 16:46:31 +0800748 if (priv->cfg->sku & IWL_SKU_G)
749 priv->scan_bands |= BIT(IEEE80211_BAND_2GHZ);
750 if (priv->cfg->sku & IWL_SKU_A)
751 priv->scan_bands |= BIT(IEEE80211_BAND_5GHZ);
Zhu Yib481de92007-09-25 17:54:57 -0700752 set_bit(STATUS_SCANNING, &priv->status);
753 priv->scan_start = jiffies;
754 priv->scan_pass_start = priv->scan_start;
755
756 queue_work(priv->workqueue, &priv->request_scan);
757
758 return 0;
759}
760
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800761static int iwl3945_set_mode(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -0700762{
Johannes Berg05c914f2008-09-11 00:01:58 +0200763 if (mode == NL80211_IFTYPE_ADHOC) {
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800764 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -0700765
Samuel Ortize6148912009-01-23 13:45:15 -0800766 ch_info = iwl_get_channel_info(priv,
Johannes Berg8318d782008-01-24 19:38:38 +0100767 priv->band,
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800768 le16_to_cpu(priv->staging_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700769
770 if (!ch_info || !is_channel_ibss(ch_info)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800771 IWL_ERR(priv, "channel %d not IBSS channel\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800772 le16_to_cpu(priv->staging_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700773 return -EINVAL;
774 }
775 }
776
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800777 iwl_connection_init_rx_config(priv, mode);
Zhu Yib481de92007-09-25 17:54:57 -0700778
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800779 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700780
Tomas Winklera96a27f2008-10-23 23:48:56 -0700781 /* don't commit rxon if rf-kill is on*/
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800782 if (!iwl_is_ready_rf(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +0800783 return -EAGAIN;
784
785 cancel_delayed_work(&priv->scan_check);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -0800786 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800787 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
Tomas Winklere1623442009-01-27 14:27:56 -0800788 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +0800789 return -EAGAIN;
790 }
791
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800792 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700793
794 return 0;
795}
796
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800797static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
Johannes Berge039fa42008-05-15 12:55:29 +0200798 struct ieee80211_tx_info *info,
Winkler, Tomasc2d79b482008-12-19 10:37:34 +0800799 struct iwl_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -0700800 struct sk_buff *skb_frag,
801 int last_frag)
802{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800803 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
Ivo van Doorn1c014422008-04-17 19:41:02 +0200804 struct iwl3945_hw_key *keyinfo =
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800805 &priv->stations_39[info->control.hw_key->hw_key_idx].keyinfo;
Zhu Yib481de92007-09-25 17:54:57 -0700806
807 switch (keyinfo->alg) {
808 case ALG_CCMP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800809 tx->sec_ctl = TX_CMD_SEC_CCM;
810 memcpy(tx->key, keyinfo->key, keyinfo->keylen);
Tomas Winklere1623442009-01-27 14:27:56 -0800811 IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
Zhu Yib481de92007-09-25 17:54:57 -0700812 break;
813
814 case ALG_TKIP:
815#if 0
Winkler, Tomase52119c2008-12-22 11:31:19 +0800816 tx->sec_ctl = TX_CMD_SEC_TKIP;
Zhu Yib481de92007-09-25 17:54:57 -0700817
818 if (last_frag)
Winkler, Tomase52119c2008-12-22 11:31:19 +0800819 memcpy(tx->tkip_mic.byte, skb_frag->tail - 8,
Zhu Yib481de92007-09-25 17:54:57 -0700820 8);
821 else
Winkler, Tomase52119c2008-12-22 11:31:19 +0800822 memset(tx->tkip_mic.byte, 0, 8);
Zhu Yib481de92007-09-25 17:54:57 -0700823#endif
824 break;
825
826 case ALG_WEP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800827 tx->sec_ctl = TX_CMD_SEC_WEP |
Johannes Berge039fa42008-05-15 12:55:29 +0200828 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
Zhu Yib481de92007-09-25 17:54:57 -0700829
830 if (keyinfo->keylen == 13)
Winkler, Tomase52119c2008-12-22 11:31:19 +0800831 tx->sec_ctl |= TX_CMD_SEC_KEY128;
Zhu Yib481de92007-09-25 17:54:57 -0700832
Winkler, Tomase52119c2008-12-22 11:31:19 +0800833 memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen);
Zhu Yib481de92007-09-25 17:54:57 -0700834
Tomas Winklere1623442009-01-27 14:27:56 -0800835 IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
Johannes Berge039fa42008-05-15 12:55:29 +0200836 "with key %d\n", info->control.hw_key->hw_key_idx);
Zhu Yib481de92007-09-25 17:54:57 -0700837 break;
838
Zhu Yib481de92007-09-25 17:54:57 -0700839 default:
Tomas Winkler978785a2008-12-19 10:37:31 +0800840 IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg);
Zhu Yib481de92007-09-25 17:54:57 -0700841 break;
842 }
843}
844
845/*
846 * handle build REPLY_TX command notification.
847 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800848static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
Winkler, Tomasc2d79b482008-12-19 10:37:34 +0800849 struct iwl_cmd *cmd,
Johannes Berge039fa42008-05-15 12:55:29 +0200850 struct ieee80211_tx_info *info,
Winkler, Tomase52119c2008-12-22 11:31:19 +0800851 struct ieee80211_hdr *hdr, u8 std_id)
Zhu Yib481de92007-09-25 17:54:57 -0700852{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800853 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
854 __le32 tx_flags = tx->tx_flags;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700855 __le16 fc = hdr->frame_control;
Johannes Berge6a98542008-10-21 12:40:02 +0200856 u8 rc_flags = info->control.rates[0].flags;
Zhu Yib481de92007-09-25 17:54:57 -0700857
Winkler, Tomase52119c2008-12-22 11:31:19 +0800858 tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Johannes Berge039fa42008-05-15 12:55:29 +0200859 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
Zhu Yib481de92007-09-25 17:54:57 -0700860 tx_flags |= TX_CMD_FLG_ACK_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700861 if (ieee80211_is_mgmt(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700862 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700863 if (ieee80211_is_probe_resp(fc) &&
Zhu Yib481de92007-09-25 17:54:57 -0700864 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
865 tx_flags |= TX_CMD_FLG_TSF_MSK;
866 } else {
867 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
868 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
869 }
870
Winkler, Tomase52119c2008-12-22 11:31:19 +0800871 tx->sta_id = std_id;
Harvey Harrison8b7b1e02008-06-11 14:21:56 -0700872 if (ieee80211_has_morefrags(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700873 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
874
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700875 if (ieee80211_is_data_qos(fc)) {
876 u8 *qc = ieee80211_get_qos_ctl(hdr);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800877 tx->tid_tspec = qc[0] & 0xf;
Zhu Yib481de92007-09-25 17:54:57 -0700878 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800879 } else {
Zhu Yib481de92007-09-25 17:54:57 -0700880 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800881 }
Zhu Yib481de92007-09-25 17:54:57 -0700882
Johannes Berge6a98542008-10-21 12:40:02 +0200883 if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
Zhu Yib481de92007-09-25 17:54:57 -0700884 tx_flags |= TX_CMD_FLG_RTS_MSK;
885 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
Johannes Berge6a98542008-10-21 12:40:02 +0200886 } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
Zhu Yib481de92007-09-25 17:54:57 -0700887 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
888 tx_flags |= TX_CMD_FLG_CTS_MSK;
889 }
890
891 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
892 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
893
894 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700895 if (ieee80211_is_mgmt(fc)) {
896 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
Winkler, Tomase52119c2008-12-22 11:31:19 +0800897 tx->timeout.pm_frame_timeout = cpu_to_le16(3);
Zhu Yib481de92007-09-25 17:54:57 -0700898 else
Winkler, Tomase52119c2008-12-22 11:31:19 +0800899 tx->timeout.pm_frame_timeout = cpu_to_le16(2);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700900 } else {
Winkler, Tomase52119c2008-12-22 11:31:19 +0800901 tx->timeout.pm_frame_timeout = 0;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700902#ifdef CONFIG_IWL3945_LEDS
903 priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
904#endif
905 }
Zhu Yib481de92007-09-25 17:54:57 -0700906
Winkler, Tomase52119c2008-12-22 11:31:19 +0800907 tx->driver_txop = 0;
908 tx->tx_flags = tx_flags;
909 tx->next_frame_len = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700910}
911
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800912/**
913 * iwl3945_get_sta_id - Find station's index within station table
914 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800915static int iwl3945_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
Zhu Yib481de92007-09-25 17:54:57 -0700916{
917 int sta_id;
918 u16 fc = le16_to_cpu(hdr->frame_control);
919
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800920 /* If this frame is broadcast or management, use broadcast station id */
Zhu Yib481de92007-09-25 17:54:57 -0700921 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
922 is_multicast_ether_addr(hdr->addr1))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800923 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700924
925 switch (priv->iw_mode) {
926
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800927 /* If we are a client station in a BSS network, use the special
928 * AP station entry (that's the only station we communicate with) */
Johannes Berg05c914f2008-09-11 00:01:58 +0200929 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -0700930 return IWL_AP_ID;
931
932 /* If we are an AP, then find the station, or use BCAST */
Johannes Berg05c914f2008-09-11 00:01:58 +0200933 case NL80211_IFTYPE_AP:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800934 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700935 if (sta_id != IWL_INVALID_STATION)
936 return sta_id;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800937 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700938
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800939 /* If this frame is going out to an IBSS network, find the station,
940 * or create a new station table entry */
Johannes Berg05c914f2008-09-11 00:01:58 +0200941 case NL80211_IFTYPE_ADHOC: {
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800942 /* Create new station table entry */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800943 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700944 if (sta_id != IWL_INVALID_STATION)
945 return sta_id;
946
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800947 sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
Zhu Yib481de92007-09-25 17:54:57 -0700948
949 if (sta_id != IWL_INVALID_STATION)
950 return sta_id;
951
Tomas Winklere1623442009-01-27 14:27:56 -0800952 IWL_DEBUG_DROP(priv, "Station %pM not in station map. "
Zhu Yib481de92007-09-25 17:54:57 -0700953 "Defaulting to broadcast...\n",
Johannes Berge1749612008-10-27 15:59:26 -0700954 hdr->addr1);
Samuel Ortiz40b8ec02008-12-19 10:37:08 +0800955 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800956 return priv->hw_params.bcast_sta_id;
Joe Perches0795af52007-10-03 17:59:30 -0700957 }
Stefanik Gábor914233d2008-06-30 17:23:30 +0800958 /* If we are in monitor mode, use BCAST. This is required for
959 * packet injection. */
Johannes Berg05c914f2008-09-11 00:01:58 +0200960 case NL80211_IFTYPE_MONITOR:
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800961 return priv->hw_params.bcast_sta_id;
Stefanik Gábor914233d2008-06-30 17:23:30 +0800962
Zhu Yib481de92007-09-25 17:54:57 -0700963 default:
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800964 IWL_WARN(priv, "Unknown mode of operation: %d\n",
965 priv->iw_mode);
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800966 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700967 }
968}
969
970/*
971 * start REPLY_TX command process
972 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800973static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -0700974{
975 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berge039fa42008-05-15 12:55:29 +0200976 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800977 struct iwl3945_tx_cmd *tx;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800978 struct iwl_tx_queue *txq = NULL;
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800979 struct iwl_queue *q = NULL;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800980 struct iwl_cmd *out_cmd = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700981 dma_addr_t phys_addr;
982 dma_addr_t txcmd_phys;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800983 int txq_id = skb_get_queue_mapping(skb);
Tomas Winkler54dbb522008-05-15 13:54:06 +0800984 u16 len, idx, len_org, hdr_len;
985 u8 id;
986 u8 unicast;
Zhu Yib481de92007-09-25 17:54:57 -0700987 u8 sta_id;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800988 u8 tid = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700989 u16 seq_number = 0;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700990 __le16 fc;
Zhu Yib481de92007-09-25 17:54:57 -0700991 u8 wait_write_ptr = 0;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800992 u8 *qc = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700993 unsigned long flags;
994 int rc;
995
996 spin_lock_irqsave(&priv->lock, flags);
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800997 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800998 IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
Zhu Yib481de92007-09-25 17:54:57 -0700999 goto drop_unlock;
1000 }
1001
Johannes Berge039fa42008-05-15 12:55:29 +02001002 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001003 IWL_ERR(priv, "ERROR: No TX rate available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001004 goto drop_unlock;
1005 }
1006
1007 unicast = !is_multicast_ether_addr(hdr->addr1);
1008 id = 0;
1009
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001010 fc = hdr->frame_control;
Zhu Yib481de92007-09-25 17:54:57 -07001011
Samuel Ortizd08853a2009-01-23 13:45:17 -08001012#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001013 if (ieee80211_is_auth(fc))
Tomas Winklere1623442009-01-27 14:27:56 -08001014 IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001015 else if (ieee80211_is_assoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -08001016 IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001017 else if (ieee80211_is_reassoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -08001018 IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
Zhu Yib481de92007-09-25 17:54:57 -07001019#endif
1020
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08001021 /* drop all data frame if we are not associated */
Stefanik Gábor914233d2008-06-30 17:23:30 +08001022 if (ieee80211_is_data(fc) &&
Johannes Berg05c914f2008-09-11 00:01:58 +02001023 (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001024 (!iwl_is_associated(priv) ||
Johannes Berg05c914f2008-09-11 00:01:58 +02001025 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
Tomas Winklere1623442009-01-27 14:27:56 -08001026 IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n");
Zhu Yib481de92007-09-25 17:54:57 -07001027 goto drop_unlock;
1028 }
1029
1030 spin_unlock_irqrestore(&priv->lock, flags);
1031
Harvey Harrison7294ec92008-07-15 18:43:59 -07001032 hdr_len = ieee80211_hdrlen(fc);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001033
1034 /* Find (or create) index into station table for destination station */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001035 sta_id = iwl3945_get_sta_id(priv, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07001036 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -08001037 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07001038 hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07001039 goto drop;
1040 }
1041
Tomas Winklere1623442009-01-27 14:27:56 -08001042 IWL_DEBUG_RATE(priv, "station Id %d\n", sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07001043
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001044 if (ieee80211_is_data_qos(fc)) {
1045 qc = ieee80211_get_qos_ctl(hdr);
Harvey Harrison7294ec92008-07-15 18:43:59 -07001046 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001047 seq_number = priv->stations_39[sta_id].tid[tid].seq_number &
Zhu Yib481de92007-09-25 17:54:57 -07001048 IEEE80211_SCTL_SEQ;
1049 hdr->seq_ctrl = cpu_to_le16(seq_number) |
1050 (hdr->seq_ctrl &
1051 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG));
1052 seq_number += 0x10;
1053 }
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001054
1055 /* Descriptor for chosen Tx queue */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001056 txq = &priv->txq[txq_id];
Zhu Yib481de92007-09-25 17:54:57 -07001057 q = &txq->q;
1058
1059 spin_lock_irqsave(&priv->lock, flags);
1060
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001061 idx = get_cmd_index(q, q->write_ptr, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001062
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001063 /* Set up driver data for this TFD */
Winkler, Tomasdbb66542008-12-22 11:31:14 +08001064 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001065 txq->txb[q->write_ptr].skb[0] = skb;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001066
1067 /* Init first empty entry in queue's array of Tx/cmd buffers */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001068 out_cmd = txq->cmd[idx];
Winkler, Tomase52119c2008-12-22 11:31:19 +08001069 tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
Zhu Yib481de92007-09-25 17:54:57 -07001070 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
Winkler, Tomase52119c2008-12-22 11:31:19 +08001071 memset(tx, 0, sizeof(*tx));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001072
1073 /*
1074 * Set up the Tx-command (not MAC!) header.
1075 * Store the chosen Tx queue and TFD index within the sequence field;
1076 * after Tx, uCode's Tx response will return this value so driver can
1077 * locate the frame within the tx queue and do post-tx processing.
1078 */
Zhu Yib481de92007-09-25 17:54:57 -07001079 out_cmd->hdr.cmd = REPLY_TX;
1080 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001081 INDEX_TO_SEQ(q->write_ptr)));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001082
1083 /* Copy MAC header from skb into command buffer */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001084 memcpy(tx->hdr, hdr, hdr_len);
Zhu Yib481de92007-09-25 17:54:57 -07001085
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001086 /*
1087 * Use the first empty entry in this queue's command buffer array
1088 * to contain the Tx command and MAC header concatenated together
1089 * (payload data will be in another buffer).
1090 * Size of this varies, due to varying MAC header length.
1091 * If end is not dword aligned, we'll have 2 extra bytes at the end
1092 * of the MAC header (device reads on dword boundaries).
1093 * We'll tell device about this padding later.
1094 */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001095 len = sizeof(struct iwl3945_tx_cmd) +
Tomas Winkler4c897252008-12-19 10:37:05 +08001096 sizeof(struct iwl_cmd_header) + hdr_len;
Zhu Yib481de92007-09-25 17:54:57 -07001097
1098 len_org = len;
1099 len = (len + 3) & ~3;
1100
1101 if (len_org != len)
1102 len_org = 1;
1103 else
1104 len_org = 0;
1105
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001106 /* Physical address of this Tx command's header (not MAC header!),
1107 * within command buffer array. */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001108 txcmd_phys = pci_map_single(priv->pci_dev,
1109 out_cmd, sizeof(struct iwl_cmd),
1110 PCI_DMA_TODEVICE);
1111 pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys);
1112 pci_unmap_len_set(&out_cmd->meta, len, sizeof(struct iwl_cmd));
1113 /* Add buffer containing Tx command and MAC(!) header to TFD's
1114 * first entry */
1115 txcmd_phys += offsetof(struct iwl_cmd, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07001116
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001117 /* Add buffer containing Tx command and MAC(!) header to TFD's
1118 * first entry */
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001119 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1120 txcmd_phys, len, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001121
Johannes Bergd0f09802008-07-29 11:32:07 +02001122 if (info->control.hw_key)
Johannes Berge039fa42008-05-15 12:55:29 +02001123 iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001124
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001125 /* Set up TFD's 2nd entry to point directly to remainder of skb,
1126 * if any (802.11 null frames have no payload). */
Zhu Yib481de92007-09-25 17:54:57 -07001127 len = skb->len - hdr_len;
1128 if (len) {
1129 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
1130 len, PCI_DMA_TODEVICE);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001131 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1132 phys_addr, len,
1133 0, U32_PAD(len));
Zhu Yib481de92007-09-25 17:54:57 -07001134 }
1135
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001136 /* Total # bytes to be transmitted */
Zhu Yib481de92007-09-25 17:54:57 -07001137 len = (u16)skb->len;
Winkler, Tomase52119c2008-12-22 11:31:19 +08001138 tx->len = cpu_to_le16(len);
Zhu Yib481de92007-09-25 17:54:57 -07001139
1140 /* TODO need this for burst mode later on */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001141 iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07001142
1143 /* set is_hcca to 0; it probably will never be implemented */
Johannes Berge039fa42008-05-15 12:55:29 +02001144 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001145
Winkler, Tomase52119c2008-12-22 11:31:19 +08001146 tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
1147 tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001148
Harvey Harrison8b7b1e02008-06-11 14:21:56 -07001149 if (!ieee80211_has_morefrags(hdr->frame_control)) {
Zhu Yib481de92007-09-25 17:54:57 -07001150 txq->need_update = 1;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001151 if (qc)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001152 priv->stations_39[sta_id].tid[tid].seq_number = seq_number;
Zhu Yib481de92007-09-25 17:54:57 -07001153 } else {
1154 wait_write_ptr = 1;
1155 txq->need_update = 0;
1156 }
1157
Winkler, Tomase52119c2008-12-22 11:31:19 +08001158 iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx));
Zhu Yib481de92007-09-25 17:54:57 -07001159
Winkler, Tomase52119c2008-12-22 11:31:19 +08001160 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr,
Harvey Harrison7294ec92008-07-15 18:43:59 -07001161 ieee80211_hdrlen(fc));
Zhu Yib481de92007-09-25 17:54:57 -07001162
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001163 /* Tell device the write index *just past* this latest filled TFD */
Tomas Winklerc54b6792008-03-06 17:36:53 -08001164 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001165 rc = iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001166 spin_unlock_irqrestore(&priv->lock, flags);
1167
1168 if (rc)
1169 return rc;
1170
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001171 if ((iwl_queue_space(q) < q->high_mark)
Zhu Yib481de92007-09-25 17:54:57 -07001172 && priv->mac80211_registered) {
1173 if (wait_write_ptr) {
1174 spin_lock_irqsave(&priv->lock, flags);
1175 txq->need_update = 1;
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001176 iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001177 spin_unlock_irqrestore(&priv->lock, flags);
1178 }
1179
Johannes Berge2530082008-05-17 00:57:14 +02001180 ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb));
Zhu Yib481de92007-09-25 17:54:57 -07001181 }
1182
1183 return 0;
1184
1185drop_unlock:
1186 spin_unlock_irqrestore(&priv->lock, flags);
1187drop:
1188 return -1;
1189}
1190
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001191static void iwl3945_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
Zhu Yib481de92007-09-25 17:54:57 -07001192{
1193 unsigned long flags;
1194
1195 if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
1196 return;
1197
Tomas Winklere1623442009-01-27 14:27:56 -08001198 IWL_DEBUG_RF_KILL(priv, "Manual SW RF KILL set to: RADIO %s\n",
Zhu Yib481de92007-09-25 17:54:57 -07001199 disable_radio ? "OFF" : "ON");
1200
1201 if (disable_radio) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08001202 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001203 /* FIXME: This is a workaround for AP */
Johannes Berg05c914f2008-09-11 00:01:58 +02001204 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07001205 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001206 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001207 CSR_UCODE_SW_BIT_RFKILL);
1208 spin_unlock_irqrestore(&priv->lock, flags);
Samuel Ortizc4962942008-12-22 11:31:18 +08001209 iwl_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001210 set_bit(STATUS_RF_KILL_SW, &priv->status);
1211 }
1212 return;
1213 }
1214
1215 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001216 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07001217
1218 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1219 spin_unlock_irqrestore(&priv->lock, flags);
1220
1221 /* wake up ucode */
1222 msleep(10);
1223
1224 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001225 iwl_read32(priv, CSR_UCODE_DRV_GP1);
1226 if (!iwl_grab_nic_access(priv))
1227 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001228 spin_unlock_irqrestore(&priv->lock, flags);
1229
1230 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08001231 IWL_DEBUG_RF_KILL(priv, "Can not turn radio back on - "
Zhu Yib481de92007-09-25 17:54:57 -07001232 "disabled by HW switch\n");
1233 return;
1234 }
1235
Zhu Yi808e72a2008-06-12 09:47:17 +08001236 if (priv->is_open)
1237 queue_work(priv->workqueue, &priv->restart);
Zhu Yib481de92007-09-25 17:54:57 -07001238 return;
1239}
1240
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001241#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07001242
1243#include "iwl-spectrum.h"
1244
1245#define BEACON_TIME_MASK_LOW 0x00FFFFFF
1246#define BEACON_TIME_MASK_HIGH 0xFF000000
1247#define TIME_UNIT 1024
1248
1249/*
1250 * extended beacon time format
1251 * time in usec will be changed into a 32-bit value in 8:24 format
1252 * the high 1 byte is the beacon counts
1253 * the lower 3 bytes is the time in usec within one beacon interval
1254 */
1255
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001256static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001257{
1258 u32 quot;
1259 u32 rem;
1260 u32 interval = beacon_interval * 1024;
1261
1262 if (!interval || !usec)
1263 return 0;
1264
1265 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
1266 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
1267
1268 return (quot << 24) + rem;
1269}
1270
1271/* base is usually what we get from ucode with each received frame,
1272 * the same as HW timer counter counting down
1273 */
1274
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001275static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001276{
1277 u32 base_low = base & BEACON_TIME_MASK_LOW;
1278 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
1279 u32 interval = beacon_interval * TIME_UNIT;
1280 u32 res = (base & BEACON_TIME_MASK_HIGH) +
1281 (addon & BEACON_TIME_MASK_HIGH);
1282
1283 if (base_low > addon_low)
1284 res += base_low - addon_low;
1285 else if (base_low < addon_low) {
1286 res += interval + base_low - addon_low;
1287 res += (1 << 24);
1288 } else
1289 res += (1 << 24);
1290
1291 return cpu_to_le32(res);
1292}
1293
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001294static int iwl3945_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001295 struct ieee80211_measurement_params *params,
1296 u8 type)
1297{
Tomas Winkler600c0e12008-12-19 10:37:04 +08001298 struct iwl_spectrum_cmd spectrum;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001299 struct iwl_rx_packet *res;
Winkler, Tomasc2d79b482008-12-19 10:37:34 +08001300 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001301 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
1302 .data = (void *)&spectrum,
1303 .meta.flags = CMD_WANT_SKB,
1304 };
1305 u32 add_time = le64_to_cpu(params->start_time);
1306 int rc;
1307 int spectrum_resp_status;
1308 int duration = le16_to_cpu(params->duration);
1309
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001310 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001311 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001312 iwl3945_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -07001313 le64_to_cpu(params->start_time) - priv->last_tsf,
1314 le16_to_cpu(priv->rxon_timing.beacon_interval));
1315
1316 memset(&spectrum, 0, sizeof(spectrum));
1317
1318 spectrum.channel_count = cpu_to_le16(1);
1319 spectrum.flags =
1320 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
1321 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
1322 cmd.len = sizeof(spectrum);
1323 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
1324
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001325 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001326 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001327 iwl3945_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -07001328 add_time,
1329 le16_to_cpu(priv->rxon_timing.beacon_interval));
1330 else
1331 spectrum.start_time = 0;
1332
1333 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
1334 spectrum.channels[0].channel = params->channel;
1335 spectrum.channels[0].type = type;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001336 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
Zhu Yib481de92007-09-25 17:54:57 -07001337 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
1338 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
1339
Samuel Ortiz518099a2009-01-19 15:30:27 -08001340 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001341 if (rc)
1342 return rc;
1343
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001344 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001345 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001346 IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -07001347 rc = -EIO;
1348 }
1349
1350 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
1351 switch (spectrum_resp_status) {
1352 case 0: /* Command will be handled */
1353 if (res->u.spectrum.id != 0xff) {
Tomas Winklere1623442009-01-27 14:27:56 -08001354 IWL_DEBUG_INFO(priv, "Replaced existing measurement: %d\n",
Ian Schrambc434dd2007-10-25 17:15:29 +08001355 res->u.spectrum.id);
Zhu Yib481de92007-09-25 17:54:57 -07001356 priv->measurement_status &= ~MEASUREMENT_READY;
1357 }
1358 priv->measurement_status |= MEASUREMENT_ACTIVE;
1359 rc = 0;
1360 break;
1361
1362 case 1: /* Command will not be handled */
1363 rc = -EAGAIN;
1364 break;
1365 }
1366
1367 dev_kfree_skb_any(cmd.meta.u.skb);
1368
1369 return rc;
1370}
1371#endif
1372
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001373static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001374 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001375{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001376 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
1377 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -07001378 struct delayed_work *pwork;
1379
1380 palive = &pkt->u.alive_frame;
1381
Tomas Winklere1623442009-01-27 14:27:56 -08001382 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
Zhu Yib481de92007-09-25 17:54:57 -07001383 "0x%01X 0x%01X\n",
1384 palive->is_valid, palive->ver_type,
1385 palive->ver_subtype);
1386
1387 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
Tomas Winklere1623442009-01-27 14:27:56 -08001388 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001389 memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
1390 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001391 pwork = &priv->init_alive_start;
1392 } else {
Tomas Winklere1623442009-01-27 14:27:56 -08001393 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001394 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001395 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001396 pwork = &priv->alive_start;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001397 iwl3945_disable_events(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001398 }
1399
1400 /* We delay the ALIVE response by 5ms to
1401 * give the HW RF Kill time to activate... */
1402 if (palive->is_valid == UCODE_VALID_OK)
1403 queue_delayed_work(priv->workqueue, pwork,
1404 msecs_to_jiffies(5));
1405 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001406 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001407}
1408
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001409static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001410 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001411{
Helmut Schaac7e035a2009-01-19 13:02:15 +01001412#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001413 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Helmut Schaac7e035a2009-01-19 13:02:15 +01001414#endif
Zhu Yib481de92007-09-25 17:54:57 -07001415
Tomas Winklere1623442009-01-27 14:27:56 -08001416 IWL_DEBUG_RX(priv, "Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
Zhu Yib481de92007-09-25 17:54:57 -07001417 return;
1418}
1419
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001420static void iwl3945_rx_reply_error(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{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001423 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001424
Winkler, Tomas15b16872008-12-19 10:37:33 +08001425 IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
Zhu Yib481de92007-09-25 17:54:57 -07001426 "seq 0x%04X ser 0x%08X\n",
1427 le32_to_cpu(pkt->u.err_resp.error_type),
1428 get_cmd_string(pkt->u.err_resp.cmd_id),
1429 pkt->u.err_resp.cmd_id,
1430 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
1431 le32_to_cpu(pkt->u.err_resp.error_info));
1432}
1433
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001434static void iwl3945_rx_spectrum_measure_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001435 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001436{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001437#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001438 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler600c0e12008-12-19 10:37:04 +08001439 struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001440
1441 if (!report->state) {
Tomas Winklere1623442009-01-27 14:27:56 -08001442 IWL_DEBUG(priv, IWL_DL_11H | IWL_DL_INFO,
Zhu Yib481de92007-09-25 17:54:57 -07001443 "Spectrum Measure Notification: Start\n");
1444 return;
1445 }
1446
1447 memcpy(&priv->measure_report, report, sizeof(*report));
1448 priv->measurement_status |= MEASUREMENT_READY;
1449#endif
1450}
1451
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001452static void iwl3945_rx_pm_sleep_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001453 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001454{
Samuel Ortizd08853a2009-01-23 13:45:17 -08001455#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001456 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler600c0e12008-12-19 10:37:04 +08001457 struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
Tomas Winklere1623442009-01-27 14:27:56 -08001458 IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07001459 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
1460#endif
1461}
1462
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001463static void iwl3945_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001464 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001465{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001466 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winklere1623442009-01-27 14:27:56 -08001467 IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
Zhu Yib481de92007-09-25 17:54:57 -07001468 "notification for %s:\n",
1469 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08001470 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw,
1471 le32_to_cpu(pkt->len));
Zhu Yib481de92007-09-25 17:54:57 -07001472}
1473
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001474static void iwl3945_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07001475{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001476 struct iwl_priv *priv =
1477 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07001478 struct sk_buff *beacon;
1479
1480 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02001481 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07001482
1483 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001484 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07001485 return;
1486 }
1487
1488 mutex_lock(&priv->mutex);
1489 /* new beacon skb is allocated every time; dispose previous.*/
1490 if (priv->ibss_beacon)
1491 dev_kfree_skb(priv->ibss_beacon);
1492
1493 priv->ibss_beacon = beacon;
1494 mutex_unlock(&priv->mutex);
1495
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001496 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001497}
1498
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001499static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001500 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001501{
Samuel Ortizd08853a2009-01-23 13:45:17 -08001502#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001503 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001504 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
Zhu Yib481de92007-09-25 17:54:57 -07001505 u8 rate = beacon->beacon_notify_hdr.rate;
1506
Tomas Winklere1623442009-01-27 14:27:56 -08001507 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
Zhu Yib481de92007-09-25 17:54:57 -07001508 "tsf %d %d rate %d\n",
1509 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
1510 beacon->beacon_notify_hdr.failure_frame,
1511 le32_to_cpu(beacon->ibss_mgr_status),
1512 le32_to_cpu(beacon->high_tsf),
1513 le32_to_cpu(beacon->low_tsf), rate);
1514#endif
1515
Johannes Berg05c914f2008-09-11 00:01:58 +02001516 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -07001517 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1518 queue_work(priv->workqueue, &priv->beacon_update);
1519}
1520
1521/* Service response to REPLY_SCAN_CMD (0x80) */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001522static void iwl3945_rx_reply_scan(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001523 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001524{
Samuel Ortizd08853a2009-01-23 13:45:17 -08001525#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001526 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler4c897252008-12-19 10:37:05 +08001527 struct iwl_scanreq_notification *notif =
1528 (struct iwl_scanreq_notification *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07001529
Tomas Winklere1623442009-01-27 14:27:56 -08001530 IWL_DEBUG_RX(priv, "Scan request status = 0x%x\n", notif->status);
Zhu Yib481de92007-09-25 17:54:57 -07001531#endif
1532}
1533
1534/* Service SCAN_START_NOTIFICATION (0x82) */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001535static void iwl3945_rx_scan_start_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001536 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001537{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001538 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler4c897252008-12-19 10:37:05 +08001539 struct iwl_scanstart_notification *notif =
1540 (struct iwl_scanstart_notification *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07001541 priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
Tomas Winklere1623442009-01-27 14:27:56 -08001542 IWL_DEBUG_SCAN(priv, "Scan start: "
Zhu Yib481de92007-09-25 17:54:57 -07001543 "%d [802.11%s] "
1544 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
1545 notif->channel,
1546 notif->band ? "bg" : "a",
1547 notif->tsf_high,
1548 notif->tsf_low, notif->status, notif->beacon_timer);
1549}
1550
1551/* Service SCAN_RESULTS_NOTIFICATION (0x83) */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001552static void iwl3945_rx_scan_results_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001553 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001554{
Helmut Schaac7e035a2009-01-19 13:02:15 +01001555#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001556 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler4c897252008-12-19 10:37:05 +08001557 struct iwl_scanresults_notification *notif =
1558 (struct iwl_scanresults_notification *)pkt->u.raw;
Helmut Schaac7e035a2009-01-19 13:02:15 +01001559#endif
Zhu Yib481de92007-09-25 17:54:57 -07001560
Tomas Winklere1623442009-01-27 14:27:56 -08001561 IWL_DEBUG_SCAN(priv, "Scan ch.res: "
Zhu Yib481de92007-09-25 17:54:57 -07001562 "%d [802.11%s] "
1563 "(TSF: 0x%08X:%08X) - %d "
1564 "elapsed=%lu usec (%dms since last)\n",
1565 notif->channel,
1566 notif->band ? "bg" : "a",
1567 le32_to_cpu(notif->tsf_high),
1568 le32_to_cpu(notif->tsf_low),
1569 le32_to_cpu(notif->statistics[0]),
1570 le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf,
1571 jiffies_to_msecs(elapsed_jiffies
1572 (priv->last_scan_jiffies, jiffies)));
1573
1574 priv->last_scan_jiffies = jiffies;
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08001575 priv->next_scan_jiffies = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001576}
1577
1578/* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001579static void iwl3945_rx_scan_complete_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001580 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001581{
Helmut Schaac7e035a2009-01-19 13:02:15 +01001582#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001583 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler4c897252008-12-19 10:37:05 +08001584 struct iwl_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
Helmut Schaac7e035a2009-01-19 13:02:15 +01001585#endif
Zhu Yib481de92007-09-25 17:54:57 -07001586
Tomas Winklere1623442009-01-27 14:27:56 -08001587 IWL_DEBUG_SCAN(priv, "Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07001588 scan_notif->scanned_channels,
1589 scan_notif->tsf_low,
1590 scan_notif->tsf_high, scan_notif->status);
1591
1592 /* The HW is no longer scanning */
1593 clear_bit(STATUS_SCAN_HW, &priv->status);
1594
1595 /* The scan completion notification came in, so kill that timer... */
1596 cancel_delayed_work(&priv->scan_check);
1597
Tomas Winklere1623442009-01-27 14:27:56 -08001598 IWL_DEBUG_INFO(priv, "Scan pass on %sGHz took %dms\n",
Ron Rindjunsky66b50042008-06-25 16:46:31 +08001599 (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) ?
1600 "2.4" : "5.2",
Zhu Yib481de92007-09-25 17:54:57 -07001601 jiffies_to_msecs(elapsed_jiffies
1602 (priv->scan_pass_start, jiffies)));
1603
Ron Rindjunsky66b50042008-06-25 16:46:31 +08001604 /* Remove this scanned band from the list of pending
1605 * bands to scan, band G precedes A in order of scanning
1606 * as seen in iwl3945_bg_request_scan */
1607 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ))
1608 priv->scan_bands &= ~BIT(IEEE80211_BAND_2GHZ);
1609 else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ))
1610 priv->scan_bands &= ~BIT(IEEE80211_BAND_5GHZ);
Zhu Yib481de92007-09-25 17:54:57 -07001611
1612 /* If a request to abort was given, or the scan did not succeed
1613 * then we reset the scan state machine and terminate,
1614 * re-queuing another scan if one has been requested */
1615 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08001616 IWL_DEBUG_INFO(priv, "Aborted scan completed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001617 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1618 } else {
1619 /* If there are more bands on this scan pass reschedule */
1620 if (priv->scan_bands > 0)
1621 goto reschedule;
1622 }
1623
1624 priv->last_scan_jiffies = jiffies;
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08001625 priv->next_scan_jiffies = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08001626 IWL_DEBUG_INFO(priv, "Setting scan to off\n");
Zhu Yib481de92007-09-25 17:54:57 -07001627
1628 clear_bit(STATUS_SCANNING, &priv->status);
1629
Tomas Winklere1623442009-01-27 14:27:56 -08001630 IWL_DEBUG_INFO(priv, "Scan took %dms\n",
Zhu Yib481de92007-09-25 17:54:57 -07001631 jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies)));
1632
1633 queue_work(priv->workqueue, &priv->scan_completed);
1634
1635 return;
1636
1637reschedule:
1638 priv->scan_pass_start = jiffies;
1639 queue_work(priv->workqueue, &priv->request_scan);
1640}
1641
1642/* Handle notification from uCode that card's power state is changing
1643 * due to software, hardware, or critical temperature RFKILL */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001644static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001645 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001646{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001647 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001648 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1649 unsigned long status = priv->status;
1650
Tomas Winklere1623442009-01-27 14:27:56 -08001651 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n",
Zhu Yib481de92007-09-25 17:54:57 -07001652 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1653 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1654
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001655 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001656 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1657
1658 if (flags & HW_CARD_DISABLED)
1659 set_bit(STATUS_RF_KILL_HW, &priv->status);
1660 else
1661 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1662
1663
1664 if (flags & SW_CARD_DISABLED)
1665 set_bit(STATUS_RF_KILL_SW, &priv->status);
1666 else
1667 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1668
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08001669 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001670
1671 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1672 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1673 (test_bit(STATUS_RF_KILL_SW, &status) !=
1674 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1675 queue_work(priv->workqueue, &priv->rf_kill);
1676 else
1677 wake_up_interruptible(&priv->wait_command_queue);
1678}
1679
1680/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001681 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07001682 *
1683 * Setup the RX handlers for each of the reply types sent from the uCode
1684 * to the host.
1685 *
1686 * This function chains into the hardware specific files for them to setup
1687 * any hardware specific handlers as well.
1688 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001689static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001690{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001691 priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
1692 priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
1693 priv->rx_handlers[REPLY_ERROR] = iwl3945_rx_reply_error;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001694 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Zhu Yib481de92007-09-25 17:54:57 -07001695 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001696 iwl3945_rx_spectrum_measure_notif;
1697 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl3945_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001698 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001699 iwl3945_rx_pm_debug_statistics_notif;
1700 priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001701
Ben Cahill9fbab512007-11-29 11:09:47 +08001702 /*
1703 * The same handler is used for both the REPLY to a discrete
1704 * statistics request from the host as well as for the periodic
1705 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07001706 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001707 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
1708 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
Zhu Yib481de92007-09-25 17:54:57 -07001709
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001710 priv->rx_handlers[REPLY_SCAN_CMD] = iwl3945_rx_reply_scan;
1711 priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl3945_rx_scan_start_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001712 priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001713 iwl3945_rx_scan_results_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001714 priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001715 iwl3945_rx_scan_complete_notif;
1716 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001717
Ben Cahill9fbab512007-11-29 11:09:47 +08001718 /* Set up hardware specific Rx handlers */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001719 iwl3945_hw_rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001720}
1721
1722/**
Tomas Winkler91c066f2008-03-06 17:36:55 -08001723 * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries
1724 * When FW advances 'R' index, all entries between old and new 'R' index
1725 * need to be reclaimed.
1726 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001727static void iwl3945_cmd_queue_reclaim(struct iwl_priv *priv,
Tomas Winkler91c066f2008-03-06 17:36:55 -08001728 int txq_id, int index)
1729{
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001730 struct iwl_tx_queue *txq = &priv->txq[txq_id];
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001731 struct iwl_queue *q = &txq->q;
Tomas Winkler91c066f2008-03-06 17:36:55 -08001732 int nfreed = 0;
1733
Winkler, Tomas625a3812009-01-08 10:19:55 -08001734 if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001735 IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, "
Tomas Winkler91c066f2008-03-06 17:36:55 -08001736 "is out of range [0-%d] %d %d.\n", txq_id,
1737 index, q->n_bd, q->write_ptr, q->read_ptr);
1738 return;
1739 }
1740
1741 for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
1742 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
1743 if (nfreed > 1) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001744 IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", index,
Tomas Winkler91c066f2008-03-06 17:36:55 -08001745 q->write_ptr, q->read_ptr);
1746 queue_work(priv->workqueue, &priv->restart);
1747 break;
1748 }
1749 nfreed++;
1750 }
1751}
1752
1753
1754/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001755 * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
Zhu Yib481de92007-09-25 17:54:57 -07001756 * @rxb: Rx buffer to reclaim
1757 *
1758 * If an Rx buffer has an async callback associated with it the callback
1759 * will be executed. The attached skb (if present) will only be freed
1760 * if the callback returns 1
1761 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001762static void iwl3945_tx_cmd_complete(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001763 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001764{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001765 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001766 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
1767 int txq_id = SEQ_TO_QUEUE(sequence);
1768 int index = SEQ_TO_INDEX(sequence);
Tomas Winkler600c0e12008-12-19 10:37:04 +08001769 int huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
Zhu Yib481de92007-09-25 17:54:57 -07001770 int cmd_index;
Winkler, Tomasc2d79b482008-12-19 10:37:34 +08001771 struct iwl_cmd *cmd;
Zhu Yib481de92007-09-25 17:54:57 -07001772
Chatre, Reinette638d0eb2009-01-19 15:30:24 -08001773 if (WARN(txq_id != IWL_CMD_QUEUE_NUM,
1774 "wrong command queue %d, sequence 0x%X readp=%d writep=%d\n",
1775 txq_id, sequence,
1776 priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr,
1777 priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) {
1778 iwl_print_hex_dump(priv, IWL_DL_INFO , rxb, 32);
1779 return;
1780 }
Zhu Yib481de92007-09-25 17:54:57 -07001781
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001782 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
1783 cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
Zhu Yib481de92007-09-25 17:54:57 -07001784
1785 /* Input error checking is done when commands are added to queue. */
1786 if (cmd->meta.flags & CMD_WANT_SKB) {
1787 cmd->meta.source->u.skb = rxb->skb;
1788 rxb->skb = NULL;
1789 } else if (cmd->meta.u.callback &&
1790 !cmd->meta.u.callback(priv, cmd, rxb->skb))
1791 rxb->skb = NULL;
1792
Tomas Winkler91c066f2008-03-06 17:36:55 -08001793 iwl3945_cmd_queue_reclaim(priv, txq_id, index);
Zhu Yib481de92007-09-25 17:54:57 -07001794
1795 if (!(cmd->meta.flags & CMD_ASYNC)) {
1796 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1797 wake_up_interruptible(&priv->wait_command_queue);
1798 }
1799}
1800
1801/************************** RX-FUNCTIONS ****************************/
1802/*
1803 * Rx theory of operation
1804 *
1805 * The host allocates 32 DMA target addresses and passes the host address
1806 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
1807 * 0 to 31
1808 *
1809 * Rx Queue Indexes
1810 * The host/firmware share two index registers for managing the Rx buffers.
1811 *
1812 * The READ index maps to the first position that the firmware may be writing
1813 * to -- the driver can read up to (but not including) this position and get
1814 * good data.
1815 * The READ index is managed by the firmware once the card is enabled.
1816 *
1817 * The WRITE index maps to the last position the driver has read from -- the
1818 * position preceding WRITE is the last slot the firmware can place a packet.
1819 *
1820 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
1821 * WRITE = READ.
1822 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001823 * During initialization, the host sets up the READ queue position to the first
Zhu Yib481de92007-09-25 17:54:57 -07001824 * INDEX position, and WRITE to the last (READ - 1 wrapped)
1825 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001826 * When the firmware places a packet in a buffer, it will advance the READ index
Zhu Yib481de92007-09-25 17:54:57 -07001827 * and fire the RX interrupt. The driver can then query the READ index and
1828 * process as many packets as possible, moving the WRITE index forward as it
1829 * resets the Rx queue buffers with new memory.
1830 *
1831 * The management in the driver is as follows:
1832 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
1833 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Ian Schram01ebd062007-10-25 17:15:22 +08001834 * to replenish the iwl->rxq->rx_free.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001835 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
Zhu Yib481de92007-09-25 17:54:57 -07001836 * iwl->rxq is replenished and the READ INDEX is updated (updating the
1837 * 'processed' and 'read' driver indexes as well)
1838 * + A received packet is processed and handed to the kernel network stack,
1839 * detached from the iwl->rxq. The driver 'processed' index is updated.
1840 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
1841 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
1842 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
1843 * were enough free buffers and RX_STALLED is set it is cleared.
1844 *
1845 *
1846 * Driver sequence:
1847 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001848 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001849 * iwl3945_rx_queue_restock
Ben Cahill9fbab512007-11-29 11:09:47 +08001850 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
Zhu Yib481de92007-09-25 17:54:57 -07001851 * queue, updates firmware pointers, and updates
1852 * the WRITE index. If insufficient rx_free buffers
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001853 * are available, schedules iwl3945_rx_replenish
Zhu Yib481de92007-09-25 17:54:57 -07001854 *
1855 * -- enable interrupts --
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001856 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
Zhu Yib481de92007-09-25 17:54:57 -07001857 * READ INDEX, detaching the SKB from the pool.
1858 * Moves the packet buffer from queue to rx_used.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001859 * Calls iwl3945_rx_queue_restock to refill any empty
Zhu Yib481de92007-09-25 17:54:57 -07001860 * slots.
1861 * ...
1862 *
1863 */
1864
1865/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001866 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
Zhu Yib481de92007-09-25 17:54:57 -07001867 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001868static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001869 dma_addr_t dma_addr)
1870{
1871 return cpu_to_le32((u32)dma_addr);
1872}
1873
1874/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001875 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
Zhu Yib481de92007-09-25 17:54:57 -07001876 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001877 * If there are slots in the RX queue that need to be restocked,
Zhu Yib481de92007-09-25 17:54:57 -07001878 * and we have free pre-allocated buffers, fill the ranks as much
Ben Cahill9fbab512007-11-29 11:09:47 +08001879 * as we can, pulling from rx_free.
Zhu Yib481de92007-09-25 17:54:57 -07001880 *
1881 * This moves the 'write' index forward to catch up with 'processed', and
1882 * also updates the memory address in the firmware to reference the new
1883 * target buffer.
1884 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001885static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001886{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001887 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001888 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001889 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001890 unsigned long flags;
1891 int write, rc;
1892
1893 spin_lock_irqsave(&rxq->lock, flags);
1894 write = rxq->write & ~0x7;
Winkler, Tomas37d68312009-01-08 10:19:54 -08001895 while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001896 /* Get next free Rx buffer, remove from free list */
Zhu Yib481de92007-09-25 17:54:57 -07001897 element = rxq->rx_free.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001898 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Zhu Yib481de92007-09-25 17:54:57 -07001899 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001900
1901 /* Point to Rx buffer via next RBD in circular buffer */
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001902 rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
Zhu Yib481de92007-09-25 17:54:57 -07001903 rxq->queue[rxq->write] = rxb;
1904 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
1905 rxq->free_count--;
1906 }
1907 spin_unlock_irqrestore(&rxq->lock, flags);
1908 /* If the pre-allocated buffer pool is dropping low, schedule to
1909 * refill it */
1910 if (rxq->free_count <= RX_LOW_WATERMARK)
1911 queue_work(priv->workqueue, &priv->rx_replenish);
1912
1913
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001914 /* If we've added more space for the firmware to place data, tell it.
1915 * Increment device's write pointer in multiples of 8. */
Zhu Yib481de92007-09-25 17:54:57 -07001916 if ((write != (rxq->write & ~0x7))
1917 || (abs(rxq->write - rxq->read) > 7)) {
1918 spin_lock_irqsave(&rxq->lock, flags);
1919 rxq->need_update = 1;
1920 spin_unlock_irqrestore(&rxq->lock, flags);
Winkler, Tomas141c43a2009-01-08 10:19:53 -08001921 rc = iwl_rx_queue_update_write_ptr(priv, rxq);
Zhu Yib481de92007-09-25 17:54:57 -07001922 if (rc)
1923 return rc;
1924 }
1925
1926 return 0;
1927}
1928
1929/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001930 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
Zhu Yib481de92007-09-25 17:54:57 -07001931 *
1932 * When moving to rx_free an SKB is allocated for the slot.
1933 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001934 * Also restock the Rx queue via iwl3945_rx_queue_restock.
Ian Schram01ebd062007-10-25 17:15:22 +08001935 * This is called as a scheduled work item (except for during initialization)
Zhu Yib481de92007-09-25 17:54:57 -07001936 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001937static void iwl3945_rx_allocate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001938{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001939 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001940 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001941 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001942 unsigned long flags;
1943 spin_lock_irqsave(&rxq->lock, flags);
1944 while (!list_empty(&rxq->rx_used)) {
1945 element = rxq->rx_used.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001946 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001947
1948 /* Alloc a new receive buffer */
Zhu Yib481de92007-09-25 17:54:57 -07001949 rxb->skb =
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001950 alloc_skb(priv->hw_params.rx_buf_size,
1951 __GFP_NOWARN | GFP_ATOMIC);
Zhu Yib481de92007-09-25 17:54:57 -07001952 if (!rxb->skb) {
1953 if (net_ratelimit())
Tomas Winkler978785a2008-12-19 10:37:31 +08001954 IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
Zhu Yib481de92007-09-25 17:54:57 -07001955 /* We don't reschedule replenish work here -- we will
1956 * call the restock method and if it still needs
1957 * more buffers it will schedule replenish */
1958 break;
1959 }
Zhu Yi12342c42007-12-20 11:27:32 +08001960
1961 /* If radiotap head is required, reserve some headroom here.
1962 * The physical head count is a variable rx_stats->phy_count.
1963 * We reserve 4 bytes here. Plus these extra bytes, the
1964 * headroom of the physical head should be enough for the
1965 * radiotap head that iwl3945 supported. See iwl3945_rt.
1966 */
1967 skb_reserve(rxb->skb, 4);
1968
Zhu Yib481de92007-09-25 17:54:57 -07001969 priv->alloc_rxb_skb++;
1970 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001971
1972 /* Get physical address of RB/SKB */
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001973 rxb->real_dma_addr = pci_map_single(priv->pci_dev,
1974 rxb->skb->data,
1975 priv->hw_params.rx_buf_size,
1976 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001977 list_add_tail(&rxb->list, &rxq->rx_free);
1978 rxq->free_count++;
1979 }
1980 spin_unlock_irqrestore(&rxq->lock, flags);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001981}
1982
1983/*
1984 * this should be called while priv->lock is locked
1985 */
Tomas Winkler4fd1f842007-12-05 20:59:58 +02001986static void __iwl3945_rx_replenish(void *data)
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001987{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001988 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001989
1990 iwl3945_rx_allocate(priv);
1991 iwl3945_rx_queue_restock(priv);
1992}
1993
1994
1995void iwl3945_rx_replenish(void *data)
1996{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001997 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001998 unsigned long flags;
1999
2000 iwl3945_rx_allocate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002001
2002 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002003 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002004 spin_unlock_irqrestore(&priv->lock, flags);
2005}
2006
Zhu Yib481de92007-09-25 17:54:57 -07002007/* Convert linear signal-to-noise ratio into dB */
2008static u8 ratio2dB[100] = {
2009/* 0 1 2 3 4 5 6 7 8 9 */
2010 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
2011 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
2012 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
2013 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
2014 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
2015 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
2016 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
2017 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
2018 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
2019 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
2020};
2021
2022/* Calculates a relative dB value from a ratio of linear
2023 * (i.e. not dB) signal levels.
2024 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002025int iwl3945_calc_db_from_ratio(int sig_ratio)
Zhu Yib481de92007-09-25 17:54:57 -07002026{
Adrian Bunk221c80c2008-02-02 23:19:01 +02002027 /* 1000:1 or higher just report as 60 dB */
2028 if (sig_ratio >= 1000)
Zhu Yib481de92007-09-25 17:54:57 -07002029 return 60;
2030
Adrian Bunk221c80c2008-02-02 23:19:01 +02002031 /* 100:1 or higher, divide by 10 and use table,
Zhu Yib481de92007-09-25 17:54:57 -07002032 * add 20 dB to make up for divide by 10 */
Adrian Bunk221c80c2008-02-02 23:19:01 +02002033 if (sig_ratio >= 100)
Tomas Winkler3ac7f142008-07-21 02:40:14 +03002034 return 20 + (int)ratio2dB[sig_ratio/10];
Zhu Yib481de92007-09-25 17:54:57 -07002035
2036 /* We shouldn't see this */
2037 if (sig_ratio < 1)
2038 return 0;
2039
2040 /* Use table for ratios 1:1 - 99:1 */
2041 return (int)ratio2dB[sig_ratio];
2042}
2043
2044#define PERFECT_RSSI (-20) /* dBm */
2045#define WORST_RSSI (-95) /* dBm */
2046#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
2047
2048/* Calculate an indication of rx signal quality (a percentage, not dBm!).
2049 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
2050 * about formulas used below. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002051int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
Zhu Yib481de92007-09-25 17:54:57 -07002052{
2053 int sig_qual;
2054 int degradation = PERFECT_RSSI - rssi_dbm;
2055
2056 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
2057 * as indicator; formula is (signal dbm - noise dbm).
2058 * SNR at or above 40 is a great signal (100%).
2059 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
2060 * Weakest usable signal is usually 10 - 15 dB SNR. */
2061 if (noise_dbm) {
2062 if (rssi_dbm - noise_dbm >= 40)
2063 return 100;
2064 else if (rssi_dbm < noise_dbm)
2065 return 0;
2066 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
2067
2068 /* Else use just the signal level.
2069 * This formula is a least squares fit of data points collected and
2070 * compared with a reference system that had a percentage (%) display
2071 * for signal quality. */
2072 } else
2073 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
2074 (15 * RSSI_RANGE + 62 * degradation)) /
2075 (RSSI_RANGE * RSSI_RANGE);
2076
2077 if (sig_qual > 100)
2078 sig_qual = 100;
2079 else if (sig_qual < 1)
2080 sig_qual = 0;
2081
2082 return sig_qual;
2083}
2084
2085/**
Ben Cahill9fbab512007-11-29 11:09:47 +08002086 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07002087 *
2088 * Uses the priv->rx_handlers callback function array to invoke
2089 * the appropriate handlers, including command responses,
2090 * frame-received notifications, and other notifications.
2091 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002092static void iwl3945_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002093{
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002094 struct iwl_rx_mem_buffer *rxb;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002095 struct iwl_rx_packet *pkt;
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08002096 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07002097 u32 r, i;
2098 int reclaim;
2099 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002100 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08002101 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07002102
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002103 /* uCode's read index (stored in shared DRAM) indicates the last Rx
2104 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8cd812b2008-12-19 10:37:43 +08002105 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07002106 i = rxq->read;
2107
Winkler, Tomas37d68312009-01-08 10:19:54 -08002108 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002109 fill_rx = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002110 /* Rx interrupt, but nothing sent from uCode */
2111 if (i == r)
Tomas Winklere1623442009-01-27 14:27:56 -08002112 IWL_DEBUG(priv, IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07002113
2114 while (i != r) {
2115 rxb = rxq->queue[i];
2116
Ben Cahill9fbab512007-11-29 11:09:47 +08002117 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07002118 * then a bug has been introduced in the queue refilling
2119 * routines -- catch it here */
2120 BUG_ON(rxb == NULL);
2121
2122 rxq->queue[i] = NULL;
2123
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002124 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08002125 priv->hw_params.rx_buf_size,
Zhu Yib481de92007-09-25 17:54:57 -07002126 PCI_DMA_FROMDEVICE);
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002127 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002128
2129 /* Reclaim a command buffer only if this packet is a response
2130 * to a (driver-originated) command.
2131 * If the packet (e.g. Rx frame) originated from uCode,
2132 * there is no command buffer to reclaim.
2133 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
2134 * but apparently a few don't get set; catch them here. */
2135 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
2136 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
2137 (pkt->hdr.cmd != REPLY_TX);
2138
2139 /* Based on type of command response or notification,
2140 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002141 * rx_handlers table. See iwl3945_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07002142 if (priv->rx_handlers[pkt->hdr.cmd]) {
Tomas Winklere1623442009-01-27 14:27:56 -08002143 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07002144 "r = %d, i = %d, %s, 0x%02x\n", r, i,
2145 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
2146 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
2147 } else {
2148 /* No handling needed */
Tomas Winklere1623442009-01-27 14:27:56 -08002149 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07002150 "r %d i %d No handler needed for %s, 0x%02x\n",
2151 r, i, get_cmd_string(pkt->hdr.cmd),
2152 pkt->hdr.cmd);
2153 }
2154
2155 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08002156 /* Invoke any callbacks, transfer the skb to caller, and
Samuel Ortiz518099a2009-01-19 15:30:27 -08002157 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07002158 * as we reclaim the driver command queue */
2159 if (rxb && rxb->skb)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002160 iwl3945_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07002161 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002162 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07002163 }
2164
2165 /* For now we just don't re-use anything. We can tweak this
2166 * later to try and re-use notification packets and SKBs that
2167 * fail to Rx correctly */
2168 if (rxb->skb != NULL) {
2169 priv->alloc_rxb_skb--;
2170 dev_kfree_skb_any(rxb->skb);
2171 rxb->skb = NULL;
2172 }
2173
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002174 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08002175 priv->hw_params.rx_buf_size,
2176 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07002177 spin_lock_irqsave(&rxq->lock, flags);
2178 list_add_tail(&rxb->list, &priv->rxq.rx_used);
2179 spin_unlock_irqrestore(&rxq->lock, flags);
2180 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002181 /* If there are a lot of unused frames,
2182 * restock the Rx queue so ucode won't assert. */
2183 if (fill_rx) {
2184 count++;
2185 if (count >= 8) {
2186 priv->rxq.read = i;
2187 __iwl3945_rx_replenish(priv);
2188 count = 0;
2189 }
2190 }
Zhu Yib481de92007-09-25 17:54:57 -07002191 }
2192
2193 /* Backtrack one entry */
2194 priv->rxq.read = i;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002195 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002196}
2197
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002198static void iwl3945_enable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002199{
Tomas Winklere1623442009-01-27 14:27:56 -08002200 IWL_DEBUG_ISR(priv, "Enabling interrupts\n");
Zhu Yib481de92007-09-25 17:54:57 -07002201 set_bit(STATUS_INT_ENABLED, &priv->status);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002202 iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07002203}
2204
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002205
2206/* call this function to flush any scheduled tasklet */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002207static inline void iwl_synchronize_irq(struct iwl_priv *priv)
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002208{
Tomas Winklera96a27f2008-10-23 23:48:56 -07002209 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002210 synchronize_irq(priv->pci_dev->irq);
2211 tasklet_kill(&priv->irq_tasklet);
2212}
2213
2214
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002215static inline void iwl3945_disable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002216{
2217 clear_bit(STATUS_INT_ENABLED, &priv->status);
2218
2219 /* disable interrupts from uCode/NIC to host */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002220 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07002221
2222 /* acknowledge/clear/reset any interrupts still pending
2223 * from uCode or flow handler (Rx/Tx DMA) */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002224 iwl_write32(priv, CSR_INT, 0xffffffff);
2225 iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
Tomas Winklere1623442009-01-27 14:27:56 -08002226 IWL_DEBUG_ISR(priv, "Disabled interrupts\n");
Zhu Yib481de92007-09-25 17:54:57 -07002227}
2228
2229static const char *desc_lookup(int i)
2230{
2231 switch (i) {
2232 case 1:
2233 return "FAIL";
2234 case 2:
2235 return "BAD_PARAM";
2236 case 3:
2237 return "BAD_CHECKSUM";
2238 case 4:
2239 return "NMI_INTERRUPT";
2240 case 5:
2241 return "SYSASSERT";
2242 case 6:
2243 return "FATAL_ERROR";
2244 }
2245
2246 return "UNKNOWN";
2247}
2248
2249#define ERROR_START_OFFSET (1 * sizeof(u32))
2250#define ERROR_ELEM_SIZE (7 * sizeof(u32))
2251
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002252static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002253{
2254 u32 i;
2255 u32 desc, time, count, base, data1;
2256 u32 blink1, blink2, ilink1, ilink2;
2257 int rc;
2258
2259 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
2260
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002261 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002262 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07002263 return;
2264 }
2265
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002266 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002267 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002268 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002269 return;
2270 }
2271
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002272 count = iwl_read_targ_mem(priv, base);
Zhu Yib481de92007-09-25 17:54:57 -07002273
2274 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002275 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
2276 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
2277 priv->status, count);
Zhu Yib481de92007-09-25 17:54:57 -07002278 }
2279
Winkler, Tomas15b16872008-12-19 10:37:33 +08002280 IWL_ERR(priv, "Desc Time asrtPC blink2 "
Zhu Yib481de92007-09-25 17:54:57 -07002281 "ilink1 nmiPC Line\n");
2282 for (i = ERROR_START_OFFSET;
2283 i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
2284 i += ERROR_ELEM_SIZE) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002285 desc = iwl_read_targ_mem(priv, base + i);
Zhu Yib481de92007-09-25 17:54:57 -07002286 time =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002287 iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002288 blink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002289 iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002290 blink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002291 iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002292 ilink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002293 iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002294 ilink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002295 iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002296 data1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002297 iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002298
Winkler, Tomas15b16872008-12-19 10:37:33 +08002299 IWL_ERR(priv,
2300 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
2301 desc_lookup(desc), desc, time, blink1, blink2,
2302 ilink1, ilink2, data1);
Zhu Yib481de92007-09-25 17:54:57 -07002303 }
2304
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002305 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002306
2307}
2308
Ben Cahillf58177b2007-11-29 11:09:43 +08002309#define EVENT_START_OFFSET (6 * sizeof(u32))
Zhu Yib481de92007-09-25 17:54:57 -07002310
2311/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002312 * iwl3945_print_event_log - Dump error event log to syslog
Zhu Yib481de92007-09-25 17:54:57 -07002313 *
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002314 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
Zhu Yib481de92007-09-25 17:54:57 -07002315 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002316static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
Zhu Yib481de92007-09-25 17:54:57 -07002317 u32 num_events, u32 mode)
2318{
2319 u32 i;
2320 u32 base; /* SRAM byte address of event log header */
2321 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
2322 u32 ptr; /* SRAM byte address of log data */
2323 u32 ev, time, data; /* event log data */
2324
2325 if (num_events == 0)
2326 return;
2327
2328 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
2329
2330 if (mode == 0)
2331 event_size = 2 * sizeof(u32);
2332 else
2333 event_size = 3 * sizeof(u32);
2334
2335 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
2336
2337 /* "time" is actually "data" for mode 0 (no timestamp).
2338 * place event id # at far right for easier visual parsing. */
2339 for (i = 0; i < num_events; i++) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002340 ev = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002341 ptr += sizeof(u32);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002342 time = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002343 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002344 if (mode == 0) {
2345 /* data, ev */
2346 IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
2347 } else {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002348 data = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002349 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002350 IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
Zhu Yib481de92007-09-25 17:54:57 -07002351 }
2352 }
2353}
2354
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002355static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002356{
2357 int rc;
2358 u32 base; /* SRAM byte address of event log header */
2359 u32 capacity; /* event log capacity in # entries */
2360 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
2361 u32 num_wraps; /* # times uCode wrapped to top of log */
2362 u32 next_entry; /* index of next entry to be written by uCode */
2363 u32 size; /* # entries that we'll print */
2364
2365 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002366 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002367 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07002368 return;
2369 }
2370
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002371 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002372 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002373 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002374 return;
2375 }
2376
2377 /* event log header */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002378 capacity = iwl_read_targ_mem(priv, base);
2379 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
2380 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
2381 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
Zhu Yib481de92007-09-25 17:54:57 -07002382
2383 size = num_wraps ? capacity : next_entry;
2384
2385 /* bail out if nothing in log */
2386 if (size == 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002387 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002388 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002389 return;
2390 }
2391
Winkler, Tomas15b16872008-12-19 10:37:33 +08002392 IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07002393 size, num_wraps);
2394
2395 /* if uCode has wrapped back to top of log, start at the oldest entry,
2396 * i.e the next one that uCode would fill. */
2397 if (num_wraps)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002398 iwl3945_print_event_log(priv, next_entry,
Zhu Yib481de92007-09-25 17:54:57 -07002399 capacity - next_entry, mode);
2400
2401 /* (then/else) start at top of log */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002402 iwl3945_print_event_log(priv, 0, next_entry, mode);
Zhu Yib481de92007-09-25 17:54:57 -07002403
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002404 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002405}
2406
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002407static void iwl3945_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002408{
2409 unsigned long flags;
2410
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002411 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
2412 sizeof(priv->staging_rxon));
2413 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002414 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002415
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002416 iwl3945_add_station(priv, priv->bssid, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002417
2418 spin_lock_irqsave(&priv->lock, flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002419 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07002420 priv->error_recovering = 0;
2421 spin_unlock_irqrestore(&priv->lock, flags);
2422}
2423
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002424static void iwl3945_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002425{
2426 u32 inta, handled = 0;
2427 u32 inta_fh;
2428 unsigned long flags;
Samuel Ortizd08853a2009-01-23 13:45:17 -08002429#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07002430 u32 inta_mask;
2431#endif
2432
2433 spin_lock_irqsave(&priv->lock, flags);
2434
2435 /* Ack/clear/reset pending uCode interrupts.
2436 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
2437 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002438 inta = iwl_read32(priv, CSR_INT);
2439 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07002440
2441 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
2442 * Any new interrupts that happen after this, either while we're
2443 * in this tasklet, or later, will show up in next ISR/tasklet. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002444 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
2445 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07002446
Samuel Ortizd08853a2009-01-23 13:45:17 -08002447#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002448 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08002449 /* just for debug */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002450 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Tomas Winklere1623442009-01-27 14:27:56 -08002451 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002452 inta, inta_mask, inta_fh);
2453 }
2454#endif
2455
2456 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
2457 * atomic, make sure that inta covers all the interrupts that
2458 * we've discovered, even if FH interrupt came in just after
2459 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002460 if (inta_fh & CSR39_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002461 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002462 if (inta_fh & CSR39_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002463 inta |= CSR_INT_BIT_FH_TX;
2464
2465 /* Now service all interrupt bits discovered above. */
2466 if (inta & CSR_INT_BIT_HW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002467 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002468
2469 /* Tell the device to stop sending interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002470 iwl3945_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002471
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002472 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002473
2474 handled |= CSR_INT_BIT_HW_ERR;
2475
2476 spin_unlock_irqrestore(&priv->lock, flags);
2477
2478 return;
2479 }
2480
Samuel Ortizd08853a2009-01-23 13:45:17 -08002481#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002482 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07002483 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002484 if (inta & CSR_INT_BIT_SCD)
Tomas Winklere1623442009-01-27 14:27:56 -08002485 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
Joonwoo Park25c03d82008-01-23 10:15:20 -08002486 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002487
2488 /* Alive notification via Rx interrupt will do the real work */
2489 if (inta & CSR_INT_BIT_ALIVE)
Tomas Winklere1623442009-01-27 14:27:56 -08002490 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002491 }
2492#endif
2493 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002494 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07002495
Zhu Yib481de92007-09-25 17:54:57 -07002496 /* Error detected by uCode */
2497 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002498 IWL_ERR(priv, "Microcode SW error detected. "
2499 "Restarting 0x%X.\n", inta);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002500 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002501 handled |= CSR_INT_BIT_SW_ERR;
2502 }
2503
2504 /* uCode wakes up after power-down sleep */
2505 if (inta & CSR_INT_BIT_WAKEUP) {
Tomas Winklere1623442009-01-27 14:27:56 -08002506 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
Winkler, Tomas141c43a2009-01-08 10:19:53 -08002507 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08002508 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
2509 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
2510 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
2511 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
2512 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
2513 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07002514
2515 handled |= CSR_INT_BIT_WAKEUP;
2516 }
2517
2518 /* All uCode command responses, including Tx command responses,
2519 * Rx "responses" (frame-received notification), and other
2520 * notifications from uCode come through here*/
2521 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002522 iwl3945_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002523 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
2524 }
2525
2526 if (inta & CSR_INT_BIT_FH_TX) {
Tomas Winklere1623442009-01-27 14:27:56 -08002527 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002528
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002529 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
2530 if (!iwl_grab_nic_access(priv)) {
2531 iwl_write_direct32(priv, FH39_TCSR_CREDIT
Tomas Winklerbddadf82008-12-19 10:37:01 +08002532 (FH39_SRVC_CHNL), 0x0);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002533 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002534 }
2535 handled |= CSR_INT_BIT_FH_TX;
2536 }
2537
2538 if (inta & ~handled)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002539 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Zhu Yib481de92007-09-25 17:54:57 -07002540
2541 if (inta & ~CSR_INI_SET_MASK) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002542 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Zhu Yib481de92007-09-25 17:54:57 -07002543 inta & ~CSR_INI_SET_MASK);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002544 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07002545 }
2546
2547 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002548 /* only Re-enable if disabled by irq */
2549 if (test_bit(STATUS_INT_ENABLED, &priv->status))
2550 iwl3945_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002551
Samuel Ortizd08853a2009-01-23 13:45:17 -08002552#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002553 if (priv->debug_level & (IWL_DL_ISR)) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002554 inta = iwl_read32(priv, CSR_INT);
2555 inta_mask = iwl_read32(priv, CSR_INT_MASK);
2556 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Tomas Winklere1623442009-01-27 14:27:56 -08002557 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
Zhu Yib481de92007-09-25 17:54:57 -07002558 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
2559 }
2560#endif
2561 spin_unlock_irqrestore(&priv->lock, flags);
2562}
2563
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002564static irqreturn_t iwl3945_isr(int irq, void *data)
Zhu Yib481de92007-09-25 17:54:57 -07002565{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002566 struct iwl_priv *priv = data;
Zhu Yib481de92007-09-25 17:54:57 -07002567 u32 inta, inta_mask;
2568 u32 inta_fh;
2569 if (!priv)
2570 return IRQ_NONE;
2571
2572 spin_lock(&priv->lock);
2573
2574 /* Disable (but don't clear!) interrupts here to avoid
2575 * back-to-back ISRs and sporadic interrupts from our NIC.
2576 * If we have something to service, the tasklet will re-enable ints.
2577 * If we *don't* have something, we'll re-enable before leaving here. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002578 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
2579 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07002580
2581 /* Discover which interrupts are active/pending */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002582 inta = iwl_read32(priv, CSR_INT);
2583 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07002584
2585 /* Ignore interrupt if there's nothing in NIC to service.
2586 * This may be due to IRQ shared with another device,
2587 * or due to sporadic interrupts thrown from our NIC. */
2588 if (!inta && !inta_fh) {
Tomas Winklere1623442009-01-27 14:27:56 -08002589 IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0, inta_fh == 0\n");
Zhu Yib481de92007-09-25 17:54:57 -07002590 goto none;
2591 }
2592
2593 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
2594 /* Hardware disappeared */
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002595 IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
Oliver Neukumcb4da1a2007-11-13 21:10:32 -08002596 goto unplugged;
Zhu Yib481de92007-09-25 17:54:57 -07002597 }
2598
Tomas Winklere1623442009-01-27 14:27:56 -08002599 IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002600 inta, inta_mask, inta_fh);
2601
Joonwoo Park25c03d82008-01-23 10:15:20 -08002602 inta &= ~CSR_INT_BIT_SCD;
2603
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002604 /* iwl3945_irq_tasklet() will service interrupts and re-enable them */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002605 if (likely(inta || inta_fh))
2606 tasklet_schedule(&priv->irq_tasklet);
Oliver Neukumcb4da1a2007-11-13 21:10:32 -08002607unplugged:
Zhu Yib481de92007-09-25 17:54:57 -07002608 spin_unlock(&priv->lock);
2609
2610 return IRQ_HANDLED;
2611
2612 none:
2613 /* re-enable interrupts here since we don't have anything to service. */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002614 /* only Re-enable if disabled by irq */
2615 if (test_bit(STATUS_INT_ENABLED, &priv->status))
2616 iwl3945_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002617 spin_unlock(&priv->lock);
2618 return IRQ_NONE;
2619}
2620
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002621static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01002622 enum ieee80211_band band,
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08002623 u8 is_active, u8 n_probes,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002624 struct iwl3945_scan_channel *scan_ch)
Zhu Yib481de92007-09-25 17:54:57 -07002625{
2626 const struct ieee80211_channel *channels = NULL;
Johannes Berg8318d782008-01-24 19:38:38 +01002627 const struct ieee80211_supported_band *sband;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08002628 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07002629 u16 passive_dwell = 0;
2630 u16 active_dwell = 0;
2631 int added, i;
2632
Kolekar, Abhijeetcbba18c2008-12-19 10:37:42 +08002633 sband = iwl_get_hw_mode(priv, band);
Johannes Berg8318d782008-01-24 19:38:38 +01002634 if (!sband)
Zhu Yib481de92007-09-25 17:54:57 -07002635 return 0;
2636
Johannes Berg8318d782008-01-24 19:38:38 +01002637 channels = sband->channels;
Zhu Yib481de92007-09-25 17:54:57 -07002638
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08002639 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
2640 passive_dwell = iwl_get_passive_dwell_time(priv, band);
Zhu Yib481de92007-09-25 17:54:57 -07002641
Abhijeet Kolekar8f4807a2008-09-03 11:26:31 +08002642 if (passive_dwell <= active_dwell)
2643 passive_dwell = active_dwell + 1;
2644
Johannes Berg8318d782008-01-24 19:38:38 +01002645 for (i = 0, added = 0; i < sband->n_channels; i++) {
Johannes Berg182e2e62008-04-04 10:41:56 +02002646 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
2647 continue;
2648
Johannes Berg8318d782008-01-24 19:38:38 +01002649 scan_ch->channel = channels[i].hw_value;
Zhu Yib481de92007-09-25 17:54:57 -07002650
Samuel Ortize6148912009-01-23 13:45:15 -08002651 ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
Zhu Yib481de92007-09-25 17:54:57 -07002652 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002653 IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
Zhu Yib481de92007-09-25 17:54:57 -07002654 scan_ch->channel);
2655 continue;
2656 }
2657
Zhu Yib481de92007-09-25 17:54:57 -07002658 scan_ch->active_dwell = cpu_to_le16(active_dwell);
2659 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002660 /* If passive , set up for auto-switch
2661 * and use long active_dwell time.
2662 */
2663 if (!is_active || is_channel_passive(ch_info) ||
2664 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
2665 scan_ch->type = 0; /* passive */
2666 if (IWL_UCODE_API(priv->ucode_ver) == 1)
2667 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
2668 } else {
2669 scan_ch->type = 1; /* active */
2670 }
2671
2672 /* Set direct probe bits. These may be used both for active
2673 * scan channels (probes gets sent right away),
2674 * or for passive channels (probes get se sent only after
2675 * hearing clear Rx packet).*/
2676 if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
2677 if (n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002678 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002679 } else {
2680 /* uCode v1 does not allow setting direct probe bits on
2681 * passive channel. */
2682 if ((scan_ch->type & 1) && n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002683 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002684 }
Zhu Yib481de92007-09-25 17:54:57 -07002685
Ben Cahill9fbab512007-11-29 11:09:47 +08002686 /* Set txpower levels to defaults */
Zhu Yib481de92007-09-25 17:54:57 -07002687 scan_ch->tpc.dsp_atten = 110;
2688 /* scan_pwr_info->tpc.dsp_atten; */
2689
2690 /*scan_pwr_info->tpc.tx_gain; */
Johannes Berg8318d782008-01-24 19:38:38 +01002691 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -07002692 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
2693 else {
2694 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
2695 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
Ben Cahill9fbab512007-11-29 11:09:47 +08002696 * power level:
Reinette Chatre8a1b0242008-01-14 17:46:25 -08002697 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
Zhu Yib481de92007-09-25 17:54:57 -07002698 */
2699 }
2700
Tomas Winklere1623442009-01-27 14:27:56 -08002701 IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n",
Zhu Yib481de92007-09-25 17:54:57 -07002702 scan_ch->channel,
2703 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
2704 (scan_ch->type & 1) ?
2705 active_dwell : passive_dwell);
2706
2707 scan_ch++;
2708 added++;
2709 }
2710
Tomas Winklere1623442009-01-27 14:27:56 -08002711 IWL_DEBUG_SCAN(priv, "total channels to scan %d \n", added);
Zhu Yib481de92007-09-25 17:54:57 -07002712 return added;
2713}
2714
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002715static void iwl3945_init_hw_rates(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002716 struct ieee80211_rate *rates)
2717{
2718 int i;
2719
2720 for (i = 0; i < IWL_RATE_COUNT; i++) {
Johannes Berg8318d782008-01-24 19:38:38 +01002721 rates[i].bitrate = iwl3945_rates[i].ieee * 5;
2722 rates[i].hw_value = i; /* Rate scaling will work on indexes */
2723 rates[i].hw_value_short = i;
2724 rates[i].flags = 0;
Samuel Ortizd9829a62008-12-19 10:37:12 +08002725 if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
Zhu Yib481de92007-09-25 17:54:57 -07002726 /*
Johannes Berg8318d782008-01-24 19:38:38 +01002727 * If CCK != 1M then set short preamble rate flag.
Zhu Yib481de92007-09-25 17:54:57 -07002728 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002729 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
Johannes Berg8318d782008-01-24 19:38:38 +01002730 0 : IEEE80211_RATE_SHORT_PREAMBLE;
Zhu Yib481de92007-09-25 17:54:57 -07002731 }
Zhu Yib481de92007-09-25 17:54:57 -07002732 }
2733}
2734
Zhu Yib481de92007-09-25 17:54:57 -07002735/******************************************************************************
2736 *
2737 * uCode download functions
2738 *
2739 ******************************************************************************/
2740
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002741static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002742{
Tomas Winkler98c92212008-01-14 17:46:20 -08002743 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
2744 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
2745 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
2746 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
2747 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
2748 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07002749}
2750
2751/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002752 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002753 * looking at all data.
2754 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002755static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002756{
2757 u32 val;
2758 u32 save_len = len;
2759 int rc = 0;
2760 u32 errcnt;
2761
Tomas Winklere1623442009-01-27 14:27:56 -08002762 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002763
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002764 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002765 if (rc)
2766 return rc;
2767
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002768 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002769 IWL39_RTC_INST_LOWER_BOUND);
Zhu Yib481de92007-09-25 17:54:57 -07002770
2771 errcnt = 0;
2772 for (; len > 0; len -= sizeof(u32), image++) {
2773 /* read data comes through single port, auto-incr addr */
2774 /* NOTE: Use the debugless read so we don't flood kernel log
2775 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002776 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002777 if (val != le32_to_cpu(*image)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002778 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002779 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2780 save_len - len, val, le32_to_cpu(*image));
2781 rc = -EIO;
2782 errcnt++;
2783 if (errcnt >= 20)
2784 break;
2785 }
2786 }
2787
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002788 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002789
2790 if (!errcnt)
Tomas Winklere1623442009-01-27 14:27:56 -08002791 IWL_DEBUG_INFO(priv,
2792 "ucode image in INSTRUCTION memory is good\n");
Zhu Yib481de92007-09-25 17:54:57 -07002793
2794 return rc;
2795}
2796
2797
2798/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002799 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002800 * using sample data 100 bytes apart. If these sample points are good,
2801 * it's a pretty good bet that everything between them is good, too.
2802 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002803static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002804{
2805 u32 val;
2806 int rc = 0;
2807 u32 errcnt = 0;
2808 u32 i;
2809
Tomas Winklere1623442009-01-27 14:27:56 -08002810 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002811
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002812 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002813 if (rc)
2814 return rc;
2815
2816 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
2817 /* read data comes through single port, auto-incr addr */
2818 /* NOTE: Use the debugless read so we don't flood kernel log
2819 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002820 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002821 i + IWL39_RTC_INST_LOWER_BOUND);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002822 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002823 if (val != le32_to_cpu(*image)) {
2824#if 0 /* Enable this if you want to see details */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002825 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002826 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2827 i, val, *image);
2828#endif
2829 rc = -EIO;
2830 errcnt++;
2831 if (errcnt >= 3)
2832 break;
2833 }
2834 }
2835
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002836 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002837
2838 return rc;
2839}
2840
2841
2842/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002843 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
Zhu Yib481de92007-09-25 17:54:57 -07002844 * and verify its contents
2845 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002846static int iwl3945_verify_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002847{
2848 __le32 *image;
2849 u32 len;
2850 int rc = 0;
2851
2852 /* Try bootstrap */
2853 image = (__le32 *)priv->ucode_boot.v_addr;
2854 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002855 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002856 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002857 IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002858 return 0;
2859 }
2860
2861 /* Try initialize */
2862 image = (__le32 *)priv->ucode_init.v_addr;
2863 len = priv->ucode_init.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002864 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002865 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002866 IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002867 return 0;
2868 }
2869
2870 /* Try runtime/protocol */
2871 image = (__le32 *)priv->ucode_code.v_addr;
2872 len = priv->ucode_code.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002873 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002874 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002875 IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002876 return 0;
2877 }
2878
Winkler, Tomas15b16872008-12-19 10:37:33 +08002879 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
Zhu Yib481de92007-09-25 17:54:57 -07002880
Ben Cahill9fbab512007-11-29 11:09:47 +08002881 /* Since nothing seems to match, show first several data entries in
2882 * instruction SRAM, so maybe visual inspection will give a clue.
2883 * Selection of bootstrap image (vs. other images) is arbitrary. */
Zhu Yib481de92007-09-25 17:54:57 -07002884 image = (__le32 *)priv->ucode_boot.v_addr;
2885 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002886 rc = iwl3945_verify_inst_full(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002887
2888 return rc;
2889}
2890
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002891static void iwl3945_nic_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002892{
2893 /* Remove all resets to allow NIC to operate */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002894 iwl_write32(priv, CSR_RESET, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002895}
2896
2897/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002898 * iwl3945_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07002899 *
2900 * Copy into buffers for card to fetch via bus-mastering
2901 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002902static int iwl3945_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002903{
Kolekar, Abhijeeta78fe752008-12-19 10:37:21 +08002904 struct iwl_ucode *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002905 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07002906 const struct firmware *ucode_raw;
2907 /* firmware file name contains uCode/driver compatibility version */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002908 const char *name_pre = priv->cfg->fw_name_pre;
2909 const unsigned int api_max = priv->cfg->ucode_api_max;
2910 const unsigned int api_min = priv->cfg->ucode_api_min;
2911 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07002912 u8 *src;
2913 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002914 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07002915
2916 /* Ask kernel firmware_class module to get the boot firmware off disk.
2917 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002918 for (index = api_max; index >= api_min; index--) {
2919 sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
2920 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
2921 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002922 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002923 buf, ret);
2924 if (ret == -ENOENT)
2925 continue;
2926 else
2927 goto error;
2928 } else {
2929 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002930 IWL_ERR(priv, "Loaded firmware %s, "
2931 "which is deprecated. "
2932 " Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002933 buf, api_max);
Tomas Winklere1623442009-01-27 14:27:56 -08002934 IWL_DEBUG_INFO(priv, "Got firmware '%s' file "
2935 "(%zd bytes) from disk\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002936 buf, ucode_raw->size);
2937 break;
2938 }
Zhu Yib481de92007-09-25 17:54:57 -07002939 }
2940
Reinette Chatrea0987a82008-12-02 12:14:06 -08002941 if (ret < 0)
2942 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07002943
2944 /* Make sure that we got at least our header! */
2945 if (ucode_raw->size < sizeof(*ucode)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002946 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002947 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002948 goto err_release;
2949 }
2950
2951 /* Data from ucode file: header followed by uCode images */
2952 ucode = (void *)ucode_raw->data;
2953
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08002954 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08002955 api_ver = IWL_UCODE_API(priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07002956 inst_size = le32_to_cpu(ucode->inst_size);
2957 data_size = le32_to_cpu(ucode->data_size);
2958 init_size = le32_to_cpu(ucode->init_size);
2959 init_data_size = le32_to_cpu(ucode->init_data_size);
2960 boot_size = le32_to_cpu(ucode->boot_size);
2961
Reinette Chatrea0987a82008-12-02 12:14:06 -08002962 /* api_ver should match the api version forming part of the
2963 * firmware filename ... but we don't check for that and only rely
2964 * on the API version read from firware header from here on forward */
2965
2966 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002967 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002968 "Driver supports v%u, firmware is v%u.\n",
2969 api_max, api_ver);
2970 priv->ucode_ver = 0;
2971 ret = -EINVAL;
2972 goto err_release;
2973 }
2974 if (api_ver != api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002975 IWL_ERR(priv, "Firmware has old API version. Expected %u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002976 "got %u. New firmware can be obtained "
2977 "from http://www.intellinuxwireless.org.\n",
2978 api_max, api_ver);
2979
Tomas Winkler978785a2008-12-19 10:37:31 +08002980 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
2981 IWL_UCODE_MAJOR(priv->ucode_ver),
2982 IWL_UCODE_MINOR(priv->ucode_ver),
2983 IWL_UCODE_API(priv->ucode_ver),
2984 IWL_UCODE_SERIAL(priv->ucode_ver));
2985
Tomas Winklere1623442009-01-27 14:27:56 -08002986 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002987 priv->ucode_ver);
Tomas Winklere1623442009-01-27 14:27:56 -08002988 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
2989 inst_size);
2990 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
2991 data_size);
2992 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
2993 init_size);
2994 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
2995 init_data_size);
2996 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
2997 boot_size);
Zhu Yib481de92007-09-25 17:54:57 -07002998
Reinette Chatrea0987a82008-12-02 12:14:06 -08002999
Zhu Yib481de92007-09-25 17:54:57 -07003000 /* Verify size of file vs. image size info in file's header */
3001 if (ucode_raw->size < sizeof(*ucode) +
3002 inst_size + data_size + init_size +
3003 init_data_size + boot_size) {
3004
Tomas Winklere1623442009-01-27 14:27:56 -08003005 IWL_DEBUG_INFO(priv, "uCode file size %zd too small\n",
3006 ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08003007 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003008 goto err_release;
3009 }
3010
3011 /* Verify that uCode images will fit in card's SRAM */
Samuel Ortiz250bdd22008-12-19 10:37:11 +08003012 if (inst_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08003013 IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08003014 inst_size);
3015 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003016 goto err_release;
3017 }
3018
Samuel Ortiz250bdd22008-12-19 10:37:11 +08003019 if (data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08003020 IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08003021 data_size);
3022 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003023 goto err_release;
3024 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08003025 if (init_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08003026 IWL_DEBUG_INFO(priv,
3027 "uCode init instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08003028 init_size);
3029 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003030 goto err_release;
3031 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08003032 if (init_data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08003033 IWL_DEBUG_INFO(priv,
3034 "uCode init data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08003035 init_data_size);
3036 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003037 goto err_release;
3038 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08003039 if (boot_size > IWL39_MAX_BSM_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08003040 IWL_DEBUG_INFO(priv,
3041 "uCode boot instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08003042 boot_size);
3043 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003044 goto err_release;
3045 }
3046
3047 /* Allocate ucode buffers for card's bus-master loading ... */
3048
3049 /* Runtime instructions and 2 copies of data:
3050 * 1) unmodified from disk
3051 * 2) backup cache for save/restore during power-downs */
3052 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003053 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07003054
3055 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003056 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07003057
3058 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003059 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07003060
3061 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
Tomas Winkler90e759d2007-11-29 11:09:41 +08003062 !priv->ucode_data_backup.v_addr)
Zhu Yib481de92007-09-25 17:54:57 -07003063 goto err_pci_alloc;
3064
Tomas Winkler90e759d2007-11-29 11:09:41 +08003065 /* Initialization instructions and data */
3066 if (init_size && init_data_size) {
3067 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003068 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Tomas Winkler90e759d2007-11-29 11:09:41 +08003069
3070 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003071 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08003072
3073 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
3074 goto err_pci_alloc;
3075 }
3076
3077 /* Bootstrap (instructions only, no data) */
3078 if (boot_size) {
3079 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003080 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Tomas Winkler90e759d2007-11-29 11:09:41 +08003081
3082 if (!priv->ucode_boot.v_addr)
3083 goto err_pci_alloc;
3084 }
3085
Zhu Yib481de92007-09-25 17:54:57 -07003086 /* Copy images into buffers for card's bus-master reads ... */
3087
3088 /* Runtime instructions (first block of data in file) */
3089 src = &ucode->data[0];
3090 len = priv->ucode_code.len;
Tomas Winklere1623442009-01-27 14:27:56 -08003091 IWL_DEBUG_INFO(priv,
3092 "Copying (but not loading) uCode instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07003093 memcpy(priv->ucode_code.v_addr, src, len);
Tomas Winklere1623442009-01-27 14:27:56 -08003094 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07003095 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
3096
3097 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003098 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
Zhu Yib481de92007-09-25 17:54:57 -07003099 src = &ucode->data[inst_size];
3100 len = priv->ucode_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08003101 IWL_DEBUG_INFO(priv,
3102 "Copying (but not loading) uCode data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07003103 memcpy(priv->ucode_data.v_addr, src, len);
3104 memcpy(priv->ucode_data_backup.v_addr, src, len);
3105
3106 /* Initialization instructions (3rd block) */
3107 if (init_size) {
3108 src = &ucode->data[inst_size + data_size];
3109 len = priv->ucode_init.len;
Tomas Winklere1623442009-01-27 14:27:56 -08003110 IWL_DEBUG_INFO(priv,
3111 "Copying (but not loading) init instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07003112 memcpy(priv->ucode_init.v_addr, src, len);
3113 }
3114
3115 /* Initialization data (4th block) */
3116 if (init_data_size) {
3117 src = &ucode->data[inst_size + data_size + init_size];
3118 len = priv->ucode_init_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08003119 IWL_DEBUG_INFO(priv,
3120 "Copying (but not loading) init data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07003121 memcpy(priv->ucode_init_data.v_addr, src, len);
3122 }
3123
3124 /* Bootstrap instructions (5th block) */
3125 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
3126 len = priv->ucode_boot.len;
Tomas Winklere1623442009-01-27 14:27:56 -08003127 IWL_DEBUG_INFO(priv,
3128 "Copying (but not loading) boot instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07003129 memcpy(priv->ucode_boot.v_addr, src, len);
3130
3131 /* We have our copies now, allow OS release its copies */
3132 release_firmware(ucode_raw);
3133 return 0;
3134
3135 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08003136 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08003137 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003138 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003139
3140 err_release:
3141 release_firmware(ucode_raw);
3142
3143 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08003144 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003145}
3146
3147
3148/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003149 * iwl3945_set_ucode_ptrs - Set uCode address location
Zhu Yib481de92007-09-25 17:54:57 -07003150 *
3151 * Tell initialization uCode where to find runtime uCode.
3152 *
3153 * BSM registers initially contain pointers to initialization uCode.
3154 * We need to replace them to load runtime uCode inst and data,
3155 * and to save runtime data when powering down.
3156 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003157static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003158{
3159 dma_addr_t pinst;
3160 dma_addr_t pdata;
3161 int rc = 0;
3162 unsigned long flags;
3163
3164 /* bits 31:0 for 3945 */
3165 pinst = priv->ucode_code.p_addr;
3166 pdata = priv->ucode_data_backup.p_addr;
3167
3168 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003169 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003170 if (rc) {
3171 spin_unlock_irqrestore(&priv->lock, flags);
3172 return rc;
3173 }
3174
3175 /* Tell bootstrap uCode where to find image to load */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003176 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
3177 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
3178 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07003179 priv->ucode_data.len);
3180
Tomas Winklera96a27f2008-10-23 23:48:56 -07003181 /* Inst byte count must be last to set up, bit 31 signals uCode
Zhu Yib481de92007-09-25 17:54:57 -07003182 * that all new ptr/size info is in place */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003183 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07003184 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
3185
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003186 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003187
3188 spin_unlock_irqrestore(&priv->lock, flags);
3189
Tomas Winklere1623442009-01-27 14:27:56 -08003190 IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003191
3192 return rc;
3193}
3194
3195/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003196 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07003197 *
3198 * Called after REPLY_ALIVE notification received from "initialize" uCode.
3199 *
Zhu Yib481de92007-09-25 17:54:57 -07003200 * Tell "initialize" uCode to go ahead and load the runtime uCode.
Ben Cahill9fbab512007-11-29 11:09:47 +08003201 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003202static void iwl3945_init_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003203{
3204 /* Check alive response for "valid" sign from uCode */
3205 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
3206 /* We had an error bringing up the hardware, so take it
3207 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08003208 IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003209 goto restart;
3210 }
3211
3212 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
3213 * This is a paranoid check, because we would not have gotten the
3214 * "initialize" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003215 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003216 /* Runtime instruction load was bad;
3217 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08003218 IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003219 goto restart;
3220 }
3221
3222 /* Send pointers to protocol/runtime uCode image ... init code will
3223 * load and launch runtime uCode, which will send us another "Alive"
3224 * notification. */
Tomas Winklere1623442009-01-27 14:27:56 -08003225 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003226 if (iwl3945_set_ucode_ptrs(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003227 /* Runtime instruction load won't happen;
3228 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08003229 IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003230 goto restart;
3231 }
3232 return;
3233
3234 restart:
3235 queue_work(priv->workqueue, &priv->restart);
3236}
3237
3238
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003239/* temporary */
3240static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw,
3241 struct sk_buff *skb);
3242
Zhu Yib481de92007-09-25 17:54:57 -07003243/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003244 * iwl3945_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07003245 * from protocol/runtime uCode (initialization uCode's
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003246 * Alive gets handled by iwl3945_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07003247 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003248static void iwl3945_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003249{
3250 int rc = 0;
3251 int thermal_spin = 0;
3252 u32 rfkill;
3253
Tomas Winklere1623442009-01-27 14:27:56 -08003254 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003255
3256 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
3257 /* We had an error bringing up the hardware, so take it
3258 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08003259 IWL_DEBUG_INFO(priv, "Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003260 goto restart;
3261 }
3262
3263 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
3264 * This is a paranoid check, because we would not have gotten the
3265 * "runtime" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003266 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003267 /* Runtime instruction load was bad;
3268 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08003269 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003270 goto restart;
3271 }
3272
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003273 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003274
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003275 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003276 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003277 IWL_WARN(priv, "Can not read RFKILL status from adapter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003278 return;
3279 }
3280
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003281 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
Tomas Winklere1623442009-01-27 14:27:56 -08003282 IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003283 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003284
3285 if (rfkill & 0x1) {
3286 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winklera96a27f2008-10-23 23:48:56 -07003287 /* if RFKILL is not on, then wait for thermal
Zhu Yib481de92007-09-25 17:54:57 -07003288 * sensor in adapter to kick in */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003289 while (iwl3945_hw_get_temperature(priv) == 0) {
Zhu Yib481de92007-09-25 17:54:57 -07003290 thermal_spin++;
3291 udelay(10);
3292 }
3293
3294 if (thermal_spin)
Tomas Winklere1623442009-01-27 14:27:56 -08003295 IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n",
Zhu Yib481de92007-09-25 17:54:57 -07003296 thermal_spin * 10);
3297 } else
3298 set_bit(STATUS_RF_KILL_HW, &priv->status);
3299
Ben Cahill9fbab512007-11-29 11:09:47 +08003300 /* After the ALIVE response, we can send commands to 3945 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07003301 set_bit(STATUS_ALIVE, &priv->status);
3302
3303 /* Clear out the uCode error bit if it is set */
3304 clear_bit(STATUS_FW_ERROR, &priv->status);
3305
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003306 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003307 return;
3308
Johannes Berg36d68252008-05-15 12:55:26 +02003309 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07003310
3311 priv->active_rate = priv->rates_mask;
3312 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
3313
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08003314 iwl_power_update_mode(priv, false);
Zhu Yib481de92007-09-25 17:54:57 -07003315
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003316 if (iwl_is_associated(priv)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003317 struct iwl3945_rxon_cmd *active_rxon =
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003318 (struct iwl3945_rxon_cmd *)(&priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07003319
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003320 memcpy(&priv->staging_rxon, &priv->active_rxon,
3321 sizeof(priv->staging_rxon));
Zhu Yib481de92007-09-25 17:54:57 -07003322 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3323 } else {
3324 /* Initialize our rx_config data */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003325 iwl_connection_init_rx_config(priv, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003326 }
3327
Ben Cahill9fbab512007-11-29 11:09:47 +08003328 /* Configure Bluetooth device coexistence support */
Samuel Ortiz17f841c2009-01-23 13:45:20 -08003329 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003330
3331 /* Configure the adapter for unassociated operation */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003332 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003333
Zhu Yib481de92007-09-25 17:54:57 -07003334 iwl3945_reg_txpower_periodic(priv);
3335
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07003336 iwl3945_led_register(priv);
3337
Tomas Winklere1623442009-01-27 14:27:56 -08003338 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07003339 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003340 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07003341
3342 if (priv->error_recovering)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003343 iwl3945_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003344
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003345 /* reassociate for ADHOC mode */
3346 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
3347 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
3348 priv->vif);
3349 if (beacon)
3350 iwl3945_mac_beacon_update(priv->hw, beacon);
3351 }
3352
Zhu Yib481de92007-09-25 17:54:57 -07003353 return;
3354
3355 restart:
3356 queue_work(priv->workqueue, &priv->restart);
3357}
3358
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003359static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07003360
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003361static void __iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003362{
3363 unsigned long flags;
3364 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
3365 struct ieee80211_conf *conf = NULL;
3366
Tomas Winklere1623442009-01-27 14:27:56 -08003367 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07003368
3369 conf = ieee80211_get_hw_conf(priv->hw);
3370
3371 if (!exit_pending)
3372 set_bit(STATUS_EXIT_PENDING, &priv->status);
3373
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07003374 iwl3945_led_unregister(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003375 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003376
3377 /* Unblock any waiting calls */
3378 wake_up_interruptible_all(&priv->wait_command_queue);
3379
Zhu Yib481de92007-09-25 17:54:57 -07003380 /* Wipe out the EXIT_PENDING status bit if we are not actually
3381 * exiting the module */
3382 if (!exit_pending)
3383 clear_bit(STATUS_EXIT_PENDING, &priv->status);
3384
3385 /* stop and reset the on-board processor */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003386 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07003387
3388 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003389 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003390 iwl3945_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003391 spin_unlock_irqrestore(&priv->lock, flags);
3392 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003393
3394 if (priv->mac80211_registered)
3395 ieee80211_stop_queues(priv->hw);
3396
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003397 /* If we have not previously called iwl3945_init() then
Zhu Yib481de92007-09-25 17:54:57 -07003398 * clear all bits but the RF Kill and SUSPEND bits and return */
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003399 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003400 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3401 STATUS_RF_KILL_HW |
3402 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3403 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08003404 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3405 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07003406 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003407 STATUS_IN_SUSPEND |
3408 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3409 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07003410 goto exit;
3411 }
3412
3413 /* ...otherwise clear out all the status bits but the RF Kill and
3414 * SUSPEND bits and continue taking the NIC down. */
3415 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3416 STATUS_RF_KILL_HW |
3417 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3418 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08003419 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3420 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07003421 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
3422 STATUS_IN_SUSPEND |
3423 test_bit(STATUS_FW_ERROR, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003424 STATUS_FW_ERROR |
3425 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3426 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07003427
Abbas, Mohamede9414b62009-01-20 21:33:55 -08003428 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003429 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003430 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07003431 spin_unlock_irqrestore(&priv->lock, flags);
3432
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003433 iwl3945_hw_txq_ctx_stop(priv);
3434 iwl3945_hw_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003435
3436 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003437 if (!iwl_grab_nic_access(priv)) {
3438 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07003439 APMG_CLK_VAL_DMA_CLK_RQT);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003440 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003441 }
3442 spin_unlock_irqrestore(&priv->lock, flags);
3443
3444 udelay(5);
3445
Abbas, Mohamede9414b62009-01-20 21:33:55 -08003446 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
3447 priv->cfg->ops->lib->apm_ops.stop(priv);
3448 else
3449 priv->cfg->ops->lib->apm_ops.reset(priv);
3450
Zhu Yib481de92007-09-25 17:54:57 -07003451 exit:
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08003452 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07003453
3454 if (priv->ibss_beacon)
3455 dev_kfree_skb(priv->ibss_beacon);
3456 priv->ibss_beacon = NULL;
3457
3458 /* clear out any free frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003459 iwl3945_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003460}
3461
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003462static void iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003463{
3464 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003465 __iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003466 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08003467
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003468 iwl3945_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003469}
3470
3471#define MAX_HW_RESTARTS 5
3472
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003473static int __iwl3945_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003474{
3475 int rc, i;
3476
3477 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003478 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003479 return -EIO;
3480 }
3481
3482 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003483 IWL_WARN(priv, "Radio disabled by SW RF kill (module "
Zhu Yib481de92007-09-25 17:54:57 -07003484 "parameter)\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003485 return -ENODEV;
3486 }
3487
Reinette Chatree903fbd2008-01-30 22:05:15 -08003488 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003489 IWL_ERR(priv, "ucode not available for device bring up\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08003490 return -EIO;
3491 }
3492
Zhu Yie655b9f2008-01-24 02:19:38 -08003493 /* If platform's RF_KILL switch is NOT set to KILL */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003494 if (iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yie655b9f2008-01-24 02:19:38 -08003495 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3496 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3497 else {
3498 set_bit(STATUS_RF_KILL_HW, &priv->status);
3499 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003500 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003501 return -ENODEV;
3502 }
Zhu Yib481de92007-09-25 17:54:57 -07003503 }
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02003504
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003505 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07003506
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003507 rc = iwl3945_hw_nic_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003508 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003509 IWL_ERR(priv, "Unable to int nic\n");
Zhu Yib481de92007-09-25 17:54:57 -07003510 return rc;
3511 }
3512
3513 /* make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003514 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3515 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07003516 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
3517
3518 /* clear (again), then enable host interrupts */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003519 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003520 iwl3945_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003521
3522 /* really make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003523 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3524 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07003525
3526 /* Copy original ucode data image from disk into backup cache.
3527 * This will be used to initialize the on-board processor's
3528 * data SRAM for a clean start when the runtime program first loads. */
3529 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a66926a2008-01-14 17:46:18 -08003530 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07003531
Zhu Yie655b9f2008-01-24 02:19:38 -08003532 /* We return success when we resume from suspend and rf_kill is on. */
3533 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
3534 return 0;
3535
Zhu Yib481de92007-09-25 17:54:57 -07003536 for (i = 0; i < MAX_HW_RESTARTS; i++) {
3537
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003538 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003539
3540 /* load bootstrap state machine,
3541 * load bootstrap program into processor's memory,
3542 * prepare to load the "initialize" uCode */
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08003543 priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003544
3545 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003546 IWL_ERR(priv,
3547 "Unable to set up bootstrap uCode: %d\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -07003548 continue;
3549 }
3550
3551 /* start card; "initialize" will load runtime ucode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003552 iwl3945_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003553
Tomas Winklere1623442009-01-27 14:27:56 -08003554 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003555
3556 return 0;
3557 }
3558
3559 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003560 __iwl3945_down(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003561 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003562
3563 /* tried to restart and config the device for as long as our
3564 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08003565 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07003566 return -EIO;
3567}
3568
3569
3570/*****************************************************************************
3571 *
3572 * Workqueue callbacks
3573 *
3574 *****************************************************************************/
3575
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003576static void iwl3945_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003577{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003578 struct iwl_priv *priv =
3579 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003580
3581 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3582 return;
3583
3584 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003585 iwl3945_init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003586 mutex_unlock(&priv->mutex);
3587}
3588
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003589static void iwl3945_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003590{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003591 struct iwl_priv *priv =
3592 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003593
3594 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3595 return;
3596
3597 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003598 iwl3945_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003599 mutex_unlock(&priv->mutex);
3600}
3601
Helmut Schaa26635162009-01-15 09:38:44 +01003602static void iwl3945_rfkill_poll(struct work_struct *data)
3603{
3604 struct iwl_priv *priv =
3605 container_of(data, struct iwl_priv, rfkill_poll.work);
3606 unsigned long status = priv->status;
3607
3608 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3609 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3610 else
3611 set_bit(STATUS_RF_KILL_HW, &priv->status);
3612
3613 if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status))
3614 queue_work(priv->workqueue, &priv->rf_kill);
3615
3616 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3617 round_jiffies_relative(2 * HZ));
3618
3619}
3620
Zhu Yib481de92007-09-25 17:54:57 -07003621#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003622static void iwl3945_bg_request_scan(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003623{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003624 struct iwl_priv *priv =
3625 container_of(data, struct iwl_priv, request_scan);
Winkler, Tomasc2d79b482008-12-19 10:37:34 +08003626 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07003627 .id = REPLY_SCAN_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003628 .len = sizeof(struct iwl3945_scan_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07003629 .meta.flags = CMD_SIZE_HUGE,
3630 };
3631 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003632 struct iwl3945_scan_cmd *scan;
Zhu Yib481de92007-09-25 17:54:57 -07003633 struct ieee80211_conf *conf = NULL;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003634 u8 n_probes = 2;
Johannes Berg8318d782008-01-24 19:38:38 +01003635 enum ieee80211_band band;
John W. Linville9387b7c2008-09-30 20:59:05 -04003636 DECLARE_SSID_BUF(ssid);
Zhu Yib481de92007-09-25 17:54:57 -07003637
3638 conf = ieee80211_get_hw_conf(priv->hw);
3639
3640 mutex_lock(&priv->mutex);
3641
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003642 if (!iwl_is_ready(priv)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003643 IWL_WARN(priv, "request scan called when driver not ready.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003644 goto done;
3645 }
3646
Tomas Winklera96a27f2008-10-23 23:48:56 -07003647 /* Make sure the scan wasn't canceled before this queued work
Zhu Yib481de92007-09-25 17:54:57 -07003648 * was given the chance to run... */
3649 if (!test_bit(STATUS_SCANNING, &priv->status))
3650 goto done;
3651
3652 /* This should never be called or scheduled if there is currently
3653 * a scan active in the hardware. */
3654 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003655 IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests "
3656 "Ignoring second request.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003657 rc = -EIO;
3658 goto done;
3659 }
3660
3661 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003662 IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n");
Zhu Yib481de92007-09-25 17:54:57 -07003663 goto done;
3664 }
3665
3666 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003667 IWL_DEBUG_HC(priv,
3668 "Scan request while abort pending. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003669 goto done;
3670 }
3671
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003672 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003673 IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n");
Zhu Yib481de92007-09-25 17:54:57 -07003674 goto done;
3675 }
3676
3677 if (!test_bit(STATUS_READY, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003678 IWL_DEBUG_HC(priv,
3679 "Scan request while uninitialized. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003680 goto done;
3681 }
3682
3683 if (!priv->scan_bands) {
Tomas Winklere1623442009-01-27 14:27:56 -08003684 IWL_DEBUG_HC(priv, "Aborting scan due to no requested bands\n");
Zhu Yib481de92007-09-25 17:54:57 -07003685 goto done;
3686 }
3687
Winkler, Tomas805cee52009-01-19 15:30:28 -08003688 if (!priv->scan) {
3689 priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
Zhu Yib481de92007-09-25 17:54:57 -07003690 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
Winkler, Tomas805cee52009-01-19 15:30:28 -08003691 if (!priv->scan) {
Zhu Yib481de92007-09-25 17:54:57 -07003692 rc = -ENOMEM;
3693 goto done;
3694 }
3695 }
Winkler, Tomas805cee52009-01-19 15:30:28 -08003696 scan = priv->scan;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003697 memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07003698
3699 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
3700 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
3701
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003702 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003703 u16 interval = 0;
3704 u32 extra;
3705 u32 suspend_time = 100;
3706 u32 scan_suspend_time = 100;
3707 unsigned long flags;
3708
Tomas Winklere1623442009-01-27 14:27:56 -08003709 IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
Zhu Yib481de92007-09-25 17:54:57 -07003710
3711 spin_lock_irqsave(&priv->lock, flags);
3712 interval = priv->beacon_int;
3713 spin_unlock_irqrestore(&priv->lock, flags);
3714
3715 scan->suspend_time = 0;
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003716 scan->max_out_time = cpu_to_le32(200 * 1024);
Zhu Yib481de92007-09-25 17:54:57 -07003717 if (!interval)
3718 interval = suspend_time;
3719 /*
3720 * suspend time format:
3721 * 0-19: beacon interval in usec (time before exec.)
3722 * 20-23: 0
3723 * 24-31: number of beacons (suspend between channels)
3724 */
3725
3726 extra = (suspend_time / interval) << 24;
3727 scan_suspend_time = 0xFF0FFFFF &
3728 (extra | ((suspend_time % interval) * 1024));
3729
3730 scan->suspend_time = cpu_to_le32(scan_suspend_time);
Tomas Winklere1623442009-01-27 14:27:56 -08003731 IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003732 scan_suspend_time, interval);
3733 }
3734
3735 /* We should add the ability for user to lock to PASSIVE ONLY */
3736 if (priv->one_direct_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08003737 IWL_DEBUG_SCAN(priv, "Kicking off one direct scan for '%s'\n",
3738 print_ssid(ssid, priv->direct_ssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04003739 priv->direct_ssid_len));
Zhu Yib481de92007-09-25 17:54:57 -07003740 scan->direct_scan[0].id = WLAN_EID_SSID;
3741 scan->direct_scan[0].len = priv->direct_ssid_len;
3742 memcpy(scan->direct_scan[0].ssid,
3743 priv->direct_ssid, priv->direct_ssid_len);
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003744 n_probes++;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003745 } else
Tomas Winklere1623442009-01-27 14:27:56 -08003746 IWL_DEBUG_SCAN(priv, "Kicking off one indirect scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003747
3748 /* We don't build a direct scan probe request; the uCode will do
3749 * that based on the direct_mask added to each channel entry */
Zhu Yib481de92007-09-25 17:54:57 -07003750 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08003751 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07003752 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
3753
3754 /* flags + rate selection */
3755
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003756 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003757 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
3758 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
3759 scan->good_CRC_th = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01003760 band = IEEE80211_BAND_2GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003761 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003762 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
3763 scan->good_CRC_th = IWL_GOOD_CRC_TH;
Johannes Berg8318d782008-01-24 19:38:38 +01003764 band = IEEE80211_BAND_5GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003765 } else {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003766 IWL_WARN(priv, "Invalid scan band count\n");
Zhu Yib481de92007-09-25 17:54:57 -07003767 goto done;
3768 }
3769
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08003770 scan->tx_cmd.len = cpu_to_le16(
3771 iwl_fill_probe_req(priv, band,
3772 (struct ieee80211_mgmt *)scan->data,
3773 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
3774
Zhu Yib481de92007-09-25 17:54:57 -07003775 /* select Rx antennas */
3776 scan->flags |= iwl3945_get_antenna_flags(priv);
3777
Johannes Berg05c914f2008-09-11 00:01:58 +02003778 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
Zhu Yib481de92007-09-25 17:54:57 -07003779 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
3780
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003781 scan->channel_count =
3782 iwl3945_get_channels_for_scan(priv, band, 1, /* active */
3783 n_probes,
3784 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
Zhu Yib481de92007-09-25 17:54:57 -07003785
Reinette Chatre14b54332008-11-04 12:21:35 -08003786 if (scan->channel_count == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08003787 IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
Reinette Chatre14b54332008-11-04 12:21:35 -08003788 goto done;
3789 }
3790
Zhu Yib481de92007-09-25 17:54:57 -07003791 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003792 scan->channel_count * sizeof(struct iwl3945_scan_channel);
Zhu Yib481de92007-09-25 17:54:57 -07003793 cmd.data = scan;
3794 scan->len = cpu_to_le16(cmd.len);
3795
3796 set_bit(STATUS_SCAN_HW, &priv->status);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003797 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07003798 if (rc)
3799 goto done;
3800
3801 queue_delayed_work(priv->workqueue, &priv->scan_check,
3802 IWL_SCAN_CHECK_WATCHDOG);
3803
3804 mutex_unlock(&priv->mutex);
3805 return;
3806
3807 done:
Mohamed Abbas2420ebc2008-11-04 12:21:34 -08003808 /* can not perform scan make sure we clear scanning
3809 * bits from status so next scan request can be performed.
3810 * if we dont clear scanning status bit here all next scan
3811 * will fail
3812 */
3813 clear_bit(STATUS_SCAN_HW, &priv->status);
3814 clear_bit(STATUS_SCANNING, &priv->status);
3815
Ian Schram01ebd062007-10-25 17:15:22 +08003816 /* inform mac80211 scan aborted */
Zhu Yib481de92007-09-25 17:54:57 -07003817 queue_work(priv->workqueue, &priv->scan_completed);
3818 mutex_unlock(&priv->mutex);
3819}
3820
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003821static void iwl3945_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003822{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003823 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07003824
3825 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3826 return;
3827
3828 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003829 __iwl3945_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003830 mutex_unlock(&priv->mutex);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003831 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003832}
3833
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003834static void iwl3945_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003835{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003836 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07003837
3838 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3839 return;
3840
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003841 iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003842 queue_work(priv->workqueue, &priv->up);
3843}
3844
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003845static void iwl3945_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003846{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003847 struct iwl_priv *priv =
3848 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07003849
3850 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3851 return;
3852
3853 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003854 iwl3945_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003855 mutex_unlock(&priv->mutex);
3856}
3857
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003858#define IWL_DELAY_NEXT_SCAN (HZ*2)
3859
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003860static void iwl3945_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003861{
Zhu Yib481de92007-09-25 17:54:57 -07003862 int rc = 0;
3863 struct ieee80211_conf *conf = NULL;
3864
Johannes Berg05c914f2008-09-11 00:01:58 +02003865 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003866 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07003867 return;
3868 }
3869
3870
Tomas Winklere1623442009-01-27 14:27:56 -08003871 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003872 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07003873
3874 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3875 return;
3876
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003877 if (!priv->vif || !priv->is_open)
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003878 return;
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003879
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003880 iwl_scan_cancel_timeout(priv, 200);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003881
Zhu Yib481de92007-09-25 17:54:57 -07003882 conf = ieee80211_get_hw_conf(priv->hw);
3883
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003884 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003885 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003886
Tomas Winkler28afaf92008-12-19 10:37:06 +08003887 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003888 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003889 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07003890 sizeof(priv->rxon_timing), &priv->rxon_timing);
3891 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003892 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003893 "Attempting to continue.\n");
3894
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003895 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003896
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003897 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003898
Tomas Winklere1623442009-01-27 14:27:56 -08003899 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003900 priv->assoc_id, priv->beacon_int);
3901
3902 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003903 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003904 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003905 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003906
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003907 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003908 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003909 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003910 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003911 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003912
Johannes Berg05c914f2008-09-11 00:01:58 +02003913 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003914 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003915
3916 }
3917
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003918 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003919
3920 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02003921 case NL80211_IFTYPE_STATION:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003922 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07003923 break;
3924
Johannes Berg05c914f2008-09-11 00:01:58 +02003925 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07003926
Abhijeet Kolekarce546fd2008-11-19 15:32:22 -08003927 priv->assoc_id = 1;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003928 iwl3945_add_station(priv, priv->bssid, 0, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003929 iwl3945_sync_sta(priv, IWL_STA_ID,
Johannes Berg8318d782008-01-24 19:38:38 +01003930 (priv->band == IEEE80211_BAND_5GHZ) ?
Zhu Yib481de92007-09-25 17:54:57 -07003931 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
3932 CMD_ASYNC);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003933 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
3934 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003935
3936 break;
3937
3938 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08003939 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003940 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003941 break;
3942 }
3943
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003944 iwl3945_activate_qos(priv, 0);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08003945
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003946 /* we have just associated, don't start scan too early */
3947 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08003948}
3949
Johannes Berge8975582008-10-09 12:18:51 +02003950static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003951
Zhu Yib481de92007-09-25 17:54:57 -07003952/*****************************************************************************
3953 *
3954 * mac80211 entry point functions
3955 *
3956 *****************************************************************************/
3957
Zhu Yi5a66926a2008-01-14 17:46:18 -08003958#define UCODE_READY_TIMEOUT (2 * HZ)
3959
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003960static int iwl3945_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003961{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003962 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003963 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003964
Tomas Winklere1623442009-01-27 14:27:56 -08003965 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003966
3967 /* we should be verifying the device is ready to be opened */
3968 mutex_lock(&priv->mutex);
3969
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003970 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
Zhu Yi5a66926a2008-01-14 17:46:18 -08003971 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
3972 * ucode filename and max sizes are card-specific. */
3973
3974 if (!priv->ucode_code.len) {
3975 ret = iwl3945_read_ucode(priv);
3976 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003977 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003978 mutex_unlock(&priv->mutex);
3979 goto out_release_irq;
3980 }
3981 }
3982
Zhu Yie655b9f2008-01-24 02:19:38 -08003983 ret = __iwl3945_up(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003984
Zhu Yib481de92007-09-25 17:54:57 -07003985 mutex_unlock(&priv->mutex);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003986
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003987 iwl_rfkill_set_hw_state(priv);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02003988
Zhu Yie655b9f2008-01-24 02:19:38 -08003989 if (ret)
3990 goto out_release_irq;
3991
Tomas Winklere1623442009-01-27 14:27:56 -08003992 IWL_DEBUG_INFO(priv, "Start UP work.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003993
3994 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
3995 return 0;
3996
Zhu Yi5a66926a2008-01-14 17:46:18 -08003997 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
3998 * mac80211 will not be run successfully. */
3999 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
4000 test_bit(STATUS_READY, &priv->status),
4001 UCODE_READY_TIMEOUT);
4002 if (!ret) {
4003 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004004 IWL_ERR(priv,
4005 "Wait for START_ALIVE timeout after %dms.\n",
4006 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Zhu Yi5a66926a2008-01-14 17:46:18 -08004007 ret = -ETIMEDOUT;
4008 goto out_release_irq;
4009 }
4010 }
4011
Helmut Schaa26635162009-01-15 09:38:44 +01004012 /* ucode is running and will send rfkill notifications,
4013 * no need to poll the killswitch state anymore */
4014 cancel_delayed_work(&priv->rfkill_poll);
4015
Zhu Yie655b9f2008-01-24 02:19:38 -08004016 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08004017 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004018 return 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08004019
4020out_release_irq:
Zhu Yie655b9f2008-01-24 02:19:38 -08004021 priv->is_open = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08004022 IWL_DEBUG_MAC80211(priv, "leave - failed\n");
Zhu Yi5a66926a2008-01-14 17:46:18 -08004023 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004024}
4025
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004026static void iwl3945_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07004027{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004028 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004029
Tomas Winklere1623442009-01-27 14:27:56 -08004030 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004031
Zhu Yie655b9f2008-01-24 02:19:38 -08004032 if (!priv->is_open) {
Tomas Winklere1623442009-01-27 14:27:56 -08004033 IWL_DEBUG_MAC80211(priv, "leave - skip\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08004034 return;
4035 }
4036
Zhu Yib481de92007-09-25 17:54:57 -07004037 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08004038
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004039 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08004040 /* stop mac, cancel any scan request and clear
4041 * RXON_FILTER_ASSOC_MSK BIT
4042 */
Zhu Yi5a66926a2008-01-14 17:46:18 -08004043 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004044 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08004045 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08004046 }
4047
Zhu Yi5a66926a2008-01-14 17:46:18 -08004048 iwl3945_down(priv);
4049
4050 flush_workqueue(priv->workqueue);
Helmut Schaa26635162009-01-15 09:38:44 +01004051
4052 /* start polling the killswitch state again */
4053 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
4054 round_jiffies_relative(2 * HZ));
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004055
Tomas Winklere1623442009-01-27 14:27:56 -08004056 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004057}
4058
Johannes Berge039fa42008-05-15 12:55:29 +02004059static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07004060{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004061 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004062
Tomas Winklere1623442009-01-27 14:27:56 -08004063 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004064
Tomas Winklere1623442009-01-27 14:27:56 -08004065 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02004066 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07004067
Johannes Berge039fa42008-05-15 12:55:29 +02004068 if (iwl3945_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07004069 dev_kfree_skb_any(skb);
4070
Tomas Winklere1623442009-01-27 14:27:56 -08004071 IWL_DEBUG_MAC80211(priv, "leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08004072 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07004073}
4074
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004075static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004076 struct ieee80211_if_init_conf *conf)
4077{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004078 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004079 unsigned long flags;
4080
Tomas Winklere1623442009-01-27 14:27:56 -08004081 IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07004082
Johannes Berg32bfd352007-12-19 01:31:26 +01004083 if (priv->vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08004084 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
Tomas Winkler864792e2007-11-27 21:00:52 +02004085 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07004086 }
4087
4088 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01004089 priv->vif = conf->vif;
Zhu, Yi60294de2008-10-29 14:05:45 -07004090 priv->iw_mode = conf->type;
Zhu Yib481de92007-09-25 17:54:57 -07004091
4092 spin_unlock_irqrestore(&priv->lock, flags);
4093
4094 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02004095
4096 if (conf->mac_addr) {
Tomas Winklere1623442009-01-27 14:27:56 -08004097 IWL_DEBUG_MAC80211(priv, "Set: %pM\n", conf->mac_addr);
Tomas Winkler864792e2007-11-27 21:00:52 +02004098 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
4099 }
4100
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004101 if (iwl_is_ready(priv))
Zhu Yi5a66926a2008-01-14 17:46:18 -08004102 iwl3945_set_mode(priv, conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07004103
Zhu Yib481de92007-09-25 17:54:57 -07004104 mutex_unlock(&priv->mutex);
4105
Tomas Winklere1623442009-01-27 14:27:56 -08004106 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004107 return 0;
4108}
4109
4110/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004111 * iwl3945_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07004112 *
4113 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
4114 * be set inappropriately and the driver currently sets the hardware up to
4115 * use it whenever needed.
4116 */
Johannes Berge8975582008-10-09 12:18:51 +02004117static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed)
Zhu Yib481de92007-09-25 17:54:57 -07004118{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004119 struct iwl_priv *priv = hw->priv;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004120 const struct iwl_channel_info *ch_info;
Johannes Berge8975582008-10-09 12:18:51 +02004121 struct ieee80211_conf *conf = &hw->conf;
Zhu Yib481de92007-09-25 17:54:57 -07004122 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08004123 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004124
4125 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08004126 IWL_DEBUG_MAC80211(priv, "enter to channel %d\n",
4127 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07004128
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004129 if (!iwl_is_ready(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004130 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08004131 ret = -EIO;
4132 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004133 }
4134
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004135 if (unlikely(!iwl3945_mod_params.disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07004136 test_bit(STATUS_SCANNING, &priv->status))) {
Tomas Winklere1623442009-01-27 14:27:56 -08004137 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
Zhu Yia0646472007-12-20 14:10:01 +08004138 set_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07004139 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08004140 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07004141 }
4142
4143 spin_lock_irqsave(&priv->lock, flags);
4144
Samuel Ortize6148912009-01-23 13:45:15 -08004145 ch_info = iwl_get_channel_info(priv, conf->channel->band,
4146 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07004147 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004148 IWL_DEBUG_SCAN(priv,
4149 "Channel %d [%d] is INVALID for this band.\n",
4150 conf->channel->hw_value, conf->channel->band);
4151 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
Zhu Yib481de92007-09-25 17:54:57 -07004152 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yi76bb77e2007-11-22 10:53:22 +08004153 ret = -EINVAL;
4154 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004155 }
4156
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004157 iwl_set_rxon_channel(priv, conf->channel);
Zhu Yib481de92007-09-25 17:54:57 -07004158
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004159 iwl_set_flags_for_band(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07004160
4161 /* The list of supported rates and rate mask can be different
4162 * for each phymode; since the phymode may have changed, reset
4163 * the rate mask to what mac80211 lists */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004164 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004165
4166 spin_unlock_irqrestore(&priv->lock, flags);
4167
4168#ifdef IEEE80211_CONF_CHANNEL_SWITCH
4169 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004170 iwl3945_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08004171 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004172 }
4173#endif
4174
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004175 iwl3945_radio_kill_sw(priv, !conf->radio_enabled);
Zhu Yib481de92007-09-25 17:54:57 -07004176
4177 if (!conf->radio_enabled) {
Tomas Winklere1623442009-01-27 14:27:56 -08004178 IWL_DEBUG_MAC80211(priv, "leave - radio disabled\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08004179 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004180 }
4181
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004182 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004183 IWL_DEBUG_MAC80211(priv, "leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08004184 ret = -EIO;
4185 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004186 }
4187
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004188 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004189
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004190 if (memcmp(&priv->active_rxon,
4191 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004192 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004193 else
Tomas Winklere1623442009-01-27 14:27:56 -08004194 IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration\n");
Zhu Yib481de92007-09-25 17:54:57 -07004195
Tomas Winklere1623442009-01-27 14:27:56 -08004196 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004197
Zhu Yi76bb77e2007-11-22 10:53:22 +08004198out:
Zhu Yia0646472007-12-20 14:10:01 +08004199 clear_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07004200 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08004201 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004202}
4203
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004204static void iwl3945_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004205{
4206 int rc = 0;
4207
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08004208 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07004209 return;
4210
4211 /* The following should be done only at AP bring up */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004212 if (!(iwl_is_associated(priv))) {
Zhu Yib481de92007-09-25 17:54:57 -07004213
4214 /* RXON - unassoc (to set timing command) */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004215 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004216 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004217
4218 /* RXON Timing */
Tomas Winkler28afaf92008-12-19 10:37:06 +08004219 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004220 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08004221 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
4222 sizeof(priv->rxon_timing),
4223 &priv->rxon_timing);
Zhu Yib481de92007-09-25 17:54:57 -07004224 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004225 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07004226 "Attempting to continue.\n");
4227
4228 /* FIXME: what should be the assoc_id for AP? */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004229 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07004230 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004231 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07004232 RXON_FLG_SHORT_PREAMBLE_MSK;
4233 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004234 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07004235 ~RXON_FLG_SHORT_PREAMBLE_MSK;
4236
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004237 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07004238 if (priv->assoc_capability &
4239 WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004240 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07004241 RXON_FLG_SHORT_SLOT_MSK;
4242 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004243 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07004244 ~RXON_FLG_SHORT_SLOT_MSK;
4245
Johannes Berg05c914f2008-09-11 00:01:58 +02004246 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004247 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07004248 ~RXON_FLG_SHORT_SLOT_MSK;
4249 }
4250 /* restore RXON assoc */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004251 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004252 iwl3945_commit_rxon(priv);
Kolekar, Abhijeetb5323d32008-12-19 10:37:22 +08004253 iwl3945_add_station(priv, iwl_bcast_addr, 0, 0);
Zhu Yi556f8db2007-09-27 11:27:33 +08004254 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004255 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004256
4257 /* FIXME - we need to add code here to detect a totally new
4258 * configuration, reset the AP, unassoc, rxon timing, assoc,
4259 * clear sta table, add BCAST sta... */
4260}
4261
Johannes Berg32bfd352007-12-19 01:31:26 +01004262static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
4263 struct ieee80211_vif *vif,
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004264 struct ieee80211_if_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07004265{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004266 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004267 int rc;
4268
4269 if (conf == NULL)
4270 return -EIO;
4271
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08004272 if (priv->vif != vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08004273 IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08004274 return 0;
4275 }
4276
Johannes Berg9d139c82008-07-09 14:40:37 +02004277 /* handle this temporarily here */
Johannes Berg05c914f2008-09-11 00:01:58 +02004278 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Johannes Berg9d139c82008-07-09 14:40:37 +02004279 conf->changed & IEEE80211_IFCC_BEACON) {
4280 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
4281 if (!beacon)
4282 return -ENOMEM;
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08004283 mutex_lock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02004284 rc = iwl3945_mac_beacon_update(hw, beacon);
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08004285 mutex_unlock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02004286 if (rc)
4287 return rc;
4288 }
4289
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004290 if (!iwl_is_alive(priv))
Zhu Yi5a66926a2008-01-14 17:46:18 -08004291 return -EAGAIN;
4292
Zhu Yib481de92007-09-25 17:54:57 -07004293 mutex_lock(&priv->mutex);
4294
Zhu Yib481de92007-09-25 17:54:57 -07004295 if (conf->bssid)
Tomas Winklere1623442009-01-27 14:27:56 -08004296 IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07004297
Johannes Berg4150c572007-09-17 01:29:23 -04004298/*
4299 * very dubious code was here; the probe filtering flag is never set:
4300 *
Zhu Yib481de92007-09-25 17:54:57 -07004301 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
4302 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04004303 */
Zhu Yib481de92007-09-25 17:54:57 -07004304
Johannes Berg05c914f2008-09-11 00:01:58 +02004305 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07004306 if (!conf->bssid) {
4307 conf->bssid = priv->mac_addr;
4308 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08004309 IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07004310 conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07004311 }
4312 if (priv->ibss_beacon)
4313 dev_kfree_skb(priv->ibss_beacon);
4314
Johannes Berg9d139c82008-07-09 14:40:37 +02004315 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
Zhu Yib481de92007-09-25 17:54:57 -07004316 }
4317
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004318 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08004319 goto done;
4320
Zhu Yib481de92007-09-25 17:54:57 -07004321 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
4322 !is_multicast_ether_addr(conf->bssid)) {
4323 /* If there is currently a HW scan going on in the background
4324 * then we need to cancel it else the RXON below will fail. */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004325 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004326 IWL_WARN(priv, "Aborted scan still in progress "
Zhu Yib481de92007-09-25 17:54:57 -07004327 "after 100ms\n");
Tomas Winklere1623442009-01-27 14:27:56 -08004328 IWL_DEBUG_MAC80211(priv, "leaving:scan abort failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07004329 mutex_unlock(&priv->mutex);
4330 return -EAGAIN;
4331 }
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004332 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07004333
4334 /* TODO: Audit driver for usage of these members and see
4335 * if mac80211 deprecates them (priv->bssid looks like it
4336 * shouldn't be there, but I haven't scanned the IBSS code
4337 * to verify) - jpk */
4338 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
4339
Johannes Berg05c914f2008-09-11 00:01:58 +02004340 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004341 iwl3945_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004342 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004343 rc = iwl3945_commit_rxon(priv);
Johannes Berg05c914f2008-09-11 00:01:58 +02004344 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004345 iwl3945_add_station(priv,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004346 priv->active_rxon.bssid_addr, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004347 }
4348
4349 } else {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004350 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004351 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004352 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004353 }
4354
Mohamed Abbasfde35712007-11-29 11:10:15 +08004355 done:
Tomas Winklere1623442009-01-27 14:27:56 -08004356 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004357 mutex_unlock(&priv->mutex);
4358
4359 return 0;
4360}
4361
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004362static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004363 struct ieee80211_if_init_conf *conf)
4364{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004365 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004366
Tomas Winklere1623442009-01-27 14:27:56 -08004367 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004368
4369 mutex_lock(&priv->mutex);
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004370
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004371 if (iwl_is_ready_rf(priv)) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004372 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004373 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Mohamed Abbasfde35712007-11-29 11:10:15 +08004374 iwl3945_commit_rxon(priv);
4375 }
Johannes Berg32bfd352007-12-19 01:31:26 +01004376 if (priv->vif == conf->vif) {
4377 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07004378 memset(priv->bssid, 0, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07004379 }
4380 mutex_unlock(&priv->mutex);
4381
Tomas Winklere1623442009-01-27 14:27:56 -08004382 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004383}
4384
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004385#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
4386
4387static void iwl3945_bss_info_changed(struct ieee80211_hw *hw,
4388 struct ieee80211_vif *vif,
4389 struct ieee80211_bss_conf *bss_conf,
4390 u32 changes)
4391{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004392 struct iwl_priv *priv = hw->priv;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004393
Tomas Winklere1623442009-01-27 14:27:56 -08004394 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004395
4396 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
Tomas Winklere1623442009-01-27 14:27:56 -08004397 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004398 bss_conf->use_short_preamble);
4399 if (bss_conf->use_short_preamble)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004400 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004401 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004402 priv->staging_rxon.flags &=
4403 ~RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004404 }
4405
4406 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
Tomas Winklere1623442009-01-27 14:27:56 -08004407 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n",
4408 bss_conf->use_cts_prot);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004409 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004410 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004411 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004412 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004413 }
4414
4415 if (changes & BSS_CHANGED_ASSOC) {
Tomas Winklere1623442009-01-27 14:27:56 -08004416 IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004417 /* This should never happen as this function should
4418 * never be called from interrupt context. */
4419 if (WARN_ON_ONCE(in_interrupt()))
4420 return;
4421 if (bss_conf->assoc) {
4422 priv->assoc_id = bss_conf->aid;
4423 priv->beacon_int = bss_conf->beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08004424 priv->timestamp = bss_conf->timestamp;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004425 priv->assoc_capability = bss_conf->assoc_capability;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08004426 priv->power_data.dtim_period = bss_conf->dtim_period;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004427 priv->next_scan_jiffies = jiffies +
4428 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
4429 mutex_lock(&priv->mutex);
4430 iwl3945_post_associate(priv);
4431 mutex_unlock(&priv->mutex);
4432 } else {
4433 priv->assoc_id = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08004434 IWL_DEBUG_MAC80211(priv,
4435 "DISASSOC %d\n", bss_conf->assoc);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004436 }
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004437 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
Tomas Winklere1623442009-01-27 14:27:56 -08004438 IWL_DEBUG_MAC80211(priv,
4439 "Associated Changes %d\n", changes);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004440 iwl3945_send_rxon_assoc(priv);
4441 }
4442
4443}
4444
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004445static int iwl3945_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
Zhu Yib481de92007-09-25 17:54:57 -07004446{
4447 int rc = 0;
4448 unsigned long flags;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004449 struct iwl_priv *priv = hw->priv;
John W. Linville9387b7c2008-09-30 20:59:05 -04004450 DECLARE_SSID_BUF(ssid_buf);
Zhu Yib481de92007-09-25 17:54:57 -07004451
Tomas Winklere1623442009-01-27 14:27:56 -08004452 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004453
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004454 mutex_lock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07004455 spin_lock_irqsave(&priv->lock, flags);
4456
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004457 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004458 rc = -EIO;
Tomas Winklere1623442009-01-27 14:27:56 -08004459 IWL_DEBUG_MAC80211(priv, "leave - not ready or exit pending\n");
Zhu Yib481de92007-09-25 17:54:57 -07004460 goto out_unlock;
4461 }
4462
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08004463 /* we don't schedule scan within next_scan_jiffies period */
4464 if (priv->next_scan_jiffies &&
4465 time_after(priv->next_scan_jiffies, jiffies)) {
4466 rc = -EAGAIN;
4467 goto out_unlock;
4468 }
Bill Moss15dbf1b2008-05-06 11:05:15 +08004469 /* if we just finished scan ask for delay for a broadcast scan */
4470 if ((len == 0) && priv->last_scan_jiffies &&
4471 time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN,
4472 jiffies)) {
Zhu Yib481de92007-09-25 17:54:57 -07004473 rc = -EAGAIN;
4474 goto out_unlock;
4475 }
4476 if (len) {
Tomas Winklere1623442009-01-27 14:27:56 -08004477 IWL_DEBUG_SCAN(priv, "direct scan for %s [%zd]\n ",
4478 print_ssid(ssid_buf, ssid, len), len);
Zhu Yib481de92007-09-25 17:54:57 -07004479
4480 priv->one_direct_scan = 1;
4481 priv->direct_ssid_len = (u8)
4482 min((u8) len, (u8) IW_ESSID_MAX_SIZE);
4483 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004484 } else
4485 priv->one_direct_scan = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004486
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004487 rc = iwl3945_scan_initiate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004488
Tomas Winklere1623442009-01-27 14:27:56 -08004489 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004490
4491out_unlock:
4492 spin_unlock_irqrestore(&priv->lock, flags);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004493 mutex_unlock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07004494
4495 return rc;
4496}
4497
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004498static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01004499 struct ieee80211_vif *vif,
4500 struct ieee80211_sta *sta,
4501 struct ieee80211_key_conf *key)
Zhu Yib481de92007-09-25 17:54:57 -07004502{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004503 struct iwl_priv *priv = hw->priv;
Johannes Bergdc822b52008-12-29 12:55:09 +01004504 const u8 *addr;
Winkler, Tomas42986792009-01-19 15:30:22 -08004505 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07004506 u8 sta_id;
4507
Tomas Winklere1623442009-01-27 14:27:56 -08004508 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004509
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004510 if (iwl3945_mod_params.sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08004511 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07004512 return -EOPNOTSUPP;
4513 }
4514
Winkler, Tomas42986792009-01-19 15:30:22 -08004515 addr = sta ? sta->addr : iwl_bcast_addr;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004516 sta_id = iwl3945_hw_find_station(priv, addr);
Zhu Yib481de92007-09-25 17:54:57 -07004517 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -08004518 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
Johannes Berge1749612008-10-27 15:59:26 -07004519 addr);
Zhu Yib481de92007-09-25 17:54:57 -07004520 return -EINVAL;
4521 }
4522
4523 mutex_lock(&priv->mutex);
4524
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004525 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004526
Zhu Yib481de92007-09-25 17:54:57 -07004527 switch (cmd) {
4528 case SET_KEY:
Winkler, Tomas42986792009-01-19 15:30:22 -08004529 ret = iwl3945_update_sta_key_info(priv, key, sta_id);
4530 if (!ret) {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004531 iwl_set_rxon_hwcrypto(priv, 1);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004532 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004533 key->hw_key_idx = sta_id;
Tomas Winklere1623442009-01-27 14:27:56 -08004534 IWL_DEBUG_MAC80211(priv,
4535 "set_key success, using hwcrypto\n");
Zhu Yib481de92007-09-25 17:54:57 -07004536 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
4537 }
4538 break;
4539 case DISABLE_KEY:
Winkler, Tomas42986792009-01-19 15:30:22 -08004540 ret = iwl3945_clear_sta_key_info(priv, sta_id);
4541 if (!ret) {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004542 iwl_set_rxon_hwcrypto(priv, 0);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004543 iwl3945_commit_rxon(priv);
Tomas Winklere1623442009-01-27 14:27:56 -08004544 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07004545 }
4546 break;
4547 default:
Winkler, Tomas42986792009-01-19 15:30:22 -08004548 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07004549 }
4550
Tomas Winklere1623442009-01-27 14:27:56 -08004551 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004552 mutex_unlock(&priv->mutex);
4553
Winkler, Tomas42986792009-01-19 15:30:22 -08004554 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004555}
4556
Johannes Berge100bb62008-04-30 18:51:21 +02004557static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
Zhu Yib481de92007-09-25 17:54:57 -07004558 const struct ieee80211_tx_queue_params *params)
4559{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004560 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004561 unsigned long flags;
4562 int q;
Zhu Yib481de92007-09-25 17:54:57 -07004563
Tomas Winklere1623442009-01-27 14:27:56 -08004564 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004565
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004566 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004567 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004568 return -EIO;
4569 }
4570
4571 if (queue >= AC_NUM) {
Tomas Winklere1623442009-01-27 14:27:56 -08004572 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
Zhu Yib481de92007-09-25 17:54:57 -07004573 return 0;
4574 }
4575
Zhu Yib481de92007-09-25 17:54:57 -07004576 q = AC_NUM - 1 - queue;
4577
4578 spin_lock_irqsave(&priv->lock, flags);
4579
4580 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
4581 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
4582 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
4583 priv->qos_data.def_qos_parm.ac[q].edca_txop =
Johannes Berg3330d7b2008-02-10 16:49:38 +01004584 cpu_to_le16((params->txop * 32));
Zhu Yib481de92007-09-25 17:54:57 -07004585
4586 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
4587 priv->qos_data.qos_active = 1;
4588
4589 spin_unlock_irqrestore(&priv->lock, flags);
4590
4591 mutex_lock(&priv->mutex);
Johannes Berg05c914f2008-09-11 00:01:58 +02004592 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004593 iwl3945_activate_qos(priv, 1);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004594 else if (priv->assoc_id && iwl_is_associated(priv))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004595 iwl3945_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004596
4597 mutex_unlock(&priv->mutex);
4598
Tomas Winklere1623442009-01-27 14:27:56 -08004599 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004600 return 0;
4601}
4602
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004603static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004604 struct ieee80211_tx_queue_stats *stats)
4605{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004606 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004607 int i, avail;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08004608 struct iwl_tx_queue *txq;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004609 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07004610 unsigned long flags;
4611
Tomas Winklere1623442009-01-27 14:27:56 -08004612 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004613
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004614 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004615 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004616 return -EIO;
4617 }
4618
4619 spin_lock_irqsave(&priv->lock, flags);
4620
4621 for (i = 0; i < AC_NUM; i++) {
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08004622 txq = &priv->txq[i];
Zhu Yib481de92007-09-25 17:54:57 -07004623 q = &txq->q;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004624 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07004625
Johannes Berg57ffc582008-04-29 17:18:59 +02004626 stats[i].len = q->n_window - avail;
4627 stats[i].limit = q->n_window - q->high_mark;
4628 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07004629
4630 }
4631 spin_unlock_irqrestore(&priv->lock, flags);
4632
Tomas Winklere1623442009-01-27 14:27:56 -08004633 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004634
4635 return 0;
4636}
4637
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004638static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07004639{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004640 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004641 unsigned long flags;
4642
4643 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08004644 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004645
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004646 iwl_reset_qos(priv);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08004647
Zhu Yib481de92007-09-25 17:54:57 -07004648 spin_lock_irqsave(&priv->lock, flags);
4649 priv->assoc_id = 0;
4650 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004651
4652 /* new association get rid of ibss beacon skb */
4653 if (priv->ibss_beacon)
4654 dev_kfree_skb(priv->ibss_beacon);
4655
4656 priv->ibss_beacon = NULL;
4657
4658 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08004659 priv->timestamp = 0;
Johannes Berg05c914f2008-09-11 00:01:58 +02004660 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
Zhu Yib481de92007-09-25 17:54:57 -07004661 priv->beacon_int = 0;
4662
4663 spin_unlock_irqrestore(&priv->lock, flags);
4664
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004665 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004666 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +08004667 mutex_unlock(&priv->mutex);
4668 return;
4669 }
4670
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004671 /* we are restarting association process
4672 * clear RXON_FILTER_ASSOC_MSK bit
4673 */
Johannes Berg05c914f2008-09-11 00:01:58 +02004674 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004675 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004676 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004677 iwl3945_commit_rxon(priv);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004678 }
4679
Zhu Yib481de92007-09-25 17:54:57 -07004680 /* Per mac80211.h: This is only used in IBSS mode... */
Johannes Berg05c914f2008-09-11 00:01:58 +02004681 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004682
Tomas Winklere1623442009-01-27 14:27:56 -08004683 IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07004684 mutex_unlock(&priv->mutex);
4685 return;
4686 }
4687
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004688 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004689
4690 mutex_unlock(&priv->mutex);
4691
Tomas Winklere1623442009-01-27 14:27:56 -08004692 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004693
4694}
4695
Johannes Berge039fa42008-05-15 12:55:29 +02004696static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07004697{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004698 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004699 unsigned long flags;
4700
Tomas Winklere1623442009-01-27 14:27:56 -08004701 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004702
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004703 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004704 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004705 return -EIO;
4706 }
4707
Johannes Berg05c914f2008-09-11 00:01:58 +02004708 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Tomas Winklere1623442009-01-27 14:27:56 -08004709 IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07004710 return -EIO;
4711 }
4712
4713 spin_lock_irqsave(&priv->lock, flags);
4714
4715 if (priv->ibss_beacon)
4716 dev_kfree_skb(priv->ibss_beacon);
4717
4718 priv->ibss_beacon = skb;
4719
4720 priv->assoc_id = 0;
4721
Tomas Winklere1623442009-01-27 14:27:56 -08004722 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004723 spin_unlock_irqrestore(&priv->lock, flags);
4724
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004725 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004726
Abhijeet Kolekardc4b1e72008-09-03 11:26:30 +08004727 iwl3945_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004728
Zhu Yib481de92007-09-25 17:54:57 -07004729
4730 return 0;
4731}
4732
4733/*****************************************************************************
4734 *
4735 * sysfs attributes
4736 *
4737 *****************************************************************************/
4738
Samuel Ortizd08853a2009-01-23 13:45:17 -08004739#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07004740
4741/*
4742 * The following adds a new attribute to the sysfs representation
4743 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
4744 * used for controlling the debug level.
4745 *
4746 * See the level definitions in iwl for details.
4747 */
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004748static ssize_t show_debug_level(struct device *d,
4749 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07004750{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004751 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004752
4753 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07004754}
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004755static ssize_t store_debug_level(struct device *d,
4756 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07004757 const char *buf, size_t count)
4758{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004759 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004760 unsigned long val;
4761 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07004762
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004763 ret = strict_strtoul(buf, 0, &val);
4764 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08004765 IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07004766 else
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004767 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07004768
4769 return strnlen(buf, count);
4770}
4771
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004772static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
4773 show_debug_level, store_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07004774
Samuel Ortizd08853a2009-01-23 13:45:17 -08004775#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07004776
Zhu Yib481de92007-09-25 17:54:57 -07004777static ssize_t show_temperature(struct device *d,
4778 struct device_attribute *attr, char *buf)
4779{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004780 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004781
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004782 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004783 return -EAGAIN;
4784
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004785 return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
Zhu Yib481de92007-09-25 17:54:57 -07004786}
4787
4788static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
4789
Zhu Yib481de92007-09-25 17:54:57 -07004790static ssize_t show_tx_power(struct device *d,
4791 struct device_attribute *attr, char *buf)
4792{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004793 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08004794 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07004795}
4796
4797static ssize_t store_tx_power(struct device *d,
4798 struct device_attribute *attr,
4799 const char *buf, size_t count)
4800{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004801 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004802 char *p = (char *)buf;
4803 u32 val;
4804
4805 val = simple_strtoul(p, &p, 10);
4806 if (p == buf)
Tomas Winkler978785a2008-12-19 10:37:31 +08004807 IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07004808 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004809 iwl3945_hw_reg_set_txpower(priv, val);
Zhu Yib481de92007-09-25 17:54:57 -07004810
4811 return count;
4812}
4813
4814static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
4815
4816static ssize_t show_flags(struct device *d,
4817 struct device_attribute *attr, char *buf)
4818{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004819 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004820
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004821 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
Zhu Yib481de92007-09-25 17:54:57 -07004822}
4823
4824static ssize_t store_flags(struct device *d,
4825 struct device_attribute *attr,
4826 const char *buf, size_t count)
4827{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004828 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004829 u32 flags = simple_strtoul(buf, NULL, 0);
4830
4831 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004832 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
Zhu Yib481de92007-09-25 17:54:57 -07004833 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004834 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004835 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004836 else {
Tomas Winklere1623442009-01-27 14:27:56 -08004837 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
Zhu Yib481de92007-09-25 17:54:57 -07004838 flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004839 priv->staging_rxon.flags = cpu_to_le32(flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004840 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004841 }
4842 }
4843 mutex_unlock(&priv->mutex);
4844
4845 return count;
4846}
4847
4848static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
4849
4850static ssize_t show_filter_flags(struct device *d,
4851 struct device_attribute *attr, char *buf)
4852{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004853 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004854
4855 return sprintf(buf, "0x%04X\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004856 le32_to_cpu(priv->active_rxon.filter_flags));
Zhu Yib481de92007-09-25 17:54:57 -07004857}
4858
4859static ssize_t store_filter_flags(struct device *d,
4860 struct device_attribute *attr,
4861 const char *buf, size_t count)
4862{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004863 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004864 u32 filter_flags = simple_strtoul(buf, NULL, 0);
4865
4866 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004867 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
Zhu Yib481de92007-09-25 17:54:57 -07004868 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004869 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004870 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004871 else {
Tomas Winklere1623442009-01-27 14:27:56 -08004872 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
Zhu Yib481de92007-09-25 17:54:57 -07004873 "0x%04X\n", filter_flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004874 priv->staging_rxon.filter_flags =
Zhu Yib481de92007-09-25 17:54:57 -07004875 cpu_to_le32(filter_flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004876 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004877 }
4878 }
4879 mutex_unlock(&priv->mutex);
4880
4881 return count;
4882}
4883
4884static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
4885 store_filter_flags);
4886
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004887#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004888
4889static ssize_t show_measurement(struct device *d,
4890 struct device_attribute *attr, char *buf)
4891{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004892 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler600c0e12008-12-19 10:37:04 +08004893 struct iwl_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004894 u32 size = sizeof(measure_report), len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03004895 u8 *data = (u8 *)&measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004896 unsigned long flags;
4897
4898 spin_lock_irqsave(&priv->lock, flags);
4899 if (!(priv->measurement_status & MEASUREMENT_READY)) {
4900 spin_unlock_irqrestore(&priv->lock, flags);
4901 return 0;
4902 }
4903 memcpy(&measure_report, &priv->measure_report, size);
4904 priv->measurement_status = 0;
4905 spin_unlock_irqrestore(&priv->lock, flags);
4906
4907 while (size && (PAGE_SIZE - len)) {
4908 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4909 PAGE_SIZE - len, 1);
4910 len = strlen(buf);
4911 if (PAGE_SIZE - len)
4912 buf[len++] = '\n';
4913
4914 ofs += 16;
4915 size -= min(size, 16U);
4916 }
4917
4918 return len;
4919}
4920
4921static ssize_t store_measurement(struct device *d,
4922 struct device_attribute *attr,
4923 const char *buf, size_t count)
4924{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004925 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004926 struct ieee80211_measurement_params params = {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004927 .channel = le16_to_cpu(priv->active_rxon.channel),
Zhu Yib481de92007-09-25 17:54:57 -07004928 .start_time = cpu_to_le64(priv->last_tsf),
4929 .duration = cpu_to_le16(1),
4930 };
4931 u8 type = IWL_MEASURE_BASIC;
4932 u8 buffer[32];
4933 u8 channel;
4934
4935 if (count) {
4936 char *p = buffer;
4937 strncpy(buffer, buf, min(sizeof(buffer), count));
4938 channel = simple_strtoul(p, NULL, 0);
4939 if (channel)
4940 params.channel = channel;
4941
4942 p = buffer;
4943 while (*p && *p != ' ')
4944 p++;
4945 if (*p)
4946 type = simple_strtoul(p + 1, NULL, 0);
4947 }
4948
Tomas Winklere1623442009-01-27 14:27:56 -08004949 IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on "
Zhu Yib481de92007-09-25 17:54:57 -07004950 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004951 iwl3945_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07004952
4953 return count;
4954}
4955
4956static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
4957 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004958#endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07004959
Zhu Yib481de92007-09-25 17:54:57 -07004960static ssize_t store_retry_rate(struct device *d,
4961 struct device_attribute *attr,
4962 const char *buf, size_t count)
4963{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004964 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004965
4966 priv->retry_rate = simple_strtoul(buf, NULL, 0);
4967 if (priv->retry_rate <= 0)
4968 priv->retry_rate = 1;
4969
4970 return count;
4971}
4972
4973static ssize_t show_retry_rate(struct device *d,
4974 struct device_attribute *attr, char *buf)
4975{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004976 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004977 return sprintf(buf, "%d", priv->retry_rate);
4978}
4979
4980static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
4981 store_retry_rate);
4982
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004983
Zhu Yib481de92007-09-25 17:54:57 -07004984static ssize_t store_power_level(struct device *d,
4985 struct device_attribute *attr,
4986 const char *buf, size_t count)
4987{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004988 struct iwl_priv *priv = dev_get_drvdata(d);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004989 int ret;
4990 unsigned long mode;
Zhu Yib481de92007-09-25 17:54:57 -07004991
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004992
Zhu Yib481de92007-09-25 17:54:57 -07004993 mutex_lock(&priv->mutex);
4994
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004995 if (!iwl_is_ready(priv)) {
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004996 ret = -EAGAIN;
Zhu Yib481de92007-09-25 17:54:57 -07004997 goto out;
4998 }
4999
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08005000 ret = strict_strtoul(buf, 10, &mode);
5001 if (ret)
5002 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07005003
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08005004 ret = iwl_power_set_user_mode(priv, mode);
5005 if (ret) {
5006 IWL_DEBUG_MAC80211(priv, "failed setting power mode.\n");
5007 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07005008 }
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08005009 ret = count;
Zhu Yib481de92007-09-25 17:54:57 -07005010
5011 out:
5012 mutex_unlock(&priv->mutex);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08005013 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07005014}
5015
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08005016static ssize_t show_power_level(struct device *d,
5017 struct device_attribute *attr, char *buf)
5018{
5019 struct iwl_priv *priv = dev_get_drvdata(d);
5020 int mode = priv->power_data.user_power_setting;
5021 int system = priv->power_data.system_power_setting;
5022 int level = priv->power_data.power_mode;
5023 char *p = buf;
5024
5025 switch (system) {
5026 case IWL_POWER_SYS_AUTO:
5027 p += sprintf(p, "SYSTEM:auto");
5028 break;
5029 case IWL_POWER_SYS_AC:
5030 p += sprintf(p, "SYSTEM:ac");
5031 break;
5032 case IWL_POWER_SYS_BATTERY:
5033 p += sprintf(p, "SYSTEM:battery");
5034 break;
5035 }
5036
5037 p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
5038 "fixed" : "auto");
5039 p += sprintf(p, "\tINDEX:%d", level);
5040 p += sprintf(p, "\n");
5041 return p - buf + 1;
5042}
5043
5044static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR,
5045 show_power_level, store_power_level);
5046
Zhu Yib481de92007-09-25 17:54:57 -07005047#define MAX_WX_STRING 80
5048
5049/* Values are in microsecond */
5050static const s32 timeout_duration[] = {
5051 350000,
5052 250000,
5053 75000,
5054 37000,
5055 25000,
5056};
5057static const s32 period_duration[] = {
5058 400000,
5059 700000,
5060 1000000,
5061 1000000,
5062 1000000
5063};
5064
Zhu Yib481de92007-09-25 17:54:57 -07005065static ssize_t show_channels(struct device *d,
5066 struct device_attribute *attr, char *buf)
5067{
Johannes Berg8318d782008-01-24 19:38:38 +01005068 /* all this shit doesn't belong into sysfs anyway */
5069 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07005070}
5071
5072static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
5073
5074static ssize_t show_statistics(struct device *d,
5075 struct device_attribute *attr, char *buf)
5076{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005077 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005078 u32 size = sizeof(struct iwl3945_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07005079 u32 len = 0, ofs = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005080 u8 *data = (u8 *)&priv->statistics_39;
Zhu Yib481de92007-09-25 17:54:57 -07005081 int rc = 0;
5082
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005083 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07005084 return -EAGAIN;
5085
5086 mutex_lock(&priv->mutex);
Samuel Ortiz17f841c2009-01-23 13:45:20 -08005087 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07005088 mutex_unlock(&priv->mutex);
5089
5090 if (rc) {
5091 len = sprintf(buf,
5092 "Error sending statistics request: 0x%08X\n", rc);
5093 return len;
5094 }
5095
5096 while (size && (PAGE_SIZE - len)) {
5097 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
5098 PAGE_SIZE - len, 1);
5099 len = strlen(buf);
5100 if (PAGE_SIZE - len)
5101 buf[len++] = '\n';
5102
5103 ofs += 16;
5104 size -= min(size, 16U);
5105 }
5106
5107 return len;
5108}
5109
5110static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
5111
5112static ssize_t show_antenna(struct device *d,
5113 struct device_attribute *attr, char *buf)
5114{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005115 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07005116
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005117 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07005118 return -EAGAIN;
5119
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08005120 return sprintf(buf, "%d\n", iwl3945_mod_params.antenna);
Zhu Yib481de92007-09-25 17:54:57 -07005121}
5122
5123static ssize_t store_antenna(struct device *d,
5124 struct device_attribute *attr,
5125 const char *buf, size_t count)
5126{
Winkler, Tomas7530f852009-01-27 14:27:53 -08005127 struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07005128 int ant;
Zhu Yib481de92007-09-25 17:54:57 -07005129
5130 if (count == 0)
5131 return 0;
5132
5133 if (sscanf(buf, "%1i", &ant) != 1) {
Tomas Winklere1623442009-01-27 14:27:56 -08005134 IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n");
Zhu Yib481de92007-09-25 17:54:57 -07005135 return count;
5136 }
5137
5138 if ((ant >= 0) && (ant <= 2)) {
Tomas Winklere1623442009-01-27 14:27:56 -08005139 IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant);
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08005140 iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant;
Zhu Yib481de92007-09-25 17:54:57 -07005141 } else
Tomas Winklere1623442009-01-27 14:27:56 -08005142 IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant);
Zhu Yib481de92007-09-25 17:54:57 -07005143
5144
5145 return count;
5146}
5147
5148static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
5149
5150static ssize_t show_status(struct device *d,
5151 struct device_attribute *attr, char *buf)
5152{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005153 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005154 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07005155 return -EAGAIN;
5156 return sprintf(buf, "0x%08x\n", (int)priv->status);
5157}
5158
5159static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
5160
5161static ssize_t dump_error_log(struct device *d,
5162 struct device_attribute *attr,
5163 const char *buf, size_t count)
5164{
5165 char *p = (char *)buf;
5166
5167 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005168 iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07005169
5170 return strnlen(buf, count);
5171}
5172
5173static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
5174
5175static ssize_t dump_event_log(struct device *d,
5176 struct device_attribute *attr,
5177 const char *buf, size_t count)
5178{
5179 char *p = (char *)buf;
5180
5181 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005182 iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07005183
5184 return strnlen(buf, count);
5185}
5186
5187static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
5188
5189/*****************************************************************************
5190 *
Tomas Winklera96a27f2008-10-23 23:48:56 -07005191 * driver setup and tear down
Zhu Yib481de92007-09-25 17:54:57 -07005192 *
5193 *****************************************************************************/
5194
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005195static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005196{
5197 priv->workqueue = create_workqueue(DRV_NAME);
5198
5199 init_waitqueue_head(&priv->wait_command_queue);
5200
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005201 INIT_WORK(&priv->up, iwl3945_bg_up);
5202 INIT_WORK(&priv->restart, iwl3945_bg_restart);
5203 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005204 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005205 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005206 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
5207 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
Helmut Schaa26635162009-01-15 09:38:44 +01005208 INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll);
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08005209 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
5210 INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
5211 INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
5212 INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
Zhu Yib481de92007-09-25 17:54:57 -07005213
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005214 iwl3945_hw_setup_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005215
5216 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005217 iwl3945_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07005218}
5219
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005220static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005221{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005222 iwl3945_hw_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005223
Joonwoo Parke47eb6a2007-11-29 10:42:49 +09005224 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07005225 cancel_delayed_work(&priv->scan_check);
5226 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07005227 cancel_work_sync(&priv->beacon_update);
5228}
5229
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005230static struct attribute *iwl3945_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07005231 &dev_attr_antenna.attr,
5232 &dev_attr_channels.attr,
5233 &dev_attr_dump_errors.attr,
5234 &dev_attr_dump_events.attr,
5235 &dev_attr_flags.attr,
5236 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08005237#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07005238 &dev_attr_measurement.attr,
5239#endif
5240 &dev_attr_power_level.attr,
Zhu Yib481de92007-09-25 17:54:57 -07005241 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07005242 &dev_attr_statistics.attr,
5243 &dev_attr_status.attr,
5244 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07005245 &dev_attr_tx_power.attr,
Samuel Ortizd08853a2009-01-23 13:45:17 -08005246#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005247 &dev_attr_debug_level.attr,
5248#endif
Zhu Yib481de92007-09-25 17:54:57 -07005249 NULL
5250};
5251
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005252static struct attribute_group iwl3945_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07005253 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005254 .attrs = iwl3945_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07005255};
5256
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005257static struct ieee80211_ops iwl3945_hw_ops = {
5258 .tx = iwl3945_mac_tx,
5259 .start = iwl3945_mac_start,
5260 .stop = iwl3945_mac_stop,
5261 .add_interface = iwl3945_mac_add_interface,
5262 .remove_interface = iwl3945_mac_remove_interface,
5263 .config = iwl3945_mac_config,
5264 .config_interface = iwl3945_mac_config_interface,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08005265 .configure_filter = iwl_configure_filter,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005266 .set_key = iwl3945_mac_set_key,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005267 .get_tx_stats = iwl3945_mac_get_tx_stats,
5268 .conf_tx = iwl3945_mac_conf_tx,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005269 .reset_tsf = iwl3945_mac_reset_tsf,
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005270 .bss_info_changed = iwl3945_bss_info_changed,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005271 .hw_scan = iwl3945_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07005272};
5273
Winkler, Tomase52119c2008-12-22 11:31:19 +08005274static int iwl3945_init_drv(struct iwl_priv *priv)
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005275{
5276 int ret;
Samuel Ortize6148912009-01-23 13:45:15 -08005277 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005278
5279 priv->retry_rate = 1;
5280 priv->ibss_beacon = NULL;
5281
5282 spin_lock_init(&priv->lock);
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08005283 spin_lock_init(&priv->power_data.lock);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005284 spin_lock_init(&priv->sta_lock);
5285 spin_lock_init(&priv->hcmd_lock);
5286
5287 INIT_LIST_HEAD(&priv->free_frames);
5288
5289 mutex_init(&priv->mutex);
5290
5291 /* Clear the driver's (not device's) station table */
5292 iwl3945_clear_stations_table(priv);
5293
5294 priv->data_retry_limit = -1;
5295 priv->ieee_channels = NULL;
5296 priv->ieee_rates = NULL;
5297 priv->band = IEEE80211_BAND_2GHZ;
5298
5299 priv->iw_mode = NL80211_IFTYPE_STATION;
5300
5301 iwl_reset_qos(priv);
5302
5303 priv->qos_data.qos_active = 0;
5304 priv->qos_data.qos_cap.val = 0;
5305
5306 priv->rates_mask = IWL_RATES_MASK;
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08005307 /* If power management is turned on, default to CAM mode */
5308 priv->power_mode = IWL_POWER_MODE_CAM;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08005309 priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005310
Samuel Ortize6148912009-01-23 13:45:15 -08005311 if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
5312 IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
5313 eeprom->version);
5314 ret = -EINVAL;
5315 goto err;
5316 }
5317 ret = iwl_init_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005318 if (ret) {
5319 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
5320 goto err;
5321 }
5322
Samuel Ortize6148912009-01-23 13:45:15 -08005323 /* Set up txpower settings in driver for all channels */
5324 if (iwl3945_txpower_set_from_eeprom(priv)) {
5325 ret = -EIO;
5326 goto err_free_channel_map;
5327 }
5328
Samuel Ortiz534166d2009-01-23 13:45:16 -08005329 ret = iwlcore_init_geos(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005330 if (ret) {
5331 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
5332 goto err_free_channel_map;
5333 }
Samuel Ortiz534166d2009-01-23 13:45:16 -08005334 iwl3945_init_hw_rates(priv, priv->ieee_rates);
5335
5336 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
5337 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
5338 &priv->bands[IEEE80211_BAND_2GHZ];
5339 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
5340 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
5341 &priv->bands[IEEE80211_BAND_5GHZ];
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005342
5343 return 0;
5344
5345err_free_channel_map:
Samuel Ortize6148912009-01-23 13:45:15 -08005346 iwl_free_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005347err:
5348 return ret;
5349}
5350
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005351static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07005352{
5353 int err = 0;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005354 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07005355 struct ieee80211_hw *hw;
Kolekar, Abhijeetc0f20d92008-12-19 10:37:19 +08005356 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Samuel Ortize6148912009-01-23 13:45:15 -08005357 struct iwl3945_eeprom *eeprom;
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005358 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07005359
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005360 /***********************
5361 * 1. Allocating HW data
5362 * ********************/
5363
Zhu Yib481de92007-09-25 17:54:57 -07005364 /* mac80211 allocates memory for this device instance, including
5365 * space for this driver's private structure */
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005366 hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
Zhu Yib481de92007-09-25 17:54:57 -07005367 if (hw == NULL) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005368 printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
Zhu Yib481de92007-09-25 17:54:57 -07005369 err = -ENOMEM;
5370 goto out;
5371 }
Zhu Yib481de92007-09-25 17:54:57 -07005372 priv = hw->priv;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005373 SET_IEEE80211_DEV(hw, &pdev->dev);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005374
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005375 if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) ||
5376 (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005377 IWL_ERR(priv,
5378 "invalid queues_num, should be between %d and %d\n",
5379 IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES);
Samuel Ortiza3139c52008-12-19 10:37:09 +08005380 err = -EINVAL;
5381 goto out;
5382 }
5383
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005384 /*
5385 * Disabling hardware scan means that mac80211 will perform scans
5386 * "the hard way", rather than using device's scan.
5387 */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005388 if (iwl3945_mod_params.disable_hw_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08005389 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005390 iwl3945_hw_ops.hw_scan = NULL;
5391 }
5392
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005393
Tomas Winklere1623442009-01-27 14:27:56 -08005394 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005395 priv->cfg = cfg;
5396 priv->pci_dev = pdev;
5397
Samuel Ortizd08853a2009-01-23 13:45:17 -08005398#ifdef CONFIG_IWLWIFI_DEBUG
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005399 priv->debug_level = iwl3945_mod_params.debug;
5400 atomic_set(&priv->restrict_refcnt, 0);
5401#endif
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005402 hw->rate_control_algorithm = "iwl-3945-rs";
5403 hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
5404
Bruno Randolf566bfe52008-05-08 19:15:40 +02005405 /* Tell mac80211 our characteristics */
Johannes Berg605a0bd2008-07-15 10:10:01 +02005406 hw->flags = IEEE80211_HW_SIGNAL_DBM |
Bruno Randolf566bfe52008-05-08 19:15:40 +02005407 IEEE80211_HW_NOISE_DBM;
Zhu Yib481de92007-09-25 17:54:57 -07005408
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -07005409 hw->wiphy->interface_modes =
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -07005410 BIT(NL80211_IFTYPE_STATION) |
5411 BIT(NL80211_IFTYPE_ADHOC);
5412
Luis R. Rodriguez2a44f912009-01-22 15:05:49 -08005413 hw->wiphy->custom_regulatory = true;
Luis R. Rodriguezea4a82dc2008-11-12 14:22:04 -08005414
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005415 /* 4 EDCA QOS priorities */
Zhu Yib481de92007-09-25 17:54:57 -07005416 hw->queues = 4;
5417
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005418 /***************************
5419 * 2. Initializing PCI bus
5420 * *************************/
Zhu Yib481de92007-09-25 17:54:57 -07005421 if (pci_enable_device(pdev)) {
5422 err = -ENODEV;
5423 goto out_ieee80211_free_hw;
5424 }
5425
5426 pci_set_master(pdev);
5427
Zhu Yib481de92007-09-25 17:54:57 -07005428 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
5429 if (!err)
5430 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
5431 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08005432 IWL_WARN(priv, "No suitable DMA available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07005433 goto out_pci_disable_device;
5434 }
5435
5436 pci_set_drvdata(pdev, priv);
5437 err = pci_request_regions(pdev, DRV_NAME);
5438 if (err)
5439 goto out_pci_disable_device;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005440
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005441 /***********************
5442 * 3. Read REV Register
5443 * ********************/
Zhu Yib481de92007-09-25 17:54:57 -07005444 priv->hw_base = pci_iomap(pdev, 0, 0);
5445 if (!priv->hw_base) {
5446 err = -ENODEV;
5447 goto out_pci_release_regions;
5448 }
5449
Tomas Winklere1623442009-01-27 14:27:56 -08005450 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Zhu Yib481de92007-09-25 17:54:57 -07005451 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08005452 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Zhu Yib481de92007-09-25 17:54:57 -07005453
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005454 /* We disable the RETRY_TIMEOUT register (0x41) to keep
5455 * PCI Tx retries from interfering with C3 CPU state */
5456 pci_write_config_byte(pdev, 0x41, 0x00);
Zhu Yib481de92007-09-25 17:54:57 -07005457
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005458 /* amp init */
5459 err = priv->cfg->ops->lib->apm_ops.init(priv);
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005460 if (err < 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08005461 IWL_DEBUG_INFO(priv, "Failed to init APMG\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005462 goto out_iounmap;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005463 }
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005464
5465 /***********************
5466 * 4. Read EEPROM
5467 * ********************/
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005468
Zhu Yi5a66926a2008-01-14 17:46:18 -08005469 /* Read the EEPROM */
Samuel Ortize6148912009-01-23 13:45:15 -08005470 err = iwl_eeprom_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005471 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005472 IWL_ERR(priv, "Unable to init EEPROM\n");
Zhu Yi5a66926a2008-01-14 17:46:18 -08005473 goto out_remove_sysfs;
5474 }
5475 /* MAC Address location in EEPROM same for 3945/4965 */
Samuel Ortize6148912009-01-23 13:45:15 -08005476 eeprom = (struct iwl3945_eeprom *)priv->eeprom;
5477 memcpy(priv->mac_addr, eeprom->mac_address, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08005478 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
Zhu Yi5a66926a2008-01-14 17:46:18 -08005479 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
5480
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005481 /***********************
5482 * 5. Setup HW Constants
5483 * ********************/
5484 /* Device-specific setup */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005485 if (iwl3945_hw_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005486 IWL_ERR(priv, "failed to set hw settings\n");
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005487 goto out_iounmap;
5488 }
5489
5490 /***********************
5491 * 6. Setup priv
5492 * ********************/
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005493
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005494 err = iwl3945_init_drv(priv);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005495 if (err) {
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005496 IWL_ERR(priv, "initializing driver failed\n");
5497 goto out_free_geos;
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005498 }
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005499
Tomas Winkler978785a2008-12-19 10:37:31 +08005500 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
5501 priv->cfg->name);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005502
5503 /***********************************
5504 * 7. Initialize Module Parameters
5505 * **********************************/
5506
5507 /* Initialize module parameter values here */
5508 /* Disable radio (SW RF KILL) via parameter when loading driver */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005509 if (iwl3945_mod_params.disable) {
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005510 set_bit(STATUS_RF_KILL_SW, &priv->status);
Tomas Winklere1623442009-01-27 14:27:56 -08005511 IWL_DEBUG_INFO(priv, "Radio disabled.\n");
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005512 }
5513
5514
5515 /***********************
5516 * 8. Setup Services
5517 * ********************/
5518
5519 spin_lock_irqsave(&priv->lock, flags);
5520 iwl3945_disable_interrupts(priv);
5521 spin_unlock_irqrestore(&priv->lock, flags);
5522
Helmut Schaa26635162009-01-15 09:38:44 +01005523 pci_enable_msi(priv->pci_dev);
5524
5525 err = request_irq(priv->pci_dev->irq, iwl3945_isr, IRQF_SHARED,
5526 DRV_NAME, priv);
5527 if (err) {
5528 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
5529 goto out_disable_msi;
5530 }
5531
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005532 err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
5533 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005534 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005535 goto out_release_irq;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005536 }
5537
Samuel Ortiz8ccde882009-01-27 14:27:52 -08005538 iwl_set_rxon_channel(priv,
5539 &priv->bands[IEEE80211_BAND_2GHZ].channels[5]);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005540 iwl3945_setup_deferred_work(priv);
5541 iwl3945_setup_rx_handlers(priv);
5542
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005543 /*********************************
Helmut Schaa26635162009-01-15 09:38:44 +01005544 * 9. Setup and Register mac80211
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005545 * *******************************/
5546
Zhu Yi5a66926a2008-01-14 17:46:18 -08005547 err = ieee80211_register_hw(priv->hw);
5548 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005549 IWL_ERR(priv, "Failed to register network device: %d\n", err);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005550 goto out_remove_sysfs;
Zhu Yib481de92007-09-25 17:54:57 -07005551 }
5552
Zhu Yi5a66926a2008-01-14 17:46:18 -08005553 priv->hw->conf.beacon_int = 100;
5554 priv->mac80211_registered = 1;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005555
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005556 err = iwl_rfkill_init(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005557 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08005558 IWL_ERR(priv, "Unable to initialize RFKILL system. "
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005559 "Ignoring error: %d\n", err);
5560
Helmut Schaa26635162009-01-15 09:38:44 +01005561 /* Start monitoring the killswitch */
5562 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
5563 2 * HZ);
5564
Zhu Yib481de92007-09-25 17:54:57 -07005565 return 0;
5566
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005567 out_remove_sysfs:
5568 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005569 out_free_geos:
Samuel Ortiz534166d2009-01-23 13:45:16 -08005570 iwlcore_free_geos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005571
5572 out_release_irq:
Helmut Schaa26635162009-01-15 09:38:44 +01005573 free_irq(priv->pci_dev->irq, priv);
Zhu Yib481de92007-09-25 17:54:57 -07005574 destroy_workqueue(priv->workqueue);
5575 priv->workqueue = NULL;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005576 iwl3945_unset_hw_params(priv);
Helmut Schaa26635162009-01-15 09:38:44 +01005577 out_disable_msi:
5578 pci_disable_msi(priv->pci_dev);
Zhu Yib481de92007-09-25 17:54:57 -07005579 out_iounmap:
5580 pci_iounmap(pdev, priv->hw_base);
5581 out_pci_release_regions:
5582 pci_release_regions(pdev);
5583 out_pci_disable_device:
5584 pci_disable_device(pdev);
5585 pci_set_drvdata(pdev, NULL);
5586 out_ieee80211_free_hw:
5587 ieee80211_free_hw(priv->hw);
5588 out:
5589 return err;
5590}
5591
Reinette Chatrec83dbf62008-03-21 13:53:41 -07005592static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07005593{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005594 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005595 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07005596
5597 if (!priv)
5598 return;
5599
Tomas Winklere1623442009-01-27 14:27:56 -08005600 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07005601
Zhu Yib481de92007-09-25 17:54:57 -07005602 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08005603
Kolekar, Abhijeetd552bfb2008-12-19 10:37:41 +08005604 if (priv->mac80211_registered) {
5605 ieee80211_unregister_hw(priv->hw);
5606 priv->mac80211_registered = 0;
5607 } else {
5608 iwl3945_down(priv);
5609 }
Zhu Yib481de92007-09-25 17:54:57 -07005610
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005611 /* make sure we flush any pending irq or
5612 * tasklet for the driver
5613 */
5614 spin_lock_irqsave(&priv->lock, flags);
5615 iwl3945_disable_interrupts(priv);
5616 spin_unlock_irqrestore(&priv->lock, flags);
5617
5618 iwl_synchronize_irq(priv);
5619
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005620 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07005621
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005622 iwl_rfkill_unregister(priv);
Helmut Schaa26635162009-01-15 09:38:44 +01005623 cancel_delayed_work(&priv->rfkill_poll);
5624
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005625 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005626
5627 if (priv->rxq.bd)
Winkler, Tomas51af3d32008-12-22 11:31:23 +08005628 iwl_rx_queue_free(priv, &priv->rxq);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005629 iwl3945_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005630
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005631 iwl3945_unset_hw_params(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005632 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005633
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08005634 /*netif_stop_queue(dev); */
5635 flush_workqueue(priv->workqueue);
5636
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005637 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07005638 * priv->workqueue... so we can't take down the workqueue
5639 * until now... */
5640 destroy_workqueue(priv->workqueue);
5641 priv->workqueue = NULL;
5642
Helmut Schaa26635162009-01-15 09:38:44 +01005643 free_irq(pdev->irq, priv);
5644 pci_disable_msi(pdev);
5645
Zhu Yib481de92007-09-25 17:54:57 -07005646 pci_iounmap(pdev, priv->hw_base);
5647 pci_release_regions(pdev);
5648 pci_disable_device(pdev);
5649 pci_set_drvdata(pdev, NULL);
5650
Samuel Ortize6148912009-01-23 13:45:15 -08005651 iwl_free_channel_map(priv);
Samuel Ortiz534166d2009-01-23 13:45:16 -08005652 iwlcore_free_geos(priv);
Winkler, Tomas805cee52009-01-19 15:30:28 -08005653 kfree(priv->scan);
Zhu Yib481de92007-09-25 17:54:57 -07005654 if (priv->ibss_beacon)
5655 dev_kfree_skb(priv->ibss_beacon);
5656
5657 ieee80211_free_hw(priv->hw);
5658}
5659
5660#ifdef CONFIG_PM
5661
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005662static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07005663{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005664 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005665
Zhu Yie655b9f2008-01-24 02:19:38 -08005666 if (priv->is_open) {
5667 set_bit(STATUS_IN_SUSPEND, &priv->status);
5668 iwl3945_mac_stop(priv->hw);
5669 priv->is_open = 1;
5670 }
Helmut Schaa26635162009-01-15 09:38:44 +01005671 pci_save_state(pdev);
5672 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005673 pci_set_power_state(pdev, PCI_D3hot);
5674
Zhu Yib481de92007-09-25 17:54:57 -07005675 return 0;
5676}
5677
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005678static int iwl3945_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07005679{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005680 struct iwl_priv *priv = pci_get_drvdata(pdev);
Winkler, Tomas450154e2009-01-27 14:27:55 -08005681 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07005682
Zhu Yib481de92007-09-25 17:54:57 -07005683 pci_set_power_state(pdev, PCI_D0);
Winkler, Tomas450154e2009-01-27 14:27:55 -08005684 ret = pci_enable_device(pdev);
5685 if (ret)
5686 return ret;
Helmut Schaa26635162009-01-15 09:38:44 +01005687 pci_restore_state(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005688
Zhu Yie655b9f2008-01-24 02:19:38 -08005689 if (priv->is_open)
5690 iwl3945_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07005691
Zhu Yie655b9f2008-01-24 02:19:38 -08005692 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07005693 return 0;
5694}
5695
5696#endif /* CONFIG_PM */
5697
5698/*****************************************************************************
5699 *
5700 * driver and module entry point
5701 *
5702 *****************************************************************************/
5703
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005704static struct pci_driver iwl3945_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07005705 .name = DRV_NAME,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005706 .id_table = iwl3945_hw_card_ids,
5707 .probe = iwl3945_pci_probe,
5708 .remove = __devexit_p(iwl3945_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07005709#ifdef CONFIG_PM
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005710 .suspend = iwl3945_pci_suspend,
5711 .resume = iwl3945_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07005712#endif
5713};
5714
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005715static int __init iwl3945_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07005716{
5717
5718 int ret;
5719 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
5720 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005721
5722 ret = iwl3945_rate_control_register();
5723 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005724 printk(KERN_ERR DRV_NAME
5725 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005726 return ret;
5727 }
5728
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005729 ret = pci_register_driver(&iwl3945_driver);
Zhu Yib481de92007-09-25 17:54:57 -07005730 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005731 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005732 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07005733 }
Zhu Yib481de92007-09-25 17:54:57 -07005734
5735 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005736
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005737error_register:
5738 iwl3945_rate_control_unregister();
5739 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07005740}
5741
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005742static void __exit iwl3945_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07005743{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005744 pci_unregister_driver(&iwl3945_driver);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005745 iwl3945_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07005746}
5747
Reinette Chatrea0987a82008-12-02 12:14:06 -08005748MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
Zhu Yi25cb6ca2008-09-11 11:45:22 +08005749
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005750module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005751MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005752module_param_named(disable, iwl3945_mod_params.disable, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005753MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -08005754module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
5755MODULE_PARM_DESC(swcrypto,
5756 "using software crypto (default 1 [software])\n");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005757module_param_named(debug, iwl3945_mod_params.debug, uint, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005758MODULE_PARM_DESC(debug, "debug output mask");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005759module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005760MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
5761
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005762module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005763MODULE_PARM_DESC(queues_num, "number of hw queues.");
5764
Samuel Ortizaf48d042009-01-23 13:45:19 -08005765module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, 0444);
5766MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error");
5767
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005768module_exit(iwl3945_exit);
5769module_init(iwl3945_init);