blob: a2bde78e548d3a09b3d69cc7a4bd2d8e25fa73c9 [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Reinette Chatre01f81622009-01-08 10:20:02 -08003 * Copyright(c) 2003 - 2009 Intel Corporation. All rights reserved.
Zhu Yib481de92007-09-25 17:54:57 -07004 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
Winkler, Tomas759ef892008-12-09 11:28:58 -080025 * Intel Linux Wireless <ilw@linux.intel.com>
Zhu Yib481de92007-09-25 17:54:57 -070026 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
Zhu Yib481de92007-09-25 17:54:57 -070030#include <linux/kernel.h>
31#include <linux/module.h>
Zhu Yib481de92007-09-25 17:54:57 -070032#include <linux/init.h>
33#include <linux/pci.h>
34#include <linux/dma-mapping.h>
35#include <linux/delay.h>
36#include <linux/skbuff.h>
37#include <linux/netdevice.h>
38#include <linux/wireless.h>
39#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070040#include <linux/etherdevice.h>
41#include <linux/if_arp.h>
42
43#include <net/ieee80211_radiotap.h>
John W. Linville7e272fc2008-09-24 18:13:14 -040044#include <net/lib80211.h>
Zhu Yib481de92007-09-25 17:54:57 -070045#include <net/mac80211.h>
46
47#include <asm/div64.h>
48
Samuel Ortiza3139c52008-12-19 10:37:09 +080049#define DRV_NAME "iwl3945"
50
Winkler, Tomasdbb66542008-12-22 11:31:14 +080051#include "iwl-fh.h"
52#include "iwl-3945-fh.h"
Tomas Winkler600c0e12008-12-19 10:37:04 +080053#include "iwl-commands.h"
Samuel Ortiz17f841c2009-01-23 13:45:20 -080054#include "iwl-sta.h"
Zhu Yib481de92007-09-25 17:54:57 -070055#include "iwl-3945.h"
56#include "iwl-helpers.h"
Kolekar, Abhijeet5747d472008-12-19 10:37:18 +080057#include "iwl-core.h"
Samuel Ortizd20b3c62008-12-19 10:37:15 +080058#include "iwl-dev.h"
Zhu Yib481de92007-09-25 17:54:57 -070059
Zhu Yib481de92007-09-25 17:54:57 -070060/*
61 * module name, copyright, version, etc.
Zhu Yib481de92007-09-25 17:54:57 -070062 */
63
64#define DRV_DESCRIPTION \
65"Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
66
Samuel Ortizd08853a2009-01-23 13:45:17 -080067#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070068#define VD "d"
69#else
70#define VD
71#endif
72
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080073#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -070074#define VS "s"
75#else
76#define VS
77#endif
78
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080079#define IWL39_VERSION "1.2.26k" VD VS
Reinette Chatre01f81622009-01-08 10:20:02 -080080#define DRV_COPYRIGHT "Copyright(c) 2003-2009 Intel Corporation"
Tomas Winklera7b75202008-12-11 10:33:41 -080081#define DRV_AUTHOR "<ilw@linux.intel.com>"
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080082#define DRV_VERSION IWL39_VERSION
Zhu Yib481de92007-09-25 17:54:57 -070083
Zhu Yib481de92007-09-25 17:54:57 -070084
85MODULE_DESCRIPTION(DRV_DESCRIPTION);
86MODULE_VERSION(DRV_VERSION);
Tomas Winklera7b75202008-12-11 10:33:41 -080087MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
Zhu Yib481de92007-09-25 17:54:57 -070088MODULE_LICENSE("GPL");
89
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080090 /* module parameters */
91struct iwl_mod_params iwl3945_mod_params = {
92 .num_of_queues = IWL39_MAX_NUM_QUEUES,
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -080093 .sw_crypto = 1,
Samuel Ortizaf48d042009-01-23 13:45:19 -080094 .restart_fw = 1,
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080095 /* the rest are 0 by default */
96};
97
Zhu Yib481de92007-09-25 17:54:57 -070098/*************** STATION TABLE MANAGEMENT ****
Ben Cahill9fbab512007-11-29 11:09:47 +080099 * mac80211 should be examined to determine if sta_info is duplicating
Zhu Yib481de92007-09-25 17:54:57 -0700100 * the functionality provided here
101 */
102
103/**************************************************************/
Ian Schram01ebd062007-10-25 17:15:22 +0800104#if 0 /* temporary disable till we add real remove station */
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800105/**
106 * iwl3945_remove_station - Remove driver's knowledge of station.
107 *
108 * NOTE: This does not remove station from device's station table.
109 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800110static u8 iwl3945_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
Zhu Yib481de92007-09-25 17:54:57 -0700111{
112 int index = IWL_INVALID_STATION;
113 int i;
114 unsigned long flags;
115
116 spin_lock_irqsave(&priv->sta_lock, flags);
117
118 if (is_ap)
119 index = IWL_AP_ID;
120 else if (is_broadcast_ether_addr(addr))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800121 index = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700122 else
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800123 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800124 if (priv->stations_39[i].used &&
125 !compare_ether_addr(priv->stations_39[i].sta.sta.addr,
Zhu Yib481de92007-09-25 17:54:57 -0700126 addr)) {
127 index = i;
128 break;
129 }
130
131 if (unlikely(index == IWL_INVALID_STATION))
132 goto out;
133
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800134 if (priv->stations_39[index].used) {
135 priv->stations_39[index].used = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700136 priv->num_stations--;
137 }
138
139 BUG_ON(priv->num_stations < 0);
140
141out:
142 spin_unlock_irqrestore(&priv->sta_lock, flags);
143 return 0;
144}
Zhu Yi556f8db2007-09-27 11:27:33 +0800145#endif
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800146
147/**
148 * iwl3945_clear_stations_table - Clear the driver's station table
149 *
150 * NOTE: This does not clear or otherwise alter the device's station table.
151 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800152static void iwl3945_clear_stations_table(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700153{
154 unsigned long flags;
155
156 spin_lock_irqsave(&priv->sta_lock, flags);
157
158 priv->num_stations = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800159 memset(priv->stations_39, 0, sizeof(priv->stations_39));
Zhu Yib481de92007-09-25 17:54:57 -0700160
161 spin_unlock_irqrestore(&priv->sta_lock, flags);
162}
163
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800164/**
165 * iwl3945_add_station - Add station to station tables in driver and device
166 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800167u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags)
Zhu Yib481de92007-09-25 17:54:57 -0700168{
169 int i;
170 int index = IWL_INVALID_STATION;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800171 struct iwl3945_station_entry *station;
Zhu Yib481de92007-09-25 17:54:57 -0700172 unsigned long flags_spin;
Zhu Yic14c5212007-09-27 11:27:35 +0800173 u8 rate;
Zhu Yib481de92007-09-25 17:54:57 -0700174
175 spin_lock_irqsave(&priv->sta_lock, flags_spin);
176 if (is_ap)
177 index = IWL_AP_ID;
178 else if (is_broadcast_ether_addr(addr))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800179 index = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700180 else
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800181 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800182 if (!compare_ether_addr(priv->stations_39[i].sta.sta.addr,
Zhu Yib481de92007-09-25 17:54:57 -0700183 addr)) {
184 index = i;
185 break;
186 }
187
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800188 if (!priv->stations_39[i].used &&
Zhu Yib481de92007-09-25 17:54:57 -0700189 index == IWL_INVALID_STATION)
190 index = i;
191 }
192
Ian Schram01ebd062007-10-25 17:15:22 +0800193 /* These two conditions has the same outcome but keep them separate
Zhu Yib481de92007-09-25 17:54:57 -0700194 since they have different meaning */
195 if (unlikely(index == IWL_INVALID_STATION)) {
196 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
197 return index;
198 }
199
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800200 if (priv->stations_39[index].used &&
201 !compare_ether_addr(priv->stations_39[index].sta.sta.addr, addr)) {
Zhu Yib481de92007-09-25 17:54:57 -0700202 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
203 return index;
204 }
205
Tomas Winklere1623442009-01-27 14:27:56 -0800206 IWL_DEBUG_ASSOC(priv, "Add STA ID %d: %pM\n", index, addr);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800207 station = &priv->stations_39[index];
Zhu Yib481de92007-09-25 17:54:57 -0700208 station->used = 1;
209 priv->num_stations++;
210
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800211 /* Set up the REPLY_ADD_STA command to send to device */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800212 memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd));
Zhu Yib481de92007-09-25 17:54:57 -0700213 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
214 station->sta.mode = 0;
215 station->sta.sta.sta_id = index;
216 station->sta.station_flags = 0;
217
Johannes Berg8318d782008-01-24 19:38:38 +0100218 if (priv->band == IEEE80211_BAND_5GHZ)
Tomas Winkler69946332007-10-25 17:15:27 +0800219 rate = IWL_RATE_6M_PLCP;
220 else
221 rate = IWL_RATE_1M_PLCP;
Zhu Yic14c5212007-09-27 11:27:35 +0800222
223 /* Turn on both antennas for the station... */
224 station->sta.rate_n_flags =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800225 iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK);
Zhu Yic14c5212007-09-27 11:27:35 +0800226
Zhu Yib481de92007-09-25 17:54:57 -0700227 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800228
229 /* Add station to device's station table */
Samuel Ortiz17f841c2009-01-23 13:45:20 -0800230 iwl_send_add_sta(priv,
231 (struct iwl_addsta_cmd *)&station->sta, flags);
Zhu Yib481de92007-09-25 17:54:57 -0700232 return index;
233
234}
235
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800236static int iwl3945_send_rxon_assoc(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700237{
238 int rc = 0;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800239 struct iwl_rx_packet *res = NULL;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800240 struct iwl3945_rxon_assoc_cmd rxon_assoc;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800241 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700242 .id = REPLY_RXON_ASSOC,
243 .len = sizeof(rxon_assoc),
244 .meta.flags = CMD_WANT_SKB,
245 .data = &rxon_assoc,
246 };
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800247 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
248 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
Zhu Yib481de92007-09-25 17:54:57 -0700249
250 if ((rxon1->flags == rxon2->flags) &&
251 (rxon1->filter_flags == rxon2->filter_flags) &&
252 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
253 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800254 IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700255 return 0;
256 }
257
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800258 rxon_assoc.flags = priv->staging_rxon.flags;
259 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
260 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
261 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
Zhu Yib481de92007-09-25 17:54:57 -0700262 rxon_assoc.reserved = 0;
263
Samuel Ortiz518099a2009-01-19 15:30:27 -0800264 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700265 if (rc)
266 return rc;
267
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800268 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700269 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800270 IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -0700271 rc = -EIO;
272 }
273
274 priv->alloc_rxb_skb--;
275 dev_kfree_skb_any(cmd.meta.u.skb);
276
277 return rc;
278}
279
280/**
Samuel Ortiz7e4bca52009-01-23 13:45:18 -0800281 * iwl3945_get_antenna_flags - Get antenna flags for RXON command
282 * @priv: eeprom and antenna fields are used to determine antenna flags
283 *
284 * priv->eeprom39 is used to determine if antenna AUX/MAIN are reversed
285 * iwl3945_mod_params.antenna specifies the antenna diversity mode:
286 *
287 * IWL_ANTENNA_DIVERSITY - NIC selects best antenna by itself
288 * IWL_ANTENNA_MAIN - Force MAIN antenna
289 * IWL_ANTENNA_AUX - Force AUX antenna
290 */
291__le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv)
292{
293 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
294
295 switch (iwl3945_mod_params.antenna) {
296 case IWL_ANTENNA_DIVERSITY:
297 return 0;
298
299 case IWL_ANTENNA_MAIN:
300 if (eeprom->antenna_switch_type)
301 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
302 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
303
304 case IWL_ANTENNA_AUX:
305 if (eeprom->antenna_switch_type)
306 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
307 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
308 }
309
310 /* bad antenna selector value */
311 IWL_ERR(priv, "Bad antenna selector value (0x%x)\n",
312 iwl3945_mod_params.antenna);
313
314 return 0; /* "diversity" is default if error */
315}
316
317/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800318 * iwl3945_commit_rxon - commit staging_rxon to hardware
Zhu Yib481de92007-09-25 17:54:57 -0700319 *
Ian Schram01ebd062007-10-25 17:15:22 +0800320 * The RXON command in staging_rxon is committed to the hardware and
Zhu Yib481de92007-09-25 17:54:57 -0700321 * the active_rxon structure is updated with the new data. This
322 * function correctly transitions out of the RXON_ASSOC_MSK state if
323 * a HW tune is required based on the RXON structure changes.
324 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800325static int iwl3945_commit_rxon(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700326{
327 /* cast away the const for active_rxon in this function */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800328 struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
329 struct iwl3945_rxon_cmd *staging_rxon = (void *)&priv->staging_rxon;
Zhu Yib481de92007-09-25 17:54:57 -0700330 int rc = 0;
331
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800332 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700333 return -1;
334
335 /* always get timestamp with Rx frame */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800336 staging_rxon->flags |= RXON_FLG_TSF2HOST_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700337
338 /* select antenna */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800339 staging_rxon->flags &=
Zhu Yib481de92007-09-25 17:54:57 -0700340 ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800341 staging_rxon->flags |= iwl3945_get_antenna_flags(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700342
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800343 rc = iwl_check_rxon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700344 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800345 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700346 return -EINVAL;
347 }
348
349 /* If we don't need to send a full RXON, we can use
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800350 * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -0700351 * and other flags for the current radio configuration. */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800352 if (!iwl_full_rxon_required(priv)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800353 rc = iwl3945_send_rxon_assoc(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700354 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800355 IWL_ERR(priv, "Error setting RXON_ASSOC "
Zhu Yib481de92007-09-25 17:54:57 -0700356 "configuration (%d).\n", rc);
357 return rc;
358 }
359
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800360 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700361
362 return 0;
363 }
364
365 /* If we are currently associated and the new config requires
366 * an RXON_ASSOC and the new config wants the associated mask enabled,
367 * we must clear the associated from the active configuration
368 * before we apply the new config */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800369 if (iwl_is_associated(priv) &&
370 (staging_rxon->filter_flags & RXON_FILTER_ASSOC_MSK)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800371 IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
Zhu Yib481de92007-09-25 17:54:57 -0700372 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
373
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800374 /*
375 * reserved4 and 5 could have been filled by the iwlcore code.
376 * Let's clear them before pushing to the 3945.
377 */
378 active_rxon->reserved4 = 0;
379 active_rxon->reserved5 = 0;
Samuel Ortiz518099a2009-01-19 15:30:27 -0800380 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800381 sizeof(struct iwl3945_rxon_cmd),
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800382 &priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -0700383
384 /* If the mask clearing failed then we set
385 * active_rxon back to what it was previously */
386 if (rc) {
387 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
Winkler, Tomas15b16872008-12-19 10:37:33 +0800388 IWL_ERR(priv, "Error clearing ASSOC_MSK on current "
Zhu Yib481de92007-09-25 17:54:57 -0700389 "configuration (%d).\n", rc);
390 return rc;
391 }
Zhu Yib481de92007-09-25 17:54:57 -0700392 }
393
Tomas Winklere1623442009-01-27 14:27:56 -0800394 IWL_DEBUG_INFO(priv, "Sending RXON\n"
Zhu Yib481de92007-09-25 17:54:57 -0700395 "* with%s RXON_FILTER_ASSOC_MSK\n"
396 "* channel = %d\n"
Johannes Berge1749612008-10-27 15:59:26 -0700397 "* bssid = %pM\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800398 ((priv->staging_rxon.filter_flags &
Zhu Yib481de92007-09-25 17:54:57 -0700399 RXON_FILTER_ASSOC_MSK) ? "" : "out"),
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800400 le16_to_cpu(staging_rxon->channel),
401 staging_rxon->bssid_addr);
402
403 /*
404 * reserved4 and 5 could have been filled by the iwlcore code.
405 * Let's clear them before pushing to the 3945.
406 */
407 staging_rxon->reserved4 = 0;
408 staging_rxon->reserved5 = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700409
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800410 iwl_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
411
Zhu Yib481de92007-09-25 17:54:57 -0700412 /* Apply the new configuration */
Samuel Ortiz518099a2009-01-19 15:30:27 -0800413 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800414 sizeof(struct iwl3945_rxon_cmd),
415 staging_rxon);
Zhu Yib481de92007-09-25 17:54:57 -0700416 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800417 IWL_ERR(priv, "Error setting new configuration (%d).\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700418 return rc;
419 }
420
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800421 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700422
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800423 iwl3945_clear_stations_table(priv);
Zhu Yi556f8db2007-09-27 11:27:33 +0800424
Zhu Yib481de92007-09-25 17:54:57 -0700425 /* If we issue a new RXON command which required a tune then we must
426 * send a new TXPOWER command or we won't be able to Tx any frames */
Samuel Ortiz75bcfae2009-01-23 13:45:11 -0800427 rc = priv->cfg->ops->lib->send_tx_power(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700428 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800429 IWL_ERR(priv, "Error setting Tx power (%d).\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700430 return rc;
431 }
432
433 /* Add the broadcast address so we can send broadcast frames */
Kolekar, Abhijeetb5323d32008-12-19 10:37:22 +0800434 if (iwl3945_add_station(priv, iwl_bcast_addr, 0, 0) ==
Zhu Yib481de92007-09-25 17:54:57 -0700435 IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800436 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700437 return -EIO;
438 }
439
440 /* If we have set the ASSOC_MSK and we are in BSS mode then
441 * add the IWL_AP_ID to the station rate table */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800442 if (iwl_is_associated(priv) &&
Johannes Berg05c914f2008-09-11 00:01:58 +0200443 (priv->iw_mode == NL80211_IFTYPE_STATION))
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800444 if (iwl3945_add_station(priv, priv->active_rxon.bssid_addr,
445 1, 0)
Zhu Yib481de92007-09-25 17:54:57 -0700446 == IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800447 IWL_ERR(priv, "Error adding AP address for transmit\n");
Zhu Yib481de92007-09-25 17:54:57 -0700448 return -EIO;
449 }
450
Johannes Berg8318d782008-01-24 19:38:38 +0100451 /* Init the hardware's rate fallback order based on the band */
Zhu Yib481de92007-09-25 17:54:57 -0700452 rc = iwl3945_init_hw_rate_table(priv);
453 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800454 IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700455 return -EIO;
456 }
457
458 return 0;
459}
460
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800461static int iwl3945_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700462 struct ieee80211_key_conf *keyconf,
463 u8 sta_id)
464{
465 unsigned long flags;
466 __le16 key_flags = 0;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800467 int ret;
Zhu Yib481de92007-09-25 17:54:57 -0700468
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800469 key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
470 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
471
472 if (sta_id == priv->hw_params.bcast_sta_id)
473 key_flags |= STA_KEY_MULTICAST_MSK;
474
475 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
476 keyconf->hw_key_idx = keyconf->keyidx;
477 key_flags &= ~STA_KEY_FLG_INVALID;
478
Zhu Yib481de92007-09-25 17:54:57 -0700479 spin_lock_irqsave(&priv->sta_lock, flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800480 priv->stations_39[sta_id].keyinfo.alg = keyconf->alg;
481 priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen;
482 memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700483 keyconf->keylen);
484
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800485 memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700486 keyconf->keylen);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800487
488 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
489 == STA_KEY_FLG_NO_ENC)
490 priv->stations[sta_id].sta.key.key_offset =
491 iwl_get_free_ucode_key_index(priv);
492 /* else, we are overriding an existing key => no need to allocated room
493 * in uCode. */
494
495 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
496 "no space for a new key");
497
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800498 priv->stations_39[sta_id].sta.key.key_flags = key_flags;
499 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
500 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700501
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800502 IWL_DEBUG_INFO(priv, "hwcrypto: modify ucode station key info\n");
503
504 ret = iwl_send_add_sta(priv,
505 (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, CMD_ASYNC);
506
Zhu Yib481de92007-09-25 17:54:57 -0700507 spin_unlock_irqrestore(&priv->sta_lock, flags);
508
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800509 return ret;
510}
511
512static int iwl3945_set_tkip_dynamic_key_info(struct iwl_priv *priv,
513 struct ieee80211_key_conf *keyconf,
514 u8 sta_id)
515{
516 return -EOPNOTSUPP;
517}
518
519static int iwl3945_set_wep_dynamic_key_info(struct iwl_priv *priv,
520 struct ieee80211_key_conf *keyconf,
521 u8 sta_id)
522{
523 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -0700524}
525
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800526static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
Zhu Yib481de92007-09-25 17:54:57 -0700527{
528 unsigned long flags;
529
530 spin_lock_irqsave(&priv->sta_lock, flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800531 memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key));
532 memset(&priv->stations_39[sta_id].sta.key, 0,
Tomas Winkler4c897252008-12-19 10:37:05 +0800533 sizeof(struct iwl4965_keyinfo));
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800534 priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
535 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
536 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700537 spin_unlock_irqrestore(&priv->sta_lock, flags);
538
Tomas Winklere1623442009-01-27 14:27:56 -0800539 IWL_DEBUG_INFO(priv, "hwcrypto: clear ucode station key info\n");
Samuel Ortiz17f841c2009-01-23 13:45:20 -0800540 iwl_send_add_sta(priv,
541 (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700542 return 0;
543}
544
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800545int iwl3945_set_dynamic_key(struct iwl_priv *priv,
546 struct ieee80211_key_conf *keyconf, u8 sta_id)
547{
548 int ret = 0;
549
550 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
551
552 switch (keyconf->alg) {
553 case ALG_CCMP:
554 ret = iwl3945_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
555 break;
556 case ALG_TKIP:
557 ret = iwl3945_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
558 break;
559 case ALG_WEP:
560 ret = iwl3945_set_wep_dynamic_key_info(priv, keyconf, sta_id);
561 break;
562 default:
563 IWL_ERR(priv,"Unknown alg: %s alg = %d\n", __func__, keyconf->alg);
564 ret = -EINVAL;
565 }
566
567 IWL_DEBUG_WEP(priv, "Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n",
568 keyconf->alg, keyconf->keylen, keyconf->keyidx,
569 sta_id, ret);
570
571 return ret;
572}
573
574static int iwl3945_remove_static_key(struct iwl_priv *priv)
575{
576 int ret = -EOPNOTSUPP;
577
578 return ret;
579}
580
581static int iwl3945_set_static_key(struct iwl_priv *priv,
582 struct ieee80211_key_conf *key)
583{
584 if (key->alg == ALG_WEP)
585 return -EOPNOTSUPP;
586
587 IWL_ERR(priv, "Static key invalid: alg %d\n", key->alg);
588 return -EINVAL;
589}
590
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800591static void iwl3945_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700592{
593 struct list_head *element;
594
Tomas Winklere1623442009-01-27 14:27:56 -0800595 IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
Zhu Yib481de92007-09-25 17:54:57 -0700596 priv->frames_count);
597
598 while (!list_empty(&priv->free_frames)) {
599 element = priv->free_frames.next;
600 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800601 kfree(list_entry(element, struct iwl3945_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700602 priv->frames_count--;
603 }
604
605 if (priv->frames_count) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800606 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
Zhu Yib481de92007-09-25 17:54:57 -0700607 priv->frames_count);
608 priv->frames_count = 0;
609 }
610}
611
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800612static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700613{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800614 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700615 struct list_head *element;
616 if (list_empty(&priv->free_frames)) {
617 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
618 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800619 IWL_ERR(priv, "Could not allocate frame!\n");
Zhu Yib481de92007-09-25 17:54:57 -0700620 return NULL;
621 }
622
623 priv->frames_count++;
624 return frame;
625 }
626
627 element = priv->free_frames.next;
628 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800629 return list_entry(element, struct iwl3945_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700630}
631
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800632static void iwl3945_free_frame(struct iwl_priv *priv, struct iwl3945_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700633{
634 memset(frame, 0, sizeof(*frame));
635 list_add(&frame->list, &priv->free_frames);
636}
637
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800638unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700639 struct ieee80211_hdr *hdr,
Rami Rosen73ec1cc2008-12-16 09:37:07 +0200640 int left)
Zhu Yib481de92007-09-25 17:54:57 -0700641{
642
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800643 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200644 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
645 (priv->iw_mode != NL80211_IFTYPE_AP)))
Zhu Yib481de92007-09-25 17:54:57 -0700646 return 0;
647
648 if (priv->ibss_beacon->len > left)
649 return 0;
650
651 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
652
653 return priv->ibss_beacon->len;
654}
655
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800656static int iwl3945_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700657{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800658 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700659 unsigned int frame_size;
660 int rc;
661 u8 rate;
662
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800663 frame = iwl3945_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700664
665 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800666 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
Zhu Yib481de92007-09-25 17:54:57 -0700667 "command.\n");
668 return -ENOMEM;
669 }
670
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800671 rate = iwl_rate_get_lowest_plcp(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700672
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800673 frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -0700674
Samuel Ortiz518099a2009-01-19 15:30:27 -0800675 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700676 &frame->u.cmd[0]);
677
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800678 iwl3945_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700679
680 return rc;
681}
682
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800683static void iwl3945_unset_hw_params(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700684{
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800685 if (priv->shared_virt)
Zhu Yib481de92007-09-25 17:54:57 -0700686 pci_free_consistent(priv->pci_dev,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800687 sizeof(struct iwl3945_shared),
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800688 priv->shared_virt,
689 priv->shared_phys);
Zhu Yib481de92007-09-25 17:54:57 -0700690}
691
Zhu Yib481de92007-09-25 17:54:57 -0700692#define MAX_UCODE_BEACON_INTERVAL 1024
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -0800693#define INTEL_CONN_LISTEN_INTERVAL cpu_to_le16(0xA)
Zhu Yib481de92007-09-25 17:54:57 -0700694
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800695static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -0700696{
697 u16 new_val = 0;
698 u16 beacon_factor = 0;
699
700 beacon_factor =
701 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
702 / MAX_UCODE_BEACON_INTERVAL;
703 new_val = beacon_val / beacon_factor;
704
705 return cpu_to_le16(new_val);
706}
707
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800708static void iwl3945_setup_rxon_timing(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700709{
710 u64 interval_tm_unit;
711 u64 tsf, result;
712 unsigned long flags;
713 struct ieee80211_conf *conf = NULL;
714 u16 beacon_int = 0;
715
716 conf = ieee80211_get_hw_conf(priv->hw);
717
718 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler28afaf92008-12-19 10:37:06 +0800719 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
Zhu Yib481de92007-09-25 17:54:57 -0700720 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
721
Tomas Winkler28afaf92008-12-19 10:37:06 +0800722 tsf = priv->timestamp;
Zhu Yib481de92007-09-25 17:54:57 -0700723
724 beacon_int = priv->beacon_int;
725 spin_unlock_irqrestore(&priv->lock, flags);
726
Johannes Berg05c914f2008-09-11 00:01:58 +0200727 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Zhu Yib481de92007-09-25 17:54:57 -0700728 if (beacon_int == 0) {
729 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
730 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
731 } else {
732 priv->rxon_timing.beacon_interval =
733 cpu_to_le16(beacon_int);
734 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800735 iwl3945_adjust_beacon_interval(
Zhu Yib481de92007-09-25 17:54:57 -0700736 le16_to_cpu(priv->rxon_timing.beacon_interval));
737 }
738
739 priv->rxon_timing.atim_window = 0;
740 } else {
741 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800742 iwl3945_adjust_beacon_interval(conf->beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -0700743 /* TODO: we need to get atim_window from upper stack
744 * for now we set to 0 */
745 priv->rxon_timing.atim_window = 0;
746 }
747
748 interval_tm_unit =
749 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
750 result = do_div(tsf, interval_tm_unit);
751 priv->rxon_timing.beacon_init_val =
752 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
753
Tomas Winklere1623442009-01-27 14:27:56 -0800754 IWL_DEBUG_ASSOC(priv,
755 "beacon interval %d beacon timer %d beacon tim %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700756 le16_to_cpu(priv->rxon_timing.beacon_interval),
757 le32_to_cpu(priv->rxon_timing.beacon_init_val),
758 le16_to_cpu(priv->rxon_timing.atim_window));
759}
760
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800761static int iwl3945_set_mode(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -0700762{
Johannes Berg05c914f2008-09-11 00:01:58 +0200763 if (mode == NL80211_IFTYPE_ADHOC) {
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800764 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -0700765
Samuel Ortize6148912009-01-23 13:45:15 -0800766 ch_info = iwl_get_channel_info(priv,
Johannes Berg8318d782008-01-24 19:38:38 +0100767 priv->band,
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800768 le16_to_cpu(priv->staging_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700769
770 if (!ch_info || !is_channel_ibss(ch_info)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800771 IWL_ERR(priv, "channel %d not IBSS channel\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800772 le16_to_cpu(priv->staging_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700773 return -EINVAL;
774 }
775 }
776
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800777 iwl_connection_init_rx_config(priv, mode);
Zhu Yib481de92007-09-25 17:54:57 -0700778
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800779 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700780
Tomas Winklera96a27f2008-10-23 23:48:56 -0700781 /* don't commit rxon if rf-kill is on*/
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800782 if (!iwl_is_ready_rf(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +0800783 return -EAGAIN;
784
785 cancel_delayed_work(&priv->scan_check);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -0800786 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800787 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
Tomas Winklere1623442009-01-27 14:27:56 -0800788 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +0800789 return -EAGAIN;
790 }
791
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800792 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700793
794 return 0;
795}
796
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800797static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
Johannes Berge039fa42008-05-15 12:55:29 +0200798 struct ieee80211_tx_info *info,
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800799 struct iwl_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -0700800 struct sk_buff *skb_frag,
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800801 int sta_id)
Zhu Yib481de92007-09-25 17:54:57 -0700802{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800803 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
Ivo van Doorn1c014422008-04-17 19:41:02 +0200804 struct iwl3945_hw_key *keyinfo =
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800805 &priv->stations_39[sta_id].keyinfo;
Zhu Yib481de92007-09-25 17:54:57 -0700806
807 switch (keyinfo->alg) {
808 case ALG_CCMP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800809 tx->sec_ctl = TX_CMD_SEC_CCM;
810 memcpy(tx->key, keyinfo->key, keyinfo->keylen);
Tomas Winklere1623442009-01-27 14:27:56 -0800811 IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
Zhu Yib481de92007-09-25 17:54:57 -0700812 break;
813
814 case ALG_TKIP:
Zhu Yib481de92007-09-25 17:54:57 -0700815 break;
816
817 case ALG_WEP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800818 tx->sec_ctl = TX_CMD_SEC_WEP |
Johannes Berge039fa42008-05-15 12:55:29 +0200819 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
Zhu Yib481de92007-09-25 17:54:57 -0700820
821 if (keyinfo->keylen == 13)
Winkler, Tomase52119c2008-12-22 11:31:19 +0800822 tx->sec_ctl |= TX_CMD_SEC_KEY128;
Zhu Yib481de92007-09-25 17:54:57 -0700823
Winkler, Tomase52119c2008-12-22 11:31:19 +0800824 memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen);
Zhu Yib481de92007-09-25 17:54:57 -0700825
Tomas Winklere1623442009-01-27 14:27:56 -0800826 IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
Johannes Berge039fa42008-05-15 12:55:29 +0200827 "with key %d\n", info->control.hw_key->hw_key_idx);
Zhu Yib481de92007-09-25 17:54:57 -0700828 break;
829
Zhu Yib481de92007-09-25 17:54:57 -0700830 default:
Tomas Winkler978785a2008-12-19 10:37:31 +0800831 IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg);
Zhu Yib481de92007-09-25 17:54:57 -0700832 break;
833 }
834}
835
836/*
837 * handle build REPLY_TX command notification.
838 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800839static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800840 struct iwl_cmd *cmd,
Johannes Berge039fa42008-05-15 12:55:29 +0200841 struct ieee80211_tx_info *info,
Winkler, Tomase52119c2008-12-22 11:31:19 +0800842 struct ieee80211_hdr *hdr, u8 std_id)
Zhu Yib481de92007-09-25 17:54:57 -0700843{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800844 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
845 __le32 tx_flags = tx->tx_flags;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700846 __le16 fc = hdr->frame_control;
Johannes Berge6a98542008-10-21 12:40:02 +0200847 u8 rc_flags = info->control.rates[0].flags;
Zhu Yib481de92007-09-25 17:54:57 -0700848
Winkler, Tomase52119c2008-12-22 11:31:19 +0800849 tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Johannes Berge039fa42008-05-15 12:55:29 +0200850 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
Zhu Yib481de92007-09-25 17:54:57 -0700851 tx_flags |= TX_CMD_FLG_ACK_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700852 if (ieee80211_is_mgmt(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700853 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700854 if (ieee80211_is_probe_resp(fc) &&
Zhu Yib481de92007-09-25 17:54:57 -0700855 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
856 tx_flags |= TX_CMD_FLG_TSF_MSK;
857 } else {
858 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
859 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
860 }
861
Winkler, Tomase52119c2008-12-22 11:31:19 +0800862 tx->sta_id = std_id;
Harvey Harrison8b7b1e02008-06-11 14:21:56 -0700863 if (ieee80211_has_morefrags(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700864 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
865
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700866 if (ieee80211_is_data_qos(fc)) {
867 u8 *qc = ieee80211_get_qos_ctl(hdr);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800868 tx->tid_tspec = qc[0] & 0xf;
Zhu Yib481de92007-09-25 17:54:57 -0700869 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800870 } else {
Zhu Yib481de92007-09-25 17:54:57 -0700871 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800872 }
Zhu Yib481de92007-09-25 17:54:57 -0700873
Johannes Berge6a98542008-10-21 12:40:02 +0200874 if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
Zhu Yib481de92007-09-25 17:54:57 -0700875 tx_flags |= TX_CMD_FLG_RTS_MSK;
876 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
Johannes Berge6a98542008-10-21 12:40:02 +0200877 } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
Zhu Yib481de92007-09-25 17:54:57 -0700878 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
879 tx_flags |= TX_CMD_FLG_CTS_MSK;
880 }
881
882 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
883 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
884
885 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700886 if (ieee80211_is_mgmt(fc)) {
887 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
Winkler, Tomase52119c2008-12-22 11:31:19 +0800888 tx->timeout.pm_frame_timeout = cpu_to_le16(3);
Zhu Yib481de92007-09-25 17:54:57 -0700889 else
Winkler, Tomase52119c2008-12-22 11:31:19 +0800890 tx->timeout.pm_frame_timeout = cpu_to_le16(2);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700891 } else {
Winkler, Tomase52119c2008-12-22 11:31:19 +0800892 tx->timeout.pm_frame_timeout = 0;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700893#ifdef CONFIG_IWL3945_LEDS
894 priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
895#endif
896 }
Zhu Yib481de92007-09-25 17:54:57 -0700897
Winkler, Tomase52119c2008-12-22 11:31:19 +0800898 tx->driver_txop = 0;
899 tx->tx_flags = tx_flags;
900 tx->next_frame_len = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700901}
902
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800903/**
904 * iwl3945_get_sta_id - Find station's index within station table
905 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800906static int iwl3945_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
Zhu Yib481de92007-09-25 17:54:57 -0700907{
908 int sta_id;
909 u16 fc = le16_to_cpu(hdr->frame_control);
910
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800911 /* If this frame is broadcast or management, use broadcast station id */
Zhu Yib481de92007-09-25 17:54:57 -0700912 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
913 is_multicast_ether_addr(hdr->addr1))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800914 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700915
916 switch (priv->iw_mode) {
917
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800918 /* If we are a client station in a BSS network, use the special
919 * AP station entry (that's the only station we communicate with) */
Johannes Berg05c914f2008-09-11 00:01:58 +0200920 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -0700921 return IWL_AP_ID;
922
923 /* If we are an AP, then find the station, or use BCAST */
Johannes Berg05c914f2008-09-11 00:01:58 +0200924 case NL80211_IFTYPE_AP:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800925 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700926 if (sta_id != IWL_INVALID_STATION)
927 return sta_id;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800928 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700929
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800930 /* If this frame is going out to an IBSS network, find the station,
931 * or create a new station table entry */
Johannes Berg05c914f2008-09-11 00:01:58 +0200932 case NL80211_IFTYPE_ADHOC: {
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800933 /* Create new station table entry */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800934 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700935 if (sta_id != IWL_INVALID_STATION)
936 return sta_id;
937
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800938 sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
Zhu Yib481de92007-09-25 17:54:57 -0700939
940 if (sta_id != IWL_INVALID_STATION)
941 return sta_id;
942
Tomas Winklere1623442009-01-27 14:27:56 -0800943 IWL_DEBUG_DROP(priv, "Station %pM not in station map. "
Zhu Yib481de92007-09-25 17:54:57 -0700944 "Defaulting to broadcast...\n",
Johannes Berge1749612008-10-27 15:59:26 -0700945 hdr->addr1);
Samuel Ortiz40b8ec02008-12-19 10:37:08 +0800946 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800947 return priv->hw_params.bcast_sta_id;
Joe Perches0795af52007-10-03 17:59:30 -0700948 }
Stefanik Gábor914233d2008-06-30 17:23:30 +0800949 /* If we are in monitor mode, use BCAST. This is required for
950 * packet injection. */
Johannes Berg05c914f2008-09-11 00:01:58 +0200951 case NL80211_IFTYPE_MONITOR:
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800952 return priv->hw_params.bcast_sta_id;
Stefanik Gábor914233d2008-06-30 17:23:30 +0800953
Zhu Yib481de92007-09-25 17:54:57 -0700954 default:
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800955 IWL_WARN(priv, "Unknown mode of operation: %d\n",
956 priv->iw_mode);
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800957 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700958 }
959}
960
961/*
962 * start REPLY_TX command process
963 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800964static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -0700965{
966 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berge039fa42008-05-15 12:55:29 +0200967 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800968 struct iwl3945_tx_cmd *tx;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800969 struct iwl_tx_queue *txq = NULL;
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800970 struct iwl_queue *q = NULL;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800971 struct iwl_cmd *out_cmd = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700972 dma_addr_t phys_addr;
973 dma_addr_t txcmd_phys;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800974 int txq_id = skb_get_queue_mapping(skb);
Tomas Winkler54dbb522008-05-15 13:54:06 +0800975 u16 len, idx, len_org, hdr_len;
976 u8 id;
977 u8 unicast;
Zhu Yib481de92007-09-25 17:54:57 -0700978 u8 sta_id;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800979 u8 tid = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700980 u16 seq_number = 0;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700981 __le16 fc;
Zhu Yib481de92007-09-25 17:54:57 -0700982 u8 wait_write_ptr = 0;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800983 u8 *qc = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700984 unsigned long flags;
985 int rc;
986
987 spin_lock_irqsave(&priv->lock, flags);
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800988 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800989 IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
Zhu Yib481de92007-09-25 17:54:57 -0700990 goto drop_unlock;
991 }
992
Johannes Berge039fa42008-05-15 12:55:29 +0200993 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800994 IWL_ERR(priv, "ERROR: No TX rate available.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700995 goto drop_unlock;
996 }
997
998 unicast = !is_multicast_ether_addr(hdr->addr1);
999 id = 0;
1000
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001001 fc = hdr->frame_control;
Zhu Yib481de92007-09-25 17:54:57 -07001002
Samuel Ortizd08853a2009-01-23 13:45:17 -08001003#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001004 if (ieee80211_is_auth(fc))
Tomas Winklere1623442009-01-27 14:27:56 -08001005 IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001006 else if (ieee80211_is_assoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -08001007 IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001008 else if (ieee80211_is_reassoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -08001009 IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
Zhu Yib481de92007-09-25 17:54:57 -07001010#endif
1011
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08001012 /* drop all data frame if we are not associated */
Stefanik Gábor914233d2008-06-30 17:23:30 +08001013 if (ieee80211_is_data(fc) &&
Johannes Berg05c914f2008-09-11 00:01:58 +02001014 (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001015 (!iwl_is_associated(priv) ||
Johannes Berg05c914f2008-09-11 00:01:58 +02001016 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
Tomas Winklere1623442009-01-27 14:27:56 -08001017 IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n");
Zhu Yib481de92007-09-25 17:54:57 -07001018 goto drop_unlock;
1019 }
1020
1021 spin_unlock_irqrestore(&priv->lock, flags);
1022
Harvey Harrison7294ec92008-07-15 18:43:59 -07001023 hdr_len = ieee80211_hdrlen(fc);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001024
1025 /* Find (or create) index into station table for destination station */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001026 sta_id = iwl3945_get_sta_id(priv, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07001027 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -08001028 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07001029 hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07001030 goto drop;
1031 }
1032
Tomas Winklere1623442009-01-27 14:27:56 -08001033 IWL_DEBUG_RATE(priv, "station Id %d\n", sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07001034
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001035 if (ieee80211_is_data_qos(fc)) {
1036 qc = ieee80211_get_qos_ctl(hdr);
Harvey Harrison7294ec92008-07-15 18:43:59 -07001037 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001038 seq_number = priv->stations_39[sta_id].tid[tid].seq_number &
Zhu Yib481de92007-09-25 17:54:57 -07001039 IEEE80211_SCTL_SEQ;
1040 hdr->seq_ctrl = cpu_to_le16(seq_number) |
1041 (hdr->seq_ctrl &
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -08001042 cpu_to_le16(IEEE80211_SCTL_FRAG));
Zhu Yib481de92007-09-25 17:54:57 -07001043 seq_number += 0x10;
1044 }
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001045
1046 /* Descriptor for chosen Tx queue */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001047 txq = &priv->txq[txq_id];
Zhu Yib481de92007-09-25 17:54:57 -07001048 q = &txq->q;
1049
1050 spin_lock_irqsave(&priv->lock, flags);
1051
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001052 idx = get_cmd_index(q, q->write_ptr, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001053
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001054 /* Set up driver data for this TFD */
Winkler, Tomasdbb66542008-12-22 11:31:14 +08001055 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001056 txq->txb[q->write_ptr].skb[0] = skb;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001057
1058 /* Init first empty entry in queue's array of Tx/cmd buffers */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001059 out_cmd = txq->cmd[idx];
Winkler, Tomase52119c2008-12-22 11:31:19 +08001060 tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
Zhu Yib481de92007-09-25 17:54:57 -07001061 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
Winkler, Tomase52119c2008-12-22 11:31:19 +08001062 memset(tx, 0, sizeof(*tx));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001063
1064 /*
1065 * Set up the Tx-command (not MAC!) header.
1066 * Store the chosen Tx queue and TFD index within the sequence field;
1067 * after Tx, uCode's Tx response will return this value so driver can
1068 * locate the frame within the tx queue and do post-tx processing.
1069 */
Zhu Yib481de92007-09-25 17:54:57 -07001070 out_cmd->hdr.cmd = REPLY_TX;
1071 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001072 INDEX_TO_SEQ(q->write_ptr)));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001073
1074 /* Copy MAC header from skb into command buffer */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001075 memcpy(tx->hdr, hdr, hdr_len);
Zhu Yib481de92007-09-25 17:54:57 -07001076
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001077 /*
1078 * Use the first empty entry in this queue's command buffer array
1079 * to contain the Tx command and MAC header concatenated together
1080 * (payload data will be in another buffer).
1081 * Size of this varies, due to varying MAC header length.
1082 * If end is not dword aligned, we'll have 2 extra bytes at the end
1083 * of the MAC header (device reads on dword boundaries).
1084 * We'll tell device about this padding later.
1085 */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001086 len = sizeof(struct iwl3945_tx_cmd) +
Tomas Winkler4c897252008-12-19 10:37:05 +08001087 sizeof(struct iwl_cmd_header) + hdr_len;
Zhu Yib481de92007-09-25 17:54:57 -07001088
1089 len_org = len;
1090 len = (len + 3) & ~3;
1091
1092 if (len_org != len)
1093 len_org = 1;
1094 else
1095 len_org = 0;
1096
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001097 /* Physical address of this Tx command's header (not MAC header!),
1098 * within command buffer array. */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001099 txcmd_phys = pci_map_single(priv->pci_dev,
1100 out_cmd, sizeof(struct iwl_cmd),
1101 PCI_DMA_TODEVICE);
1102 pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys);
1103 pci_unmap_len_set(&out_cmd->meta, len, sizeof(struct iwl_cmd));
1104 /* Add buffer containing Tx command and MAC(!) header to TFD's
1105 * first entry */
1106 txcmd_phys += offsetof(struct iwl_cmd, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07001107
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001108 /* Add buffer containing Tx command and MAC(!) header to TFD's
1109 * first entry */
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001110 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1111 txcmd_phys, len, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001112
Johannes Bergd0f09802008-07-29 11:32:07 +02001113 if (info->control.hw_key)
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08001114 iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07001115
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001116 /* Set up TFD's 2nd entry to point directly to remainder of skb,
1117 * if any (802.11 null frames have no payload). */
Zhu Yib481de92007-09-25 17:54:57 -07001118 len = skb->len - hdr_len;
1119 if (len) {
1120 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
1121 len, PCI_DMA_TODEVICE);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001122 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1123 phys_addr, len,
1124 0, U32_PAD(len));
Zhu Yib481de92007-09-25 17:54:57 -07001125 }
1126
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001127 /* Total # bytes to be transmitted */
Zhu Yib481de92007-09-25 17:54:57 -07001128 len = (u16)skb->len;
Winkler, Tomase52119c2008-12-22 11:31:19 +08001129 tx->len = cpu_to_le16(len);
Zhu Yib481de92007-09-25 17:54:57 -07001130
1131 /* TODO need this for burst mode later on */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001132 iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07001133
1134 /* set is_hcca to 0; it probably will never be implemented */
Johannes Berge039fa42008-05-15 12:55:29 +02001135 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001136
Winkler, Tomase52119c2008-12-22 11:31:19 +08001137 tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
1138 tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001139
Harvey Harrison8b7b1e02008-06-11 14:21:56 -07001140 if (!ieee80211_has_morefrags(hdr->frame_control)) {
Zhu Yib481de92007-09-25 17:54:57 -07001141 txq->need_update = 1;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001142 if (qc)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001143 priv->stations_39[sta_id].tid[tid].seq_number = seq_number;
Zhu Yib481de92007-09-25 17:54:57 -07001144 } else {
1145 wait_write_ptr = 1;
1146 txq->need_update = 0;
1147 }
1148
Winkler, Tomase52119c2008-12-22 11:31:19 +08001149 iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx));
Zhu Yib481de92007-09-25 17:54:57 -07001150
Winkler, Tomase52119c2008-12-22 11:31:19 +08001151 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr,
Harvey Harrison7294ec92008-07-15 18:43:59 -07001152 ieee80211_hdrlen(fc));
Zhu Yib481de92007-09-25 17:54:57 -07001153
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001154 /* Tell device the write index *just past* this latest filled TFD */
Tomas Winklerc54b6792008-03-06 17:36:53 -08001155 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001156 rc = iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001157 spin_unlock_irqrestore(&priv->lock, flags);
1158
1159 if (rc)
1160 return rc;
1161
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001162 if ((iwl_queue_space(q) < q->high_mark)
Zhu Yib481de92007-09-25 17:54:57 -07001163 && priv->mac80211_registered) {
1164 if (wait_write_ptr) {
1165 spin_lock_irqsave(&priv->lock, flags);
1166 txq->need_update = 1;
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001167 iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001168 spin_unlock_irqrestore(&priv->lock, flags);
1169 }
1170
Johannes Berge2530082008-05-17 00:57:14 +02001171 ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb));
Zhu Yib481de92007-09-25 17:54:57 -07001172 }
1173
1174 return 0;
1175
1176drop_unlock:
1177 spin_unlock_irqrestore(&priv->lock, flags);
1178drop:
1179 return -1;
1180}
1181
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001182#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07001183
1184#include "iwl-spectrum.h"
1185
1186#define BEACON_TIME_MASK_LOW 0x00FFFFFF
1187#define BEACON_TIME_MASK_HIGH 0xFF000000
1188#define TIME_UNIT 1024
1189
1190/*
1191 * extended beacon time format
1192 * time in usec will be changed into a 32-bit value in 8:24 format
1193 * the high 1 byte is the beacon counts
1194 * the lower 3 bytes is the time in usec within one beacon interval
1195 */
1196
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001197static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001198{
1199 u32 quot;
1200 u32 rem;
1201 u32 interval = beacon_interval * 1024;
1202
1203 if (!interval || !usec)
1204 return 0;
1205
1206 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
1207 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
1208
1209 return (quot << 24) + rem;
1210}
1211
1212/* base is usually what we get from ucode with each received frame,
1213 * the same as HW timer counter counting down
1214 */
1215
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001216static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001217{
1218 u32 base_low = base & BEACON_TIME_MASK_LOW;
1219 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
1220 u32 interval = beacon_interval * TIME_UNIT;
1221 u32 res = (base & BEACON_TIME_MASK_HIGH) +
1222 (addon & BEACON_TIME_MASK_HIGH);
1223
1224 if (base_low > addon_low)
1225 res += base_low - addon_low;
1226 else if (base_low < addon_low) {
1227 res += interval + base_low - addon_low;
1228 res += (1 << 24);
1229 } else
1230 res += (1 << 24);
1231
1232 return cpu_to_le32(res);
1233}
1234
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001235static int iwl3945_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001236 struct ieee80211_measurement_params *params,
1237 u8 type)
1238{
Tomas Winkler600c0e12008-12-19 10:37:04 +08001239 struct iwl_spectrum_cmd spectrum;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001240 struct iwl_rx_packet *res;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08001241 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001242 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
1243 .data = (void *)&spectrum,
1244 .meta.flags = CMD_WANT_SKB,
1245 };
1246 u32 add_time = le64_to_cpu(params->start_time);
1247 int rc;
1248 int spectrum_resp_status;
1249 int duration = le16_to_cpu(params->duration);
1250
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001251 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001252 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001253 iwl3945_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -07001254 le64_to_cpu(params->start_time) - priv->last_tsf,
1255 le16_to_cpu(priv->rxon_timing.beacon_interval));
1256
1257 memset(&spectrum, 0, sizeof(spectrum));
1258
1259 spectrum.channel_count = cpu_to_le16(1);
1260 spectrum.flags =
1261 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
1262 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
1263 cmd.len = sizeof(spectrum);
1264 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
1265
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001266 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001267 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001268 iwl3945_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -07001269 add_time,
1270 le16_to_cpu(priv->rxon_timing.beacon_interval));
1271 else
1272 spectrum.start_time = 0;
1273
1274 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
1275 spectrum.channels[0].channel = params->channel;
1276 spectrum.channels[0].type = type;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001277 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
Zhu Yib481de92007-09-25 17:54:57 -07001278 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
1279 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
1280
Samuel Ortiz518099a2009-01-19 15:30:27 -08001281 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001282 if (rc)
1283 return rc;
1284
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001285 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001286 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001287 IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -07001288 rc = -EIO;
1289 }
1290
1291 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
1292 switch (spectrum_resp_status) {
1293 case 0: /* Command will be handled */
1294 if (res->u.spectrum.id != 0xff) {
Tomas Winklere1623442009-01-27 14:27:56 -08001295 IWL_DEBUG_INFO(priv, "Replaced existing measurement: %d\n",
Ian Schrambc434dd2007-10-25 17:15:29 +08001296 res->u.spectrum.id);
Zhu Yib481de92007-09-25 17:54:57 -07001297 priv->measurement_status &= ~MEASUREMENT_READY;
1298 }
1299 priv->measurement_status |= MEASUREMENT_ACTIVE;
1300 rc = 0;
1301 break;
1302
1303 case 1: /* Command will not be handled */
1304 rc = -EAGAIN;
1305 break;
1306 }
1307
1308 dev_kfree_skb_any(cmd.meta.u.skb);
1309
1310 return rc;
1311}
1312#endif
1313
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001314static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001315 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001316{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001317 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
1318 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -07001319 struct delayed_work *pwork;
1320
1321 palive = &pkt->u.alive_frame;
1322
Tomas Winklere1623442009-01-27 14:27:56 -08001323 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
Zhu Yib481de92007-09-25 17:54:57 -07001324 "0x%01X 0x%01X\n",
1325 palive->is_valid, palive->ver_type,
1326 palive->ver_subtype);
1327
1328 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
Tomas Winklere1623442009-01-27 14:27:56 -08001329 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001330 memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
1331 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001332 pwork = &priv->init_alive_start;
1333 } else {
Tomas Winklere1623442009-01-27 14:27:56 -08001334 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001335 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001336 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001337 pwork = &priv->alive_start;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001338 iwl3945_disable_events(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001339 }
1340
1341 /* We delay the ALIVE response by 5ms to
1342 * give the HW RF Kill time to activate... */
1343 if (palive->is_valid == UCODE_VALID_OK)
1344 queue_delayed_work(priv->workqueue, pwork,
1345 msecs_to_jiffies(5));
1346 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001347 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001348}
1349
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001350static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001351 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001352{
Helmut Schaac7e035a2009-01-19 13:02:15 +01001353#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001354 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Helmut Schaac7e035a2009-01-19 13:02:15 +01001355#endif
Zhu Yib481de92007-09-25 17:54:57 -07001356
Tomas Winklere1623442009-01-27 14:27:56 -08001357 IWL_DEBUG_RX(priv, "Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
Zhu Yib481de92007-09-25 17:54:57 -07001358 return;
1359}
1360
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001361static void iwl3945_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07001362{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001363 struct iwl_priv *priv =
1364 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07001365 struct sk_buff *beacon;
1366
1367 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02001368 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07001369
1370 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001371 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07001372 return;
1373 }
1374
1375 mutex_lock(&priv->mutex);
1376 /* new beacon skb is allocated every time; dispose previous.*/
1377 if (priv->ibss_beacon)
1378 dev_kfree_skb(priv->ibss_beacon);
1379
1380 priv->ibss_beacon = beacon;
1381 mutex_unlock(&priv->mutex);
1382
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001383 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001384}
1385
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001386static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001387 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001388{
Samuel Ortizd08853a2009-01-23 13:45:17 -08001389#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001390 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001391 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
Zhu Yib481de92007-09-25 17:54:57 -07001392 u8 rate = beacon->beacon_notify_hdr.rate;
1393
Tomas Winklere1623442009-01-27 14:27:56 -08001394 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
Zhu Yib481de92007-09-25 17:54:57 -07001395 "tsf %d %d rate %d\n",
1396 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
1397 beacon->beacon_notify_hdr.failure_frame,
1398 le32_to_cpu(beacon->ibss_mgr_status),
1399 le32_to_cpu(beacon->high_tsf),
1400 le32_to_cpu(beacon->low_tsf), rate);
1401#endif
1402
Johannes Berg05c914f2008-09-11 00:01:58 +02001403 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -07001404 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1405 queue_work(priv->workqueue, &priv->beacon_update);
1406}
1407
Zhu Yib481de92007-09-25 17:54:57 -07001408/* Handle notification from uCode that card's power state is changing
1409 * due to software, hardware, or critical temperature RFKILL */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001410static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001411 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001412{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001413 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001414 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1415 unsigned long status = priv->status;
1416
Tomas Winklere1623442009-01-27 14:27:56 -08001417 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n",
Zhu Yib481de92007-09-25 17:54:57 -07001418 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1419 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1420
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001421 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001422 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1423
1424 if (flags & HW_CARD_DISABLED)
1425 set_bit(STATUS_RF_KILL_HW, &priv->status);
1426 else
1427 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1428
1429
1430 if (flags & SW_CARD_DISABLED)
1431 set_bit(STATUS_RF_KILL_SW, &priv->status);
1432 else
1433 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1434
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08001435 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001436
1437 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1438 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1439 (test_bit(STATUS_RF_KILL_SW, &status) !=
1440 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1441 queue_work(priv->workqueue, &priv->rf_kill);
1442 else
1443 wake_up_interruptible(&priv->wait_command_queue);
1444}
1445
1446/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001447 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07001448 *
1449 * Setup the RX handlers for each of the reply types sent from the uCode
1450 * to the host.
1451 *
1452 * This function chains into the hardware specific files for them to setup
1453 * any hardware specific handlers as well.
1454 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001455static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001456{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001457 priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
1458 priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
Abhijeet Kolekar261b9c32009-02-18 15:54:29 -08001459 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001460 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -08001461 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001462 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -08001463 iwl_rx_pm_debug_statistics_notif;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001464 priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001465
Ben Cahill9fbab512007-11-29 11:09:47 +08001466 /*
1467 * The same handler is used for both the REPLY to a discrete
1468 * statistics request from the host as well as for the periodic
1469 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07001470 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001471 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
1472 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
Zhu Yib481de92007-09-25 17:54:57 -07001473
Abhijeet Kolekar261b9c32009-02-18 15:54:29 -08001474 iwl_setup_spectrum_handlers(priv);
Abhijeet Kolekarcade0eb2009-02-18 15:54:26 -08001475 iwl_setup_rx_scan_handlers(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001476 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001477
Ben Cahill9fbab512007-11-29 11:09:47 +08001478 /* Set up hardware specific Rx handlers */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001479 iwl3945_hw_rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001480}
1481
1482/**
Tomas Winkler91c066f2008-03-06 17:36:55 -08001483 * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries
1484 * When FW advances 'R' index, all entries between old and new 'R' index
1485 * need to be reclaimed.
1486 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001487static void iwl3945_cmd_queue_reclaim(struct iwl_priv *priv,
Tomas Winkler91c066f2008-03-06 17:36:55 -08001488 int txq_id, int index)
1489{
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001490 struct iwl_tx_queue *txq = &priv->txq[txq_id];
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001491 struct iwl_queue *q = &txq->q;
Tomas Winkler91c066f2008-03-06 17:36:55 -08001492 int nfreed = 0;
1493
Winkler, Tomas625a3812009-01-08 10:19:55 -08001494 if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001495 IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, "
Tomas Winkler91c066f2008-03-06 17:36:55 -08001496 "is out of range [0-%d] %d %d.\n", txq_id,
1497 index, q->n_bd, q->write_ptr, q->read_ptr);
1498 return;
1499 }
1500
1501 for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
1502 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
1503 if (nfreed > 1) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001504 IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", index,
Tomas Winkler91c066f2008-03-06 17:36:55 -08001505 q->write_ptr, q->read_ptr);
1506 queue_work(priv->workqueue, &priv->restart);
1507 break;
1508 }
1509 nfreed++;
1510 }
1511}
1512
1513
1514/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001515 * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
Zhu Yib481de92007-09-25 17:54:57 -07001516 * @rxb: Rx buffer to reclaim
1517 *
1518 * If an Rx buffer has an async callback associated with it the callback
1519 * will be executed. The attached skb (if present) will only be freed
1520 * if the callback returns 1
1521 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001522static void iwl3945_tx_cmd_complete(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{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001525 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001526 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
1527 int txq_id = SEQ_TO_QUEUE(sequence);
1528 int index = SEQ_TO_INDEX(sequence);
Tomas Winkler600c0e12008-12-19 10:37:04 +08001529 int huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
Zhu Yib481de92007-09-25 17:54:57 -07001530 int cmd_index;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08001531 struct iwl_cmd *cmd;
Zhu Yib481de92007-09-25 17:54:57 -07001532
Chatre, Reinette638d0eb2009-01-19 15:30:24 -08001533 if (WARN(txq_id != IWL_CMD_QUEUE_NUM,
1534 "wrong command queue %d, sequence 0x%X readp=%d writep=%d\n",
1535 txq_id, sequence,
1536 priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr,
1537 priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) {
1538 iwl_print_hex_dump(priv, IWL_DL_INFO , rxb, 32);
1539 return;
1540 }
Zhu Yib481de92007-09-25 17:54:57 -07001541
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001542 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
1543 cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
Zhu Yib481de92007-09-25 17:54:57 -07001544
1545 /* Input error checking is done when commands are added to queue. */
1546 if (cmd->meta.flags & CMD_WANT_SKB) {
1547 cmd->meta.source->u.skb = rxb->skb;
1548 rxb->skb = NULL;
1549 } else if (cmd->meta.u.callback &&
1550 !cmd->meta.u.callback(priv, cmd, rxb->skb))
1551 rxb->skb = NULL;
1552
Tomas Winkler91c066f2008-03-06 17:36:55 -08001553 iwl3945_cmd_queue_reclaim(priv, txq_id, index);
Zhu Yib481de92007-09-25 17:54:57 -07001554
1555 if (!(cmd->meta.flags & CMD_ASYNC)) {
1556 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1557 wake_up_interruptible(&priv->wait_command_queue);
1558 }
1559}
1560
1561/************************** RX-FUNCTIONS ****************************/
1562/*
1563 * Rx theory of operation
1564 *
1565 * The host allocates 32 DMA target addresses and passes the host address
1566 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
1567 * 0 to 31
1568 *
1569 * Rx Queue Indexes
1570 * The host/firmware share two index registers for managing the Rx buffers.
1571 *
1572 * The READ index maps to the first position that the firmware may be writing
1573 * to -- the driver can read up to (but not including) this position and get
1574 * good data.
1575 * The READ index is managed by the firmware once the card is enabled.
1576 *
1577 * The WRITE index maps to the last position the driver has read from -- the
1578 * position preceding WRITE is the last slot the firmware can place a packet.
1579 *
1580 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
1581 * WRITE = READ.
1582 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001583 * During initialization, the host sets up the READ queue position to the first
Zhu Yib481de92007-09-25 17:54:57 -07001584 * INDEX position, and WRITE to the last (READ - 1 wrapped)
1585 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001586 * When the firmware places a packet in a buffer, it will advance the READ index
Zhu Yib481de92007-09-25 17:54:57 -07001587 * and fire the RX interrupt. The driver can then query the READ index and
1588 * process as many packets as possible, moving the WRITE index forward as it
1589 * resets the Rx queue buffers with new memory.
1590 *
1591 * The management in the driver is as follows:
1592 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
1593 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Ian Schram01ebd062007-10-25 17:15:22 +08001594 * to replenish the iwl->rxq->rx_free.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001595 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
Zhu Yib481de92007-09-25 17:54:57 -07001596 * iwl->rxq is replenished and the READ INDEX is updated (updating the
1597 * 'processed' and 'read' driver indexes as well)
1598 * + A received packet is processed and handed to the kernel network stack,
1599 * detached from the iwl->rxq. The driver 'processed' index is updated.
1600 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
1601 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
1602 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
1603 * were enough free buffers and RX_STALLED is set it is cleared.
1604 *
1605 *
1606 * Driver sequence:
1607 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001608 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001609 * iwl3945_rx_queue_restock
Ben Cahill9fbab512007-11-29 11:09:47 +08001610 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
Zhu Yib481de92007-09-25 17:54:57 -07001611 * queue, updates firmware pointers, and updates
1612 * the WRITE index. If insufficient rx_free buffers
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001613 * are available, schedules iwl3945_rx_replenish
Zhu Yib481de92007-09-25 17:54:57 -07001614 *
1615 * -- enable interrupts --
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001616 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
Zhu Yib481de92007-09-25 17:54:57 -07001617 * READ INDEX, detaching the SKB from the pool.
1618 * Moves the packet buffer from queue to rx_used.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001619 * Calls iwl3945_rx_queue_restock to refill any empty
Zhu Yib481de92007-09-25 17:54:57 -07001620 * slots.
1621 * ...
1622 *
1623 */
1624
1625/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001626 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
Zhu Yib481de92007-09-25 17:54:57 -07001627 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001628static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001629 dma_addr_t dma_addr)
1630{
1631 return cpu_to_le32((u32)dma_addr);
1632}
1633
1634/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001635 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
Zhu Yib481de92007-09-25 17:54:57 -07001636 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001637 * If there are slots in the RX queue that need to be restocked,
Zhu Yib481de92007-09-25 17:54:57 -07001638 * and we have free pre-allocated buffers, fill the ranks as much
Ben Cahill9fbab512007-11-29 11:09:47 +08001639 * as we can, pulling from rx_free.
Zhu Yib481de92007-09-25 17:54:57 -07001640 *
1641 * This moves the 'write' index forward to catch up with 'processed', and
1642 * also updates the memory address in the firmware to reference the new
1643 * target buffer.
1644 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001645static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001646{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001647 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001648 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001649 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001650 unsigned long flags;
1651 int write, rc;
1652
1653 spin_lock_irqsave(&rxq->lock, flags);
1654 write = rxq->write & ~0x7;
Winkler, Tomas37d68312009-01-08 10:19:54 -08001655 while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001656 /* Get next free Rx buffer, remove from free list */
Zhu Yib481de92007-09-25 17:54:57 -07001657 element = rxq->rx_free.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001658 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Zhu Yib481de92007-09-25 17:54:57 -07001659 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001660
1661 /* Point to Rx buffer via next RBD in circular buffer */
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001662 rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
Zhu Yib481de92007-09-25 17:54:57 -07001663 rxq->queue[rxq->write] = rxb;
1664 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
1665 rxq->free_count--;
1666 }
1667 spin_unlock_irqrestore(&rxq->lock, flags);
1668 /* If the pre-allocated buffer pool is dropping low, schedule to
1669 * refill it */
1670 if (rxq->free_count <= RX_LOW_WATERMARK)
1671 queue_work(priv->workqueue, &priv->rx_replenish);
1672
1673
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001674 /* If we've added more space for the firmware to place data, tell it.
1675 * Increment device's write pointer in multiples of 8. */
Zhu Yib481de92007-09-25 17:54:57 -07001676 if ((write != (rxq->write & ~0x7))
1677 || (abs(rxq->write - rxq->read) > 7)) {
1678 spin_lock_irqsave(&rxq->lock, flags);
1679 rxq->need_update = 1;
1680 spin_unlock_irqrestore(&rxq->lock, flags);
Winkler, Tomas141c43a2009-01-08 10:19:53 -08001681 rc = iwl_rx_queue_update_write_ptr(priv, rxq);
Zhu Yib481de92007-09-25 17:54:57 -07001682 if (rc)
1683 return rc;
1684 }
1685
1686 return 0;
1687}
1688
1689/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001690 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
Zhu Yib481de92007-09-25 17:54:57 -07001691 *
1692 * When moving to rx_free an SKB is allocated for the slot.
1693 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001694 * Also restock the Rx queue via iwl3945_rx_queue_restock.
Ian Schram01ebd062007-10-25 17:15:22 +08001695 * This is called as a scheduled work item (except for during initialization)
Zhu Yib481de92007-09-25 17:54:57 -07001696 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001697static void iwl3945_rx_allocate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001698{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001699 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001700 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001701 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001702 unsigned long flags;
1703 spin_lock_irqsave(&rxq->lock, flags);
1704 while (!list_empty(&rxq->rx_used)) {
1705 element = rxq->rx_used.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001706 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001707
1708 /* Alloc a new receive buffer */
Zhu Yib481de92007-09-25 17:54:57 -07001709 rxb->skb =
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001710 alloc_skb(priv->hw_params.rx_buf_size,
1711 __GFP_NOWARN | GFP_ATOMIC);
Zhu Yib481de92007-09-25 17:54:57 -07001712 if (!rxb->skb) {
1713 if (net_ratelimit())
Tomas Winkler978785a2008-12-19 10:37:31 +08001714 IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
Zhu Yib481de92007-09-25 17:54:57 -07001715 /* We don't reschedule replenish work here -- we will
1716 * call the restock method and if it still needs
1717 * more buffers it will schedule replenish */
1718 break;
1719 }
Zhu Yi12342c42007-12-20 11:27:32 +08001720
1721 /* If radiotap head is required, reserve some headroom here.
1722 * The physical head count is a variable rx_stats->phy_count.
1723 * We reserve 4 bytes here. Plus these extra bytes, the
1724 * headroom of the physical head should be enough for the
1725 * radiotap head that iwl3945 supported. See iwl3945_rt.
1726 */
1727 skb_reserve(rxb->skb, 4);
1728
Zhu Yib481de92007-09-25 17:54:57 -07001729 priv->alloc_rxb_skb++;
1730 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001731
1732 /* Get physical address of RB/SKB */
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001733 rxb->real_dma_addr = pci_map_single(priv->pci_dev,
1734 rxb->skb->data,
1735 priv->hw_params.rx_buf_size,
1736 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001737 list_add_tail(&rxb->list, &rxq->rx_free);
1738 rxq->free_count++;
1739 }
1740 spin_unlock_irqrestore(&rxq->lock, flags);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001741}
1742
1743/*
1744 * this should be called while priv->lock is locked
1745 */
Tomas Winkler4fd1f842007-12-05 20:59:58 +02001746static void __iwl3945_rx_replenish(void *data)
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001747{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001748 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001749
1750 iwl3945_rx_allocate(priv);
1751 iwl3945_rx_queue_restock(priv);
1752}
1753
1754
1755void iwl3945_rx_replenish(void *data)
1756{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001757 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001758 unsigned long flags;
1759
1760 iwl3945_rx_allocate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001761
1762 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001763 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001764 spin_unlock_irqrestore(&priv->lock, flags);
1765}
1766
Zhu Yib481de92007-09-25 17:54:57 -07001767/* Convert linear signal-to-noise ratio into dB */
1768static u8 ratio2dB[100] = {
1769/* 0 1 2 3 4 5 6 7 8 9 */
1770 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
1771 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
1772 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
1773 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
1774 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
1775 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
1776 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
1777 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
1778 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
1779 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
1780};
1781
1782/* Calculates a relative dB value from a ratio of linear
1783 * (i.e. not dB) signal levels.
1784 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001785int iwl3945_calc_db_from_ratio(int sig_ratio)
Zhu Yib481de92007-09-25 17:54:57 -07001786{
Adrian Bunk221c80c2008-02-02 23:19:01 +02001787 /* 1000:1 or higher just report as 60 dB */
1788 if (sig_ratio >= 1000)
Zhu Yib481de92007-09-25 17:54:57 -07001789 return 60;
1790
Adrian Bunk221c80c2008-02-02 23:19:01 +02001791 /* 100:1 or higher, divide by 10 and use table,
Zhu Yib481de92007-09-25 17:54:57 -07001792 * add 20 dB to make up for divide by 10 */
Adrian Bunk221c80c2008-02-02 23:19:01 +02001793 if (sig_ratio >= 100)
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001794 return 20 + (int)ratio2dB[sig_ratio/10];
Zhu Yib481de92007-09-25 17:54:57 -07001795
1796 /* We shouldn't see this */
1797 if (sig_ratio < 1)
1798 return 0;
1799
1800 /* Use table for ratios 1:1 - 99:1 */
1801 return (int)ratio2dB[sig_ratio];
1802}
1803
1804#define PERFECT_RSSI (-20) /* dBm */
1805#define WORST_RSSI (-95) /* dBm */
1806#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
1807
1808/* Calculate an indication of rx signal quality (a percentage, not dBm!).
1809 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
1810 * about formulas used below. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001811int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
Zhu Yib481de92007-09-25 17:54:57 -07001812{
1813 int sig_qual;
1814 int degradation = PERFECT_RSSI - rssi_dbm;
1815
1816 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
1817 * as indicator; formula is (signal dbm - noise dbm).
1818 * SNR at or above 40 is a great signal (100%).
1819 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
1820 * Weakest usable signal is usually 10 - 15 dB SNR. */
1821 if (noise_dbm) {
1822 if (rssi_dbm - noise_dbm >= 40)
1823 return 100;
1824 else if (rssi_dbm < noise_dbm)
1825 return 0;
1826 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
1827
1828 /* Else use just the signal level.
1829 * This formula is a least squares fit of data points collected and
1830 * compared with a reference system that had a percentage (%) display
1831 * for signal quality. */
1832 } else
1833 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
1834 (15 * RSSI_RANGE + 62 * degradation)) /
1835 (RSSI_RANGE * RSSI_RANGE);
1836
1837 if (sig_qual > 100)
1838 sig_qual = 100;
1839 else if (sig_qual < 1)
1840 sig_qual = 0;
1841
1842 return sig_qual;
1843}
1844
1845/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001846 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001847 *
1848 * Uses the priv->rx_handlers callback function array to invoke
1849 * the appropriate handlers, including command responses,
1850 * frame-received notifications, and other notifications.
1851 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001852static void iwl3945_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001853{
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001854 struct iwl_rx_mem_buffer *rxb;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001855 struct iwl_rx_packet *pkt;
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001856 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001857 u32 r, i;
1858 int reclaim;
1859 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001860 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001861 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07001862
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001863 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1864 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8cd812b2008-12-19 10:37:43 +08001865 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07001866 i = rxq->read;
1867
Winkler, Tomas37d68312009-01-08 10:19:54 -08001868 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001869 fill_rx = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001870 /* Rx interrupt, but nothing sent from uCode */
1871 if (i == r)
Tomas Winklere1623442009-01-27 14:27:56 -08001872 IWL_DEBUG(priv, IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001873
1874 while (i != r) {
1875 rxb = rxq->queue[i];
1876
Ben Cahill9fbab512007-11-29 11:09:47 +08001877 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001878 * then a bug has been introduced in the queue refilling
1879 * routines -- catch it here */
1880 BUG_ON(rxb == NULL);
1881
1882 rxq->queue[i] = NULL;
1883
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001884 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001885 priv->hw_params.rx_buf_size,
Zhu Yib481de92007-09-25 17:54:57 -07001886 PCI_DMA_FROMDEVICE);
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001887 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001888
1889 /* Reclaim a command buffer only if this packet is a response
1890 * to a (driver-originated) command.
1891 * If the packet (e.g. Rx frame) originated from uCode,
1892 * there is no command buffer to reclaim.
1893 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1894 * but apparently a few don't get set; catch them here. */
1895 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1896 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1897 (pkt->hdr.cmd != REPLY_TX);
1898
1899 /* Based on type of command response or notification,
1900 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001901 * rx_handlers table. See iwl3945_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001902 if (priv->rx_handlers[pkt->hdr.cmd]) {
Tomas Winklere1623442009-01-27 14:27:56 -08001903 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07001904 "r = %d, i = %d, %s, 0x%02x\n", r, i,
1905 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
1906 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1907 } else {
1908 /* No handling needed */
Tomas Winklere1623442009-01-27 14:27:56 -08001909 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07001910 "r %d i %d No handler needed for %s, 0x%02x\n",
1911 r, i, get_cmd_string(pkt->hdr.cmd),
1912 pkt->hdr.cmd);
1913 }
1914
1915 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001916 /* Invoke any callbacks, transfer the skb to caller, and
Samuel Ortiz518099a2009-01-19 15:30:27 -08001917 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001918 * as we reclaim the driver command queue */
1919 if (rxb && rxb->skb)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001920 iwl3945_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001921 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001922 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07001923 }
1924
1925 /* For now we just don't re-use anything. We can tweak this
1926 * later to try and re-use notification packets and SKBs that
1927 * fail to Rx correctly */
1928 if (rxb->skb != NULL) {
1929 priv->alloc_rxb_skb--;
1930 dev_kfree_skb_any(rxb->skb);
1931 rxb->skb = NULL;
1932 }
1933
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001934 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001935 priv->hw_params.rx_buf_size,
1936 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001937 spin_lock_irqsave(&rxq->lock, flags);
1938 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1939 spin_unlock_irqrestore(&rxq->lock, flags);
1940 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001941 /* If there are a lot of unused frames,
1942 * restock the Rx queue so ucode won't assert. */
1943 if (fill_rx) {
1944 count++;
1945 if (count >= 8) {
1946 priv->rxq.read = i;
1947 __iwl3945_rx_replenish(priv);
1948 count = 0;
1949 }
1950 }
Zhu Yib481de92007-09-25 17:54:57 -07001951 }
1952
1953 /* Backtrack one entry */
1954 priv->rxq.read = i;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001955 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001956}
1957
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001958/* call this function to flush any scheduled tasklet */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001959static inline void iwl_synchronize_irq(struct iwl_priv *priv)
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001960{
Tomas Winklera96a27f2008-10-23 23:48:56 -07001961 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001962 synchronize_irq(priv->pci_dev->irq);
1963 tasklet_kill(&priv->irq_tasklet);
1964}
1965
Zhu Yib481de92007-09-25 17:54:57 -07001966static const char *desc_lookup(int i)
1967{
1968 switch (i) {
1969 case 1:
1970 return "FAIL";
1971 case 2:
1972 return "BAD_PARAM";
1973 case 3:
1974 return "BAD_CHECKSUM";
1975 case 4:
1976 return "NMI_INTERRUPT";
1977 case 5:
1978 return "SYSASSERT";
1979 case 6:
1980 return "FATAL_ERROR";
1981 }
1982
1983 return "UNKNOWN";
1984}
1985
1986#define ERROR_START_OFFSET (1 * sizeof(u32))
1987#define ERROR_ELEM_SIZE (7 * sizeof(u32))
1988
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001989static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001990{
1991 u32 i;
1992 u32 desc, time, count, base, data1;
1993 u32 blink1, blink2, ilink1, ilink2;
1994 int rc;
1995
1996 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
1997
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001998 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001999 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07002000 return;
2001 }
2002
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002003 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002004 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002005 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002006 return;
2007 }
2008
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002009 count = iwl_read_targ_mem(priv, base);
Zhu Yib481de92007-09-25 17:54:57 -07002010
2011 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002012 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
2013 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
2014 priv->status, count);
Zhu Yib481de92007-09-25 17:54:57 -07002015 }
2016
Winkler, Tomas15b16872008-12-19 10:37:33 +08002017 IWL_ERR(priv, "Desc Time asrtPC blink2 "
Zhu Yib481de92007-09-25 17:54:57 -07002018 "ilink1 nmiPC Line\n");
2019 for (i = ERROR_START_OFFSET;
2020 i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
2021 i += ERROR_ELEM_SIZE) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002022 desc = iwl_read_targ_mem(priv, base + i);
Zhu Yib481de92007-09-25 17:54:57 -07002023 time =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002024 iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002025 blink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002026 iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002027 blink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002028 iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002029 ilink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002030 iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002031 ilink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002032 iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002033 data1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002034 iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002035
Winkler, Tomas15b16872008-12-19 10:37:33 +08002036 IWL_ERR(priv,
2037 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
2038 desc_lookup(desc), desc, time, blink1, blink2,
2039 ilink1, ilink2, data1);
Zhu Yib481de92007-09-25 17:54:57 -07002040 }
2041
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002042 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002043
2044}
2045
Ben Cahillf58177b2007-11-29 11:09:43 +08002046#define EVENT_START_OFFSET (6 * sizeof(u32))
Zhu Yib481de92007-09-25 17:54:57 -07002047
2048/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002049 * iwl3945_print_event_log - Dump error event log to syslog
Zhu Yib481de92007-09-25 17:54:57 -07002050 *
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002051 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
Zhu Yib481de92007-09-25 17:54:57 -07002052 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002053static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
Zhu Yib481de92007-09-25 17:54:57 -07002054 u32 num_events, u32 mode)
2055{
2056 u32 i;
2057 u32 base; /* SRAM byte address of event log header */
2058 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
2059 u32 ptr; /* SRAM byte address of log data */
2060 u32 ev, time, data; /* event log data */
2061
2062 if (num_events == 0)
2063 return;
2064
2065 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
2066
2067 if (mode == 0)
2068 event_size = 2 * sizeof(u32);
2069 else
2070 event_size = 3 * sizeof(u32);
2071
2072 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
2073
2074 /* "time" is actually "data" for mode 0 (no timestamp).
2075 * place event id # at far right for easier visual parsing. */
2076 for (i = 0; i < num_events; i++) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002077 ev = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002078 ptr += sizeof(u32);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002079 time = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002080 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002081 if (mode == 0) {
2082 /* data, ev */
2083 IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
2084 } else {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002085 data = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002086 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002087 IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
Zhu Yib481de92007-09-25 17:54:57 -07002088 }
2089 }
2090}
2091
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002092static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002093{
2094 int rc;
2095 u32 base; /* SRAM byte address of event log header */
2096 u32 capacity; /* event log capacity in # entries */
2097 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
2098 u32 num_wraps; /* # times uCode wrapped to top of log */
2099 u32 next_entry; /* index of next entry to be written by uCode */
2100 u32 size; /* # entries that we'll print */
2101
2102 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002103 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002104 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07002105 return;
2106 }
2107
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002108 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002109 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002110 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002111 return;
2112 }
2113
2114 /* event log header */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002115 capacity = iwl_read_targ_mem(priv, base);
2116 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
2117 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
2118 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
Zhu Yib481de92007-09-25 17:54:57 -07002119
2120 size = num_wraps ? capacity : next_entry;
2121
2122 /* bail out if nothing in log */
2123 if (size == 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002124 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002125 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002126 return;
2127 }
2128
Winkler, Tomas15b16872008-12-19 10:37:33 +08002129 IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07002130 size, num_wraps);
2131
2132 /* if uCode has wrapped back to top of log, start at the oldest entry,
2133 * i.e the next one that uCode would fill. */
2134 if (num_wraps)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002135 iwl3945_print_event_log(priv, next_entry,
Zhu Yib481de92007-09-25 17:54:57 -07002136 capacity - next_entry, mode);
2137
2138 /* (then/else) start at top of log */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002139 iwl3945_print_event_log(priv, 0, next_entry, mode);
Zhu Yib481de92007-09-25 17:54:57 -07002140
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002141 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002142}
2143
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002144static void iwl3945_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002145{
2146 unsigned long flags;
2147
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002148 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
2149 sizeof(priv->staging_rxon));
2150 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002151 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002152
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002153 iwl3945_add_station(priv, priv->bssid, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002154
2155 spin_lock_irqsave(&priv->lock, flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002156 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07002157 priv->error_recovering = 0;
2158 spin_unlock_irqrestore(&priv->lock, flags);
2159}
2160
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002161static void iwl3945_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002162{
2163 u32 inta, handled = 0;
2164 u32 inta_fh;
2165 unsigned long flags;
Samuel Ortizd08853a2009-01-23 13:45:17 -08002166#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07002167 u32 inta_mask;
2168#endif
2169
2170 spin_lock_irqsave(&priv->lock, flags);
2171
2172 /* Ack/clear/reset pending uCode interrupts.
2173 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
2174 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002175 inta = iwl_read32(priv, CSR_INT);
2176 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07002177
2178 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
2179 * Any new interrupts that happen after this, either while we're
2180 * in this tasklet, or later, will show up in next ISR/tasklet. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002181 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
2182 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07002183
Samuel Ortizd08853a2009-01-23 13:45:17 -08002184#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002185 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08002186 /* just for debug */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002187 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Tomas Winklere1623442009-01-27 14:27:56 -08002188 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002189 inta, inta_mask, inta_fh);
2190 }
2191#endif
2192
2193 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
2194 * atomic, make sure that inta covers all the interrupts that
2195 * we've discovered, even if FH interrupt came in just after
2196 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002197 if (inta_fh & CSR39_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002198 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002199 if (inta_fh & CSR39_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002200 inta |= CSR_INT_BIT_FH_TX;
2201
2202 /* Now service all interrupt bits discovered above. */
2203 if (inta & CSR_INT_BIT_HW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002204 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002205
2206 /* Tell the device to stop sending interrupts */
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002207 iwl_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002208
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002209 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002210
2211 handled |= CSR_INT_BIT_HW_ERR;
2212
2213 spin_unlock_irqrestore(&priv->lock, flags);
2214
2215 return;
2216 }
2217
Samuel Ortizd08853a2009-01-23 13:45:17 -08002218#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002219 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07002220 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002221 if (inta & CSR_INT_BIT_SCD)
Tomas Winklere1623442009-01-27 14:27:56 -08002222 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
Joonwoo Park25c03d82008-01-23 10:15:20 -08002223 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002224
2225 /* Alive notification via Rx interrupt will do the real work */
2226 if (inta & CSR_INT_BIT_ALIVE)
Tomas Winklere1623442009-01-27 14:27:56 -08002227 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002228 }
2229#endif
2230 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002231 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07002232
Zhu Yib481de92007-09-25 17:54:57 -07002233 /* Error detected by uCode */
2234 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002235 IWL_ERR(priv, "Microcode SW error detected. "
2236 "Restarting 0x%X.\n", inta);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002237 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002238 handled |= CSR_INT_BIT_SW_ERR;
2239 }
2240
2241 /* uCode wakes up after power-down sleep */
2242 if (inta & CSR_INT_BIT_WAKEUP) {
Tomas Winklere1623442009-01-27 14:27:56 -08002243 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
Winkler, Tomas141c43a2009-01-08 10:19:53 -08002244 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08002245 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
2246 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
2247 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
2248 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
2249 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
2250 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07002251
2252 handled |= CSR_INT_BIT_WAKEUP;
2253 }
2254
2255 /* All uCode command responses, including Tx command responses,
2256 * Rx "responses" (frame-received notification), and other
2257 * notifications from uCode come through here*/
2258 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002259 iwl3945_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002260 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
2261 }
2262
2263 if (inta & CSR_INT_BIT_FH_TX) {
Tomas Winklere1623442009-01-27 14:27:56 -08002264 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002265
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002266 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
2267 if (!iwl_grab_nic_access(priv)) {
2268 iwl_write_direct32(priv, FH39_TCSR_CREDIT
Tomas Winklerbddadf82008-12-19 10:37:01 +08002269 (FH39_SRVC_CHNL), 0x0);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002270 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002271 }
2272 handled |= CSR_INT_BIT_FH_TX;
2273 }
2274
2275 if (inta & ~handled)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002276 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Zhu Yib481de92007-09-25 17:54:57 -07002277
2278 if (inta & ~CSR_INI_SET_MASK) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002279 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Zhu Yib481de92007-09-25 17:54:57 -07002280 inta & ~CSR_INI_SET_MASK);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002281 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07002282 }
2283
2284 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002285 /* only Re-enable if disabled by irq */
2286 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002287 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002288
Samuel Ortizd08853a2009-01-23 13:45:17 -08002289#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002290 if (priv->debug_level & (IWL_DL_ISR)) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002291 inta = iwl_read32(priv, CSR_INT);
2292 inta_mask = iwl_read32(priv, CSR_INT_MASK);
2293 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Tomas Winklere1623442009-01-27 14:27:56 -08002294 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
Zhu Yib481de92007-09-25 17:54:57 -07002295 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
2296 }
2297#endif
2298 spin_unlock_irqrestore(&priv->lock, flags);
2299}
2300
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002301static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01002302 enum ieee80211_band band,
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08002303 u8 is_active, u8 n_probes,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002304 struct iwl3945_scan_channel *scan_ch)
Zhu Yib481de92007-09-25 17:54:57 -07002305{
2306 const struct ieee80211_channel *channels = NULL;
Johannes Berg8318d782008-01-24 19:38:38 +01002307 const struct ieee80211_supported_band *sband;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08002308 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07002309 u16 passive_dwell = 0;
2310 u16 active_dwell = 0;
2311 int added, i;
2312
Kolekar, Abhijeetcbba18c2008-12-19 10:37:42 +08002313 sband = iwl_get_hw_mode(priv, band);
Johannes Berg8318d782008-01-24 19:38:38 +01002314 if (!sband)
Zhu Yib481de92007-09-25 17:54:57 -07002315 return 0;
2316
Johannes Berg8318d782008-01-24 19:38:38 +01002317 channels = sband->channels;
Zhu Yib481de92007-09-25 17:54:57 -07002318
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08002319 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
2320 passive_dwell = iwl_get_passive_dwell_time(priv, band);
Zhu Yib481de92007-09-25 17:54:57 -07002321
Abhijeet Kolekar8f4807a2008-09-03 11:26:31 +08002322 if (passive_dwell <= active_dwell)
2323 passive_dwell = active_dwell + 1;
2324
Johannes Berg8318d782008-01-24 19:38:38 +01002325 for (i = 0, added = 0; i < sband->n_channels; i++) {
Johannes Berg182e2e62008-04-04 10:41:56 +02002326 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
2327 continue;
2328
Johannes Berg8318d782008-01-24 19:38:38 +01002329 scan_ch->channel = channels[i].hw_value;
Zhu Yib481de92007-09-25 17:54:57 -07002330
Samuel Ortize6148912009-01-23 13:45:15 -08002331 ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
Zhu Yib481de92007-09-25 17:54:57 -07002332 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002333 IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
Zhu Yib481de92007-09-25 17:54:57 -07002334 scan_ch->channel);
2335 continue;
2336 }
2337
Zhu Yib481de92007-09-25 17:54:57 -07002338 scan_ch->active_dwell = cpu_to_le16(active_dwell);
2339 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002340 /* If passive , set up for auto-switch
2341 * and use long active_dwell time.
2342 */
2343 if (!is_active || is_channel_passive(ch_info) ||
2344 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
2345 scan_ch->type = 0; /* passive */
2346 if (IWL_UCODE_API(priv->ucode_ver) == 1)
2347 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
2348 } else {
2349 scan_ch->type = 1; /* active */
2350 }
2351
2352 /* Set direct probe bits. These may be used both for active
2353 * scan channels (probes gets sent right away),
2354 * or for passive channels (probes get se sent only after
2355 * hearing clear Rx packet).*/
2356 if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
2357 if (n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002358 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002359 } else {
2360 /* uCode v1 does not allow setting direct probe bits on
2361 * passive channel. */
2362 if ((scan_ch->type & 1) && n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002363 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002364 }
Zhu Yib481de92007-09-25 17:54:57 -07002365
Ben Cahill9fbab512007-11-29 11:09:47 +08002366 /* Set txpower levels to defaults */
Zhu Yib481de92007-09-25 17:54:57 -07002367 scan_ch->tpc.dsp_atten = 110;
2368 /* scan_pwr_info->tpc.dsp_atten; */
2369
2370 /*scan_pwr_info->tpc.tx_gain; */
Johannes Berg8318d782008-01-24 19:38:38 +01002371 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -07002372 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
2373 else {
2374 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
2375 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
Ben Cahill9fbab512007-11-29 11:09:47 +08002376 * power level:
Reinette Chatre8a1b0242008-01-14 17:46:25 -08002377 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
Zhu Yib481de92007-09-25 17:54:57 -07002378 */
2379 }
2380
Tomas Winklere1623442009-01-27 14:27:56 -08002381 IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n",
Zhu Yib481de92007-09-25 17:54:57 -07002382 scan_ch->channel,
2383 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
2384 (scan_ch->type & 1) ?
2385 active_dwell : passive_dwell);
2386
2387 scan_ch++;
2388 added++;
2389 }
2390
Tomas Winklere1623442009-01-27 14:27:56 -08002391 IWL_DEBUG_SCAN(priv, "total channels to scan %d \n", added);
Zhu Yib481de92007-09-25 17:54:57 -07002392 return added;
2393}
2394
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002395static void iwl3945_init_hw_rates(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002396 struct ieee80211_rate *rates)
2397{
2398 int i;
2399
2400 for (i = 0; i < IWL_RATE_COUNT; i++) {
Johannes Berg8318d782008-01-24 19:38:38 +01002401 rates[i].bitrate = iwl3945_rates[i].ieee * 5;
2402 rates[i].hw_value = i; /* Rate scaling will work on indexes */
2403 rates[i].hw_value_short = i;
2404 rates[i].flags = 0;
Samuel Ortizd9829a62008-12-19 10:37:12 +08002405 if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
Zhu Yib481de92007-09-25 17:54:57 -07002406 /*
Johannes Berg8318d782008-01-24 19:38:38 +01002407 * If CCK != 1M then set short preamble rate flag.
Zhu Yib481de92007-09-25 17:54:57 -07002408 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002409 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
Johannes Berg8318d782008-01-24 19:38:38 +01002410 0 : IEEE80211_RATE_SHORT_PREAMBLE;
Zhu Yib481de92007-09-25 17:54:57 -07002411 }
Zhu Yib481de92007-09-25 17:54:57 -07002412 }
2413}
2414
Zhu Yib481de92007-09-25 17:54:57 -07002415/******************************************************************************
2416 *
2417 * uCode download functions
2418 *
2419 ******************************************************************************/
2420
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002421static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002422{
Tomas Winkler98c92212008-01-14 17:46:20 -08002423 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
2424 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
2425 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
2426 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
2427 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
2428 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07002429}
2430
2431/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002432 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002433 * looking at all data.
2434 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002435static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002436{
2437 u32 val;
2438 u32 save_len = len;
2439 int rc = 0;
2440 u32 errcnt;
2441
Tomas Winklere1623442009-01-27 14:27:56 -08002442 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002443
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002444 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002445 if (rc)
2446 return rc;
2447
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002448 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002449 IWL39_RTC_INST_LOWER_BOUND);
Zhu Yib481de92007-09-25 17:54:57 -07002450
2451 errcnt = 0;
2452 for (; len > 0; len -= sizeof(u32), image++) {
2453 /* read data comes through single port, auto-incr addr */
2454 /* NOTE: Use the debugless read so we don't flood kernel log
2455 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002456 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002457 if (val != le32_to_cpu(*image)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002458 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002459 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2460 save_len - len, val, le32_to_cpu(*image));
2461 rc = -EIO;
2462 errcnt++;
2463 if (errcnt >= 20)
2464 break;
2465 }
2466 }
2467
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002468 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002469
2470 if (!errcnt)
Tomas Winklere1623442009-01-27 14:27:56 -08002471 IWL_DEBUG_INFO(priv,
2472 "ucode image in INSTRUCTION memory is good\n");
Zhu Yib481de92007-09-25 17:54:57 -07002473
2474 return rc;
2475}
2476
2477
2478/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002479 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002480 * using sample data 100 bytes apart. If these sample points are good,
2481 * it's a pretty good bet that everything between them is good, too.
2482 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002483static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002484{
2485 u32 val;
2486 int rc = 0;
2487 u32 errcnt = 0;
2488 u32 i;
2489
Tomas Winklere1623442009-01-27 14:27:56 -08002490 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002491
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002492 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002493 if (rc)
2494 return rc;
2495
2496 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
2497 /* read data comes through single port, auto-incr addr */
2498 /* NOTE: Use the debugless read so we don't flood kernel log
2499 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002500 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002501 i + IWL39_RTC_INST_LOWER_BOUND);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002502 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002503 if (val != le32_to_cpu(*image)) {
2504#if 0 /* Enable this if you want to see details */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002505 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002506 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2507 i, val, *image);
2508#endif
2509 rc = -EIO;
2510 errcnt++;
2511 if (errcnt >= 3)
2512 break;
2513 }
2514 }
2515
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002516 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002517
2518 return rc;
2519}
2520
2521
2522/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002523 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
Zhu Yib481de92007-09-25 17:54:57 -07002524 * and verify its contents
2525 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002526static int iwl3945_verify_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002527{
2528 __le32 *image;
2529 u32 len;
2530 int rc = 0;
2531
2532 /* Try bootstrap */
2533 image = (__le32 *)priv->ucode_boot.v_addr;
2534 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002535 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002536 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002537 IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002538 return 0;
2539 }
2540
2541 /* Try initialize */
2542 image = (__le32 *)priv->ucode_init.v_addr;
2543 len = priv->ucode_init.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002544 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002545 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002546 IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002547 return 0;
2548 }
2549
2550 /* Try runtime/protocol */
2551 image = (__le32 *)priv->ucode_code.v_addr;
2552 len = priv->ucode_code.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002553 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002554 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002555 IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002556 return 0;
2557 }
2558
Winkler, Tomas15b16872008-12-19 10:37:33 +08002559 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
Zhu Yib481de92007-09-25 17:54:57 -07002560
Ben Cahill9fbab512007-11-29 11:09:47 +08002561 /* Since nothing seems to match, show first several data entries in
2562 * instruction SRAM, so maybe visual inspection will give a clue.
2563 * Selection of bootstrap image (vs. other images) is arbitrary. */
Zhu Yib481de92007-09-25 17:54:57 -07002564 image = (__le32 *)priv->ucode_boot.v_addr;
2565 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002566 rc = iwl3945_verify_inst_full(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002567
2568 return rc;
2569}
2570
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002571static void iwl3945_nic_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002572{
2573 /* Remove all resets to allow NIC to operate */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002574 iwl_write32(priv, CSR_RESET, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002575}
2576
2577/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002578 * iwl3945_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07002579 *
2580 * Copy into buffers for card to fetch via bus-mastering
2581 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002582static int iwl3945_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002583{
Kolekar, Abhijeeta78fe752008-12-19 10:37:21 +08002584 struct iwl_ucode *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002585 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07002586 const struct firmware *ucode_raw;
2587 /* firmware file name contains uCode/driver compatibility version */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002588 const char *name_pre = priv->cfg->fw_name_pre;
2589 const unsigned int api_max = priv->cfg->ucode_api_max;
2590 const unsigned int api_min = priv->cfg->ucode_api_min;
2591 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07002592 u8 *src;
2593 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002594 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07002595
2596 /* Ask kernel firmware_class module to get the boot firmware off disk.
2597 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002598 for (index = api_max; index >= api_min; index--) {
2599 sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
2600 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
2601 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002602 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002603 buf, ret);
2604 if (ret == -ENOENT)
2605 continue;
2606 else
2607 goto error;
2608 } else {
2609 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002610 IWL_ERR(priv, "Loaded firmware %s, "
2611 "which is deprecated. "
2612 " Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002613 buf, api_max);
Tomas Winklere1623442009-01-27 14:27:56 -08002614 IWL_DEBUG_INFO(priv, "Got firmware '%s' file "
2615 "(%zd bytes) from disk\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002616 buf, ucode_raw->size);
2617 break;
2618 }
Zhu Yib481de92007-09-25 17:54:57 -07002619 }
2620
Reinette Chatrea0987a82008-12-02 12:14:06 -08002621 if (ret < 0)
2622 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07002623
2624 /* Make sure that we got at least our header! */
2625 if (ucode_raw->size < sizeof(*ucode)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002626 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002627 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002628 goto err_release;
2629 }
2630
2631 /* Data from ucode file: header followed by uCode images */
2632 ucode = (void *)ucode_raw->data;
2633
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08002634 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08002635 api_ver = IWL_UCODE_API(priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07002636 inst_size = le32_to_cpu(ucode->inst_size);
2637 data_size = le32_to_cpu(ucode->data_size);
2638 init_size = le32_to_cpu(ucode->init_size);
2639 init_data_size = le32_to_cpu(ucode->init_data_size);
2640 boot_size = le32_to_cpu(ucode->boot_size);
2641
Reinette Chatrea0987a82008-12-02 12:14:06 -08002642 /* api_ver should match the api version forming part of the
2643 * firmware filename ... but we don't check for that and only rely
2644 * on the API version read from firware header from here on forward */
2645
2646 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002647 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002648 "Driver supports v%u, firmware is v%u.\n",
2649 api_max, api_ver);
2650 priv->ucode_ver = 0;
2651 ret = -EINVAL;
2652 goto err_release;
2653 }
2654 if (api_ver != api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002655 IWL_ERR(priv, "Firmware has old API version. Expected %u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002656 "got %u. New firmware can be obtained "
2657 "from http://www.intellinuxwireless.org.\n",
2658 api_max, api_ver);
2659
Tomas Winkler978785a2008-12-19 10:37:31 +08002660 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
2661 IWL_UCODE_MAJOR(priv->ucode_ver),
2662 IWL_UCODE_MINOR(priv->ucode_ver),
2663 IWL_UCODE_API(priv->ucode_ver),
2664 IWL_UCODE_SERIAL(priv->ucode_ver));
2665
Tomas Winklere1623442009-01-27 14:27:56 -08002666 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002667 priv->ucode_ver);
Tomas Winklere1623442009-01-27 14:27:56 -08002668 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
2669 inst_size);
2670 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
2671 data_size);
2672 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
2673 init_size);
2674 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
2675 init_data_size);
2676 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
2677 boot_size);
Zhu Yib481de92007-09-25 17:54:57 -07002678
Reinette Chatrea0987a82008-12-02 12:14:06 -08002679
Zhu Yib481de92007-09-25 17:54:57 -07002680 /* Verify size of file vs. image size info in file's header */
2681 if (ucode_raw->size < sizeof(*ucode) +
2682 inst_size + data_size + init_size +
2683 init_data_size + boot_size) {
2684
Tomas Winklere1623442009-01-27 14:27:56 -08002685 IWL_DEBUG_INFO(priv, "uCode file size %zd too small\n",
2686 ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002687 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002688 goto err_release;
2689 }
2690
2691 /* Verify that uCode images will fit in card's SRAM */
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002692 if (inst_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002693 IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002694 inst_size);
2695 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002696 goto err_release;
2697 }
2698
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002699 if (data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002700 IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002701 data_size);
2702 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002703 goto err_release;
2704 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002705 if (init_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002706 IWL_DEBUG_INFO(priv,
2707 "uCode init instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002708 init_size);
2709 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002710 goto err_release;
2711 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002712 if (init_data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002713 IWL_DEBUG_INFO(priv,
2714 "uCode init data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002715 init_data_size);
2716 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002717 goto err_release;
2718 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002719 if (boot_size > IWL39_MAX_BSM_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002720 IWL_DEBUG_INFO(priv,
2721 "uCode boot instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002722 boot_size);
2723 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002724 goto err_release;
2725 }
2726
2727 /* Allocate ucode buffers for card's bus-master loading ... */
2728
2729 /* Runtime instructions and 2 copies of data:
2730 * 1) unmodified from disk
2731 * 2) backup cache for save/restore during power-downs */
2732 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002733 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07002734
2735 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002736 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07002737
2738 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002739 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07002740
2741 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
Tomas Winkler90e759d2007-11-29 11:09:41 +08002742 !priv->ucode_data_backup.v_addr)
Zhu Yib481de92007-09-25 17:54:57 -07002743 goto err_pci_alloc;
2744
Tomas Winkler90e759d2007-11-29 11:09:41 +08002745 /* Initialization instructions and data */
2746 if (init_size && init_data_size) {
2747 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002748 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002749
2750 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002751 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002752
2753 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
2754 goto err_pci_alloc;
2755 }
2756
2757 /* Bootstrap (instructions only, no data) */
2758 if (boot_size) {
2759 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002760 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002761
2762 if (!priv->ucode_boot.v_addr)
2763 goto err_pci_alloc;
2764 }
2765
Zhu Yib481de92007-09-25 17:54:57 -07002766 /* Copy images into buffers for card's bus-master reads ... */
2767
2768 /* Runtime instructions (first block of data in file) */
2769 src = &ucode->data[0];
2770 len = priv->ucode_code.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002771 IWL_DEBUG_INFO(priv,
2772 "Copying (but not loading) uCode instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002773 memcpy(priv->ucode_code.v_addr, src, len);
Tomas Winklere1623442009-01-27 14:27:56 -08002774 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002775 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
2776
2777 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002778 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
Zhu Yib481de92007-09-25 17:54:57 -07002779 src = &ucode->data[inst_size];
2780 len = priv->ucode_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002781 IWL_DEBUG_INFO(priv,
2782 "Copying (but not loading) uCode data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002783 memcpy(priv->ucode_data.v_addr, src, len);
2784 memcpy(priv->ucode_data_backup.v_addr, src, len);
2785
2786 /* Initialization instructions (3rd block) */
2787 if (init_size) {
2788 src = &ucode->data[inst_size + data_size];
2789 len = priv->ucode_init.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002790 IWL_DEBUG_INFO(priv,
2791 "Copying (but not loading) init instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002792 memcpy(priv->ucode_init.v_addr, src, len);
2793 }
2794
2795 /* Initialization data (4th block) */
2796 if (init_data_size) {
2797 src = &ucode->data[inst_size + data_size + init_size];
2798 len = priv->ucode_init_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002799 IWL_DEBUG_INFO(priv,
2800 "Copying (but not loading) init data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002801 memcpy(priv->ucode_init_data.v_addr, src, len);
2802 }
2803
2804 /* Bootstrap instructions (5th block) */
2805 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
2806 len = priv->ucode_boot.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002807 IWL_DEBUG_INFO(priv,
2808 "Copying (but not loading) boot instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002809 memcpy(priv->ucode_boot.v_addr, src, len);
2810
2811 /* We have our copies now, allow OS release its copies */
2812 release_firmware(ucode_raw);
2813 return 0;
2814
2815 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08002816 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002817 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002818 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002819
2820 err_release:
2821 release_firmware(ucode_raw);
2822
2823 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08002824 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002825}
2826
2827
2828/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002829 * iwl3945_set_ucode_ptrs - Set uCode address location
Zhu Yib481de92007-09-25 17:54:57 -07002830 *
2831 * Tell initialization uCode where to find runtime uCode.
2832 *
2833 * BSM registers initially contain pointers to initialization uCode.
2834 * We need to replace them to load runtime uCode inst and data,
2835 * and to save runtime data when powering down.
2836 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002837static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002838{
2839 dma_addr_t pinst;
2840 dma_addr_t pdata;
2841 int rc = 0;
2842 unsigned long flags;
2843
2844 /* bits 31:0 for 3945 */
2845 pinst = priv->ucode_code.p_addr;
2846 pdata = priv->ucode_data_backup.p_addr;
2847
2848 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002849 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002850 if (rc) {
2851 spin_unlock_irqrestore(&priv->lock, flags);
2852 return rc;
2853 }
2854
2855 /* Tell bootstrap uCode where to find image to load */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002856 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
2857 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
2858 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002859 priv->ucode_data.len);
2860
Tomas Winklera96a27f2008-10-23 23:48:56 -07002861 /* Inst byte count must be last to set up, bit 31 signals uCode
Zhu Yib481de92007-09-25 17:54:57 -07002862 * that all new ptr/size info is in place */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002863 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002864 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
2865
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002866 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002867
2868 spin_unlock_irqrestore(&priv->lock, flags);
2869
Tomas Winklere1623442009-01-27 14:27:56 -08002870 IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002871
2872 return rc;
2873}
2874
2875/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002876 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002877 *
2878 * Called after REPLY_ALIVE notification received from "initialize" uCode.
2879 *
Zhu Yib481de92007-09-25 17:54:57 -07002880 * Tell "initialize" uCode to go ahead and load the runtime uCode.
Ben Cahill9fbab512007-11-29 11:09:47 +08002881 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002882static void iwl3945_init_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002883{
2884 /* Check alive response for "valid" sign from uCode */
2885 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
2886 /* We had an error bringing up the hardware, so take it
2887 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002888 IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002889 goto restart;
2890 }
2891
2892 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
2893 * This is a paranoid check, because we would not have gotten the
2894 * "initialize" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002895 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002896 /* Runtime instruction load was bad;
2897 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002898 IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002899 goto restart;
2900 }
2901
2902 /* Send pointers to protocol/runtime uCode image ... init code will
2903 * load and launch runtime uCode, which will send us another "Alive"
2904 * notification. */
Tomas Winklere1623442009-01-27 14:27:56 -08002905 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002906 if (iwl3945_set_ucode_ptrs(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002907 /* Runtime instruction load won't happen;
2908 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002909 IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002910 goto restart;
2911 }
2912 return;
2913
2914 restart:
2915 queue_work(priv->workqueue, &priv->restart);
2916}
2917
2918
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08002919/* temporary */
2920static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw,
2921 struct sk_buff *skb);
2922
Zhu Yib481de92007-09-25 17:54:57 -07002923/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002924 * iwl3945_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002925 * from protocol/runtime uCode (initialization uCode's
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002926 * Alive gets handled by iwl3945_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07002927 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002928static void iwl3945_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002929{
2930 int rc = 0;
2931 int thermal_spin = 0;
2932 u32 rfkill;
2933
Tomas Winklere1623442009-01-27 14:27:56 -08002934 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002935
2936 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
2937 /* We had an error bringing up the hardware, so take it
2938 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002939 IWL_DEBUG_INFO(priv, "Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002940 goto restart;
2941 }
2942
2943 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
2944 * This is a paranoid check, because we would not have gotten the
2945 * "runtime" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002946 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002947 /* Runtime instruction load was bad;
2948 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002949 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002950 goto restart;
2951 }
2952
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002953 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002954
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002955 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002956 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002957 IWL_WARN(priv, "Can not read RFKILL status from adapter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002958 return;
2959 }
2960
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002961 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
Tomas Winklere1623442009-01-27 14:27:56 -08002962 IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002963 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002964
2965 if (rfkill & 0x1) {
2966 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winklera96a27f2008-10-23 23:48:56 -07002967 /* if RFKILL is not on, then wait for thermal
Zhu Yib481de92007-09-25 17:54:57 -07002968 * sensor in adapter to kick in */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002969 while (iwl3945_hw_get_temperature(priv) == 0) {
Zhu Yib481de92007-09-25 17:54:57 -07002970 thermal_spin++;
2971 udelay(10);
2972 }
2973
2974 if (thermal_spin)
Tomas Winklere1623442009-01-27 14:27:56 -08002975 IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n",
Zhu Yib481de92007-09-25 17:54:57 -07002976 thermal_spin * 10);
2977 } else
2978 set_bit(STATUS_RF_KILL_HW, &priv->status);
2979
Ben Cahill9fbab512007-11-29 11:09:47 +08002980 /* After the ALIVE response, we can send commands to 3945 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07002981 set_bit(STATUS_ALIVE, &priv->status);
2982
2983 /* Clear out the uCode error bit if it is set */
2984 clear_bit(STATUS_FW_ERROR, &priv->status);
2985
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002986 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002987 return;
2988
Johannes Berg36d68252008-05-15 12:55:26 +02002989 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002990
2991 priv->active_rate = priv->rates_mask;
2992 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
2993
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08002994 iwl_power_update_mode(priv, false);
Zhu Yib481de92007-09-25 17:54:57 -07002995
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002996 if (iwl_is_associated(priv)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002997 struct iwl3945_rxon_cmd *active_rxon =
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002998 (struct iwl3945_rxon_cmd *)(&priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07002999
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003000 memcpy(&priv->staging_rxon, &priv->active_rxon,
3001 sizeof(priv->staging_rxon));
Zhu Yib481de92007-09-25 17:54:57 -07003002 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3003 } else {
3004 /* Initialize our rx_config data */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003005 iwl_connection_init_rx_config(priv, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003006 }
3007
Ben Cahill9fbab512007-11-29 11:09:47 +08003008 /* Configure Bluetooth device coexistence support */
Samuel Ortiz17f841c2009-01-23 13:45:20 -08003009 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003010
3011 /* Configure the adapter for unassociated operation */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003012 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003013
Zhu Yib481de92007-09-25 17:54:57 -07003014 iwl3945_reg_txpower_periodic(priv);
3015
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07003016 iwl3945_led_register(priv);
3017
Tomas Winklere1623442009-01-27 14:27:56 -08003018 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07003019 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a669262008-01-14 17:46:18 -08003020 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07003021
3022 if (priv->error_recovering)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003023 iwl3945_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003024
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003025 /* reassociate for ADHOC mode */
3026 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
3027 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
3028 priv->vif);
3029 if (beacon)
3030 iwl3945_mac_beacon_update(priv->hw, beacon);
3031 }
3032
Zhu Yib481de92007-09-25 17:54:57 -07003033 return;
3034
3035 restart:
3036 queue_work(priv->workqueue, &priv->restart);
3037}
3038
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003039static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07003040
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003041static void __iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003042{
3043 unsigned long flags;
3044 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
3045 struct ieee80211_conf *conf = NULL;
3046
Tomas Winklere1623442009-01-27 14:27:56 -08003047 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07003048
3049 conf = ieee80211_get_hw_conf(priv->hw);
3050
3051 if (!exit_pending)
3052 set_bit(STATUS_EXIT_PENDING, &priv->status);
3053
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07003054 iwl3945_led_unregister(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003055 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003056
3057 /* Unblock any waiting calls */
3058 wake_up_interruptible_all(&priv->wait_command_queue);
3059
Zhu Yib481de92007-09-25 17:54:57 -07003060 /* Wipe out the EXIT_PENDING status bit if we are not actually
3061 * exiting the module */
3062 if (!exit_pending)
3063 clear_bit(STATUS_EXIT_PENDING, &priv->status);
3064
3065 /* stop and reset the on-board processor */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003066 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07003067
3068 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003069 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08003070 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003071 spin_unlock_irqrestore(&priv->lock, flags);
3072 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003073
3074 if (priv->mac80211_registered)
3075 ieee80211_stop_queues(priv->hw);
3076
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003077 /* If we have not previously called iwl3945_init() then
Zhu Yib481de92007-09-25 17:54:57 -07003078 * clear all bits but the RF Kill and SUSPEND bits and return */
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003079 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003080 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3081 STATUS_RF_KILL_HW |
3082 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3083 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08003084 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3085 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07003086 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003087 STATUS_IN_SUSPEND |
3088 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3089 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07003090 goto exit;
3091 }
3092
3093 /* ...otherwise clear out all the status bits but the RF Kill and
3094 * SUSPEND bits and continue taking the NIC down. */
3095 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3096 STATUS_RF_KILL_HW |
3097 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3098 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08003099 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3100 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07003101 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
3102 STATUS_IN_SUSPEND |
3103 test_bit(STATUS_FW_ERROR, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003104 STATUS_FW_ERROR |
3105 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3106 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07003107
Abbas, Mohamede9414b62009-01-20 21:33:55 -08003108 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003109 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003110 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07003111 spin_unlock_irqrestore(&priv->lock, flags);
3112
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003113 iwl3945_hw_txq_ctx_stop(priv);
3114 iwl3945_hw_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003115
3116 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003117 if (!iwl_grab_nic_access(priv)) {
3118 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07003119 APMG_CLK_VAL_DMA_CLK_RQT);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003120 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003121 }
3122 spin_unlock_irqrestore(&priv->lock, flags);
3123
3124 udelay(5);
3125
Abbas, Mohamede9414b62009-01-20 21:33:55 -08003126 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
3127 priv->cfg->ops->lib->apm_ops.stop(priv);
3128 else
3129 priv->cfg->ops->lib->apm_ops.reset(priv);
3130
Zhu Yib481de92007-09-25 17:54:57 -07003131 exit:
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08003132 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07003133
3134 if (priv->ibss_beacon)
3135 dev_kfree_skb(priv->ibss_beacon);
3136 priv->ibss_beacon = NULL;
3137
3138 /* clear out any free frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003139 iwl3945_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003140}
3141
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003142static void iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003143{
3144 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003145 __iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003146 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08003147
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003148 iwl3945_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003149}
3150
3151#define MAX_HW_RESTARTS 5
3152
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003153static int __iwl3945_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003154{
3155 int rc, i;
3156
3157 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003158 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003159 return -EIO;
3160 }
3161
3162 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003163 IWL_WARN(priv, "Radio disabled by SW RF kill (module "
Zhu Yib481de92007-09-25 17:54:57 -07003164 "parameter)\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003165 return -ENODEV;
3166 }
3167
Reinette Chatree903fbd2008-01-30 22:05:15 -08003168 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003169 IWL_ERR(priv, "ucode not available for device bring up\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08003170 return -EIO;
3171 }
3172
Zhu Yie655b9f2008-01-24 02:19:38 -08003173 /* If platform's RF_KILL switch is NOT set to KILL */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003174 if (iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yie655b9f2008-01-24 02:19:38 -08003175 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3176 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3177 else {
3178 set_bit(STATUS_RF_KILL_HW, &priv->status);
3179 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003180 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003181 return -ENODEV;
3182 }
Zhu Yib481de92007-09-25 17:54:57 -07003183 }
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02003184
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003185 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07003186
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003187 rc = iwl3945_hw_nic_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003188 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003189 IWL_ERR(priv, "Unable to int nic\n");
Zhu Yib481de92007-09-25 17:54:57 -07003190 return rc;
3191 }
3192
3193 /* make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003194 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3195 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07003196 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
3197
3198 /* clear (again), then enable host interrupts */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003199 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08003200 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003201
3202 /* really make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003203 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3204 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07003205
3206 /* Copy original ucode data image from disk into backup cache.
3207 * This will be used to initialize the on-board processor's
3208 * data SRAM for a clean start when the runtime program first loads. */
3209 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a669262008-01-14 17:46:18 -08003210 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07003211
Zhu Yie655b9f2008-01-24 02:19:38 -08003212 /* We return success when we resume from suspend and rf_kill is on. */
3213 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
3214 return 0;
3215
Zhu Yib481de92007-09-25 17:54:57 -07003216 for (i = 0; i < MAX_HW_RESTARTS; i++) {
3217
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003218 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003219
3220 /* load bootstrap state machine,
3221 * load bootstrap program into processor's memory,
3222 * prepare to load the "initialize" uCode */
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08003223 priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003224
3225 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003226 IWL_ERR(priv,
3227 "Unable to set up bootstrap uCode: %d\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -07003228 continue;
3229 }
3230
3231 /* start card; "initialize" will load runtime ucode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003232 iwl3945_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003233
Tomas Winklere1623442009-01-27 14:27:56 -08003234 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003235
3236 return 0;
3237 }
3238
3239 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003240 __iwl3945_down(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003241 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003242
3243 /* tried to restart and config the device for as long as our
3244 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08003245 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07003246 return -EIO;
3247}
3248
3249
3250/*****************************************************************************
3251 *
3252 * Workqueue callbacks
3253 *
3254 *****************************************************************************/
3255
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003256static void iwl3945_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003257{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003258 struct iwl_priv *priv =
3259 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003260
3261 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3262 return;
3263
3264 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003265 iwl3945_init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003266 mutex_unlock(&priv->mutex);
3267}
3268
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003269static void iwl3945_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003270{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003271 struct iwl_priv *priv =
3272 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003273
3274 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3275 return;
3276
3277 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003278 iwl3945_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003279 mutex_unlock(&priv->mutex);
3280}
3281
Helmut Schaa26635162009-01-15 09:38:44 +01003282static void iwl3945_rfkill_poll(struct work_struct *data)
3283{
3284 struct iwl_priv *priv =
3285 container_of(data, struct iwl_priv, rfkill_poll.work);
3286 unsigned long status = priv->status;
3287
3288 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3289 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3290 else
3291 set_bit(STATUS_RF_KILL_HW, &priv->status);
3292
3293 if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status))
3294 queue_work(priv->workqueue, &priv->rf_kill);
3295
3296 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3297 round_jiffies_relative(2 * HZ));
3298
3299}
3300
Zhu Yib481de92007-09-25 17:54:57 -07003301#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003302static void iwl3945_bg_request_scan(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003303{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003304 struct iwl_priv *priv =
3305 container_of(data, struct iwl_priv, request_scan);
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08003306 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07003307 .id = REPLY_SCAN_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003308 .len = sizeof(struct iwl3945_scan_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07003309 .meta.flags = CMD_SIZE_HUGE,
3310 };
3311 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003312 struct iwl3945_scan_cmd *scan;
Zhu Yib481de92007-09-25 17:54:57 -07003313 struct ieee80211_conf *conf = NULL;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003314 u8 n_probes = 2;
Johannes Berg8318d782008-01-24 19:38:38 +01003315 enum ieee80211_band band;
John W. Linville9387b7c2008-09-30 20:59:05 -04003316 DECLARE_SSID_BUF(ssid);
Zhu Yib481de92007-09-25 17:54:57 -07003317
3318 conf = ieee80211_get_hw_conf(priv->hw);
3319
3320 mutex_lock(&priv->mutex);
3321
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003322 if (!iwl_is_ready(priv)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003323 IWL_WARN(priv, "request scan called when driver not ready.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003324 goto done;
3325 }
3326
Tomas Winklera96a27f2008-10-23 23:48:56 -07003327 /* Make sure the scan wasn't canceled before this queued work
Zhu Yib481de92007-09-25 17:54:57 -07003328 * was given the chance to run... */
3329 if (!test_bit(STATUS_SCANNING, &priv->status))
3330 goto done;
3331
3332 /* This should never be called or scheduled if there is currently
3333 * a scan active in the hardware. */
3334 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003335 IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests "
3336 "Ignoring second request.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003337 rc = -EIO;
3338 goto done;
3339 }
3340
3341 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003342 IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n");
Zhu Yib481de92007-09-25 17:54:57 -07003343 goto done;
3344 }
3345
3346 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003347 IWL_DEBUG_HC(priv,
3348 "Scan request while abort pending. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003349 goto done;
3350 }
3351
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003352 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003353 IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n");
Zhu Yib481de92007-09-25 17:54:57 -07003354 goto done;
3355 }
3356
3357 if (!test_bit(STATUS_READY, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003358 IWL_DEBUG_HC(priv,
3359 "Scan request while uninitialized. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003360 goto done;
3361 }
3362
3363 if (!priv->scan_bands) {
Tomas Winklere1623442009-01-27 14:27:56 -08003364 IWL_DEBUG_HC(priv, "Aborting scan due to no requested bands\n");
Zhu Yib481de92007-09-25 17:54:57 -07003365 goto done;
3366 }
3367
Winkler, Tomas805cee52009-01-19 15:30:28 -08003368 if (!priv->scan) {
3369 priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
Zhu Yib481de92007-09-25 17:54:57 -07003370 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
Winkler, Tomas805cee52009-01-19 15:30:28 -08003371 if (!priv->scan) {
Zhu Yib481de92007-09-25 17:54:57 -07003372 rc = -ENOMEM;
3373 goto done;
3374 }
3375 }
Winkler, Tomas805cee52009-01-19 15:30:28 -08003376 scan = priv->scan;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003377 memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07003378
3379 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
3380 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
3381
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003382 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003383 u16 interval = 0;
3384 u32 extra;
3385 u32 suspend_time = 100;
3386 u32 scan_suspend_time = 100;
3387 unsigned long flags;
3388
Tomas Winklere1623442009-01-27 14:27:56 -08003389 IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
Zhu Yib481de92007-09-25 17:54:57 -07003390
3391 spin_lock_irqsave(&priv->lock, flags);
3392 interval = priv->beacon_int;
3393 spin_unlock_irqrestore(&priv->lock, flags);
3394
3395 scan->suspend_time = 0;
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003396 scan->max_out_time = cpu_to_le32(200 * 1024);
Zhu Yib481de92007-09-25 17:54:57 -07003397 if (!interval)
3398 interval = suspend_time;
3399 /*
3400 * suspend time format:
3401 * 0-19: beacon interval in usec (time before exec.)
3402 * 20-23: 0
3403 * 24-31: number of beacons (suspend between channels)
3404 */
3405
3406 extra = (suspend_time / interval) << 24;
3407 scan_suspend_time = 0xFF0FFFFF &
3408 (extra | ((suspend_time % interval) * 1024));
3409
3410 scan->suspend_time = cpu_to_le32(scan_suspend_time);
Tomas Winklere1623442009-01-27 14:27:56 -08003411 IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003412 scan_suspend_time, interval);
3413 }
3414
3415 /* We should add the ability for user to lock to PASSIVE ONLY */
3416 if (priv->one_direct_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08003417 IWL_DEBUG_SCAN(priv, "Kicking off one direct scan for '%s'\n",
3418 print_ssid(ssid, priv->direct_ssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04003419 priv->direct_ssid_len));
Zhu Yib481de92007-09-25 17:54:57 -07003420 scan->direct_scan[0].id = WLAN_EID_SSID;
3421 scan->direct_scan[0].len = priv->direct_ssid_len;
3422 memcpy(scan->direct_scan[0].ssid,
3423 priv->direct_ssid, priv->direct_ssid_len);
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003424 n_probes++;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003425 } else
Tomas Winklere1623442009-01-27 14:27:56 -08003426 IWL_DEBUG_SCAN(priv, "Kicking off one indirect scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003427
3428 /* We don't build a direct scan probe request; the uCode will do
3429 * that based on the direct_mask added to each channel entry */
Zhu Yib481de92007-09-25 17:54:57 -07003430 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08003431 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07003432 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
3433
3434 /* flags + rate selection */
3435
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003436 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003437 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
3438 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
3439 scan->good_CRC_th = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01003440 band = IEEE80211_BAND_2GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003441 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003442 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
3443 scan->good_CRC_th = IWL_GOOD_CRC_TH;
Johannes Berg8318d782008-01-24 19:38:38 +01003444 band = IEEE80211_BAND_5GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003445 } else {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003446 IWL_WARN(priv, "Invalid scan band count\n");
Zhu Yib481de92007-09-25 17:54:57 -07003447 goto done;
3448 }
3449
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08003450 scan->tx_cmd.len = cpu_to_le16(
3451 iwl_fill_probe_req(priv, band,
3452 (struct ieee80211_mgmt *)scan->data,
3453 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
3454
Zhu Yib481de92007-09-25 17:54:57 -07003455 /* select Rx antennas */
3456 scan->flags |= iwl3945_get_antenna_flags(priv);
3457
Johannes Berg05c914f2008-09-11 00:01:58 +02003458 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
Zhu Yib481de92007-09-25 17:54:57 -07003459 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
3460
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003461 scan->channel_count =
3462 iwl3945_get_channels_for_scan(priv, band, 1, /* active */
3463 n_probes,
3464 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
Zhu Yib481de92007-09-25 17:54:57 -07003465
Reinette Chatre14b54332008-11-04 12:21:35 -08003466 if (scan->channel_count == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08003467 IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
Reinette Chatre14b54332008-11-04 12:21:35 -08003468 goto done;
3469 }
3470
Zhu Yib481de92007-09-25 17:54:57 -07003471 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003472 scan->channel_count * sizeof(struct iwl3945_scan_channel);
Zhu Yib481de92007-09-25 17:54:57 -07003473 cmd.data = scan;
3474 scan->len = cpu_to_le16(cmd.len);
3475
3476 set_bit(STATUS_SCAN_HW, &priv->status);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003477 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07003478 if (rc)
3479 goto done;
3480
3481 queue_delayed_work(priv->workqueue, &priv->scan_check,
3482 IWL_SCAN_CHECK_WATCHDOG);
3483
3484 mutex_unlock(&priv->mutex);
3485 return;
3486
3487 done:
Mohamed Abbas2420ebc2008-11-04 12:21:34 -08003488 /* can not perform scan make sure we clear scanning
3489 * bits from status so next scan request can be performed.
3490 * if we dont clear scanning status bit here all next scan
3491 * will fail
3492 */
3493 clear_bit(STATUS_SCAN_HW, &priv->status);
3494 clear_bit(STATUS_SCANNING, &priv->status);
3495
Ian Schram01ebd062007-10-25 17:15:22 +08003496 /* inform mac80211 scan aborted */
Zhu Yib481de92007-09-25 17:54:57 -07003497 queue_work(priv->workqueue, &priv->scan_completed);
3498 mutex_unlock(&priv->mutex);
3499}
3500
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003501static void iwl3945_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003502{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003503 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07003504
3505 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3506 return;
3507
3508 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003509 __iwl3945_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003510 mutex_unlock(&priv->mutex);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003511 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003512}
3513
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003514static void iwl3945_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003515{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003516 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07003517
3518 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3519 return;
3520
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003521 iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003522 queue_work(priv->workqueue, &priv->up);
3523}
3524
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003525static void iwl3945_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003526{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003527 struct iwl_priv *priv =
3528 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07003529
3530 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3531 return;
3532
3533 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003534 iwl3945_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003535 mutex_unlock(&priv->mutex);
3536}
3537
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003538#define IWL_DELAY_NEXT_SCAN (HZ*2)
3539
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003540static void iwl3945_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003541{
Zhu Yib481de92007-09-25 17:54:57 -07003542 int rc = 0;
3543 struct ieee80211_conf *conf = NULL;
3544
Johannes Berg05c914f2008-09-11 00:01:58 +02003545 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003546 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07003547 return;
3548 }
3549
3550
Tomas Winklere1623442009-01-27 14:27:56 -08003551 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003552 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07003553
3554 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3555 return;
3556
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003557 if (!priv->vif || !priv->is_open)
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003558 return;
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003559
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003560 iwl_scan_cancel_timeout(priv, 200);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003561
Zhu Yib481de92007-09-25 17:54:57 -07003562 conf = ieee80211_get_hw_conf(priv->hw);
3563
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003564 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003565 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003566
Tomas Winkler28afaf92008-12-19 10:37:06 +08003567 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003568 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003569 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07003570 sizeof(priv->rxon_timing), &priv->rxon_timing);
3571 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003572 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003573 "Attempting to continue.\n");
3574
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003575 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003576
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003577 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003578
Tomas Winklere1623442009-01-27 14:27:56 -08003579 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003580 priv->assoc_id, priv->beacon_int);
3581
3582 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003583 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003584 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003585 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003586
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003587 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003588 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003589 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003590 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003591 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003592
Johannes Berg05c914f2008-09-11 00:01:58 +02003593 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003594 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003595
3596 }
3597
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003598 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003599
3600 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02003601 case NL80211_IFTYPE_STATION:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003602 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07003603 break;
3604
Johannes Berg05c914f2008-09-11 00:01:58 +02003605 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07003606
Abhijeet Kolekarce546fd2008-11-19 15:32:22 -08003607 priv->assoc_id = 1;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003608 iwl3945_add_station(priv, priv->bssid, 0, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003609 iwl3945_sync_sta(priv, IWL_STA_ID,
Johannes Berg8318d782008-01-24 19:38:38 +01003610 (priv->band == IEEE80211_BAND_5GHZ) ?
Zhu Yib481de92007-09-25 17:54:57 -07003611 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
3612 CMD_ASYNC);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003613 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
3614 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003615
3616 break;
3617
3618 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08003619 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003620 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003621 break;
3622 }
3623
Abhijeet Kolekar14d2aac2009-02-27 16:21:24 -08003624 iwl_activate_qos(priv, 0);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08003625
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003626 /* we have just associated, don't start scan too early */
3627 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08003628}
3629
Johannes Berge8975582008-10-09 12:18:51 +02003630static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003631
Zhu Yib481de92007-09-25 17:54:57 -07003632/*****************************************************************************
3633 *
3634 * mac80211 entry point functions
3635 *
3636 *****************************************************************************/
3637
Zhu Yi5a669262008-01-14 17:46:18 -08003638#define UCODE_READY_TIMEOUT (2 * HZ)
3639
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003640static int iwl3945_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003641{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003642 struct iwl_priv *priv = hw->priv;
Zhu Yi5a669262008-01-14 17:46:18 -08003643 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003644
Tomas Winklere1623442009-01-27 14:27:56 -08003645 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003646
3647 /* we should be verifying the device is ready to be opened */
3648 mutex_lock(&priv->mutex);
3649
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003650 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
Zhu Yi5a669262008-01-14 17:46:18 -08003651 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
3652 * ucode filename and max sizes are card-specific. */
3653
3654 if (!priv->ucode_code.len) {
3655 ret = iwl3945_read_ucode(priv);
3656 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003657 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a669262008-01-14 17:46:18 -08003658 mutex_unlock(&priv->mutex);
3659 goto out_release_irq;
3660 }
3661 }
3662
Zhu Yie655b9f2008-01-24 02:19:38 -08003663 ret = __iwl3945_up(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08003664
Zhu Yib481de92007-09-25 17:54:57 -07003665 mutex_unlock(&priv->mutex);
Zhu Yi5a669262008-01-14 17:46:18 -08003666
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003667 iwl_rfkill_set_hw_state(priv);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02003668
Zhu Yie655b9f2008-01-24 02:19:38 -08003669 if (ret)
3670 goto out_release_irq;
3671
Tomas Winklere1623442009-01-27 14:27:56 -08003672 IWL_DEBUG_INFO(priv, "Start UP work.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003673
3674 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
3675 return 0;
3676
Zhu Yi5a669262008-01-14 17:46:18 -08003677 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
3678 * mac80211 will not be run successfully. */
3679 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
3680 test_bit(STATUS_READY, &priv->status),
3681 UCODE_READY_TIMEOUT);
3682 if (!ret) {
3683 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003684 IWL_ERR(priv,
3685 "Wait for START_ALIVE timeout after %dms.\n",
3686 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Zhu Yi5a669262008-01-14 17:46:18 -08003687 ret = -ETIMEDOUT;
3688 goto out_release_irq;
3689 }
3690 }
3691
Helmut Schaa26635162009-01-15 09:38:44 +01003692 /* ucode is running and will send rfkill notifications,
3693 * no need to poll the killswitch state anymore */
3694 cancel_delayed_work(&priv->rfkill_poll);
3695
Zhu Yie655b9f2008-01-24 02:19:38 -08003696 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08003697 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003698 return 0;
Zhu Yi5a669262008-01-14 17:46:18 -08003699
3700out_release_irq:
Zhu Yie655b9f2008-01-24 02:19:38 -08003701 priv->is_open = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08003702 IWL_DEBUG_MAC80211(priv, "leave - failed\n");
Zhu Yi5a669262008-01-14 17:46:18 -08003703 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003704}
3705
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003706static void iwl3945_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003707{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003708 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003709
Tomas Winklere1623442009-01-27 14:27:56 -08003710 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003711
Zhu Yie655b9f2008-01-24 02:19:38 -08003712 if (!priv->is_open) {
Tomas Winklere1623442009-01-27 14:27:56 -08003713 IWL_DEBUG_MAC80211(priv, "leave - skip\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003714 return;
3715 }
3716
Zhu Yib481de92007-09-25 17:54:57 -07003717 priv->is_open = 0;
Zhu Yi5a669262008-01-14 17:46:18 -08003718
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003719 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08003720 /* stop mac, cancel any scan request and clear
3721 * RXON_FILTER_ASSOC_MSK BIT
3722 */
Zhu Yi5a669262008-01-14 17:46:18 -08003723 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003724 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003725 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003726 }
3727
Zhu Yi5a669262008-01-14 17:46:18 -08003728 iwl3945_down(priv);
3729
3730 flush_workqueue(priv->workqueue);
Helmut Schaa26635162009-01-15 09:38:44 +01003731
3732 /* start polling the killswitch state again */
3733 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3734 round_jiffies_relative(2 * HZ));
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003735
Tomas Winklere1623442009-01-27 14:27:56 -08003736 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003737}
3738
Johannes Berge039fa42008-05-15 12:55:29 +02003739static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003740{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003741 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003742
Tomas Winklere1623442009-01-27 14:27:56 -08003743 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003744
Tomas Winklere1623442009-01-27 14:27:56 -08003745 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02003746 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07003747
Johannes Berge039fa42008-05-15 12:55:29 +02003748 if (iwl3945_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07003749 dev_kfree_skb_any(skb);
3750
Tomas Winklere1623442009-01-27 14:27:56 -08003751 IWL_DEBUG_MAC80211(priv, "leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08003752 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07003753}
3754
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003755static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003756 struct ieee80211_if_init_conf *conf)
3757{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003758 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003759 unsigned long flags;
3760
Tomas Winklere1623442009-01-27 14:27:56 -08003761 IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07003762
Johannes Berg32bfd352007-12-19 01:31:26 +01003763 if (priv->vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08003764 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
Tomas Winkler864792e2007-11-27 21:00:52 +02003765 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07003766 }
3767
3768 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01003769 priv->vif = conf->vif;
Zhu, Yi60294de2008-10-29 14:05:45 -07003770 priv->iw_mode = conf->type;
Zhu Yib481de92007-09-25 17:54:57 -07003771
3772 spin_unlock_irqrestore(&priv->lock, flags);
3773
3774 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02003775
3776 if (conf->mac_addr) {
Tomas Winklere1623442009-01-27 14:27:56 -08003777 IWL_DEBUG_MAC80211(priv, "Set: %pM\n", conf->mac_addr);
Tomas Winkler864792e2007-11-27 21:00:52 +02003778 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
3779 }
3780
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003781 if (iwl_is_ready(priv))
Zhu Yi5a669262008-01-14 17:46:18 -08003782 iwl3945_set_mode(priv, conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07003783
Zhu Yib481de92007-09-25 17:54:57 -07003784 mutex_unlock(&priv->mutex);
3785
Tomas Winklere1623442009-01-27 14:27:56 -08003786 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003787 return 0;
3788}
3789
3790/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003791 * iwl3945_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07003792 *
3793 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
3794 * be set inappropriately and the driver currently sets the hardware up to
3795 * use it whenever needed.
3796 */
Johannes Berge8975582008-10-09 12:18:51 +02003797static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed)
Zhu Yib481de92007-09-25 17:54:57 -07003798{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003799 struct iwl_priv *priv = hw->priv;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08003800 const struct iwl_channel_info *ch_info;
Johannes Berge8975582008-10-09 12:18:51 +02003801 struct ieee80211_conf *conf = &hw->conf;
Zhu Yib481de92007-09-25 17:54:57 -07003802 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08003803 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003804
3805 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08003806 IWL_DEBUG_MAC80211(priv, "enter to channel %d\n",
3807 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07003808
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003809 if (!iwl_is_ready(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003810 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08003811 ret = -EIO;
3812 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003813 }
3814
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08003815 if (unlikely(!iwl3945_mod_params.disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07003816 test_bit(STATUS_SCANNING, &priv->status))) {
Tomas Winklere1623442009-01-27 14:27:56 -08003817 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
Zhu Yia0646472007-12-20 14:10:01 +08003818 set_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003819 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08003820 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07003821 }
3822
3823 spin_lock_irqsave(&priv->lock, flags);
3824
Samuel Ortize6148912009-01-23 13:45:15 -08003825 ch_info = iwl_get_channel_info(priv, conf->channel->band,
3826 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07003827 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003828 IWL_DEBUG_SCAN(priv,
3829 "Channel %d [%d] is INVALID for this band.\n",
3830 conf->channel->hw_value, conf->channel->band);
3831 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
Zhu Yib481de92007-09-25 17:54:57 -07003832 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003833 ret = -EINVAL;
3834 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003835 }
3836
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003837 iwl_set_rxon_channel(priv, conf->channel);
Zhu Yib481de92007-09-25 17:54:57 -07003838
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003839 iwl_set_flags_for_band(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07003840
3841 /* The list of supported rates and rate mask can be different
3842 * for each phymode; since the phymode may have changed, reset
3843 * the rate mask to what mac80211 lists */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003844 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003845
3846 spin_unlock_irqrestore(&priv->lock, flags);
3847
3848#ifdef IEEE80211_CONF_CHANNEL_SWITCH
3849 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003850 iwl3945_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003851 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003852 }
3853#endif
3854
Abhijeet Kolekar7dc45f22009-02-18 15:54:32 -08003855 if (conf->radio_enabled && iwl_radio_kill_sw_enable_radio(priv)) {
3856 IWL_DEBUG_MAC80211(priv, "leave - RF-KILL - waiting for uCode\n");
3857 goto out;
3858 }
Zhu Yib481de92007-09-25 17:54:57 -07003859
3860 if (!conf->radio_enabled) {
Abhijeet Kolekar7dc45f22009-02-18 15:54:32 -08003861 iwl_radio_kill_sw_disable_radio(priv);
Tomas Winklere1623442009-01-27 14:27:56 -08003862 IWL_DEBUG_MAC80211(priv, "leave - radio disabled\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08003863 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003864 }
3865
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003866 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003867 IWL_DEBUG_MAC80211(priv, "leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08003868 ret = -EIO;
3869 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003870 }
3871
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003872 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003873
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003874 if (memcmp(&priv->active_rxon,
3875 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003876 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003877 else
Tomas Winklere1623442009-01-27 14:27:56 -08003878 IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration\n");
Zhu Yib481de92007-09-25 17:54:57 -07003879
Tomas Winklere1623442009-01-27 14:27:56 -08003880 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003881
Zhu Yi76bb77e2007-11-22 10:53:22 +08003882out:
Zhu Yia0646472007-12-20 14:10:01 +08003883 clear_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003884 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003885 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003886}
3887
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003888static void iwl3945_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003889{
3890 int rc = 0;
3891
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08003892 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07003893 return;
3894
3895 /* The following should be done only at AP bring up */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003896 if (!(iwl_is_associated(priv))) {
Zhu Yib481de92007-09-25 17:54:57 -07003897
3898 /* RXON - unassoc (to set timing command) */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003899 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003900 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003901
3902 /* RXON Timing */
Tomas Winkler28afaf92008-12-19 10:37:06 +08003903 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003904 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003905 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
3906 sizeof(priv->rxon_timing),
3907 &priv->rxon_timing);
Zhu Yib481de92007-09-25 17:54:57 -07003908 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003909 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003910 "Attempting to continue.\n");
3911
3912 /* FIXME: what should be the assoc_id for AP? */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003913 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003914 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003915 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003916 RXON_FLG_SHORT_PREAMBLE_MSK;
3917 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003918 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003919 ~RXON_FLG_SHORT_PREAMBLE_MSK;
3920
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003921 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003922 if (priv->assoc_capability &
3923 WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003924 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003925 RXON_FLG_SHORT_SLOT_MSK;
3926 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003927 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003928 ~RXON_FLG_SHORT_SLOT_MSK;
3929
Johannes Berg05c914f2008-09-11 00:01:58 +02003930 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003931 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003932 ~RXON_FLG_SHORT_SLOT_MSK;
3933 }
3934 /* restore RXON assoc */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003935 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003936 iwl3945_commit_rxon(priv);
Kolekar, Abhijeetb5323d32008-12-19 10:37:22 +08003937 iwl3945_add_station(priv, iwl_bcast_addr, 0, 0);
Zhu Yi556f8db2007-09-27 11:27:33 +08003938 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003939 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003940
3941 /* FIXME - we need to add code here to detect a totally new
3942 * configuration, reset the AP, unassoc, rxon timing, assoc,
3943 * clear sta table, add BCAST sta... */
3944}
3945
Johannes Berg32bfd352007-12-19 01:31:26 +01003946static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
3947 struct ieee80211_vif *vif,
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003948 struct ieee80211_if_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07003949{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003950 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003951 int rc;
3952
3953 if (conf == NULL)
3954 return -EIO;
3955
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08003956 if (priv->vif != vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08003957 IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08003958 return 0;
3959 }
3960
Johannes Berg9d139c82008-07-09 14:40:37 +02003961 /* handle this temporarily here */
Johannes Berg05c914f2008-09-11 00:01:58 +02003962 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Johannes Berg9d139c82008-07-09 14:40:37 +02003963 conf->changed & IEEE80211_IFCC_BEACON) {
3964 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
3965 if (!beacon)
3966 return -ENOMEM;
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003967 mutex_lock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02003968 rc = iwl3945_mac_beacon_update(hw, beacon);
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003969 mutex_unlock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02003970 if (rc)
3971 return rc;
3972 }
3973
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003974 if (!iwl_is_alive(priv))
Zhu Yi5a669262008-01-14 17:46:18 -08003975 return -EAGAIN;
3976
Zhu Yib481de92007-09-25 17:54:57 -07003977 mutex_lock(&priv->mutex);
3978
Zhu Yib481de92007-09-25 17:54:57 -07003979 if (conf->bssid)
Tomas Winklere1623442009-01-27 14:27:56 -08003980 IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07003981
Johannes Berg4150c572007-09-17 01:29:23 -04003982/*
3983 * very dubious code was here; the probe filtering flag is never set:
3984 *
Zhu Yib481de92007-09-25 17:54:57 -07003985 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
3986 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04003987 */
Zhu Yib481de92007-09-25 17:54:57 -07003988
Johannes Berg05c914f2008-09-11 00:01:58 +02003989 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07003990 if (!conf->bssid) {
3991 conf->bssid = priv->mac_addr;
3992 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08003993 IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07003994 conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07003995 }
3996 if (priv->ibss_beacon)
3997 dev_kfree_skb(priv->ibss_beacon);
3998
Johannes Berg9d139c82008-07-09 14:40:37 +02003999 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
Zhu Yib481de92007-09-25 17:54:57 -07004000 }
4001
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004002 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08004003 goto done;
4004
Zhu Yib481de92007-09-25 17:54:57 -07004005 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
4006 !is_multicast_ether_addr(conf->bssid)) {
4007 /* If there is currently a HW scan going on in the background
4008 * then we need to cancel it else the RXON below will fail. */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004009 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004010 IWL_WARN(priv, "Aborted scan still in progress "
Zhu Yib481de92007-09-25 17:54:57 -07004011 "after 100ms\n");
Tomas Winklere1623442009-01-27 14:27:56 -08004012 IWL_DEBUG_MAC80211(priv, "leaving:scan abort failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07004013 mutex_unlock(&priv->mutex);
4014 return -EAGAIN;
4015 }
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004016 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07004017
4018 /* TODO: Audit driver for usage of these members and see
4019 * if mac80211 deprecates them (priv->bssid looks like it
4020 * shouldn't be there, but I haven't scanned the IBSS code
4021 * to verify) - jpk */
4022 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
4023
Johannes Berg05c914f2008-09-11 00:01:58 +02004024 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004025 iwl3945_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004026 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004027 rc = iwl3945_commit_rxon(priv);
Johannes Berg05c914f2008-09-11 00:01:58 +02004028 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004029 iwl3945_add_station(priv,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004030 priv->active_rxon.bssid_addr, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004031 }
4032
4033 } else {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004034 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004035 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004036 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004037 }
4038
Mohamed Abbasfde35712007-11-29 11:10:15 +08004039 done:
Tomas Winklere1623442009-01-27 14:27:56 -08004040 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004041 mutex_unlock(&priv->mutex);
4042
4043 return 0;
4044}
4045
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004046static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004047 struct ieee80211_if_init_conf *conf)
4048{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004049 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004050
Tomas Winklere1623442009-01-27 14:27:56 -08004051 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004052
4053 mutex_lock(&priv->mutex);
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004054
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004055 if (iwl_is_ready_rf(priv)) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004056 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004057 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Mohamed Abbasfde35712007-11-29 11:10:15 +08004058 iwl3945_commit_rxon(priv);
4059 }
Johannes Berg32bfd352007-12-19 01:31:26 +01004060 if (priv->vif == conf->vif) {
4061 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07004062 memset(priv->bssid, 0, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07004063 }
4064 mutex_unlock(&priv->mutex);
4065
Tomas Winklere1623442009-01-27 14:27:56 -08004066 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004067}
4068
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004069#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
4070
4071static void iwl3945_bss_info_changed(struct ieee80211_hw *hw,
4072 struct ieee80211_vif *vif,
4073 struct ieee80211_bss_conf *bss_conf,
4074 u32 changes)
4075{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004076 struct iwl_priv *priv = hw->priv;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004077
Tomas Winklere1623442009-01-27 14:27:56 -08004078 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004079
4080 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
Tomas Winklere1623442009-01-27 14:27:56 -08004081 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004082 bss_conf->use_short_preamble);
4083 if (bss_conf->use_short_preamble)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004084 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004085 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004086 priv->staging_rxon.flags &=
4087 ~RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004088 }
4089
4090 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
Tomas Winklere1623442009-01-27 14:27:56 -08004091 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n",
4092 bss_conf->use_cts_prot);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004093 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004094 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004095 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004096 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004097 }
4098
4099 if (changes & BSS_CHANGED_ASSOC) {
Tomas Winklere1623442009-01-27 14:27:56 -08004100 IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004101 /* This should never happen as this function should
4102 * never be called from interrupt context. */
4103 if (WARN_ON_ONCE(in_interrupt()))
4104 return;
4105 if (bss_conf->assoc) {
4106 priv->assoc_id = bss_conf->aid;
4107 priv->beacon_int = bss_conf->beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08004108 priv->timestamp = bss_conf->timestamp;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004109 priv->assoc_capability = bss_conf->assoc_capability;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08004110 priv->power_data.dtim_period = bss_conf->dtim_period;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004111 priv->next_scan_jiffies = jiffies +
4112 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
4113 mutex_lock(&priv->mutex);
4114 iwl3945_post_associate(priv);
4115 mutex_unlock(&priv->mutex);
4116 } else {
4117 priv->assoc_id = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08004118 IWL_DEBUG_MAC80211(priv,
4119 "DISASSOC %d\n", bss_conf->assoc);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004120 }
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004121 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
Tomas Winklere1623442009-01-27 14:27:56 -08004122 IWL_DEBUG_MAC80211(priv,
4123 "Associated Changes %d\n", changes);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004124 iwl3945_send_rxon_assoc(priv);
4125 }
4126
4127}
4128
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004129static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01004130 struct ieee80211_vif *vif,
4131 struct ieee80211_sta *sta,
4132 struct ieee80211_key_conf *key)
Zhu Yib481de92007-09-25 17:54:57 -07004133{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004134 struct iwl_priv *priv = hw->priv;
Johannes Bergdc822b52008-12-29 12:55:09 +01004135 const u8 *addr;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08004136 int ret = 0;
4137 u8 sta_id = IWL_INVALID_STATION;
4138 u8 static_key;
Zhu Yib481de92007-09-25 17:54:57 -07004139
Tomas Winklere1623442009-01-27 14:27:56 -08004140 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004141
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004142 if (iwl3945_mod_params.sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08004143 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07004144 return -EOPNOTSUPP;
4145 }
4146
Winkler, Tomas42986792009-01-19 15:30:22 -08004147 addr = sta ? sta->addr : iwl_bcast_addr;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08004148 static_key = !iwl_is_associated(priv);
4149
4150 if (!static_key) {
4151 sta_id = iwl3945_hw_find_station(priv, addr);
4152 if (sta_id == IWL_INVALID_STATION) {
4153 IWL_DEBUG_MAC80211(priv, "leave - %pMnot in station map.\n",
4154 addr);
4155 return -EINVAL;
4156 }
Zhu Yib481de92007-09-25 17:54:57 -07004157 }
4158
4159 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004160 iwl_scan_cancel_timeout(priv, 100);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08004161 mutex_unlock(&priv->mutex);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004162
Zhu Yib481de92007-09-25 17:54:57 -07004163 switch (cmd) {
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08004164 case SET_KEY:
4165 if (static_key)
4166 ret = iwl3945_set_static_key(priv, key);
4167 else
4168 ret = iwl3945_set_dynamic_key(priv, key, sta_id);
4169 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07004170 break;
4171 case DISABLE_KEY:
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08004172 if (static_key)
4173 ret = iwl3945_remove_static_key(priv);
4174 else
4175 ret = iwl3945_clear_sta_key_info(priv, sta_id);
4176 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07004177 break;
4178 default:
Winkler, Tomas42986792009-01-19 15:30:22 -08004179 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07004180 }
4181
Tomas Winklere1623442009-01-27 14:27:56 -08004182 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004183
Winkler, Tomas42986792009-01-19 15:30:22 -08004184 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004185}
4186
Johannes Berge100bb62008-04-30 18:51:21 +02004187static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
Zhu Yib481de92007-09-25 17:54:57 -07004188 const struct ieee80211_tx_queue_params *params)
4189{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004190 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004191 unsigned long flags;
4192 int q;
Zhu Yib481de92007-09-25 17:54:57 -07004193
Tomas Winklere1623442009-01-27 14:27:56 -08004194 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004195
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004196 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004197 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004198 return -EIO;
4199 }
4200
4201 if (queue >= AC_NUM) {
Tomas Winklere1623442009-01-27 14:27:56 -08004202 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
Zhu Yib481de92007-09-25 17:54:57 -07004203 return 0;
4204 }
4205
Zhu Yib481de92007-09-25 17:54:57 -07004206 q = AC_NUM - 1 - queue;
4207
4208 spin_lock_irqsave(&priv->lock, flags);
4209
4210 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
4211 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
4212 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
4213 priv->qos_data.def_qos_parm.ac[q].edca_txop =
Johannes Berg3330d7b2008-02-10 16:49:38 +01004214 cpu_to_le16((params->txop * 32));
Zhu Yib481de92007-09-25 17:54:57 -07004215
4216 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
4217 priv->qos_data.qos_active = 1;
4218
4219 spin_unlock_irqrestore(&priv->lock, flags);
4220
4221 mutex_lock(&priv->mutex);
Johannes Berg05c914f2008-09-11 00:01:58 +02004222 if (priv->iw_mode == NL80211_IFTYPE_AP)
Abhijeet Kolekar14d2aac2009-02-27 16:21:24 -08004223 iwl_activate_qos(priv, 1);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004224 else if (priv->assoc_id && iwl_is_associated(priv))
Abhijeet Kolekar14d2aac2009-02-27 16:21:24 -08004225 iwl_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004226
4227 mutex_unlock(&priv->mutex);
4228
Tomas Winklere1623442009-01-27 14:27:56 -08004229 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004230 return 0;
4231}
4232
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004233static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004234 struct ieee80211_tx_queue_stats *stats)
4235{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004236 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004237 int i, avail;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08004238 struct iwl_tx_queue *txq;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004239 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07004240 unsigned long flags;
4241
Tomas Winklere1623442009-01-27 14:27:56 -08004242 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004243
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004244 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004245 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004246 return -EIO;
4247 }
4248
4249 spin_lock_irqsave(&priv->lock, flags);
4250
4251 for (i = 0; i < AC_NUM; i++) {
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08004252 txq = &priv->txq[i];
Zhu Yib481de92007-09-25 17:54:57 -07004253 q = &txq->q;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004254 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07004255
Johannes Berg57ffc582008-04-29 17:18:59 +02004256 stats[i].len = q->n_window - avail;
4257 stats[i].limit = q->n_window - q->high_mark;
4258 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07004259
4260 }
4261 spin_unlock_irqrestore(&priv->lock, flags);
4262
Tomas Winklere1623442009-01-27 14:27:56 -08004263 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004264
4265 return 0;
4266}
4267
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004268static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07004269{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004270 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004271 unsigned long flags;
4272
4273 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08004274 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004275
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004276 iwl_reset_qos(priv);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08004277
Zhu Yib481de92007-09-25 17:54:57 -07004278 spin_lock_irqsave(&priv->lock, flags);
4279 priv->assoc_id = 0;
4280 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004281
4282 /* new association get rid of ibss beacon skb */
4283 if (priv->ibss_beacon)
4284 dev_kfree_skb(priv->ibss_beacon);
4285
4286 priv->ibss_beacon = NULL;
4287
4288 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08004289 priv->timestamp = 0;
Johannes Berg05c914f2008-09-11 00:01:58 +02004290 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
Zhu Yib481de92007-09-25 17:54:57 -07004291 priv->beacon_int = 0;
4292
4293 spin_unlock_irqrestore(&priv->lock, flags);
4294
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004295 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004296 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +08004297 mutex_unlock(&priv->mutex);
4298 return;
4299 }
4300
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004301 /* we are restarting association process
4302 * clear RXON_FILTER_ASSOC_MSK bit
4303 */
Johannes Berg05c914f2008-09-11 00:01:58 +02004304 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004305 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004306 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004307 iwl3945_commit_rxon(priv);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004308 }
4309
Zhu Yib481de92007-09-25 17:54:57 -07004310 /* Per mac80211.h: This is only used in IBSS mode... */
Johannes Berg05c914f2008-09-11 00:01:58 +02004311 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004312
Tomas Winklere1623442009-01-27 14:27:56 -08004313 IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07004314 mutex_unlock(&priv->mutex);
4315 return;
4316 }
4317
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004318 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004319
4320 mutex_unlock(&priv->mutex);
4321
Tomas Winklere1623442009-01-27 14:27:56 -08004322 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004323
4324}
4325
Johannes Berge039fa42008-05-15 12:55:29 +02004326static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07004327{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004328 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004329 unsigned long flags;
Abhijeet Kolekar7c4cbb62009-02-27 16:21:20 -08004330 __le64 timestamp;
Zhu Yib481de92007-09-25 17:54:57 -07004331
Tomas Winklere1623442009-01-27 14:27:56 -08004332 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004333
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004334 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004335 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004336 return -EIO;
4337 }
4338
Johannes Berg05c914f2008-09-11 00:01:58 +02004339 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Tomas Winklere1623442009-01-27 14:27:56 -08004340 IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07004341 return -EIO;
4342 }
4343
4344 spin_lock_irqsave(&priv->lock, flags);
4345
4346 if (priv->ibss_beacon)
4347 dev_kfree_skb(priv->ibss_beacon);
4348
4349 priv->ibss_beacon = skb;
4350
4351 priv->assoc_id = 0;
Abhijeet Kolekar7c4cbb62009-02-27 16:21:20 -08004352 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
4353 priv->timestamp = le64_to_cpu(timestamp);
Zhu Yib481de92007-09-25 17:54:57 -07004354
Tomas Winklere1623442009-01-27 14:27:56 -08004355 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004356 spin_unlock_irqrestore(&priv->lock, flags);
4357
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004358 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004359
Abhijeet Kolekardc4b1e72008-09-03 11:26:30 +08004360 iwl3945_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004361
Zhu Yib481de92007-09-25 17:54:57 -07004362
4363 return 0;
4364}
4365
4366/*****************************************************************************
4367 *
4368 * sysfs attributes
4369 *
4370 *****************************************************************************/
4371
Samuel Ortizd08853a2009-01-23 13:45:17 -08004372#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07004373
4374/*
4375 * The following adds a new attribute to the sysfs representation
4376 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
4377 * used for controlling the debug level.
4378 *
4379 * See the level definitions in iwl for details.
4380 */
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004381static ssize_t show_debug_level(struct device *d,
4382 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07004383{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004384 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004385
4386 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07004387}
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004388static ssize_t store_debug_level(struct device *d,
4389 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07004390 const char *buf, size_t count)
4391{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004392 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004393 unsigned long val;
4394 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07004395
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004396 ret = strict_strtoul(buf, 0, &val);
4397 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08004398 IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07004399 else
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004400 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07004401
4402 return strnlen(buf, count);
4403}
4404
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004405static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
4406 show_debug_level, store_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07004407
Samuel Ortizd08853a2009-01-23 13:45:17 -08004408#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07004409
Zhu Yib481de92007-09-25 17:54:57 -07004410static ssize_t show_temperature(struct device *d,
4411 struct device_attribute *attr, char *buf)
4412{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004413 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004414
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004415 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004416 return -EAGAIN;
4417
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004418 return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
Zhu Yib481de92007-09-25 17:54:57 -07004419}
4420
4421static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
4422
Zhu Yib481de92007-09-25 17:54:57 -07004423static ssize_t show_tx_power(struct device *d,
4424 struct device_attribute *attr, char *buf)
4425{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004426 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08004427 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07004428}
4429
4430static ssize_t store_tx_power(struct device *d,
4431 struct device_attribute *attr,
4432 const char *buf, size_t count)
4433{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004434 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004435 char *p = (char *)buf;
4436 u32 val;
4437
4438 val = simple_strtoul(p, &p, 10);
4439 if (p == buf)
Tomas Winkler978785a2008-12-19 10:37:31 +08004440 IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07004441 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004442 iwl3945_hw_reg_set_txpower(priv, val);
Zhu Yib481de92007-09-25 17:54:57 -07004443
4444 return count;
4445}
4446
4447static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
4448
4449static ssize_t show_flags(struct device *d,
4450 struct device_attribute *attr, char *buf)
4451{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004452 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004453
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004454 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
Zhu Yib481de92007-09-25 17:54:57 -07004455}
4456
4457static ssize_t store_flags(struct device *d,
4458 struct device_attribute *attr,
4459 const char *buf, size_t count)
4460{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004461 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004462 u32 flags = simple_strtoul(buf, NULL, 0);
4463
4464 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004465 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
Zhu Yib481de92007-09-25 17:54:57 -07004466 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004467 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004468 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004469 else {
Tomas Winklere1623442009-01-27 14:27:56 -08004470 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
Zhu Yib481de92007-09-25 17:54:57 -07004471 flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004472 priv->staging_rxon.flags = cpu_to_le32(flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004473 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004474 }
4475 }
4476 mutex_unlock(&priv->mutex);
4477
4478 return count;
4479}
4480
4481static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
4482
4483static ssize_t show_filter_flags(struct device *d,
4484 struct device_attribute *attr, char *buf)
4485{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004486 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004487
4488 return sprintf(buf, "0x%04X\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004489 le32_to_cpu(priv->active_rxon.filter_flags));
Zhu Yib481de92007-09-25 17:54:57 -07004490}
4491
4492static ssize_t store_filter_flags(struct device *d,
4493 struct device_attribute *attr,
4494 const char *buf, size_t count)
4495{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004496 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004497 u32 filter_flags = simple_strtoul(buf, NULL, 0);
4498
4499 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004500 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
Zhu Yib481de92007-09-25 17:54:57 -07004501 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004502 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004503 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004504 else {
Tomas Winklere1623442009-01-27 14:27:56 -08004505 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
Zhu Yib481de92007-09-25 17:54:57 -07004506 "0x%04X\n", filter_flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004507 priv->staging_rxon.filter_flags =
Zhu Yib481de92007-09-25 17:54:57 -07004508 cpu_to_le32(filter_flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004509 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004510 }
4511 }
4512 mutex_unlock(&priv->mutex);
4513
4514 return count;
4515}
4516
4517static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
4518 store_filter_flags);
4519
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004520#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004521
4522static ssize_t show_measurement(struct device *d,
4523 struct device_attribute *attr, char *buf)
4524{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004525 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler600c0e12008-12-19 10:37:04 +08004526 struct iwl_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004527 u32 size = sizeof(measure_report), len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03004528 u8 *data = (u8 *)&measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004529 unsigned long flags;
4530
4531 spin_lock_irqsave(&priv->lock, flags);
4532 if (!(priv->measurement_status & MEASUREMENT_READY)) {
4533 spin_unlock_irqrestore(&priv->lock, flags);
4534 return 0;
4535 }
4536 memcpy(&measure_report, &priv->measure_report, size);
4537 priv->measurement_status = 0;
4538 spin_unlock_irqrestore(&priv->lock, flags);
4539
4540 while (size && (PAGE_SIZE - len)) {
4541 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4542 PAGE_SIZE - len, 1);
4543 len = strlen(buf);
4544 if (PAGE_SIZE - len)
4545 buf[len++] = '\n';
4546
4547 ofs += 16;
4548 size -= min(size, 16U);
4549 }
4550
4551 return len;
4552}
4553
4554static ssize_t store_measurement(struct device *d,
4555 struct device_attribute *attr,
4556 const char *buf, size_t count)
4557{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004558 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004559 struct ieee80211_measurement_params params = {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004560 .channel = le16_to_cpu(priv->active_rxon.channel),
Zhu Yib481de92007-09-25 17:54:57 -07004561 .start_time = cpu_to_le64(priv->last_tsf),
4562 .duration = cpu_to_le16(1),
4563 };
4564 u8 type = IWL_MEASURE_BASIC;
4565 u8 buffer[32];
4566 u8 channel;
4567
4568 if (count) {
4569 char *p = buffer;
4570 strncpy(buffer, buf, min(sizeof(buffer), count));
4571 channel = simple_strtoul(p, NULL, 0);
4572 if (channel)
4573 params.channel = channel;
4574
4575 p = buffer;
4576 while (*p && *p != ' ')
4577 p++;
4578 if (*p)
4579 type = simple_strtoul(p + 1, NULL, 0);
4580 }
4581
Tomas Winklere1623442009-01-27 14:27:56 -08004582 IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on "
Zhu Yib481de92007-09-25 17:54:57 -07004583 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004584 iwl3945_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07004585
4586 return count;
4587}
4588
4589static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
4590 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004591#endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07004592
Zhu Yib481de92007-09-25 17:54:57 -07004593static ssize_t store_retry_rate(struct device *d,
4594 struct device_attribute *attr,
4595 const char *buf, size_t count)
4596{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004597 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004598
4599 priv->retry_rate = simple_strtoul(buf, NULL, 0);
4600 if (priv->retry_rate <= 0)
4601 priv->retry_rate = 1;
4602
4603 return count;
4604}
4605
4606static ssize_t show_retry_rate(struct device *d,
4607 struct device_attribute *attr, char *buf)
4608{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004609 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004610 return sprintf(buf, "%d", priv->retry_rate);
4611}
4612
4613static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
4614 store_retry_rate);
4615
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004616
Zhu Yib481de92007-09-25 17:54:57 -07004617static ssize_t store_power_level(struct device *d,
4618 struct device_attribute *attr,
4619 const char *buf, size_t count)
4620{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004621 struct iwl_priv *priv = dev_get_drvdata(d);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004622 int ret;
4623 unsigned long mode;
Zhu Yib481de92007-09-25 17:54:57 -07004624
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004625
Zhu Yib481de92007-09-25 17:54:57 -07004626 mutex_lock(&priv->mutex);
4627
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004628 if (!iwl_is_ready(priv)) {
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004629 ret = -EAGAIN;
Zhu Yib481de92007-09-25 17:54:57 -07004630 goto out;
4631 }
4632
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004633 ret = strict_strtoul(buf, 10, &mode);
4634 if (ret)
4635 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004636
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004637 ret = iwl_power_set_user_mode(priv, mode);
4638 if (ret) {
4639 IWL_DEBUG_MAC80211(priv, "failed setting power mode.\n");
4640 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004641 }
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004642 ret = count;
Zhu Yib481de92007-09-25 17:54:57 -07004643
4644 out:
4645 mutex_unlock(&priv->mutex);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004646 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004647}
4648
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004649static ssize_t show_power_level(struct device *d,
4650 struct device_attribute *attr, char *buf)
4651{
4652 struct iwl_priv *priv = dev_get_drvdata(d);
4653 int mode = priv->power_data.user_power_setting;
4654 int system = priv->power_data.system_power_setting;
4655 int level = priv->power_data.power_mode;
4656 char *p = buf;
4657
4658 switch (system) {
4659 case IWL_POWER_SYS_AUTO:
4660 p += sprintf(p, "SYSTEM:auto");
4661 break;
4662 case IWL_POWER_SYS_AC:
4663 p += sprintf(p, "SYSTEM:ac");
4664 break;
4665 case IWL_POWER_SYS_BATTERY:
4666 p += sprintf(p, "SYSTEM:battery");
4667 break;
4668 }
4669
4670 p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
4671 "fixed" : "auto");
4672 p += sprintf(p, "\tINDEX:%d", level);
4673 p += sprintf(p, "\n");
4674 return p - buf + 1;
4675}
4676
4677static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR,
4678 show_power_level, store_power_level);
4679
Zhu Yib481de92007-09-25 17:54:57 -07004680#define MAX_WX_STRING 80
4681
4682/* Values are in microsecond */
4683static const s32 timeout_duration[] = {
4684 350000,
4685 250000,
4686 75000,
4687 37000,
4688 25000,
4689};
4690static const s32 period_duration[] = {
4691 400000,
4692 700000,
4693 1000000,
4694 1000000,
4695 1000000
4696};
4697
Zhu Yib481de92007-09-25 17:54:57 -07004698static ssize_t show_channels(struct device *d,
4699 struct device_attribute *attr, char *buf)
4700{
Johannes Berg8318d782008-01-24 19:38:38 +01004701 /* all this shit doesn't belong into sysfs anyway */
4702 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07004703}
4704
4705static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
4706
4707static ssize_t show_statistics(struct device *d,
4708 struct device_attribute *attr, char *buf)
4709{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004710 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004711 u32 size = sizeof(struct iwl3945_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07004712 u32 len = 0, ofs = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004713 u8 *data = (u8 *)&priv->statistics_39;
Zhu Yib481de92007-09-25 17:54:57 -07004714 int rc = 0;
4715
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004716 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004717 return -EAGAIN;
4718
4719 mutex_lock(&priv->mutex);
Samuel Ortiz17f841c2009-01-23 13:45:20 -08004720 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004721 mutex_unlock(&priv->mutex);
4722
4723 if (rc) {
4724 len = sprintf(buf,
4725 "Error sending statistics request: 0x%08X\n", rc);
4726 return len;
4727 }
4728
4729 while (size && (PAGE_SIZE - len)) {
4730 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4731 PAGE_SIZE - len, 1);
4732 len = strlen(buf);
4733 if (PAGE_SIZE - len)
4734 buf[len++] = '\n';
4735
4736 ofs += 16;
4737 size -= min(size, 16U);
4738 }
4739
4740 return len;
4741}
4742
4743static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
4744
4745static ssize_t show_antenna(struct device *d,
4746 struct device_attribute *attr, char *buf)
4747{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004748 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004749
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004750 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004751 return -EAGAIN;
4752
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08004753 return sprintf(buf, "%d\n", iwl3945_mod_params.antenna);
Zhu Yib481de92007-09-25 17:54:57 -07004754}
4755
4756static ssize_t store_antenna(struct device *d,
4757 struct device_attribute *attr,
4758 const char *buf, size_t count)
4759{
Winkler, Tomas7530f852009-01-27 14:27:53 -08004760 struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004761 int ant;
Zhu Yib481de92007-09-25 17:54:57 -07004762
4763 if (count == 0)
4764 return 0;
4765
4766 if (sscanf(buf, "%1i", &ant) != 1) {
Tomas Winklere1623442009-01-27 14:27:56 -08004767 IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004768 return count;
4769 }
4770
4771 if ((ant >= 0) && (ant <= 2)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004772 IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant);
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08004773 iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant;
Zhu Yib481de92007-09-25 17:54:57 -07004774 } else
Tomas Winklere1623442009-01-27 14:27:56 -08004775 IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant);
Zhu Yib481de92007-09-25 17:54:57 -07004776
4777
4778 return count;
4779}
4780
4781static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
4782
4783static ssize_t show_status(struct device *d,
4784 struct device_attribute *attr, char *buf)
4785{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004786 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004787 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004788 return -EAGAIN;
4789 return sprintf(buf, "0x%08x\n", (int)priv->status);
4790}
4791
4792static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
4793
4794static ssize_t dump_error_log(struct device *d,
4795 struct device_attribute *attr,
4796 const char *buf, size_t count)
4797{
4798 char *p = (char *)buf;
4799
4800 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004801 iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07004802
4803 return strnlen(buf, count);
4804}
4805
4806static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
4807
4808static ssize_t dump_event_log(struct device *d,
4809 struct device_attribute *attr,
4810 const char *buf, size_t count)
4811{
4812 char *p = (char *)buf;
4813
4814 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004815 iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07004816
4817 return strnlen(buf, count);
4818}
4819
4820static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
4821
4822/*****************************************************************************
4823 *
Tomas Winklera96a27f2008-10-23 23:48:56 -07004824 * driver setup and tear down
Zhu Yib481de92007-09-25 17:54:57 -07004825 *
4826 *****************************************************************************/
4827
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004828static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004829{
Reinette Chatred21050c2009-02-13 11:51:18 -08004830 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07004831
4832 init_waitqueue_head(&priv->wait_command_queue);
4833
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004834 INIT_WORK(&priv->up, iwl3945_bg_up);
4835 INIT_WORK(&priv->restart, iwl3945_bg_restart);
4836 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01004837 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004838 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004839 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
4840 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
Helmut Schaa26635162009-01-15 09:38:44 +01004841 INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll);
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08004842 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
4843 INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
4844 INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
4845 INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
Zhu Yib481de92007-09-25 17:54:57 -07004846
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004847 iwl3945_hw_setup_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004848
4849 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004850 iwl3945_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07004851}
4852
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004853static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004854{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004855 iwl3945_hw_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004856
Joonwoo Parke47eb6a2007-11-29 10:42:49 +09004857 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004858 cancel_delayed_work(&priv->scan_check);
4859 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004860 cancel_work_sync(&priv->beacon_update);
4861}
4862
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004863static struct attribute *iwl3945_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07004864 &dev_attr_antenna.attr,
4865 &dev_attr_channels.attr,
4866 &dev_attr_dump_errors.attr,
4867 &dev_attr_dump_events.attr,
4868 &dev_attr_flags.attr,
4869 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004870#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004871 &dev_attr_measurement.attr,
4872#endif
4873 &dev_attr_power_level.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004874 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004875 &dev_attr_statistics.attr,
4876 &dev_attr_status.attr,
4877 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004878 &dev_attr_tx_power.attr,
Samuel Ortizd08853a2009-01-23 13:45:17 -08004879#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004880 &dev_attr_debug_level.attr,
4881#endif
Zhu Yib481de92007-09-25 17:54:57 -07004882 NULL
4883};
4884
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004885static struct attribute_group iwl3945_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07004886 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004887 .attrs = iwl3945_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07004888};
4889
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004890static struct ieee80211_ops iwl3945_hw_ops = {
4891 .tx = iwl3945_mac_tx,
4892 .start = iwl3945_mac_start,
4893 .stop = iwl3945_mac_stop,
4894 .add_interface = iwl3945_mac_add_interface,
4895 .remove_interface = iwl3945_mac_remove_interface,
4896 .config = iwl3945_mac_config,
4897 .config_interface = iwl3945_mac_config_interface,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004898 .configure_filter = iwl_configure_filter,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004899 .set_key = iwl3945_mac_set_key,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004900 .get_tx_stats = iwl3945_mac_get_tx_stats,
4901 .conf_tx = iwl3945_mac_conf_tx,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004902 .reset_tsf = iwl3945_mac_reset_tsf,
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004903 .bss_info_changed = iwl3945_bss_info_changed,
Abhijeet Kolekare9dde6f62009-02-18 15:54:27 -08004904 .hw_scan = iwl_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07004905};
4906
Winkler, Tomase52119c2008-12-22 11:31:19 +08004907static int iwl3945_init_drv(struct iwl_priv *priv)
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004908{
4909 int ret;
Samuel Ortize6148912009-01-23 13:45:15 -08004910 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004911
4912 priv->retry_rate = 1;
4913 priv->ibss_beacon = NULL;
4914
4915 spin_lock_init(&priv->lock);
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08004916 spin_lock_init(&priv->power_data.lock);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004917 spin_lock_init(&priv->sta_lock);
4918 spin_lock_init(&priv->hcmd_lock);
4919
4920 INIT_LIST_HEAD(&priv->free_frames);
4921
4922 mutex_init(&priv->mutex);
4923
4924 /* Clear the driver's (not device's) station table */
4925 iwl3945_clear_stations_table(priv);
4926
4927 priv->data_retry_limit = -1;
4928 priv->ieee_channels = NULL;
4929 priv->ieee_rates = NULL;
4930 priv->band = IEEE80211_BAND_2GHZ;
4931
4932 priv->iw_mode = NL80211_IFTYPE_STATION;
4933
4934 iwl_reset_qos(priv);
4935
4936 priv->qos_data.qos_active = 0;
4937 priv->qos_data.qos_cap.val = 0;
4938
4939 priv->rates_mask = IWL_RATES_MASK;
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004940 /* If power management is turned on, default to CAM mode */
4941 priv->power_mode = IWL_POWER_MODE_CAM;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08004942 priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004943
Samuel Ortize6148912009-01-23 13:45:15 -08004944 if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
4945 IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
4946 eeprom->version);
4947 ret = -EINVAL;
4948 goto err;
4949 }
4950 ret = iwl_init_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004951 if (ret) {
4952 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
4953 goto err;
4954 }
4955
Samuel Ortize6148912009-01-23 13:45:15 -08004956 /* Set up txpower settings in driver for all channels */
4957 if (iwl3945_txpower_set_from_eeprom(priv)) {
4958 ret = -EIO;
4959 goto err_free_channel_map;
4960 }
4961
Samuel Ortiz534166d2009-01-23 13:45:16 -08004962 ret = iwlcore_init_geos(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004963 if (ret) {
4964 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
4965 goto err_free_channel_map;
4966 }
Samuel Ortiz534166d2009-01-23 13:45:16 -08004967 iwl3945_init_hw_rates(priv, priv->ieee_rates);
4968
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004969 return 0;
4970
4971err_free_channel_map:
Samuel Ortize6148912009-01-23 13:45:15 -08004972 iwl_free_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004973err:
4974 return ret;
4975}
4976
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004977static int iwl3945_setup_mac(struct iwl_priv *priv)
4978{
4979 int ret;
4980 struct ieee80211_hw *hw = priv->hw;
4981
4982 hw->rate_control_algorithm = "iwl-3945-rs";
4983 hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
4984
4985 /* Tell mac80211 our characteristics */
4986 hw->flags = IEEE80211_HW_SIGNAL_DBM |
4987 IEEE80211_HW_NOISE_DBM;
4988
4989 hw->wiphy->interface_modes =
4990 BIT(NL80211_IFTYPE_STATION) |
4991 BIT(NL80211_IFTYPE_ADHOC);
4992
4993 hw->wiphy->custom_regulatory = true;
4994
4995 /* Default value; 4 EDCA QOS priorities */
4996 hw->queues = 4;
4997
4998 hw->conf.beacon_int = 100;
4999
5000 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
5001 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
5002 &priv->bands[IEEE80211_BAND_2GHZ];
5003
5004 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
5005 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
5006 &priv->bands[IEEE80211_BAND_5GHZ];
5007
5008 ret = ieee80211_register_hw(priv->hw);
5009 if (ret) {
5010 IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
5011 return ret;
5012 }
5013 priv->mac80211_registered = 1;
5014
5015 return 0;
5016}
5017
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005018static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07005019{
5020 int err = 0;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005021 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07005022 struct ieee80211_hw *hw;
Kolekar, Abhijeetc0f20d92008-12-19 10:37:19 +08005023 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Samuel Ortize6148912009-01-23 13:45:15 -08005024 struct iwl3945_eeprom *eeprom;
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005025 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07005026
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005027 /***********************
5028 * 1. Allocating HW data
5029 * ********************/
5030
Zhu Yib481de92007-09-25 17:54:57 -07005031 /* mac80211 allocates memory for this device instance, including
5032 * space for this driver's private structure */
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005033 hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
Zhu Yib481de92007-09-25 17:54:57 -07005034 if (hw == NULL) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005035 printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
Zhu Yib481de92007-09-25 17:54:57 -07005036 err = -ENOMEM;
5037 goto out;
5038 }
Zhu Yib481de92007-09-25 17:54:57 -07005039 priv = hw->priv;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005040 SET_IEEE80211_DEV(hw, &pdev->dev);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005041
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005042 if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) ||
5043 (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005044 IWL_ERR(priv,
5045 "invalid queues_num, should be between %d and %d\n",
5046 IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES);
Samuel Ortiza3139c52008-12-19 10:37:09 +08005047 err = -EINVAL;
Reinette Chatrec8f16132009-02-27 16:21:22 -08005048 goto out_ieee80211_free_hw;
Samuel Ortiza3139c52008-12-19 10:37:09 +08005049 }
5050
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005051 /*
5052 * Disabling hardware scan means that mac80211 will perform scans
5053 * "the hard way", rather than using device's scan.
5054 */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005055 if (iwl3945_mod_params.disable_hw_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08005056 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005057 iwl3945_hw_ops.hw_scan = NULL;
5058 }
5059
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005060
Tomas Winklere1623442009-01-27 14:27:56 -08005061 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005062 priv->cfg = cfg;
5063 priv->pci_dev = pdev;
5064
Samuel Ortizd08853a2009-01-23 13:45:17 -08005065#ifdef CONFIG_IWLWIFI_DEBUG
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005066 priv->debug_level = iwl3945_mod_params.debug;
5067 atomic_set(&priv->restrict_refcnt, 0);
5068#endif
Zhu Yib481de92007-09-25 17:54:57 -07005069
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005070 /***************************
5071 * 2. Initializing PCI bus
5072 * *************************/
Zhu Yib481de92007-09-25 17:54:57 -07005073 if (pci_enable_device(pdev)) {
5074 err = -ENODEV;
5075 goto out_ieee80211_free_hw;
5076 }
5077
5078 pci_set_master(pdev);
5079
Zhu Yib481de92007-09-25 17:54:57 -07005080 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
5081 if (!err)
5082 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
5083 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08005084 IWL_WARN(priv, "No suitable DMA available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07005085 goto out_pci_disable_device;
5086 }
5087
5088 pci_set_drvdata(pdev, priv);
5089 err = pci_request_regions(pdev, DRV_NAME);
5090 if (err)
5091 goto out_pci_disable_device;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005092
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005093 /***********************
5094 * 3. Read REV Register
5095 * ********************/
Zhu Yib481de92007-09-25 17:54:57 -07005096 priv->hw_base = pci_iomap(pdev, 0, 0);
5097 if (!priv->hw_base) {
5098 err = -ENODEV;
5099 goto out_pci_release_regions;
5100 }
5101
Tomas Winklere1623442009-01-27 14:27:56 -08005102 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Zhu Yib481de92007-09-25 17:54:57 -07005103 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08005104 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Zhu Yib481de92007-09-25 17:54:57 -07005105
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005106 /* We disable the RETRY_TIMEOUT register (0x41) to keep
5107 * PCI Tx retries from interfering with C3 CPU state */
5108 pci_write_config_byte(pdev, 0x41, 0x00);
Zhu Yib481de92007-09-25 17:54:57 -07005109
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005110 /* amp init */
5111 err = priv->cfg->ops->lib->apm_ops.init(priv);
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005112 if (err < 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08005113 IWL_DEBUG_INFO(priv, "Failed to init APMG\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005114 goto out_iounmap;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005115 }
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005116
5117 /***********************
5118 * 4. Read EEPROM
5119 * ********************/
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005120
Zhu Yi5a669262008-01-14 17:46:18 -08005121 /* Read the EEPROM */
Samuel Ortize6148912009-01-23 13:45:15 -08005122 err = iwl_eeprom_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005123 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005124 IWL_ERR(priv, "Unable to init EEPROM\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08005125 goto out_iounmap;
Zhu Yi5a669262008-01-14 17:46:18 -08005126 }
5127 /* MAC Address location in EEPROM same for 3945/4965 */
Samuel Ortize6148912009-01-23 13:45:15 -08005128 eeprom = (struct iwl3945_eeprom *)priv->eeprom;
5129 memcpy(priv->mac_addr, eeprom->mac_address, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08005130 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
Zhu Yi5a669262008-01-14 17:46:18 -08005131 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
5132
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005133 /***********************
5134 * 5. Setup HW Constants
5135 * ********************/
5136 /* Device-specific setup */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005137 if (iwl3945_hw_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005138 IWL_ERR(priv, "failed to set hw settings\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08005139 goto out_eeprom_free;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005140 }
5141
5142 /***********************
5143 * 6. Setup priv
5144 * ********************/
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005145
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005146 err = iwl3945_init_drv(priv);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005147 if (err) {
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005148 IWL_ERR(priv, "initializing driver failed\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08005149 goto out_unset_hw_params;
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005150 }
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005151
Tomas Winkler978785a2008-12-19 10:37:31 +08005152 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
5153 priv->cfg->name);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005154
5155 /***********************************
5156 * 7. Initialize Module Parameters
5157 * **********************************/
5158
5159 /* Initialize module parameter values here */
5160 /* Disable radio (SW RF KILL) via parameter when loading driver */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005161 if (iwl3945_mod_params.disable) {
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005162 set_bit(STATUS_RF_KILL_SW, &priv->status);
Tomas Winklere1623442009-01-27 14:27:56 -08005163 IWL_DEBUG_INFO(priv, "Radio disabled.\n");
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005164 }
5165
5166
5167 /***********************
5168 * 8. Setup Services
5169 * ********************/
5170
5171 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08005172 iwl_disable_interrupts(priv);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005173 spin_unlock_irqrestore(&priv->lock, flags);
5174
Helmut Schaa26635162009-01-15 09:38:44 +01005175 pci_enable_msi(priv->pci_dev);
5176
Abhijeet Kolekarf17d08a2009-02-18 15:54:31 -08005177 err = request_irq(priv->pci_dev->irq, iwl_isr, IRQF_SHARED,
Helmut Schaa26635162009-01-15 09:38:44 +01005178 DRV_NAME, priv);
5179 if (err) {
5180 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
5181 goto out_disable_msi;
5182 }
5183
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005184 err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
5185 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005186 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005187 goto out_release_irq;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005188 }
5189
Samuel Ortiz8ccde882009-01-27 14:27:52 -08005190 iwl_set_rxon_channel(priv,
5191 &priv->bands[IEEE80211_BAND_2GHZ].channels[5]);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005192 iwl3945_setup_deferred_work(priv);
5193 iwl3945_setup_rx_handlers(priv);
5194
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005195 /*********************************
Helmut Schaa26635162009-01-15 09:38:44 +01005196 * 9. Setup and Register mac80211
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005197 * *******************************/
5198
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08005199 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005200
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08005201 err = iwl3945_setup_mac(priv);
5202 if (err)
5203 goto out_remove_sysfs;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005204
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005205 err = iwl_rfkill_init(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005206 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08005207 IWL_ERR(priv, "Unable to initialize RFKILL system. "
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005208 "Ignoring error: %d\n", err);
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08005209 else
5210 iwl_rfkill_set_hw_state(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005211
Helmut Schaa26635162009-01-15 09:38:44 +01005212 /* Start monitoring the killswitch */
5213 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
5214 2 * HZ);
5215
Zhu Yib481de92007-09-25 17:54:57 -07005216 return 0;
5217
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005218 out_remove_sysfs:
Zhu Yib481de92007-09-25 17:54:57 -07005219 destroy_workqueue(priv->workqueue);
5220 priv->workqueue = NULL;
Reinette Chatrec8f16132009-02-27 16:21:22 -08005221 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
5222 out_release_irq:
5223 free_irq(priv->pci_dev->irq, priv);
Helmut Schaa26635162009-01-15 09:38:44 +01005224 out_disable_msi:
5225 pci_disable_msi(priv->pci_dev);
Reinette Chatrec8f16132009-02-27 16:21:22 -08005226 iwlcore_free_geos(priv);
5227 iwl_free_channel_map(priv);
5228 out_unset_hw_params:
5229 iwl3945_unset_hw_params(priv);
5230 out_eeprom_free:
5231 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005232 out_iounmap:
5233 pci_iounmap(pdev, priv->hw_base);
5234 out_pci_release_regions:
5235 pci_release_regions(pdev);
5236 out_pci_disable_device:
5237 pci_disable_device(pdev);
5238 pci_set_drvdata(pdev, NULL);
5239 out_ieee80211_free_hw:
5240 ieee80211_free_hw(priv->hw);
5241 out:
5242 return err;
5243}
5244
Reinette Chatrec83dbf62008-03-21 13:53:41 -07005245static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07005246{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005247 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005248 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07005249
5250 if (!priv)
5251 return;
5252
Tomas Winklere1623442009-01-27 14:27:56 -08005253 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07005254
Zhu Yib481de92007-09-25 17:54:57 -07005255 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08005256
Kolekar, Abhijeetd552bfb2008-12-19 10:37:41 +08005257 if (priv->mac80211_registered) {
5258 ieee80211_unregister_hw(priv->hw);
5259 priv->mac80211_registered = 0;
5260 } else {
5261 iwl3945_down(priv);
5262 }
Zhu Yib481de92007-09-25 17:54:57 -07005263
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005264 /* make sure we flush any pending irq or
5265 * tasklet for the driver
5266 */
5267 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08005268 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005269 spin_unlock_irqrestore(&priv->lock, flags);
5270
5271 iwl_synchronize_irq(priv);
5272
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005273 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07005274
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005275 iwl_rfkill_unregister(priv);
Helmut Schaa26635162009-01-15 09:38:44 +01005276 cancel_delayed_work(&priv->rfkill_poll);
5277
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005278 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005279
5280 if (priv->rxq.bd)
Winkler, Tomas51af3d32008-12-22 11:31:23 +08005281 iwl_rx_queue_free(priv, &priv->rxq);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005282 iwl3945_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005283
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005284 iwl3945_unset_hw_params(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005285 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005286
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08005287 /*netif_stop_queue(dev); */
5288 flush_workqueue(priv->workqueue);
5289
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005290 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07005291 * priv->workqueue... so we can't take down the workqueue
5292 * until now... */
5293 destroy_workqueue(priv->workqueue);
5294 priv->workqueue = NULL;
5295
Helmut Schaa26635162009-01-15 09:38:44 +01005296 free_irq(pdev->irq, priv);
5297 pci_disable_msi(pdev);
5298
Zhu Yib481de92007-09-25 17:54:57 -07005299 pci_iounmap(pdev, priv->hw_base);
5300 pci_release_regions(pdev);
5301 pci_disable_device(pdev);
5302 pci_set_drvdata(pdev, NULL);
5303
Samuel Ortize6148912009-01-23 13:45:15 -08005304 iwl_free_channel_map(priv);
Samuel Ortiz534166d2009-01-23 13:45:16 -08005305 iwlcore_free_geos(priv);
Winkler, Tomas805cee52009-01-19 15:30:28 -08005306 kfree(priv->scan);
Zhu Yib481de92007-09-25 17:54:57 -07005307 if (priv->ibss_beacon)
5308 dev_kfree_skb(priv->ibss_beacon);
5309
5310 ieee80211_free_hw(priv->hw);
5311}
5312
5313#ifdef CONFIG_PM
5314
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005315static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07005316{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005317 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005318
Zhu Yie655b9f2008-01-24 02:19:38 -08005319 if (priv->is_open) {
5320 set_bit(STATUS_IN_SUSPEND, &priv->status);
5321 iwl3945_mac_stop(priv->hw);
5322 priv->is_open = 1;
5323 }
Helmut Schaa26635162009-01-15 09:38:44 +01005324 pci_save_state(pdev);
5325 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005326 pci_set_power_state(pdev, PCI_D3hot);
5327
Zhu Yib481de92007-09-25 17:54:57 -07005328 return 0;
5329}
5330
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005331static int iwl3945_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07005332{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005333 struct iwl_priv *priv = pci_get_drvdata(pdev);
Winkler, Tomas450154e2009-01-27 14:27:55 -08005334 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07005335
Zhu Yib481de92007-09-25 17:54:57 -07005336 pci_set_power_state(pdev, PCI_D0);
Winkler, Tomas450154e2009-01-27 14:27:55 -08005337 ret = pci_enable_device(pdev);
5338 if (ret)
5339 return ret;
Helmut Schaa26635162009-01-15 09:38:44 +01005340 pci_restore_state(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005341
Zhu Yie655b9f2008-01-24 02:19:38 -08005342 if (priv->is_open)
5343 iwl3945_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07005344
Zhu Yie655b9f2008-01-24 02:19:38 -08005345 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07005346 return 0;
5347}
5348
5349#endif /* CONFIG_PM */
5350
5351/*****************************************************************************
5352 *
5353 * driver and module entry point
5354 *
5355 *****************************************************************************/
5356
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005357static struct pci_driver iwl3945_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07005358 .name = DRV_NAME,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005359 .id_table = iwl3945_hw_card_ids,
5360 .probe = iwl3945_pci_probe,
5361 .remove = __devexit_p(iwl3945_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07005362#ifdef CONFIG_PM
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005363 .suspend = iwl3945_pci_suspend,
5364 .resume = iwl3945_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07005365#endif
5366};
5367
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005368static int __init iwl3945_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07005369{
5370
5371 int ret;
5372 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
5373 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005374
5375 ret = iwl3945_rate_control_register();
5376 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005377 printk(KERN_ERR DRV_NAME
5378 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005379 return ret;
5380 }
5381
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005382 ret = pci_register_driver(&iwl3945_driver);
Zhu Yib481de92007-09-25 17:54:57 -07005383 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005384 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005385 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07005386 }
Zhu Yib481de92007-09-25 17:54:57 -07005387
5388 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005389
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005390error_register:
5391 iwl3945_rate_control_unregister();
5392 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07005393}
5394
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005395static void __exit iwl3945_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07005396{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005397 pci_unregister_driver(&iwl3945_driver);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005398 iwl3945_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07005399}
5400
Reinette Chatrea0987a82008-12-02 12:14:06 -08005401MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
Zhu Yi25cb6ca2008-09-11 11:45:22 +08005402
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005403module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005404MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005405module_param_named(disable, iwl3945_mod_params.disable, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005406MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -08005407module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
5408MODULE_PARM_DESC(swcrypto,
5409 "using software crypto (default 1 [software])\n");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005410module_param_named(debug, iwl3945_mod_params.debug, uint, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005411MODULE_PARM_DESC(debug, "debug output mask");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005412module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005413MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
5414
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005415module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005416MODULE_PARM_DESC(queues_num, "number of hw queues.");
5417
Samuel Ortizaf48d042009-01-23 13:45:19 -08005418module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, 0444);
5419MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error");
5420
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005421module_exit(iwl3945_exit);
5422module_init(iwl3945_init);