blob: d0596e7f64e61b103094e4daa284a35659b752d7 [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
410 /* Apply the new configuration */
Samuel Ortiz518099a2009-01-19 15:30:27 -0800411 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800412 sizeof(struct iwl3945_rxon_cmd),
413 staging_rxon);
Zhu Yib481de92007-09-25 17:54:57 -0700414 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800415 IWL_ERR(priv, "Error setting new configuration (%d).\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700416 return rc;
417 }
418
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800419 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700420
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800421 iwl3945_clear_stations_table(priv);
Zhu Yi556f8db2007-09-27 11:27:33 +0800422
Zhu Yib481de92007-09-25 17:54:57 -0700423 /* If we issue a new RXON command which required a tune then we must
424 * send a new TXPOWER command or we won't be able to Tx any frames */
Samuel Ortiz75bcfae2009-01-23 13:45:11 -0800425 rc = priv->cfg->ops->lib->send_tx_power(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700426 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800427 IWL_ERR(priv, "Error setting Tx power (%d).\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700428 return rc;
429 }
430
431 /* Add the broadcast address so we can send broadcast frames */
Kolekar, Abhijeetb5323d32008-12-19 10:37:22 +0800432 if (iwl3945_add_station(priv, iwl_bcast_addr, 0, 0) ==
Zhu Yib481de92007-09-25 17:54:57 -0700433 IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800434 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700435 return -EIO;
436 }
437
438 /* If we have set the ASSOC_MSK and we are in BSS mode then
439 * add the IWL_AP_ID to the station rate table */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800440 if (iwl_is_associated(priv) &&
Johannes Berg05c914f2008-09-11 00:01:58 +0200441 (priv->iw_mode == NL80211_IFTYPE_STATION))
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800442 if (iwl3945_add_station(priv, priv->active_rxon.bssid_addr,
443 1, 0)
Zhu Yib481de92007-09-25 17:54:57 -0700444 == IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800445 IWL_ERR(priv, "Error adding AP address for transmit\n");
Zhu Yib481de92007-09-25 17:54:57 -0700446 return -EIO;
447 }
448
Johannes Berg8318d782008-01-24 19:38:38 +0100449 /* Init the hardware's rate fallback order based on the band */
Zhu Yib481de92007-09-25 17:54:57 -0700450 rc = iwl3945_init_hw_rate_table(priv);
451 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800452 IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700453 return -EIO;
454 }
455
456 return 0;
457}
458
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800459static int iwl3945_update_sta_key_info(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700460 struct ieee80211_key_conf *keyconf,
461 u8 sta_id)
462{
463 unsigned long flags;
464 __le16 key_flags = 0;
465
466 switch (keyconf->alg) {
467 case ALG_CCMP:
468 key_flags |= STA_KEY_FLG_CCMP;
469 key_flags |= cpu_to_le16(
470 keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
471 key_flags &= ~STA_KEY_FLG_INVALID;
472 break;
473 case ALG_TKIP:
474 case ALG_WEP:
Zhu Yib481de92007-09-25 17:54:57 -0700475 default:
476 return -EINVAL;
477 }
478 spin_lock_irqsave(&priv->sta_lock, flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800479 priv->stations_39[sta_id].keyinfo.alg = keyconf->alg;
480 priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen;
481 memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700482 keyconf->keylen);
483
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800484 memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700485 keyconf->keylen);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800486 priv->stations_39[sta_id].sta.key.key_flags = key_flags;
487 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
488 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700489
490 spin_unlock_irqrestore(&priv->sta_lock, flags);
491
Tomas Winklere1623442009-01-27 14:27:56 -0800492 IWL_DEBUG_INFO(priv, "hwcrypto: modify ucode station key info\n");
Samuel Ortiz17f841c2009-01-23 13:45:20 -0800493 iwl_send_add_sta(priv,
494 (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700495 return 0;
496}
497
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800498static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
Zhu Yib481de92007-09-25 17:54:57 -0700499{
500 unsigned long flags;
501
502 spin_lock_irqsave(&priv->sta_lock, flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800503 memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key));
504 memset(&priv->stations_39[sta_id].sta.key, 0,
Tomas Winkler4c897252008-12-19 10:37:05 +0800505 sizeof(struct iwl4965_keyinfo));
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800506 priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
507 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
508 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700509 spin_unlock_irqrestore(&priv->sta_lock, flags);
510
Tomas Winklere1623442009-01-27 14:27:56 -0800511 IWL_DEBUG_INFO(priv, "hwcrypto: clear ucode station key info\n");
Samuel Ortiz17f841c2009-01-23 13:45:20 -0800512 iwl_send_add_sta(priv,
513 (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700514 return 0;
515}
516
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800517static void iwl3945_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700518{
519 struct list_head *element;
520
Tomas Winklere1623442009-01-27 14:27:56 -0800521 IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
Zhu Yib481de92007-09-25 17:54:57 -0700522 priv->frames_count);
523
524 while (!list_empty(&priv->free_frames)) {
525 element = priv->free_frames.next;
526 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800527 kfree(list_entry(element, struct iwl3945_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700528 priv->frames_count--;
529 }
530
531 if (priv->frames_count) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800532 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
Zhu Yib481de92007-09-25 17:54:57 -0700533 priv->frames_count);
534 priv->frames_count = 0;
535 }
536}
537
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800538static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700539{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800540 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700541 struct list_head *element;
542 if (list_empty(&priv->free_frames)) {
543 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
544 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800545 IWL_ERR(priv, "Could not allocate frame!\n");
Zhu Yib481de92007-09-25 17:54:57 -0700546 return NULL;
547 }
548
549 priv->frames_count++;
550 return frame;
551 }
552
553 element = priv->free_frames.next;
554 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800555 return list_entry(element, struct iwl3945_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700556}
557
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800558static void iwl3945_free_frame(struct iwl_priv *priv, struct iwl3945_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700559{
560 memset(frame, 0, sizeof(*frame));
561 list_add(&frame->list, &priv->free_frames);
562}
563
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800564unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700565 struct ieee80211_hdr *hdr,
Rami Rosen73ec1cc2008-12-16 09:37:07 +0200566 int left)
Zhu Yib481de92007-09-25 17:54:57 -0700567{
568
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800569 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200570 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
571 (priv->iw_mode != NL80211_IFTYPE_AP)))
Zhu Yib481de92007-09-25 17:54:57 -0700572 return 0;
573
574 if (priv->ibss_beacon->len > left)
575 return 0;
576
577 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
578
579 return priv->ibss_beacon->len;
580}
581
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800582static int iwl3945_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700583{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800584 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700585 unsigned int frame_size;
586 int rc;
587 u8 rate;
588
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800589 frame = iwl3945_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700590
591 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800592 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
Zhu Yib481de92007-09-25 17:54:57 -0700593 "command.\n");
594 return -ENOMEM;
595 }
596
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800597 rate = iwl_rate_get_lowest_plcp(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700598
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800599 frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -0700600
Samuel Ortiz518099a2009-01-19 15:30:27 -0800601 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700602 &frame->u.cmd[0]);
603
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800604 iwl3945_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700605
606 return rc;
607}
608
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800609static void iwl3945_unset_hw_params(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700610{
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800611 if (priv->shared_virt)
Zhu Yib481de92007-09-25 17:54:57 -0700612 pci_free_consistent(priv->pci_dev,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800613 sizeof(struct iwl3945_shared),
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800614 priv->shared_virt,
615 priv->shared_phys);
Zhu Yib481de92007-09-25 17:54:57 -0700616}
617
Zhu Yib481de92007-09-25 17:54:57 -0700618/*
619 * QoS support
620*/
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800621static int iwl3945_send_qos_params_command(struct iwl_priv *priv,
Tomas Winkler4c897252008-12-19 10:37:05 +0800622 struct iwl_qosparam_cmd *qos)
Zhu Yib481de92007-09-25 17:54:57 -0700623{
624
Samuel Ortiz518099a2009-01-19 15:30:27 -0800625 return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM,
Tomas Winkler4c897252008-12-19 10:37:05 +0800626 sizeof(struct iwl_qosparam_cmd), qos);
Zhu Yib481de92007-09-25 17:54:57 -0700627}
628
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800629static void iwl3945_activate_qos(struct iwl_priv *priv, u8 force)
Zhu Yib481de92007-09-25 17:54:57 -0700630{
631 unsigned long flags;
632
Zhu Yib481de92007-09-25 17:54:57 -0700633 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
634 return;
635
Zhu Yib481de92007-09-25 17:54:57 -0700636 spin_lock_irqsave(&priv->lock, flags);
637 priv->qos_data.def_qos_parm.qos_flags = 0;
638
639 if (priv->qos_data.qos_cap.q_AP.queue_request &&
640 !priv->qos_data.qos_cap.q_AP.txop_request)
641 priv->qos_data.def_qos_parm.qos_flags |=
642 QOS_PARAM_FLG_TXOP_TYPE_MSK;
643
644 if (priv->qos_data.qos_active)
645 priv->qos_data.def_qos_parm.qos_flags |=
646 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
647
648 spin_unlock_irqrestore(&priv->lock, flags);
649
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800650 if (force || iwl_is_associated(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800651 IWL_DEBUG_QOS(priv, "send QoS cmd with QoS active %d \n",
Zhu Yib481de92007-09-25 17:54:57 -0700652 priv->qos_data.qos_active);
653
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800654 iwl3945_send_qos_params_command(priv,
Zhu Yib481de92007-09-25 17:54:57 -0700655 &(priv->qos_data.def_qos_parm));
656 }
657}
658
Zhu Yib481de92007-09-25 17:54:57 -0700659
Zhu Yib481de92007-09-25 17:54:57 -0700660#define MAX_UCODE_BEACON_INTERVAL 1024
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -0800661#define INTEL_CONN_LISTEN_INTERVAL cpu_to_le16(0xA)
Zhu Yib481de92007-09-25 17:54:57 -0700662
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800663static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -0700664{
665 u16 new_val = 0;
666 u16 beacon_factor = 0;
667
668 beacon_factor =
669 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
670 / MAX_UCODE_BEACON_INTERVAL;
671 new_val = beacon_val / beacon_factor;
672
673 return cpu_to_le16(new_val);
674}
675
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800676static void iwl3945_setup_rxon_timing(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700677{
678 u64 interval_tm_unit;
679 u64 tsf, result;
680 unsigned long flags;
681 struct ieee80211_conf *conf = NULL;
682 u16 beacon_int = 0;
683
684 conf = ieee80211_get_hw_conf(priv->hw);
685
686 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler28afaf92008-12-19 10:37:06 +0800687 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
Zhu Yib481de92007-09-25 17:54:57 -0700688 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
689
Tomas Winkler28afaf92008-12-19 10:37:06 +0800690 tsf = priv->timestamp;
Zhu Yib481de92007-09-25 17:54:57 -0700691
692 beacon_int = priv->beacon_int;
693 spin_unlock_irqrestore(&priv->lock, flags);
694
Johannes Berg05c914f2008-09-11 00:01:58 +0200695 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Zhu Yib481de92007-09-25 17:54:57 -0700696 if (beacon_int == 0) {
697 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
698 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
699 } else {
700 priv->rxon_timing.beacon_interval =
701 cpu_to_le16(beacon_int);
702 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800703 iwl3945_adjust_beacon_interval(
Zhu Yib481de92007-09-25 17:54:57 -0700704 le16_to_cpu(priv->rxon_timing.beacon_interval));
705 }
706
707 priv->rxon_timing.atim_window = 0;
708 } else {
709 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800710 iwl3945_adjust_beacon_interval(conf->beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -0700711 /* TODO: we need to get atim_window from upper stack
712 * for now we set to 0 */
713 priv->rxon_timing.atim_window = 0;
714 }
715
716 interval_tm_unit =
717 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
718 result = do_div(tsf, interval_tm_unit);
719 priv->rxon_timing.beacon_init_val =
720 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
721
Tomas Winklere1623442009-01-27 14:27:56 -0800722 IWL_DEBUG_ASSOC(priv,
723 "beacon interval %d beacon timer %d beacon tim %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700724 le16_to_cpu(priv->rxon_timing.beacon_interval),
725 le32_to_cpu(priv->rxon_timing.beacon_init_val),
726 le16_to_cpu(priv->rxon_timing.atim_window));
727}
728
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800729static int iwl3945_set_mode(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -0700730{
Johannes Berg05c914f2008-09-11 00:01:58 +0200731 if (mode == NL80211_IFTYPE_ADHOC) {
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800732 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -0700733
Samuel Ortize6148912009-01-23 13:45:15 -0800734 ch_info = iwl_get_channel_info(priv,
Johannes Berg8318d782008-01-24 19:38:38 +0100735 priv->band,
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800736 le16_to_cpu(priv->staging_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700737
738 if (!ch_info || !is_channel_ibss(ch_info)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800739 IWL_ERR(priv, "channel %d not IBSS channel\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800740 le16_to_cpu(priv->staging_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700741 return -EINVAL;
742 }
743 }
744
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800745 iwl_connection_init_rx_config(priv, mode);
Zhu Yib481de92007-09-25 17:54:57 -0700746
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800747 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700748
Tomas Winklera96a27f2008-10-23 23:48:56 -0700749 /* don't commit rxon if rf-kill is on*/
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800750 if (!iwl_is_ready_rf(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +0800751 return -EAGAIN;
752
753 cancel_delayed_work(&priv->scan_check);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -0800754 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800755 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
Tomas Winklere1623442009-01-27 14:27:56 -0800756 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +0800757 return -EAGAIN;
758 }
759
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800760 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700761
762 return 0;
763}
764
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800765static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
Johannes Berge039fa42008-05-15 12:55:29 +0200766 struct ieee80211_tx_info *info,
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800767 struct iwl_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -0700768 struct sk_buff *skb_frag,
769 int last_frag)
770{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800771 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
Ivo van Doorn1c014422008-04-17 19:41:02 +0200772 struct iwl3945_hw_key *keyinfo =
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800773 &priv->stations_39[info->control.hw_key->hw_key_idx].keyinfo;
Zhu Yib481de92007-09-25 17:54:57 -0700774
775 switch (keyinfo->alg) {
776 case ALG_CCMP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800777 tx->sec_ctl = TX_CMD_SEC_CCM;
778 memcpy(tx->key, keyinfo->key, keyinfo->keylen);
Tomas Winklere1623442009-01-27 14:27:56 -0800779 IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
Zhu Yib481de92007-09-25 17:54:57 -0700780 break;
781
782 case ALG_TKIP:
783#if 0
Winkler, Tomase52119c2008-12-22 11:31:19 +0800784 tx->sec_ctl = TX_CMD_SEC_TKIP;
Zhu Yib481de92007-09-25 17:54:57 -0700785
786 if (last_frag)
Winkler, Tomase52119c2008-12-22 11:31:19 +0800787 memcpy(tx->tkip_mic.byte, skb_frag->tail - 8,
Zhu Yib481de92007-09-25 17:54:57 -0700788 8);
789 else
Winkler, Tomase52119c2008-12-22 11:31:19 +0800790 memset(tx->tkip_mic.byte, 0, 8);
Zhu Yib481de92007-09-25 17:54:57 -0700791#endif
792 break;
793
794 case ALG_WEP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800795 tx->sec_ctl = TX_CMD_SEC_WEP |
Johannes Berge039fa42008-05-15 12:55:29 +0200796 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
Zhu Yib481de92007-09-25 17:54:57 -0700797
798 if (keyinfo->keylen == 13)
Winkler, Tomase52119c2008-12-22 11:31:19 +0800799 tx->sec_ctl |= TX_CMD_SEC_KEY128;
Zhu Yib481de92007-09-25 17:54:57 -0700800
Winkler, Tomase52119c2008-12-22 11:31:19 +0800801 memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen);
Zhu Yib481de92007-09-25 17:54:57 -0700802
Tomas Winklere1623442009-01-27 14:27:56 -0800803 IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
Johannes Berge039fa42008-05-15 12:55:29 +0200804 "with key %d\n", info->control.hw_key->hw_key_idx);
Zhu Yib481de92007-09-25 17:54:57 -0700805 break;
806
Zhu Yib481de92007-09-25 17:54:57 -0700807 default:
Tomas Winkler978785a2008-12-19 10:37:31 +0800808 IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg);
Zhu Yib481de92007-09-25 17:54:57 -0700809 break;
810 }
811}
812
813/*
814 * handle build REPLY_TX command notification.
815 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800816static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800817 struct iwl_cmd *cmd,
Johannes Berge039fa42008-05-15 12:55:29 +0200818 struct ieee80211_tx_info *info,
Winkler, Tomase52119c2008-12-22 11:31:19 +0800819 struct ieee80211_hdr *hdr, u8 std_id)
Zhu Yib481de92007-09-25 17:54:57 -0700820{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800821 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
822 __le32 tx_flags = tx->tx_flags;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700823 __le16 fc = hdr->frame_control;
Johannes Berge6a98542008-10-21 12:40:02 +0200824 u8 rc_flags = info->control.rates[0].flags;
Zhu Yib481de92007-09-25 17:54:57 -0700825
Winkler, Tomase52119c2008-12-22 11:31:19 +0800826 tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Johannes Berge039fa42008-05-15 12:55:29 +0200827 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
Zhu Yib481de92007-09-25 17:54:57 -0700828 tx_flags |= TX_CMD_FLG_ACK_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700829 if (ieee80211_is_mgmt(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700830 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700831 if (ieee80211_is_probe_resp(fc) &&
Zhu Yib481de92007-09-25 17:54:57 -0700832 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
833 tx_flags |= TX_CMD_FLG_TSF_MSK;
834 } else {
835 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
836 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
837 }
838
Winkler, Tomase52119c2008-12-22 11:31:19 +0800839 tx->sta_id = std_id;
Harvey Harrison8b7b1e02008-06-11 14:21:56 -0700840 if (ieee80211_has_morefrags(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700841 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
842
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700843 if (ieee80211_is_data_qos(fc)) {
844 u8 *qc = ieee80211_get_qos_ctl(hdr);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800845 tx->tid_tspec = qc[0] & 0xf;
Zhu Yib481de92007-09-25 17:54:57 -0700846 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800847 } else {
Zhu Yib481de92007-09-25 17:54:57 -0700848 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800849 }
Zhu Yib481de92007-09-25 17:54:57 -0700850
Johannes Berge6a98542008-10-21 12:40:02 +0200851 if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
Zhu Yib481de92007-09-25 17:54:57 -0700852 tx_flags |= TX_CMD_FLG_RTS_MSK;
853 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
Johannes Berge6a98542008-10-21 12:40:02 +0200854 } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
Zhu Yib481de92007-09-25 17:54:57 -0700855 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
856 tx_flags |= TX_CMD_FLG_CTS_MSK;
857 }
858
859 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
860 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
861
862 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700863 if (ieee80211_is_mgmt(fc)) {
864 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
Winkler, Tomase52119c2008-12-22 11:31:19 +0800865 tx->timeout.pm_frame_timeout = cpu_to_le16(3);
Zhu Yib481de92007-09-25 17:54:57 -0700866 else
Winkler, Tomase52119c2008-12-22 11:31:19 +0800867 tx->timeout.pm_frame_timeout = cpu_to_le16(2);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700868 } else {
Winkler, Tomase52119c2008-12-22 11:31:19 +0800869 tx->timeout.pm_frame_timeout = 0;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700870#ifdef CONFIG_IWL3945_LEDS
871 priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
872#endif
873 }
Zhu Yib481de92007-09-25 17:54:57 -0700874
Winkler, Tomase52119c2008-12-22 11:31:19 +0800875 tx->driver_txop = 0;
876 tx->tx_flags = tx_flags;
877 tx->next_frame_len = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700878}
879
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800880/**
881 * iwl3945_get_sta_id - Find station's index within station table
882 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800883static int iwl3945_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
Zhu Yib481de92007-09-25 17:54:57 -0700884{
885 int sta_id;
886 u16 fc = le16_to_cpu(hdr->frame_control);
887
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800888 /* If this frame is broadcast or management, use broadcast station id */
Zhu Yib481de92007-09-25 17:54:57 -0700889 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
890 is_multicast_ether_addr(hdr->addr1))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800891 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700892
893 switch (priv->iw_mode) {
894
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800895 /* If we are a client station in a BSS network, use the special
896 * AP station entry (that's the only station we communicate with) */
Johannes Berg05c914f2008-09-11 00:01:58 +0200897 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -0700898 return IWL_AP_ID;
899
900 /* If we are an AP, then find the station, or use BCAST */
Johannes Berg05c914f2008-09-11 00:01:58 +0200901 case NL80211_IFTYPE_AP:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800902 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700903 if (sta_id != IWL_INVALID_STATION)
904 return sta_id;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800905 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700906
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800907 /* If this frame is going out to an IBSS network, find the station,
908 * or create a new station table entry */
Johannes Berg05c914f2008-09-11 00:01:58 +0200909 case NL80211_IFTYPE_ADHOC: {
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800910 /* Create new station table entry */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800911 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700912 if (sta_id != IWL_INVALID_STATION)
913 return sta_id;
914
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800915 sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
Zhu Yib481de92007-09-25 17:54:57 -0700916
917 if (sta_id != IWL_INVALID_STATION)
918 return sta_id;
919
Tomas Winklere1623442009-01-27 14:27:56 -0800920 IWL_DEBUG_DROP(priv, "Station %pM not in station map. "
Zhu Yib481de92007-09-25 17:54:57 -0700921 "Defaulting to broadcast...\n",
Johannes Berge1749612008-10-27 15:59:26 -0700922 hdr->addr1);
Samuel Ortiz40b8ec02008-12-19 10:37:08 +0800923 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800924 return priv->hw_params.bcast_sta_id;
Joe Perches0795af52007-10-03 17:59:30 -0700925 }
Stefanik Gábor914233d2008-06-30 17:23:30 +0800926 /* If we are in monitor mode, use BCAST. This is required for
927 * packet injection. */
Johannes Berg05c914f2008-09-11 00:01:58 +0200928 case NL80211_IFTYPE_MONITOR:
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800929 return priv->hw_params.bcast_sta_id;
Stefanik Gábor914233d2008-06-30 17:23:30 +0800930
Zhu Yib481de92007-09-25 17:54:57 -0700931 default:
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800932 IWL_WARN(priv, "Unknown mode of operation: %d\n",
933 priv->iw_mode);
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800934 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700935 }
936}
937
938/*
939 * start REPLY_TX command process
940 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800941static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -0700942{
943 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berge039fa42008-05-15 12:55:29 +0200944 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800945 struct iwl3945_tx_cmd *tx;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800946 struct iwl_tx_queue *txq = NULL;
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800947 struct iwl_queue *q = NULL;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800948 struct iwl_cmd *out_cmd = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700949 dma_addr_t phys_addr;
950 dma_addr_t txcmd_phys;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800951 int txq_id = skb_get_queue_mapping(skb);
Tomas Winkler54dbb522008-05-15 13:54:06 +0800952 u16 len, idx, len_org, hdr_len;
953 u8 id;
954 u8 unicast;
Zhu Yib481de92007-09-25 17:54:57 -0700955 u8 sta_id;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800956 u8 tid = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700957 u16 seq_number = 0;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700958 __le16 fc;
Zhu Yib481de92007-09-25 17:54:57 -0700959 u8 wait_write_ptr = 0;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800960 u8 *qc = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700961 unsigned long flags;
962 int rc;
963
964 spin_lock_irqsave(&priv->lock, flags);
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800965 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800966 IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
Zhu Yib481de92007-09-25 17:54:57 -0700967 goto drop_unlock;
968 }
969
Johannes Berge039fa42008-05-15 12:55:29 +0200970 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800971 IWL_ERR(priv, "ERROR: No TX rate available.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700972 goto drop_unlock;
973 }
974
975 unicast = !is_multicast_ether_addr(hdr->addr1);
976 id = 0;
977
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700978 fc = hdr->frame_control;
Zhu Yib481de92007-09-25 17:54:57 -0700979
Samuel Ortizd08853a2009-01-23 13:45:17 -0800980#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -0700981 if (ieee80211_is_auth(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800982 IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700983 else if (ieee80211_is_assoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800984 IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700985 else if (ieee80211_is_reassoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800986 IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
Zhu Yib481de92007-09-25 17:54:57 -0700987#endif
988
Mohamed Abbas7878a5a2007-11-29 11:10:13 +0800989 /* drop all data frame if we are not associated */
Stefanik Gábor914233d2008-06-30 17:23:30 +0800990 if (ieee80211_is_data(fc) &&
Johannes Berg05c914f2008-09-11 00:01:58 +0200991 (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800992 (!iwl_is_associated(priv) ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200993 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
Tomas Winklere1623442009-01-27 14:27:56 -0800994 IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n");
Zhu Yib481de92007-09-25 17:54:57 -0700995 goto drop_unlock;
996 }
997
998 spin_unlock_irqrestore(&priv->lock, flags);
999
Harvey Harrison7294ec92008-07-15 18:43:59 -07001000 hdr_len = ieee80211_hdrlen(fc);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001001
1002 /* Find (or create) index into station table for destination station */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001003 sta_id = iwl3945_get_sta_id(priv, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07001004 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -08001005 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07001006 hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07001007 goto drop;
1008 }
1009
Tomas Winklere1623442009-01-27 14:27:56 -08001010 IWL_DEBUG_RATE(priv, "station Id %d\n", sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07001011
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001012 if (ieee80211_is_data_qos(fc)) {
1013 qc = ieee80211_get_qos_ctl(hdr);
Harvey Harrison7294ec92008-07-15 18:43:59 -07001014 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001015 seq_number = priv->stations_39[sta_id].tid[tid].seq_number &
Zhu Yib481de92007-09-25 17:54:57 -07001016 IEEE80211_SCTL_SEQ;
1017 hdr->seq_ctrl = cpu_to_le16(seq_number) |
1018 (hdr->seq_ctrl &
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -08001019 cpu_to_le16(IEEE80211_SCTL_FRAG));
Zhu Yib481de92007-09-25 17:54:57 -07001020 seq_number += 0x10;
1021 }
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001022
1023 /* Descriptor for chosen Tx queue */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001024 txq = &priv->txq[txq_id];
Zhu Yib481de92007-09-25 17:54:57 -07001025 q = &txq->q;
1026
1027 spin_lock_irqsave(&priv->lock, flags);
1028
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001029 idx = get_cmd_index(q, q->write_ptr, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001030
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001031 /* Set up driver data for this TFD */
Winkler, Tomasdbb66542008-12-22 11:31:14 +08001032 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001033 txq->txb[q->write_ptr].skb[0] = skb;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001034
1035 /* Init first empty entry in queue's array of Tx/cmd buffers */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001036 out_cmd = txq->cmd[idx];
Winkler, Tomase52119c2008-12-22 11:31:19 +08001037 tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
Zhu Yib481de92007-09-25 17:54:57 -07001038 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
Winkler, Tomase52119c2008-12-22 11:31:19 +08001039 memset(tx, 0, sizeof(*tx));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001040
1041 /*
1042 * Set up the Tx-command (not MAC!) header.
1043 * Store the chosen Tx queue and TFD index within the sequence field;
1044 * after Tx, uCode's Tx response will return this value so driver can
1045 * locate the frame within the tx queue and do post-tx processing.
1046 */
Zhu Yib481de92007-09-25 17:54:57 -07001047 out_cmd->hdr.cmd = REPLY_TX;
1048 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001049 INDEX_TO_SEQ(q->write_ptr)));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001050
1051 /* Copy MAC header from skb into command buffer */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001052 memcpy(tx->hdr, hdr, hdr_len);
Zhu Yib481de92007-09-25 17:54:57 -07001053
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001054 /*
1055 * Use the first empty entry in this queue's command buffer array
1056 * to contain the Tx command and MAC header concatenated together
1057 * (payload data will be in another buffer).
1058 * Size of this varies, due to varying MAC header length.
1059 * If end is not dword aligned, we'll have 2 extra bytes at the end
1060 * of the MAC header (device reads on dword boundaries).
1061 * We'll tell device about this padding later.
1062 */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001063 len = sizeof(struct iwl3945_tx_cmd) +
Tomas Winkler4c897252008-12-19 10:37:05 +08001064 sizeof(struct iwl_cmd_header) + hdr_len;
Zhu Yib481de92007-09-25 17:54:57 -07001065
1066 len_org = len;
1067 len = (len + 3) & ~3;
1068
1069 if (len_org != len)
1070 len_org = 1;
1071 else
1072 len_org = 0;
1073
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001074 /* Physical address of this Tx command's header (not MAC header!),
1075 * within command buffer array. */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001076 txcmd_phys = pci_map_single(priv->pci_dev,
1077 out_cmd, sizeof(struct iwl_cmd),
1078 PCI_DMA_TODEVICE);
1079 pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys);
1080 pci_unmap_len_set(&out_cmd->meta, len, sizeof(struct iwl_cmd));
1081 /* Add buffer containing Tx command and MAC(!) header to TFD's
1082 * first entry */
1083 txcmd_phys += offsetof(struct iwl_cmd, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07001084
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001085 /* Add buffer containing Tx command and MAC(!) header to TFD's
1086 * first entry */
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001087 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1088 txcmd_phys, len, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001089
Johannes Bergd0f09802008-07-29 11:32:07 +02001090 if (info->control.hw_key)
Johannes Berge039fa42008-05-15 12:55:29 +02001091 iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001092
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001093 /* Set up TFD's 2nd entry to point directly to remainder of skb,
1094 * if any (802.11 null frames have no payload). */
Zhu Yib481de92007-09-25 17:54:57 -07001095 len = skb->len - hdr_len;
1096 if (len) {
1097 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
1098 len, PCI_DMA_TODEVICE);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001099 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1100 phys_addr, len,
1101 0, U32_PAD(len));
Zhu Yib481de92007-09-25 17:54:57 -07001102 }
1103
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001104 /* Total # bytes to be transmitted */
Zhu Yib481de92007-09-25 17:54:57 -07001105 len = (u16)skb->len;
Winkler, Tomase52119c2008-12-22 11:31:19 +08001106 tx->len = cpu_to_le16(len);
Zhu Yib481de92007-09-25 17:54:57 -07001107
1108 /* TODO need this for burst mode later on */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001109 iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07001110
1111 /* set is_hcca to 0; it probably will never be implemented */
Johannes Berge039fa42008-05-15 12:55:29 +02001112 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001113
Winkler, Tomase52119c2008-12-22 11:31:19 +08001114 tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
1115 tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001116
Harvey Harrison8b7b1e02008-06-11 14:21:56 -07001117 if (!ieee80211_has_morefrags(hdr->frame_control)) {
Zhu Yib481de92007-09-25 17:54:57 -07001118 txq->need_update = 1;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001119 if (qc)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001120 priv->stations_39[sta_id].tid[tid].seq_number = seq_number;
Zhu Yib481de92007-09-25 17:54:57 -07001121 } else {
1122 wait_write_ptr = 1;
1123 txq->need_update = 0;
1124 }
1125
Winkler, Tomase52119c2008-12-22 11:31:19 +08001126 iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx));
Zhu Yib481de92007-09-25 17:54:57 -07001127
Winkler, Tomase52119c2008-12-22 11:31:19 +08001128 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr,
Harvey Harrison7294ec92008-07-15 18:43:59 -07001129 ieee80211_hdrlen(fc));
Zhu Yib481de92007-09-25 17:54:57 -07001130
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001131 /* Tell device the write index *just past* this latest filled TFD */
Tomas Winklerc54b6792008-03-06 17:36:53 -08001132 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001133 rc = iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001134 spin_unlock_irqrestore(&priv->lock, flags);
1135
1136 if (rc)
1137 return rc;
1138
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001139 if ((iwl_queue_space(q) < q->high_mark)
Zhu Yib481de92007-09-25 17:54:57 -07001140 && priv->mac80211_registered) {
1141 if (wait_write_ptr) {
1142 spin_lock_irqsave(&priv->lock, flags);
1143 txq->need_update = 1;
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001144 iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001145 spin_unlock_irqrestore(&priv->lock, flags);
1146 }
1147
Johannes Berge2530082008-05-17 00:57:14 +02001148 ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb));
Zhu Yib481de92007-09-25 17:54:57 -07001149 }
1150
1151 return 0;
1152
1153drop_unlock:
1154 spin_unlock_irqrestore(&priv->lock, flags);
1155drop:
1156 return -1;
1157}
1158
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001159#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07001160
1161#include "iwl-spectrum.h"
1162
1163#define BEACON_TIME_MASK_LOW 0x00FFFFFF
1164#define BEACON_TIME_MASK_HIGH 0xFF000000
1165#define TIME_UNIT 1024
1166
1167/*
1168 * extended beacon time format
1169 * time in usec will be changed into a 32-bit value in 8:24 format
1170 * the high 1 byte is the beacon counts
1171 * the lower 3 bytes is the time in usec within one beacon interval
1172 */
1173
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001174static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001175{
1176 u32 quot;
1177 u32 rem;
1178 u32 interval = beacon_interval * 1024;
1179
1180 if (!interval || !usec)
1181 return 0;
1182
1183 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
1184 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
1185
1186 return (quot << 24) + rem;
1187}
1188
1189/* base is usually what we get from ucode with each received frame,
1190 * the same as HW timer counter counting down
1191 */
1192
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001193static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001194{
1195 u32 base_low = base & BEACON_TIME_MASK_LOW;
1196 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
1197 u32 interval = beacon_interval * TIME_UNIT;
1198 u32 res = (base & BEACON_TIME_MASK_HIGH) +
1199 (addon & BEACON_TIME_MASK_HIGH);
1200
1201 if (base_low > addon_low)
1202 res += base_low - addon_low;
1203 else if (base_low < addon_low) {
1204 res += interval + base_low - addon_low;
1205 res += (1 << 24);
1206 } else
1207 res += (1 << 24);
1208
1209 return cpu_to_le32(res);
1210}
1211
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001212static int iwl3945_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001213 struct ieee80211_measurement_params *params,
1214 u8 type)
1215{
Tomas Winkler600c0e12008-12-19 10:37:04 +08001216 struct iwl_spectrum_cmd spectrum;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001217 struct iwl_rx_packet *res;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08001218 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001219 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
1220 .data = (void *)&spectrum,
1221 .meta.flags = CMD_WANT_SKB,
1222 };
1223 u32 add_time = le64_to_cpu(params->start_time);
1224 int rc;
1225 int spectrum_resp_status;
1226 int duration = le16_to_cpu(params->duration);
1227
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001228 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001229 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001230 iwl3945_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -07001231 le64_to_cpu(params->start_time) - priv->last_tsf,
1232 le16_to_cpu(priv->rxon_timing.beacon_interval));
1233
1234 memset(&spectrum, 0, sizeof(spectrum));
1235
1236 spectrum.channel_count = cpu_to_le16(1);
1237 spectrum.flags =
1238 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
1239 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
1240 cmd.len = sizeof(spectrum);
1241 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
1242
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001243 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001244 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001245 iwl3945_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -07001246 add_time,
1247 le16_to_cpu(priv->rxon_timing.beacon_interval));
1248 else
1249 spectrum.start_time = 0;
1250
1251 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
1252 spectrum.channels[0].channel = params->channel;
1253 spectrum.channels[0].type = type;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001254 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
Zhu Yib481de92007-09-25 17:54:57 -07001255 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
1256 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
1257
Samuel Ortiz518099a2009-01-19 15:30:27 -08001258 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001259 if (rc)
1260 return rc;
1261
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001262 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001263 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001264 IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -07001265 rc = -EIO;
1266 }
1267
1268 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
1269 switch (spectrum_resp_status) {
1270 case 0: /* Command will be handled */
1271 if (res->u.spectrum.id != 0xff) {
Tomas Winklere1623442009-01-27 14:27:56 -08001272 IWL_DEBUG_INFO(priv, "Replaced existing measurement: %d\n",
Ian Schrambc434dd2007-10-25 17:15:29 +08001273 res->u.spectrum.id);
Zhu Yib481de92007-09-25 17:54:57 -07001274 priv->measurement_status &= ~MEASUREMENT_READY;
1275 }
1276 priv->measurement_status |= MEASUREMENT_ACTIVE;
1277 rc = 0;
1278 break;
1279
1280 case 1: /* Command will not be handled */
1281 rc = -EAGAIN;
1282 break;
1283 }
1284
1285 dev_kfree_skb_any(cmd.meta.u.skb);
1286
1287 return rc;
1288}
1289#endif
1290
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001291static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001292 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001293{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001294 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
1295 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -07001296 struct delayed_work *pwork;
1297
1298 palive = &pkt->u.alive_frame;
1299
Tomas Winklere1623442009-01-27 14:27:56 -08001300 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
Zhu Yib481de92007-09-25 17:54:57 -07001301 "0x%01X 0x%01X\n",
1302 palive->is_valid, palive->ver_type,
1303 palive->ver_subtype);
1304
1305 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
Tomas Winklere1623442009-01-27 14:27:56 -08001306 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001307 memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
1308 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001309 pwork = &priv->init_alive_start;
1310 } else {
Tomas Winklere1623442009-01-27 14:27:56 -08001311 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001312 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001313 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001314 pwork = &priv->alive_start;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001315 iwl3945_disable_events(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001316 }
1317
1318 /* We delay the ALIVE response by 5ms to
1319 * give the HW RF Kill time to activate... */
1320 if (palive->is_valid == UCODE_VALID_OK)
1321 queue_delayed_work(priv->workqueue, pwork,
1322 msecs_to_jiffies(5));
1323 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001324 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001325}
1326
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001327static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001328 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001329{
Helmut Schaac7e035a2009-01-19 13:02:15 +01001330#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001331 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Helmut Schaac7e035a2009-01-19 13:02:15 +01001332#endif
Zhu Yib481de92007-09-25 17:54:57 -07001333
Tomas Winklere1623442009-01-27 14:27:56 -08001334 IWL_DEBUG_RX(priv, "Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
Zhu Yib481de92007-09-25 17:54:57 -07001335 return;
1336}
1337
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001338static void iwl3945_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07001339{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001340 struct iwl_priv *priv =
1341 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07001342 struct sk_buff *beacon;
1343
1344 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02001345 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07001346
1347 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001348 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07001349 return;
1350 }
1351
1352 mutex_lock(&priv->mutex);
1353 /* new beacon skb is allocated every time; dispose previous.*/
1354 if (priv->ibss_beacon)
1355 dev_kfree_skb(priv->ibss_beacon);
1356
1357 priv->ibss_beacon = beacon;
1358 mutex_unlock(&priv->mutex);
1359
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001360 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001361}
1362
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001363static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001364 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001365{
Samuel Ortizd08853a2009-01-23 13:45:17 -08001366#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001367 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001368 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
Zhu Yib481de92007-09-25 17:54:57 -07001369 u8 rate = beacon->beacon_notify_hdr.rate;
1370
Tomas Winklere1623442009-01-27 14:27:56 -08001371 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
Zhu Yib481de92007-09-25 17:54:57 -07001372 "tsf %d %d rate %d\n",
1373 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
1374 beacon->beacon_notify_hdr.failure_frame,
1375 le32_to_cpu(beacon->ibss_mgr_status),
1376 le32_to_cpu(beacon->high_tsf),
1377 le32_to_cpu(beacon->low_tsf), rate);
1378#endif
1379
Johannes Berg05c914f2008-09-11 00:01:58 +02001380 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -07001381 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1382 queue_work(priv->workqueue, &priv->beacon_update);
1383}
1384
Zhu Yib481de92007-09-25 17:54:57 -07001385/* Handle notification from uCode that card's power state is changing
1386 * due to software, hardware, or critical temperature RFKILL */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001387static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001388 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001389{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001390 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001391 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1392 unsigned long status = priv->status;
1393
Tomas Winklere1623442009-01-27 14:27:56 -08001394 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n",
Zhu Yib481de92007-09-25 17:54:57 -07001395 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1396 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1397
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001398 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001399 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1400
1401 if (flags & HW_CARD_DISABLED)
1402 set_bit(STATUS_RF_KILL_HW, &priv->status);
1403 else
1404 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1405
1406
1407 if (flags & SW_CARD_DISABLED)
1408 set_bit(STATUS_RF_KILL_SW, &priv->status);
1409 else
1410 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1411
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08001412 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001413
1414 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1415 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1416 (test_bit(STATUS_RF_KILL_SW, &status) !=
1417 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1418 queue_work(priv->workqueue, &priv->rf_kill);
1419 else
1420 wake_up_interruptible(&priv->wait_command_queue);
1421}
1422
1423/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001424 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07001425 *
1426 * Setup the RX handlers for each of the reply types sent from the uCode
1427 * to the host.
1428 *
1429 * This function chains into the hardware specific files for them to setup
1430 * any hardware specific handlers as well.
1431 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001432static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001433{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001434 priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
1435 priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
Abhijeet Kolekar261b9c32009-02-18 15:54:29 -08001436 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001437 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -08001438 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001439 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -08001440 iwl_rx_pm_debug_statistics_notif;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001441 priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001442
Ben Cahill9fbab512007-11-29 11:09:47 +08001443 /*
1444 * The same handler is used for both the REPLY to a discrete
1445 * statistics request from the host as well as for the periodic
1446 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07001447 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001448 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
1449 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
Zhu Yib481de92007-09-25 17:54:57 -07001450
Abhijeet Kolekar261b9c32009-02-18 15:54:29 -08001451 iwl_setup_spectrum_handlers(priv);
Abhijeet Kolekarcade0eb2009-02-18 15:54:26 -08001452 iwl_setup_rx_scan_handlers(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001453 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001454
Ben Cahill9fbab512007-11-29 11:09:47 +08001455 /* Set up hardware specific Rx handlers */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001456 iwl3945_hw_rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001457}
1458
1459/**
Tomas Winkler91c066f2008-03-06 17:36:55 -08001460 * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries
1461 * When FW advances 'R' index, all entries between old and new 'R' index
1462 * need to be reclaimed.
1463 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001464static void iwl3945_cmd_queue_reclaim(struct iwl_priv *priv,
Tomas Winkler91c066f2008-03-06 17:36:55 -08001465 int txq_id, int index)
1466{
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001467 struct iwl_tx_queue *txq = &priv->txq[txq_id];
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001468 struct iwl_queue *q = &txq->q;
Tomas Winkler91c066f2008-03-06 17:36:55 -08001469 int nfreed = 0;
1470
Winkler, Tomas625a3812009-01-08 10:19:55 -08001471 if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001472 IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, "
Tomas Winkler91c066f2008-03-06 17:36:55 -08001473 "is out of range [0-%d] %d %d.\n", txq_id,
1474 index, q->n_bd, q->write_ptr, q->read_ptr);
1475 return;
1476 }
1477
1478 for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
1479 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
1480 if (nfreed > 1) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001481 IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", index,
Tomas Winkler91c066f2008-03-06 17:36:55 -08001482 q->write_ptr, q->read_ptr);
1483 queue_work(priv->workqueue, &priv->restart);
1484 break;
1485 }
1486 nfreed++;
1487 }
1488}
1489
1490
1491/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001492 * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
Zhu Yib481de92007-09-25 17:54:57 -07001493 * @rxb: Rx buffer to reclaim
1494 *
1495 * If an Rx buffer has an async callback associated with it the callback
1496 * will be executed. The attached skb (if present) will only be freed
1497 * if the callback returns 1
1498 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001499static void iwl3945_tx_cmd_complete(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001500 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001501{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001502 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001503 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
1504 int txq_id = SEQ_TO_QUEUE(sequence);
1505 int index = SEQ_TO_INDEX(sequence);
Tomas Winkler600c0e12008-12-19 10:37:04 +08001506 int huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
Zhu Yib481de92007-09-25 17:54:57 -07001507 int cmd_index;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08001508 struct iwl_cmd *cmd;
Zhu Yib481de92007-09-25 17:54:57 -07001509
Chatre, Reinette638d0eb2009-01-19 15:30:24 -08001510 if (WARN(txq_id != IWL_CMD_QUEUE_NUM,
1511 "wrong command queue %d, sequence 0x%X readp=%d writep=%d\n",
1512 txq_id, sequence,
1513 priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr,
1514 priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) {
1515 iwl_print_hex_dump(priv, IWL_DL_INFO , rxb, 32);
1516 return;
1517 }
Zhu Yib481de92007-09-25 17:54:57 -07001518
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001519 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
1520 cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
Zhu Yib481de92007-09-25 17:54:57 -07001521
1522 /* Input error checking is done when commands are added to queue. */
1523 if (cmd->meta.flags & CMD_WANT_SKB) {
1524 cmd->meta.source->u.skb = rxb->skb;
1525 rxb->skb = NULL;
1526 } else if (cmd->meta.u.callback &&
1527 !cmd->meta.u.callback(priv, cmd, rxb->skb))
1528 rxb->skb = NULL;
1529
Tomas Winkler91c066f2008-03-06 17:36:55 -08001530 iwl3945_cmd_queue_reclaim(priv, txq_id, index);
Zhu Yib481de92007-09-25 17:54:57 -07001531
1532 if (!(cmd->meta.flags & CMD_ASYNC)) {
1533 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1534 wake_up_interruptible(&priv->wait_command_queue);
1535 }
1536}
1537
1538/************************** RX-FUNCTIONS ****************************/
1539/*
1540 * Rx theory of operation
1541 *
1542 * The host allocates 32 DMA target addresses and passes the host address
1543 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
1544 * 0 to 31
1545 *
1546 * Rx Queue Indexes
1547 * The host/firmware share two index registers for managing the Rx buffers.
1548 *
1549 * The READ index maps to the first position that the firmware may be writing
1550 * to -- the driver can read up to (but not including) this position and get
1551 * good data.
1552 * The READ index is managed by the firmware once the card is enabled.
1553 *
1554 * The WRITE index maps to the last position the driver has read from -- the
1555 * position preceding WRITE is the last slot the firmware can place a packet.
1556 *
1557 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
1558 * WRITE = READ.
1559 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001560 * During initialization, the host sets up the READ queue position to the first
Zhu Yib481de92007-09-25 17:54:57 -07001561 * INDEX position, and WRITE to the last (READ - 1 wrapped)
1562 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001563 * When the firmware places a packet in a buffer, it will advance the READ index
Zhu Yib481de92007-09-25 17:54:57 -07001564 * and fire the RX interrupt. The driver can then query the READ index and
1565 * process as many packets as possible, moving the WRITE index forward as it
1566 * resets the Rx queue buffers with new memory.
1567 *
1568 * The management in the driver is as follows:
1569 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
1570 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Ian Schram01ebd062007-10-25 17:15:22 +08001571 * to replenish the iwl->rxq->rx_free.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001572 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
Zhu Yib481de92007-09-25 17:54:57 -07001573 * iwl->rxq is replenished and the READ INDEX is updated (updating the
1574 * 'processed' and 'read' driver indexes as well)
1575 * + A received packet is processed and handed to the kernel network stack,
1576 * detached from the iwl->rxq. The driver 'processed' index is updated.
1577 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
1578 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
1579 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
1580 * were enough free buffers and RX_STALLED is set it is cleared.
1581 *
1582 *
1583 * Driver sequence:
1584 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001585 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001586 * iwl3945_rx_queue_restock
Ben Cahill9fbab512007-11-29 11:09:47 +08001587 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
Zhu Yib481de92007-09-25 17:54:57 -07001588 * queue, updates firmware pointers, and updates
1589 * the WRITE index. If insufficient rx_free buffers
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001590 * are available, schedules iwl3945_rx_replenish
Zhu Yib481de92007-09-25 17:54:57 -07001591 *
1592 * -- enable interrupts --
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001593 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
Zhu Yib481de92007-09-25 17:54:57 -07001594 * READ INDEX, detaching the SKB from the pool.
1595 * Moves the packet buffer from queue to rx_used.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001596 * Calls iwl3945_rx_queue_restock to refill any empty
Zhu Yib481de92007-09-25 17:54:57 -07001597 * slots.
1598 * ...
1599 *
1600 */
1601
1602/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001603 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
Zhu Yib481de92007-09-25 17:54:57 -07001604 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001605static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001606 dma_addr_t dma_addr)
1607{
1608 return cpu_to_le32((u32)dma_addr);
1609}
1610
1611/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001612 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
Zhu Yib481de92007-09-25 17:54:57 -07001613 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001614 * If there are slots in the RX queue that need to be restocked,
Zhu Yib481de92007-09-25 17:54:57 -07001615 * and we have free pre-allocated buffers, fill the ranks as much
Ben Cahill9fbab512007-11-29 11:09:47 +08001616 * as we can, pulling from rx_free.
Zhu Yib481de92007-09-25 17:54:57 -07001617 *
1618 * This moves the 'write' index forward to catch up with 'processed', and
1619 * also updates the memory address in the firmware to reference the new
1620 * target buffer.
1621 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001622static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001623{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001624 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001625 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001626 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001627 unsigned long flags;
1628 int write, rc;
1629
1630 spin_lock_irqsave(&rxq->lock, flags);
1631 write = rxq->write & ~0x7;
Winkler, Tomas37d68312009-01-08 10:19:54 -08001632 while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001633 /* Get next free Rx buffer, remove from free list */
Zhu Yib481de92007-09-25 17:54:57 -07001634 element = rxq->rx_free.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001635 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Zhu Yib481de92007-09-25 17:54:57 -07001636 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001637
1638 /* Point to Rx buffer via next RBD in circular buffer */
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001639 rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
Zhu Yib481de92007-09-25 17:54:57 -07001640 rxq->queue[rxq->write] = rxb;
1641 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
1642 rxq->free_count--;
1643 }
1644 spin_unlock_irqrestore(&rxq->lock, flags);
1645 /* If the pre-allocated buffer pool is dropping low, schedule to
1646 * refill it */
1647 if (rxq->free_count <= RX_LOW_WATERMARK)
1648 queue_work(priv->workqueue, &priv->rx_replenish);
1649
1650
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001651 /* If we've added more space for the firmware to place data, tell it.
1652 * Increment device's write pointer in multiples of 8. */
Zhu Yib481de92007-09-25 17:54:57 -07001653 if ((write != (rxq->write & ~0x7))
1654 || (abs(rxq->write - rxq->read) > 7)) {
1655 spin_lock_irqsave(&rxq->lock, flags);
1656 rxq->need_update = 1;
1657 spin_unlock_irqrestore(&rxq->lock, flags);
Winkler, Tomas141c43a2009-01-08 10:19:53 -08001658 rc = iwl_rx_queue_update_write_ptr(priv, rxq);
Zhu Yib481de92007-09-25 17:54:57 -07001659 if (rc)
1660 return rc;
1661 }
1662
1663 return 0;
1664}
1665
1666/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001667 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
Zhu Yib481de92007-09-25 17:54:57 -07001668 *
1669 * When moving to rx_free an SKB is allocated for the slot.
1670 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001671 * Also restock the Rx queue via iwl3945_rx_queue_restock.
Ian Schram01ebd062007-10-25 17:15:22 +08001672 * This is called as a scheduled work item (except for during initialization)
Zhu Yib481de92007-09-25 17:54:57 -07001673 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001674static void iwl3945_rx_allocate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001675{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001676 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001677 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001678 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001679 unsigned long flags;
1680 spin_lock_irqsave(&rxq->lock, flags);
1681 while (!list_empty(&rxq->rx_used)) {
1682 element = rxq->rx_used.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001683 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001684
1685 /* Alloc a new receive buffer */
Zhu Yib481de92007-09-25 17:54:57 -07001686 rxb->skb =
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001687 alloc_skb(priv->hw_params.rx_buf_size,
1688 __GFP_NOWARN | GFP_ATOMIC);
Zhu Yib481de92007-09-25 17:54:57 -07001689 if (!rxb->skb) {
1690 if (net_ratelimit())
Tomas Winkler978785a2008-12-19 10:37:31 +08001691 IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
Zhu Yib481de92007-09-25 17:54:57 -07001692 /* We don't reschedule replenish work here -- we will
1693 * call the restock method and if it still needs
1694 * more buffers it will schedule replenish */
1695 break;
1696 }
Zhu Yi12342c42007-12-20 11:27:32 +08001697
1698 /* If radiotap head is required, reserve some headroom here.
1699 * The physical head count is a variable rx_stats->phy_count.
1700 * We reserve 4 bytes here. Plus these extra bytes, the
1701 * headroom of the physical head should be enough for the
1702 * radiotap head that iwl3945 supported. See iwl3945_rt.
1703 */
1704 skb_reserve(rxb->skb, 4);
1705
Zhu Yib481de92007-09-25 17:54:57 -07001706 priv->alloc_rxb_skb++;
1707 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001708
1709 /* Get physical address of RB/SKB */
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001710 rxb->real_dma_addr = pci_map_single(priv->pci_dev,
1711 rxb->skb->data,
1712 priv->hw_params.rx_buf_size,
1713 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001714 list_add_tail(&rxb->list, &rxq->rx_free);
1715 rxq->free_count++;
1716 }
1717 spin_unlock_irqrestore(&rxq->lock, flags);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001718}
1719
1720/*
1721 * this should be called while priv->lock is locked
1722 */
Tomas Winkler4fd1f842007-12-05 20:59:58 +02001723static void __iwl3945_rx_replenish(void *data)
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001724{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001725 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001726
1727 iwl3945_rx_allocate(priv);
1728 iwl3945_rx_queue_restock(priv);
1729}
1730
1731
1732void iwl3945_rx_replenish(void *data)
1733{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001734 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001735 unsigned long flags;
1736
1737 iwl3945_rx_allocate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001738
1739 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001740 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001741 spin_unlock_irqrestore(&priv->lock, flags);
1742}
1743
Zhu Yib481de92007-09-25 17:54:57 -07001744/* Convert linear signal-to-noise ratio into dB */
1745static u8 ratio2dB[100] = {
1746/* 0 1 2 3 4 5 6 7 8 9 */
1747 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
1748 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
1749 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
1750 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
1751 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
1752 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
1753 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
1754 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
1755 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
1756 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
1757};
1758
1759/* Calculates a relative dB value from a ratio of linear
1760 * (i.e. not dB) signal levels.
1761 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001762int iwl3945_calc_db_from_ratio(int sig_ratio)
Zhu Yib481de92007-09-25 17:54:57 -07001763{
Adrian Bunk221c80c2008-02-02 23:19:01 +02001764 /* 1000:1 or higher just report as 60 dB */
1765 if (sig_ratio >= 1000)
Zhu Yib481de92007-09-25 17:54:57 -07001766 return 60;
1767
Adrian Bunk221c80c2008-02-02 23:19:01 +02001768 /* 100:1 or higher, divide by 10 and use table,
Zhu Yib481de92007-09-25 17:54:57 -07001769 * add 20 dB to make up for divide by 10 */
Adrian Bunk221c80c2008-02-02 23:19:01 +02001770 if (sig_ratio >= 100)
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001771 return 20 + (int)ratio2dB[sig_ratio/10];
Zhu Yib481de92007-09-25 17:54:57 -07001772
1773 /* We shouldn't see this */
1774 if (sig_ratio < 1)
1775 return 0;
1776
1777 /* Use table for ratios 1:1 - 99:1 */
1778 return (int)ratio2dB[sig_ratio];
1779}
1780
1781#define PERFECT_RSSI (-20) /* dBm */
1782#define WORST_RSSI (-95) /* dBm */
1783#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
1784
1785/* Calculate an indication of rx signal quality (a percentage, not dBm!).
1786 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
1787 * about formulas used below. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001788int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
Zhu Yib481de92007-09-25 17:54:57 -07001789{
1790 int sig_qual;
1791 int degradation = PERFECT_RSSI - rssi_dbm;
1792
1793 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
1794 * as indicator; formula is (signal dbm - noise dbm).
1795 * SNR at or above 40 is a great signal (100%).
1796 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
1797 * Weakest usable signal is usually 10 - 15 dB SNR. */
1798 if (noise_dbm) {
1799 if (rssi_dbm - noise_dbm >= 40)
1800 return 100;
1801 else if (rssi_dbm < noise_dbm)
1802 return 0;
1803 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
1804
1805 /* Else use just the signal level.
1806 * This formula is a least squares fit of data points collected and
1807 * compared with a reference system that had a percentage (%) display
1808 * for signal quality. */
1809 } else
1810 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
1811 (15 * RSSI_RANGE + 62 * degradation)) /
1812 (RSSI_RANGE * RSSI_RANGE);
1813
1814 if (sig_qual > 100)
1815 sig_qual = 100;
1816 else if (sig_qual < 1)
1817 sig_qual = 0;
1818
1819 return sig_qual;
1820}
1821
1822/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001823 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001824 *
1825 * Uses the priv->rx_handlers callback function array to invoke
1826 * the appropriate handlers, including command responses,
1827 * frame-received notifications, and other notifications.
1828 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001829static void iwl3945_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001830{
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001831 struct iwl_rx_mem_buffer *rxb;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001832 struct iwl_rx_packet *pkt;
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001833 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001834 u32 r, i;
1835 int reclaim;
1836 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001837 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001838 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07001839
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001840 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1841 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8cd812b2008-12-19 10:37:43 +08001842 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07001843 i = rxq->read;
1844
Winkler, Tomas37d68312009-01-08 10:19:54 -08001845 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001846 fill_rx = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001847 /* Rx interrupt, but nothing sent from uCode */
1848 if (i == r)
Tomas Winklere1623442009-01-27 14:27:56 -08001849 IWL_DEBUG(priv, IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001850
1851 while (i != r) {
1852 rxb = rxq->queue[i];
1853
Ben Cahill9fbab512007-11-29 11:09:47 +08001854 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001855 * then a bug has been introduced in the queue refilling
1856 * routines -- catch it here */
1857 BUG_ON(rxb == NULL);
1858
1859 rxq->queue[i] = NULL;
1860
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001861 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001862 priv->hw_params.rx_buf_size,
Zhu Yib481de92007-09-25 17:54:57 -07001863 PCI_DMA_FROMDEVICE);
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001864 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001865
1866 /* Reclaim a command buffer only if this packet is a response
1867 * to a (driver-originated) command.
1868 * If the packet (e.g. Rx frame) originated from uCode,
1869 * there is no command buffer to reclaim.
1870 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1871 * but apparently a few don't get set; catch them here. */
1872 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1873 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1874 (pkt->hdr.cmd != REPLY_TX);
1875
1876 /* Based on type of command response or notification,
1877 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001878 * rx_handlers table. See iwl3945_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001879 if (priv->rx_handlers[pkt->hdr.cmd]) {
Tomas Winklere1623442009-01-27 14:27:56 -08001880 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07001881 "r = %d, i = %d, %s, 0x%02x\n", r, i,
1882 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
1883 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1884 } else {
1885 /* No handling needed */
Tomas Winklere1623442009-01-27 14:27:56 -08001886 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07001887 "r %d i %d No handler needed for %s, 0x%02x\n",
1888 r, i, get_cmd_string(pkt->hdr.cmd),
1889 pkt->hdr.cmd);
1890 }
1891
1892 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001893 /* Invoke any callbacks, transfer the skb to caller, and
Samuel Ortiz518099a2009-01-19 15:30:27 -08001894 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001895 * as we reclaim the driver command queue */
1896 if (rxb && rxb->skb)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001897 iwl3945_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001898 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001899 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07001900 }
1901
1902 /* For now we just don't re-use anything. We can tweak this
1903 * later to try and re-use notification packets and SKBs that
1904 * fail to Rx correctly */
1905 if (rxb->skb != NULL) {
1906 priv->alloc_rxb_skb--;
1907 dev_kfree_skb_any(rxb->skb);
1908 rxb->skb = NULL;
1909 }
1910
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001911 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001912 priv->hw_params.rx_buf_size,
1913 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001914 spin_lock_irqsave(&rxq->lock, flags);
1915 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1916 spin_unlock_irqrestore(&rxq->lock, flags);
1917 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001918 /* If there are a lot of unused frames,
1919 * restock the Rx queue so ucode won't assert. */
1920 if (fill_rx) {
1921 count++;
1922 if (count >= 8) {
1923 priv->rxq.read = i;
1924 __iwl3945_rx_replenish(priv);
1925 count = 0;
1926 }
1927 }
Zhu Yib481de92007-09-25 17:54:57 -07001928 }
1929
1930 /* Backtrack one entry */
1931 priv->rxq.read = i;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001932 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001933}
1934
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001935/* call this function to flush any scheduled tasklet */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001936static inline void iwl_synchronize_irq(struct iwl_priv *priv)
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001937{
Tomas Winklera96a27f2008-10-23 23:48:56 -07001938 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001939 synchronize_irq(priv->pci_dev->irq);
1940 tasklet_kill(&priv->irq_tasklet);
1941}
1942
Zhu Yib481de92007-09-25 17:54:57 -07001943static const char *desc_lookup(int i)
1944{
1945 switch (i) {
1946 case 1:
1947 return "FAIL";
1948 case 2:
1949 return "BAD_PARAM";
1950 case 3:
1951 return "BAD_CHECKSUM";
1952 case 4:
1953 return "NMI_INTERRUPT";
1954 case 5:
1955 return "SYSASSERT";
1956 case 6:
1957 return "FATAL_ERROR";
1958 }
1959
1960 return "UNKNOWN";
1961}
1962
1963#define ERROR_START_OFFSET (1 * sizeof(u32))
1964#define ERROR_ELEM_SIZE (7 * sizeof(u32))
1965
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001966static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001967{
1968 u32 i;
1969 u32 desc, time, count, base, data1;
1970 u32 blink1, blink2, ilink1, ilink2;
1971 int rc;
1972
1973 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
1974
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001975 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001976 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07001977 return;
1978 }
1979
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001980 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001981 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001982 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001983 return;
1984 }
1985
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001986 count = iwl_read_targ_mem(priv, base);
Zhu Yib481de92007-09-25 17:54:57 -07001987
1988 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001989 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
1990 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
1991 priv->status, count);
Zhu Yib481de92007-09-25 17:54:57 -07001992 }
1993
Winkler, Tomas15b16872008-12-19 10:37:33 +08001994 IWL_ERR(priv, "Desc Time asrtPC blink2 "
Zhu Yib481de92007-09-25 17:54:57 -07001995 "ilink1 nmiPC Line\n");
1996 for (i = ERROR_START_OFFSET;
1997 i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
1998 i += ERROR_ELEM_SIZE) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001999 desc = iwl_read_targ_mem(priv, base + i);
Zhu Yib481de92007-09-25 17:54:57 -07002000 time =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002001 iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002002 blink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002003 iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002004 blink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002005 iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002006 ilink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002007 iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002008 ilink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002009 iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002010 data1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002011 iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002012
Winkler, Tomas15b16872008-12-19 10:37:33 +08002013 IWL_ERR(priv,
2014 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
2015 desc_lookup(desc), desc, time, blink1, blink2,
2016 ilink1, ilink2, data1);
Zhu Yib481de92007-09-25 17:54:57 -07002017 }
2018
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002019 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002020
2021}
2022
Ben Cahillf58177b2007-11-29 11:09:43 +08002023#define EVENT_START_OFFSET (6 * sizeof(u32))
Zhu Yib481de92007-09-25 17:54:57 -07002024
2025/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002026 * iwl3945_print_event_log - Dump error event log to syslog
Zhu Yib481de92007-09-25 17:54:57 -07002027 *
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002028 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
Zhu Yib481de92007-09-25 17:54:57 -07002029 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002030static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
Zhu Yib481de92007-09-25 17:54:57 -07002031 u32 num_events, u32 mode)
2032{
2033 u32 i;
2034 u32 base; /* SRAM byte address of event log header */
2035 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
2036 u32 ptr; /* SRAM byte address of log data */
2037 u32 ev, time, data; /* event log data */
2038
2039 if (num_events == 0)
2040 return;
2041
2042 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
2043
2044 if (mode == 0)
2045 event_size = 2 * sizeof(u32);
2046 else
2047 event_size = 3 * sizeof(u32);
2048
2049 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
2050
2051 /* "time" is actually "data" for mode 0 (no timestamp).
2052 * place event id # at far right for easier visual parsing. */
2053 for (i = 0; i < num_events; i++) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002054 ev = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002055 ptr += sizeof(u32);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002056 time = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002057 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002058 if (mode == 0) {
2059 /* data, ev */
2060 IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
2061 } else {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002062 data = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002063 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002064 IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
Zhu Yib481de92007-09-25 17:54:57 -07002065 }
2066 }
2067}
2068
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002069static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002070{
2071 int rc;
2072 u32 base; /* SRAM byte address of event log header */
2073 u32 capacity; /* event log capacity in # entries */
2074 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
2075 u32 num_wraps; /* # times uCode wrapped to top of log */
2076 u32 next_entry; /* index of next entry to be written by uCode */
2077 u32 size; /* # entries that we'll print */
2078
2079 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002080 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002081 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07002082 return;
2083 }
2084
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002085 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002086 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002087 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002088 return;
2089 }
2090
2091 /* event log header */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002092 capacity = iwl_read_targ_mem(priv, base);
2093 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
2094 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
2095 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
Zhu Yib481de92007-09-25 17:54:57 -07002096
2097 size = num_wraps ? capacity : next_entry;
2098
2099 /* bail out if nothing in log */
2100 if (size == 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002101 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002102 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002103 return;
2104 }
2105
Winkler, Tomas15b16872008-12-19 10:37:33 +08002106 IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07002107 size, num_wraps);
2108
2109 /* if uCode has wrapped back to top of log, start at the oldest entry,
2110 * i.e the next one that uCode would fill. */
2111 if (num_wraps)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002112 iwl3945_print_event_log(priv, next_entry,
Zhu Yib481de92007-09-25 17:54:57 -07002113 capacity - next_entry, mode);
2114
2115 /* (then/else) start at top of log */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002116 iwl3945_print_event_log(priv, 0, next_entry, mode);
Zhu Yib481de92007-09-25 17:54:57 -07002117
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002118 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002119}
2120
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002121static void iwl3945_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002122{
2123 unsigned long flags;
2124
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002125 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
2126 sizeof(priv->staging_rxon));
2127 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002128 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002129
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002130 iwl3945_add_station(priv, priv->bssid, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002131
2132 spin_lock_irqsave(&priv->lock, flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002133 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07002134 priv->error_recovering = 0;
2135 spin_unlock_irqrestore(&priv->lock, flags);
2136}
2137
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002138static void iwl3945_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002139{
2140 u32 inta, handled = 0;
2141 u32 inta_fh;
2142 unsigned long flags;
Samuel Ortizd08853a2009-01-23 13:45:17 -08002143#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07002144 u32 inta_mask;
2145#endif
2146
2147 spin_lock_irqsave(&priv->lock, flags);
2148
2149 /* Ack/clear/reset pending uCode interrupts.
2150 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
2151 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002152 inta = iwl_read32(priv, CSR_INT);
2153 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07002154
2155 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
2156 * Any new interrupts that happen after this, either while we're
2157 * in this tasklet, or later, will show up in next ISR/tasklet. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002158 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
2159 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07002160
Samuel Ortizd08853a2009-01-23 13:45:17 -08002161#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002162 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08002163 /* just for debug */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002164 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Tomas Winklere1623442009-01-27 14:27:56 -08002165 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002166 inta, inta_mask, inta_fh);
2167 }
2168#endif
2169
2170 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
2171 * atomic, make sure that inta covers all the interrupts that
2172 * we've discovered, even if FH interrupt came in just after
2173 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002174 if (inta_fh & CSR39_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002175 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002176 if (inta_fh & CSR39_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002177 inta |= CSR_INT_BIT_FH_TX;
2178
2179 /* Now service all interrupt bits discovered above. */
2180 if (inta & CSR_INT_BIT_HW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002181 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002182
2183 /* Tell the device to stop sending interrupts */
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002184 iwl_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002185
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002186 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002187
2188 handled |= CSR_INT_BIT_HW_ERR;
2189
2190 spin_unlock_irqrestore(&priv->lock, flags);
2191
2192 return;
2193 }
2194
Samuel Ortizd08853a2009-01-23 13:45:17 -08002195#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002196 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07002197 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002198 if (inta & CSR_INT_BIT_SCD)
Tomas Winklere1623442009-01-27 14:27:56 -08002199 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
Joonwoo Park25c03d82008-01-23 10:15:20 -08002200 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002201
2202 /* Alive notification via Rx interrupt will do the real work */
2203 if (inta & CSR_INT_BIT_ALIVE)
Tomas Winklere1623442009-01-27 14:27:56 -08002204 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002205 }
2206#endif
2207 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002208 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07002209
Zhu Yib481de92007-09-25 17:54:57 -07002210 /* Error detected by uCode */
2211 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002212 IWL_ERR(priv, "Microcode SW error detected. "
2213 "Restarting 0x%X.\n", inta);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002214 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002215 handled |= CSR_INT_BIT_SW_ERR;
2216 }
2217
2218 /* uCode wakes up after power-down sleep */
2219 if (inta & CSR_INT_BIT_WAKEUP) {
Tomas Winklere1623442009-01-27 14:27:56 -08002220 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
Winkler, Tomas141c43a2009-01-08 10:19:53 -08002221 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08002222 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
2223 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
2224 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
2225 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
2226 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
2227 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07002228
2229 handled |= CSR_INT_BIT_WAKEUP;
2230 }
2231
2232 /* All uCode command responses, including Tx command responses,
2233 * Rx "responses" (frame-received notification), and other
2234 * notifications from uCode come through here*/
2235 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002236 iwl3945_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002237 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
2238 }
2239
2240 if (inta & CSR_INT_BIT_FH_TX) {
Tomas Winklere1623442009-01-27 14:27:56 -08002241 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002242
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002243 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
2244 if (!iwl_grab_nic_access(priv)) {
2245 iwl_write_direct32(priv, FH39_TCSR_CREDIT
Tomas Winklerbddadf82008-12-19 10:37:01 +08002246 (FH39_SRVC_CHNL), 0x0);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002247 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002248 }
2249 handled |= CSR_INT_BIT_FH_TX;
2250 }
2251
2252 if (inta & ~handled)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002253 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Zhu Yib481de92007-09-25 17:54:57 -07002254
2255 if (inta & ~CSR_INI_SET_MASK) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002256 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Zhu Yib481de92007-09-25 17:54:57 -07002257 inta & ~CSR_INI_SET_MASK);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002258 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07002259 }
2260
2261 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002262 /* only Re-enable if disabled by irq */
2263 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002264 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002265
Samuel Ortizd08853a2009-01-23 13:45:17 -08002266#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002267 if (priv->debug_level & (IWL_DL_ISR)) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002268 inta = iwl_read32(priv, CSR_INT);
2269 inta_mask = iwl_read32(priv, CSR_INT_MASK);
2270 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Tomas Winklere1623442009-01-27 14:27:56 -08002271 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
Zhu Yib481de92007-09-25 17:54:57 -07002272 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
2273 }
2274#endif
2275 spin_unlock_irqrestore(&priv->lock, flags);
2276}
2277
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002278static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01002279 enum ieee80211_band band,
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08002280 u8 is_active, u8 n_probes,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002281 struct iwl3945_scan_channel *scan_ch)
Zhu Yib481de92007-09-25 17:54:57 -07002282{
2283 const struct ieee80211_channel *channels = NULL;
Johannes Berg8318d782008-01-24 19:38:38 +01002284 const struct ieee80211_supported_band *sband;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08002285 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07002286 u16 passive_dwell = 0;
2287 u16 active_dwell = 0;
2288 int added, i;
2289
Kolekar, Abhijeetcbba18c2008-12-19 10:37:42 +08002290 sband = iwl_get_hw_mode(priv, band);
Johannes Berg8318d782008-01-24 19:38:38 +01002291 if (!sband)
Zhu Yib481de92007-09-25 17:54:57 -07002292 return 0;
2293
Johannes Berg8318d782008-01-24 19:38:38 +01002294 channels = sband->channels;
Zhu Yib481de92007-09-25 17:54:57 -07002295
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08002296 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
2297 passive_dwell = iwl_get_passive_dwell_time(priv, band);
Zhu Yib481de92007-09-25 17:54:57 -07002298
Abhijeet Kolekar8f4807a2008-09-03 11:26:31 +08002299 if (passive_dwell <= active_dwell)
2300 passive_dwell = active_dwell + 1;
2301
Johannes Berg8318d782008-01-24 19:38:38 +01002302 for (i = 0, added = 0; i < sband->n_channels; i++) {
Johannes Berg182e2e62008-04-04 10:41:56 +02002303 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
2304 continue;
2305
Johannes Berg8318d782008-01-24 19:38:38 +01002306 scan_ch->channel = channels[i].hw_value;
Zhu Yib481de92007-09-25 17:54:57 -07002307
Samuel Ortize6148912009-01-23 13:45:15 -08002308 ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
Zhu Yib481de92007-09-25 17:54:57 -07002309 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002310 IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
Zhu Yib481de92007-09-25 17:54:57 -07002311 scan_ch->channel);
2312 continue;
2313 }
2314
Zhu Yib481de92007-09-25 17:54:57 -07002315 scan_ch->active_dwell = cpu_to_le16(active_dwell);
2316 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002317 /* If passive , set up for auto-switch
2318 * and use long active_dwell time.
2319 */
2320 if (!is_active || is_channel_passive(ch_info) ||
2321 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
2322 scan_ch->type = 0; /* passive */
2323 if (IWL_UCODE_API(priv->ucode_ver) == 1)
2324 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
2325 } else {
2326 scan_ch->type = 1; /* active */
2327 }
2328
2329 /* Set direct probe bits. These may be used both for active
2330 * scan channels (probes gets sent right away),
2331 * or for passive channels (probes get se sent only after
2332 * hearing clear Rx packet).*/
2333 if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
2334 if (n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002335 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002336 } else {
2337 /* uCode v1 does not allow setting direct probe bits on
2338 * passive channel. */
2339 if ((scan_ch->type & 1) && n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002340 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002341 }
Zhu Yib481de92007-09-25 17:54:57 -07002342
Ben Cahill9fbab512007-11-29 11:09:47 +08002343 /* Set txpower levels to defaults */
Zhu Yib481de92007-09-25 17:54:57 -07002344 scan_ch->tpc.dsp_atten = 110;
2345 /* scan_pwr_info->tpc.dsp_atten; */
2346
2347 /*scan_pwr_info->tpc.tx_gain; */
Johannes Berg8318d782008-01-24 19:38:38 +01002348 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -07002349 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
2350 else {
2351 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
2352 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
Ben Cahill9fbab512007-11-29 11:09:47 +08002353 * power level:
Reinette Chatre8a1b0242008-01-14 17:46:25 -08002354 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
Zhu Yib481de92007-09-25 17:54:57 -07002355 */
2356 }
2357
Tomas Winklere1623442009-01-27 14:27:56 -08002358 IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n",
Zhu Yib481de92007-09-25 17:54:57 -07002359 scan_ch->channel,
2360 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
2361 (scan_ch->type & 1) ?
2362 active_dwell : passive_dwell);
2363
2364 scan_ch++;
2365 added++;
2366 }
2367
Tomas Winklere1623442009-01-27 14:27:56 -08002368 IWL_DEBUG_SCAN(priv, "total channels to scan %d \n", added);
Zhu Yib481de92007-09-25 17:54:57 -07002369 return added;
2370}
2371
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002372static void iwl3945_init_hw_rates(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002373 struct ieee80211_rate *rates)
2374{
2375 int i;
2376
2377 for (i = 0; i < IWL_RATE_COUNT; i++) {
Johannes Berg8318d782008-01-24 19:38:38 +01002378 rates[i].bitrate = iwl3945_rates[i].ieee * 5;
2379 rates[i].hw_value = i; /* Rate scaling will work on indexes */
2380 rates[i].hw_value_short = i;
2381 rates[i].flags = 0;
Samuel Ortizd9829a62008-12-19 10:37:12 +08002382 if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
Zhu Yib481de92007-09-25 17:54:57 -07002383 /*
Johannes Berg8318d782008-01-24 19:38:38 +01002384 * If CCK != 1M then set short preamble rate flag.
Zhu Yib481de92007-09-25 17:54:57 -07002385 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002386 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
Johannes Berg8318d782008-01-24 19:38:38 +01002387 0 : IEEE80211_RATE_SHORT_PREAMBLE;
Zhu Yib481de92007-09-25 17:54:57 -07002388 }
Zhu Yib481de92007-09-25 17:54:57 -07002389 }
2390}
2391
Zhu Yib481de92007-09-25 17:54:57 -07002392/******************************************************************************
2393 *
2394 * uCode download functions
2395 *
2396 ******************************************************************************/
2397
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002398static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002399{
Tomas Winkler98c92212008-01-14 17:46:20 -08002400 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
2401 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
2402 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
2403 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
2404 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
2405 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07002406}
2407
2408/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002409 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002410 * looking at all data.
2411 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002412static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002413{
2414 u32 val;
2415 u32 save_len = len;
2416 int rc = 0;
2417 u32 errcnt;
2418
Tomas Winklere1623442009-01-27 14:27:56 -08002419 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002420
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002421 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002422 if (rc)
2423 return rc;
2424
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002425 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002426 IWL39_RTC_INST_LOWER_BOUND);
Zhu Yib481de92007-09-25 17:54:57 -07002427
2428 errcnt = 0;
2429 for (; len > 0; len -= sizeof(u32), image++) {
2430 /* read data comes through single port, auto-incr addr */
2431 /* NOTE: Use the debugless read so we don't flood kernel log
2432 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002433 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002434 if (val != le32_to_cpu(*image)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002435 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002436 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2437 save_len - len, val, le32_to_cpu(*image));
2438 rc = -EIO;
2439 errcnt++;
2440 if (errcnt >= 20)
2441 break;
2442 }
2443 }
2444
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002445 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002446
2447 if (!errcnt)
Tomas Winklere1623442009-01-27 14:27:56 -08002448 IWL_DEBUG_INFO(priv,
2449 "ucode image in INSTRUCTION memory is good\n");
Zhu Yib481de92007-09-25 17:54:57 -07002450
2451 return rc;
2452}
2453
2454
2455/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002456 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002457 * using sample data 100 bytes apart. If these sample points are good,
2458 * it's a pretty good bet that everything between them is good, too.
2459 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002460static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002461{
2462 u32 val;
2463 int rc = 0;
2464 u32 errcnt = 0;
2465 u32 i;
2466
Tomas Winklere1623442009-01-27 14:27:56 -08002467 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002468
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002469 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002470 if (rc)
2471 return rc;
2472
2473 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
2474 /* read data comes through single port, auto-incr addr */
2475 /* NOTE: Use the debugless read so we don't flood kernel log
2476 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002477 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002478 i + IWL39_RTC_INST_LOWER_BOUND);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002479 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002480 if (val != le32_to_cpu(*image)) {
2481#if 0 /* Enable this if you want to see details */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002482 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002483 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2484 i, val, *image);
2485#endif
2486 rc = -EIO;
2487 errcnt++;
2488 if (errcnt >= 3)
2489 break;
2490 }
2491 }
2492
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002493 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002494
2495 return rc;
2496}
2497
2498
2499/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002500 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
Zhu Yib481de92007-09-25 17:54:57 -07002501 * and verify its contents
2502 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002503static int iwl3945_verify_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002504{
2505 __le32 *image;
2506 u32 len;
2507 int rc = 0;
2508
2509 /* Try bootstrap */
2510 image = (__le32 *)priv->ucode_boot.v_addr;
2511 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002512 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002513 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002514 IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002515 return 0;
2516 }
2517
2518 /* Try initialize */
2519 image = (__le32 *)priv->ucode_init.v_addr;
2520 len = priv->ucode_init.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002521 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002522 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002523 IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002524 return 0;
2525 }
2526
2527 /* Try runtime/protocol */
2528 image = (__le32 *)priv->ucode_code.v_addr;
2529 len = priv->ucode_code.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002530 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002531 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002532 IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002533 return 0;
2534 }
2535
Winkler, Tomas15b16872008-12-19 10:37:33 +08002536 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
Zhu Yib481de92007-09-25 17:54:57 -07002537
Ben Cahill9fbab512007-11-29 11:09:47 +08002538 /* Since nothing seems to match, show first several data entries in
2539 * instruction SRAM, so maybe visual inspection will give a clue.
2540 * Selection of bootstrap image (vs. other images) is arbitrary. */
Zhu Yib481de92007-09-25 17:54:57 -07002541 image = (__le32 *)priv->ucode_boot.v_addr;
2542 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002543 rc = iwl3945_verify_inst_full(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002544
2545 return rc;
2546}
2547
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002548static void iwl3945_nic_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002549{
2550 /* Remove all resets to allow NIC to operate */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002551 iwl_write32(priv, CSR_RESET, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002552}
2553
2554/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002555 * iwl3945_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07002556 *
2557 * Copy into buffers for card to fetch via bus-mastering
2558 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002559static int iwl3945_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002560{
Kolekar, Abhijeeta78fe752008-12-19 10:37:21 +08002561 struct iwl_ucode *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002562 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07002563 const struct firmware *ucode_raw;
2564 /* firmware file name contains uCode/driver compatibility version */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002565 const char *name_pre = priv->cfg->fw_name_pre;
2566 const unsigned int api_max = priv->cfg->ucode_api_max;
2567 const unsigned int api_min = priv->cfg->ucode_api_min;
2568 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07002569 u8 *src;
2570 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002571 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07002572
2573 /* Ask kernel firmware_class module to get the boot firmware off disk.
2574 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002575 for (index = api_max; index >= api_min; index--) {
2576 sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
2577 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
2578 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002579 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002580 buf, ret);
2581 if (ret == -ENOENT)
2582 continue;
2583 else
2584 goto error;
2585 } else {
2586 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002587 IWL_ERR(priv, "Loaded firmware %s, "
2588 "which is deprecated. "
2589 " Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002590 buf, api_max);
Tomas Winklere1623442009-01-27 14:27:56 -08002591 IWL_DEBUG_INFO(priv, "Got firmware '%s' file "
2592 "(%zd bytes) from disk\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002593 buf, ucode_raw->size);
2594 break;
2595 }
Zhu Yib481de92007-09-25 17:54:57 -07002596 }
2597
Reinette Chatrea0987a82008-12-02 12:14:06 -08002598 if (ret < 0)
2599 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07002600
2601 /* Make sure that we got at least our header! */
2602 if (ucode_raw->size < sizeof(*ucode)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002603 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002604 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002605 goto err_release;
2606 }
2607
2608 /* Data from ucode file: header followed by uCode images */
2609 ucode = (void *)ucode_raw->data;
2610
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08002611 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08002612 api_ver = IWL_UCODE_API(priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07002613 inst_size = le32_to_cpu(ucode->inst_size);
2614 data_size = le32_to_cpu(ucode->data_size);
2615 init_size = le32_to_cpu(ucode->init_size);
2616 init_data_size = le32_to_cpu(ucode->init_data_size);
2617 boot_size = le32_to_cpu(ucode->boot_size);
2618
Reinette Chatrea0987a82008-12-02 12:14:06 -08002619 /* api_ver should match the api version forming part of the
2620 * firmware filename ... but we don't check for that and only rely
2621 * on the API version read from firware header from here on forward */
2622
2623 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002624 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002625 "Driver supports v%u, firmware is v%u.\n",
2626 api_max, api_ver);
2627 priv->ucode_ver = 0;
2628 ret = -EINVAL;
2629 goto err_release;
2630 }
2631 if (api_ver != api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002632 IWL_ERR(priv, "Firmware has old API version. Expected %u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002633 "got %u. New firmware can be obtained "
2634 "from http://www.intellinuxwireless.org.\n",
2635 api_max, api_ver);
2636
Tomas Winkler978785a2008-12-19 10:37:31 +08002637 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
2638 IWL_UCODE_MAJOR(priv->ucode_ver),
2639 IWL_UCODE_MINOR(priv->ucode_ver),
2640 IWL_UCODE_API(priv->ucode_ver),
2641 IWL_UCODE_SERIAL(priv->ucode_ver));
2642
Tomas Winklere1623442009-01-27 14:27:56 -08002643 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002644 priv->ucode_ver);
Tomas Winklere1623442009-01-27 14:27:56 -08002645 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
2646 inst_size);
2647 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
2648 data_size);
2649 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
2650 init_size);
2651 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
2652 init_data_size);
2653 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
2654 boot_size);
Zhu Yib481de92007-09-25 17:54:57 -07002655
Reinette Chatrea0987a82008-12-02 12:14:06 -08002656
Zhu Yib481de92007-09-25 17:54:57 -07002657 /* Verify size of file vs. image size info in file's header */
2658 if (ucode_raw->size < sizeof(*ucode) +
2659 inst_size + data_size + init_size +
2660 init_data_size + boot_size) {
2661
Tomas Winklere1623442009-01-27 14:27:56 -08002662 IWL_DEBUG_INFO(priv, "uCode file size %zd too small\n",
2663 ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002664 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002665 goto err_release;
2666 }
2667
2668 /* Verify that uCode images will fit in card's SRAM */
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002669 if (inst_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002670 IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002671 inst_size);
2672 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002673 goto err_release;
2674 }
2675
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002676 if (data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002677 IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002678 data_size);
2679 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002680 goto err_release;
2681 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002682 if (init_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002683 IWL_DEBUG_INFO(priv,
2684 "uCode init instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002685 init_size);
2686 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002687 goto err_release;
2688 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002689 if (init_data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002690 IWL_DEBUG_INFO(priv,
2691 "uCode init data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002692 init_data_size);
2693 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002694 goto err_release;
2695 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002696 if (boot_size > IWL39_MAX_BSM_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002697 IWL_DEBUG_INFO(priv,
2698 "uCode boot instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002699 boot_size);
2700 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002701 goto err_release;
2702 }
2703
2704 /* Allocate ucode buffers for card's bus-master loading ... */
2705
2706 /* Runtime instructions and 2 copies of data:
2707 * 1) unmodified from disk
2708 * 2) backup cache for save/restore during power-downs */
2709 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002710 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07002711
2712 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002713 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07002714
2715 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002716 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07002717
2718 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
Tomas Winkler90e759d2007-11-29 11:09:41 +08002719 !priv->ucode_data_backup.v_addr)
Zhu Yib481de92007-09-25 17:54:57 -07002720 goto err_pci_alloc;
2721
Tomas Winkler90e759d2007-11-29 11:09:41 +08002722 /* Initialization instructions and data */
2723 if (init_size && init_data_size) {
2724 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002725 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002726
2727 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002728 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002729
2730 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
2731 goto err_pci_alloc;
2732 }
2733
2734 /* Bootstrap (instructions only, no data) */
2735 if (boot_size) {
2736 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002737 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002738
2739 if (!priv->ucode_boot.v_addr)
2740 goto err_pci_alloc;
2741 }
2742
Zhu Yib481de92007-09-25 17:54:57 -07002743 /* Copy images into buffers for card's bus-master reads ... */
2744
2745 /* Runtime instructions (first block of data in file) */
2746 src = &ucode->data[0];
2747 len = priv->ucode_code.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002748 IWL_DEBUG_INFO(priv,
2749 "Copying (but not loading) uCode instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002750 memcpy(priv->ucode_code.v_addr, src, len);
Tomas Winklere1623442009-01-27 14:27:56 -08002751 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002752 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
2753
2754 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002755 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
Zhu Yib481de92007-09-25 17:54:57 -07002756 src = &ucode->data[inst_size];
2757 len = priv->ucode_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002758 IWL_DEBUG_INFO(priv,
2759 "Copying (but not loading) uCode data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002760 memcpy(priv->ucode_data.v_addr, src, len);
2761 memcpy(priv->ucode_data_backup.v_addr, src, len);
2762
2763 /* Initialization instructions (3rd block) */
2764 if (init_size) {
2765 src = &ucode->data[inst_size + data_size];
2766 len = priv->ucode_init.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002767 IWL_DEBUG_INFO(priv,
2768 "Copying (but not loading) init instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002769 memcpy(priv->ucode_init.v_addr, src, len);
2770 }
2771
2772 /* Initialization data (4th block) */
2773 if (init_data_size) {
2774 src = &ucode->data[inst_size + data_size + init_size];
2775 len = priv->ucode_init_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002776 IWL_DEBUG_INFO(priv,
2777 "Copying (but not loading) init data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002778 memcpy(priv->ucode_init_data.v_addr, src, len);
2779 }
2780
2781 /* Bootstrap instructions (5th block) */
2782 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
2783 len = priv->ucode_boot.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002784 IWL_DEBUG_INFO(priv,
2785 "Copying (but not loading) boot instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002786 memcpy(priv->ucode_boot.v_addr, src, len);
2787
2788 /* We have our copies now, allow OS release its copies */
2789 release_firmware(ucode_raw);
2790 return 0;
2791
2792 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08002793 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002794 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002795 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002796
2797 err_release:
2798 release_firmware(ucode_raw);
2799
2800 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08002801 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002802}
2803
2804
2805/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002806 * iwl3945_set_ucode_ptrs - Set uCode address location
Zhu Yib481de92007-09-25 17:54:57 -07002807 *
2808 * Tell initialization uCode where to find runtime uCode.
2809 *
2810 * BSM registers initially contain pointers to initialization uCode.
2811 * We need to replace them to load runtime uCode inst and data,
2812 * and to save runtime data when powering down.
2813 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002814static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002815{
2816 dma_addr_t pinst;
2817 dma_addr_t pdata;
2818 int rc = 0;
2819 unsigned long flags;
2820
2821 /* bits 31:0 for 3945 */
2822 pinst = priv->ucode_code.p_addr;
2823 pdata = priv->ucode_data_backup.p_addr;
2824
2825 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002826 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002827 if (rc) {
2828 spin_unlock_irqrestore(&priv->lock, flags);
2829 return rc;
2830 }
2831
2832 /* Tell bootstrap uCode where to find image to load */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002833 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
2834 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
2835 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002836 priv->ucode_data.len);
2837
Tomas Winklera96a27f2008-10-23 23:48:56 -07002838 /* Inst byte count must be last to set up, bit 31 signals uCode
Zhu Yib481de92007-09-25 17:54:57 -07002839 * that all new ptr/size info is in place */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002840 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002841 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
2842
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002843 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002844
2845 spin_unlock_irqrestore(&priv->lock, flags);
2846
Tomas Winklere1623442009-01-27 14:27:56 -08002847 IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002848
2849 return rc;
2850}
2851
2852/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002853 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002854 *
2855 * Called after REPLY_ALIVE notification received from "initialize" uCode.
2856 *
Zhu Yib481de92007-09-25 17:54:57 -07002857 * Tell "initialize" uCode to go ahead and load the runtime uCode.
Ben Cahill9fbab512007-11-29 11:09:47 +08002858 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002859static void iwl3945_init_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002860{
2861 /* Check alive response for "valid" sign from uCode */
2862 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
2863 /* We had an error bringing up the hardware, so take it
2864 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002865 IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002866 goto restart;
2867 }
2868
2869 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
2870 * This is a paranoid check, because we would not have gotten the
2871 * "initialize" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002872 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002873 /* Runtime instruction load was bad;
2874 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002875 IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002876 goto restart;
2877 }
2878
2879 /* Send pointers to protocol/runtime uCode image ... init code will
2880 * load and launch runtime uCode, which will send us another "Alive"
2881 * notification. */
Tomas Winklere1623442009-01-27 14:27:56 -08002882 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002883 if (iwl3945_set_ucode_ptrs(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002884 /* Runtime instruction load won't happen;
2885 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002886 IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002887 goto restart;
2888 }
2889 return;
2890
2891 restart:
2892 queue_work(priv->workqueue, &priv->restart);
2893}
2894
2895
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08002896/* temporary */
2897static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw,
2898 struct sk_buff *skb);
2899
Zhu Yib481de92007-09-25 17:54:57 -07002900/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002901 * iwl3945_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002902 * from protocol/runtime uCode (initialization uCode's
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002903 * Alive gets handled by iwl3945_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07002904 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002905static void iwl3945_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002906{
2907 int rc = 0;
2908 int thermal_spin = 0;
2909 u32 rfkill;
2910
Tomas Winklere1623442009-01-27 14:27:56 -08002911 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002912
2913 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
2914 /* We had an error bringing up the hardware, so take it
2915 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002916 IWL_DEBUG_INFO(priv, "Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002917 goto restart;
2918 }
2919
2920 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
2921 * This is a paranoid check, because we would not have gotten the
2922 * "runtime" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002923 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002924 /* Runtime instruction load was bad;
2925 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002926 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002927 goto restart;
2928 }
2929
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002930 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002931
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002932 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002933 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002934 IWL_WARN(priv, "Can not read RFKILL status from adapter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002935 return;
2936 }
2937
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002938 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
Tomas Winklere1623442009-01-27 14:27:56 -08002939 IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002940 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002941
2942 if (rfkill & 0x1) {
2943 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winklera96a27f2008-10-23 23:48:56 -07002944 /* if RFKILL is not on, then wait for thermal
Zhu Yib481de92007-09-25 17:54:57 -07002945 * sensor in adapter to kick in */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002946 while (iwl3945_hw_get_temperature(priv) == 0) {
Zhu Yib481de92007-09-25 17:54:57 -07002947 thermal_spin++;
2948 udelay(10);
2949 }
2950
2951 if (thermal_spin)
Tomas Winklere1623442009-01-27 14:27:56 -08002952 IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n",
Zhu Yib481de92007-09-25 17:54:57 -07002953 thermal_spin * 10);
2954 } else
2955 set_bit(STATUS_RF_KILL_HW, &priv->status);
2956
Ben Cahill9fbab512007-11-29 11:09:47 +08002957 /* After the ALIVE response, we can send commands to 3945 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07002958 set_bit(STATUS_ALIVE, &priv->status);
2959
2960 /* Clear out the uCode error bit if it is set */
2961 clear_bit(STATUS_FW_ERROR, &priv->status);
2962
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002963 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002964 return;
2965
Johannes Berg36d68252008-05-15 12:55:26 +02002966 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002967
2968 priv->active_rate = priv->rates_mask;
2969 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
2970
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08002971 iwl_power_update_mode(priv, false);
Zhu Yib481de92007-09-25 17:54:57 -07002972
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002973 if (iwl_is_associated(priv)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002974 struct iwl3945_rxon_cmd *active_rxon =
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002975 (struct iwl3945_rxon_cmd *)(&priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07002976
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002977 memcpy(&priv->staging_rxon, &priv->active_rxon,
2978 sizeof(priv->staging_rxon));
Zhu Yib481de92007-09-25 17:54:57 -07002979 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2980 } else {
2981 /* Initialize our rx_config data */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002982 iwl_connection_init_rx_config(priv, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002983 }
2984
Ben Cahill9fbab512007-11-29 11:09:47 +08002985 /* Configure Bluetooth device coexistence support */
Samuel Ortiz17f841c2009-01-23 13:45:20 -08002986 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002987
2988 /* Configure the adapter for unassociated operation */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002989 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002990
Zhu Yib481de92007-09-25 17:54:57 -07002991 iwl3945_reg_txpower_periodic(priv);
2992
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07002993 iwl3945_led_register(priv);
2994
Tomas Winklere1623442009-01-27 14:27:56 -08002995 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07002996 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a669262008-01-14 17:46:18 -08002997 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07002998
2999 if (priv->error_recovering)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003000 iwl3945_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003001
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003002 /* reassociate for ADHOC mode */
3003 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
3004 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
3005 priv->vif);
3006 if (beacon)
3007 iwl3945_mac_beacon_update(priv->hw, beacon);
3008 }
3009
Zhu Yib481de92007-09-25 17:54:57 -07003010 return;
3011
3012 restart:
3013 queue_work(priv->workqueue, &priv->restart);
3014}
3015
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003016static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07003017
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003018static void __iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003019{
3020 unsigned long flags;
3021 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
3022 struct ieee80211_conf *conf = NULL;
3023
Tomas Winklere1623442009-01-27 14:27:56 -08003024 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07003025
3026 conf = ieee80211_get_hw_conf(priv->hw);
3027
3028 if (!exit_pending)
3029 set_bit(STATUS_EXIT_PENDING, &priv->status);
3030
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07003031 iwl3945_led_unregister(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003032 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003033
3034 /* Unblock any waiting calls */
3035 wake_up_interruptible_all(&priv->wait_command_queue);
3036
Zhu Yib481de92007-09-25 17:54:57 -07003037 /* Wipe out the EXIT_PENDING status bit if we are not actually
3038 * exiting the module */
3039 if (!exit_pending)
3040 clear_bit(STATUS_EXIT_PENDING, &priv->status);
3041
3042 /* stop and reset the on-board processor */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003043 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07003044
3045 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003046 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08003047 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003048 spin_unlock_irqrestore(&priv->lock, flags);
3049 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003050
3051 if (priv->mac80211_registered)
3052 ieee80211_stop_queues(priv->hw);
3053
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003054 /* If we have not previously called iwl3945_init() then
Zhu Yib481de92007-09-25 17:54:57 -07003055 * clear all bits but the RF Kill and SUSPEND bits and return */
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003056 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003057 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3058 STATUS_RF_KILL_HW |
3059 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3060 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08003061 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3062 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07003063 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003064 STATUS_IN_SUSPEND |
3065 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3066 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07003067 goto exit;
3068 }
3069
3070 /* ...otherwise clear out all the status bits but the RF Kill and
3071 * SUSPEND bits and continue taking the NIC down. */
3072 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3073 STATUS_RF_KILL_HW |
3074 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3075 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08003076 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3077 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07003078 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
3079 STATUS_IN_SUSPEND |
3080 test_bit(STATUS_FW_ERROR, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003081 STATUS_FW_ERROR |
3082 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3083 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07003084
Abbas, Mohamede9414b62009-01-20 21:33:55 -08003085 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003086 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003087 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07003088 spin_unlock_irqrestore(&priv->lock, flags);
3089
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003090 iwl3945_hw_txq_ctx_stop(priv);
3091 iwl3945_hw_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003092
3093 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003094 if (!iwl_grab_nic_access(priv)) {
3095 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07003096 APMG_CLK_VAL_DMA_CLK_RQT);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003097 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003098 }
3099 spin_unlock_irqrestore(&priv->lock, flags);
3100
3101 udelay(5);
3102
Abbas, Mohamede9414b62009-01-20 21:33:55 -08003103 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
3104 priv->cfg->ops->lib->apm_ops.stop(priv);
3105 else
3106 priv->cfg->ops->lib->apm_ops.reset(priv);
3107
Zhu Yib481de92007-09-25 17:54:57 -07003108 exit:
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08003109 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07003110
3111 if (priv->ibss_beacon)
3112 dev_kfree_skb(priv->ibss_beacon);
3113 priv->ibss_beacon = NULL;
3114
3115 /* clear out any free frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003116 iwl3945_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003117}
3118
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003119static void iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003120{
3121 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003122 __iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003123 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08003124
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003125 iwl3945_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003126}
3127
3128#define MAX_HW_RESTARTS 5
3129
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003130static int __iwl3945_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003131{
3132 int rc, i;
3133
3134 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003135 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003136 return -EIO;
3137 }
3138
3139 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003140 IWL_WARN(priv, "Radio disabled by SW RF kill (module "
Zhu Yib481de92007-09-25 17:54:57 -07003141 "parameter)\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003142 return -ENODEV;
3143 }
3144
Reinette Chatree903fbd2008-01-30 22:05:15 -08003145 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003146 IWL_ERR(priv, "ucode not available for device bring up\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08003147 return -EIO;
3148 }
3149
Zhu Yie655b9f2008-01-24 02:19:38 -08003150 /* If platform's RF_KILL switch is NOT set to KILL */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003151 if (iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yie655b9f2008-01-24 02:19:38 -08003152 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3153 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3154 else {
3155 set_bit(STATUS_RF_KILL_HW, &priv->status);
3156 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003157 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003158 return -ENODEV;
3159 }
Zhu Yib481de92007-09-25 17:54:57 -07003160 }
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02003161
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003162 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07003163
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003164 rc = iwl3945_hw_nic_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003165 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003166 IWL_ERR(priv, "Unable to int nic\n");
Zhu Yib481de92007-09-25 17:54:57 -07003167 return rc;
3168 }
3169
3170 /* make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003171 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3172 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07003173 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
3174
3175 /* clear (again), then enable host interrupts */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003176 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08003177 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003178
3179 /* really make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003180 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3181 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07003182
3183 /* Copy original ucode data image from disk into backup cache.
3184 * This will be used to initialize the on-board processor's
3185 * data SRAM for a clean start when the runtime program first loads. */
3186 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a669262008-01-14 17:46:18 -08003187 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07003188
Zhu Yie655b9f2008-01-24 02:19:38 -08003189 /* We return success when we resume from suspend and rf_kill is on. */
3190 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
3191 return 0;
3192
Zhu Yib481de92007-09-25 17:54:57 -07003193 for (i = 0; i < MAX_HW_RESTARTS; i++) {
3194
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003195 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003196
3197 /* load bootstrap state machine,
3198 * load bootstrap program into processor's memory,
3199 * prepare to load the "initialize" uCode */
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08003200 priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003201
3202 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003203 IWL_ERR(priv,
3204 "Unable to set up bootstrap uCode: %d\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -07003205 continue;
3206 }
3207
3208 /* start card; "initialize" will load runtime ucode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003209 iwl3945_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003210
Tomas Winklere1623442009-01-27 14:27:56 -08003211 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003212
3213 return 0;
3214 }
3215
3216 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003217 __iwl3945_down(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003218 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003219
3220 /* tried to restart and config the device for as long as our
3221 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08003222 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07003223 return -EIO;
3224}
3225
3226
3227/*****************************************************************************
3228 *
3229 * Workqueue callbacks
3230 *
3231 *****************************************************************************/
3232
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003233static void iwl3945_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003234{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003235 struct iwl_priv *priv =
3236 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003237
3238 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3239 return;
3240
3241 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003242 iwl3945_init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003243 mutex_unlock(&priv->mutex);
3244}
3245
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003246static void iwl3945_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003247{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003248 struct iwl_priv *priv =
3249 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003250
3251 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3252 return;
3253
3254 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003255 iwl3945_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003256 mutex_unlock(&priv->mutex);
3257}
3258
Helmut Schaa26635162009-01-15 09:38:44 +01003259static void iwl3945_rfkill_poll(struct work_struct *data)
3260{
3261 struct iwl_priv *priv =
3262 container_of(data, struct iwl_priv, rfkill_poll.work);
3263 unsigned long status = priv->status;
3264
3265 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3266 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3267 else
3268 set_bit(STATUS_RF_KILL_HW, &priv->status);
3269
3270 if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status))
3271 queue_work(priv->workqueue, &priv->rf_kill);
3272
3273 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3274 round_jiffies_relative(2 * HZ));
3275
3276}
3277
Zhu Yib481de92007-09-25 17:54:57 -07003278#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003279static void iwl3945_bg_request_scan(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003280{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003281 struct iwl_priv *priv =
3282 container_of(data, struct iwl_priv, request_scan);
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08003283 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07003284 .id = REPLY_SCAN_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003285 .len = sizeof(struct iwl3945_scan_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07003286 .meta.flags = CMD_SIZE_HUGE,
3287 };
3288 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003289 struct iwl3945_scan_cmd *scan;
Zhu Yib481de92007-09-25 17:54:57 -07003290 struct ieee80211_conf *conf = NULL;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003291 u8 n_probes = 2;
Johannes Berg8318d782008-01-24 19:38:38 +01003292 enum ieee80211_band band;
John W. Linville9387b7c2008-09-30 20:59:05 -04003293 DECLARE_SSID_BUF(ssid);
Zhu Yib481de92007-09-25 17:54:57 -07003294
3295 conf = ieee80211_get_hw_conf(priv->hw);
3296
3297 mutex_lock(&priv->mutex);
3298
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003299 if (!iwl_is_ready(priv)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003300 IWL_WARN(priv, "request scan called when driver not ready.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003301 goto done;
3302 }
3303
Tomas Winklera96a27f2008-10-23 23:48:56 -07003304 /* Make sure the scan wasn't canceled before this queued work
Zhu Yib481de92007-09-25 17:54:57 -07003305 * was given the chance to run... */
3306 if (!test_bit(STATUS_SCANNING, &priv->status))
3307 goto done;
3308
3309 /* This should never be called or scheduled if there is currently
3310 * a scan active in the hardware. */
3311 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003312 IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests "
3313 "Ignoring second request.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003314 rc = -EIO;
3315 goto done;
3316 }
3317
3318 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003319 IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n");
Zhu Yib481de92007-09-25 17:54:57 -07003320 goto done;
3321 }
3322
3323 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003324 IWL_DEBUG_HC(priv,
3325 "Scan request while abort pending. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003326 goto done;
3327 }
3328
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003329 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003330 IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n");
Zhu Yib481de92007-09-25 17:54:57 -07003331 goto done;
3332 }
3333
3334 if (!test_bit(STATUS_READY, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003335 IWL_DEBUG_HC(priv,
3336 "Scan request while uninitialized. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003337 goto done;
3338 }
3339
3340 if (!priv->scan_bands) {
Tomas Winklere1623442009-01-27 14:27:56 -08003341 IWL_DEBUG_HC(priv, "Aborting scan due to no requested bands\n");
Zhu Yib481de92007-09-25 17:54:57 -07003342 goto done;
3343 }
3344
Winkler, Tomas805cee52009-01-19 15:30:28 -08003345 if (!priv->scan) {
3346 priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
Zhu Yib481de92007-09-25 17:54:57 -07003347 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
Winkler, Tomas805cee52009-01-19 15:30:28 -08003348 if (!priv->scan) {
Zhu Yib481de92007-09-25 17:54:57 -07003349 rc = -ENOMEM;
3350 goto done;
3351 }
3352 }
Winkler, Tomas805cee52009-01-19 15:30:28 -08003353 scan = priv->scan;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003354 memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07003355
3356 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
3357 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
3358
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003359 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003360 u16 interval = 0;
3361 u32 extra;
3362 u32 suspend_time = 100;
3363 u32 scan_suspend_time = 100;
3364 unsigned long flags;
3365
Tomas Winklere1623442009-01-27 14:27:56 -08003366 IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
Zhu Yib481de92007-09-25 17:54:57 -07003367
3368 spin_lock_irqsave(&priv->lock, flags);
3369 interval = priv->beacon_int;
3370 spin_unlock_irqrestore(&priv->lock, flags);
3371
3372 scan->suspend_time = 0;
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003373 scan->max_out_time = cpu_to_le32(200 * 1024);
Zhu Yib481de92007-09-25 17:54:57 -07003374 if (!interval)
3375 interval = suspend_time;
3376 /*
3377 * suspend time format:
3378 * 0-19: beacon interval in usec (time before exec.)
3379 * 20-23: 0
3380 * 24-31: number of beacons (suspend between channels)
3381 */
3382
3383 extra = (suspend_time / interval) << 24;
3384 scan_suspend_time = 0xFF0FFFFF &
3385 (extra | ((suspend_time % interval) * 1024));
3386
3387 scan->suspend_time = cpu_to_le32(scan_suspend_time);
Tomas Winklere1623442009-01-27 14:27:56 -08003388 IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003389 scan_suspend_time, interval);
3390 }
3391
3392 /* We should add the ability for user to lock to PASSIVE ONLY */
3393 if (priv->one_direct_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08003394 IWL_DEBUG_SCAN(priv, "Kicking off one direct scan for '%s'\n",
3395 print_ssid(ssid, priv->direct_ssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04003396 priv->direct_ssid_len));
Zhu Yib481de92007-09-25 17:54:57 -07003397 scan->direct_scan[0].id = WLAN_EID_SSID;
3398 scan->direct_scan[0].len = priv->direct_ssid_len;
3399 memcpy(scan->direct_scan[0].ssid,
3400 priv->direct_ssid, priv->direct_ssid_len);
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003401 n_probes++;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003402 } else
Tomas Winklere1623442009-01-27 14:27:56 -08003403 IWL_DEBUG_SCAN(priv, "Kicking off one indirect scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003404
3405 /* We don't build a direct scan probe request; the uCode will do
3406 * that based on the direct_mask added to each channel entry */
Zhu Yib481de92007-09-25 17:54:57 -07003407 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08003408 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07003409 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
3410
3411 /* flags + rate selection */
3412
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003413 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003414 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
3415 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
3416 scan->good_CRC_th = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01003417 band = IEEE80211_BAND_2GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003418 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003419 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
3420 scan->good_CRC_th = IWL_GOOD_CRC_TH;
Johannes Berg8318d782008-01-24 19:38:38 +01003421 band = IEEE80211_BAND_5GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003422 } else {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003423 IWL_WARN(priv, "Invalid scan band count\n");
Zhu Yib481de92007-09-25 17:54:57 -07003424 goto done;
3425 }
3426
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08003427 scan->tx_cmd.len = cpu_to_le16(
3428 iwl_fill_probe_req(priv, band,
3429 (struct ieee80211_mgmt *)scan->data,
3430 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
3431
Zhu Yib481de92007-09-25 17:54:57 -07003432 /* select Rx antennas */
3433 scan->flags |= iwl3945_get_antenna_flags(priv);
3434
Johannes Berg05c914f2008-09-11 00:01:58 +02003435 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
Zhu Yib481de92007-09-25 17:54:57 -07003436 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
3437
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003438 scan->channel_count =
3439 iwl3945_get_channels_for_scan(priv, band, 1, /* active */
3440 n_probes,
3441 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
Zhu Yib481de92007-09-25 17:54:57 -07003442
Reinette Chatre14b54332008-11-04 12:21:35 -08003443 if (scan->channel_count == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08003444 IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
Reinette Chatre14b54332008-11-04 12:21:35 -08003445 goto done;
3446 }
3447
Zhu Yib481de92007-09-25 17:54:57 -07003448 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003449 scan->channel_count * sizeof(struct iwl3945_scan_channel);
Zhu Yib481de92007-09-25 17:54:57 -07003450 cmd.data = scan;
3451 scan->len = cpu_to_le16(cmd.len);
3452
3453 set_bit(STATUS_SCAN_HW, &priv->status);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003454 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07003455 if (rc)
3456 goto done;
3457
3458 queue_delayed_work(priv->workqueue, &priv->scan_check,
3459 IWL_SCAN_CHECK_WATCHDOG);
3460
3461 mutex_unlock(&priv->mutex);
3462 return;
3463
3464 done:
Mohamed Abbas2420ebc2008-11-04 12:21:34 -08003465 /* can not perform scan make sure we clear scanning
3466 * bits from status so next scan request can be performed.
3467 * if we dont clear scanning status bit here all next scan
3468 * will fail
3469 */
3470 clear_bit(STATUS_SCAN_HW, &priv->status);
3471 clear_bit(STATUS_SCANNING, &priv->status);
3472
Ian Schram01ebd062007-10-25 17:15:22 +08003473 /* inform mac80211 scan aborted */
Zhu Yib481de92007-09-25 17:54:57 -07003474 queue_work(priv->workqueue, &priv->scan_completed);
3475 mutex_unlock(&priv->mutex);
3476}
3477
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003478static void iwl3945_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003479{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003480 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07003481
3482 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3483 return;
3484
3485 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003486 __iwl3945_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003487 mutex_unlock(&priv->mutex);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003488 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003489}
3490
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003491static void iwl3945_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003492{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003493 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07003494
3495 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3496 return;
3497
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003498 iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003499 queue_work(priv->workqueue, &priv->up);
3500}
3501
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003502static void iwl3945_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003503{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003504 struct iwl_priv *priv =
3505 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07003506
3507 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3508 return;
3509
3510 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003511 iwl3945_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003512 mutex_unlock(&priv->mutex);
3513}
3514
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003515#define IWL_DELAY_NEXT_SCAN (HZ*2)
3516
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003517static void iwl3945_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003518{
Zhu Yib481de92007-09-25 17:54:57 -07003519 int rc = 0;
3520 struct ieee80211_conf *conf = NULL;
3521
Johannes Berg05c914f2008-09-11 00:01:58 +02003522 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003523 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07003524 return;
3525 }
3526
3527
Tomas Winklere1623442009-01-27 14:27:56 -08003528 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003529 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07003530
3531 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3532 return;
3533
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003534 if (!priv->vif || !priv->is_open)
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003535 return;
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003536
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003537 iwl_scan_cancel_timeout(priv, 200);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003538
Zhu Yib481de92007-09-25 17:54:57 -07003539 conf = ieee80211_get_hw_conf(priv->hw);
3540
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003541 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003542 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003543
Tomas Winkler28afaf92008-12-19 10:37:06 +08003544 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003545 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003546 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07003547 sizeof(priv->rxon_timing), &priv->rxon_timing);
3548 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003549 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003550 "Attempting to continue.\n");
3551
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003552 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003553
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003554 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003555
Tomas Winklere1623442009-01-27 14:27:56 -08003556 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003557 priv->assoc_id, priv->beacon_int);
3558
3559 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003560 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003561 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003562 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003563
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003564 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003565 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003566 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003567 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003568 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003569
Johannes Berg05c914f2008-09-11 00:01:58 +02003570 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003571 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003572
3573 }
3574
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003575 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003576
3577 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02003578 case NL80211_IFTYPE_STATION:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003579 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07003580 break;
3581
Johannes Berg05c914f2008-09-11 00:01:58 +02003582 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07003583
Abhijeet Kolekarce546fd2008-11-19 15:32:22 -08003584 priv->assoc_id = 1;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003585 iwl3945_add_station(priv, priv->bssid, 0, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003586 iwl3945_sync_sta(priv, IWL_STA_ID,
Johannes Berg8318d782008-01-24 19:38:38 +01003587 (priv->band == IEEE80211_BAND_5GHZ) ?
Zhu Yib481de92007-09-25 17:54:57 -07003588 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
3589 CMD_ASYNC);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003590 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
3591 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003592
3593 break;
3594
3595 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08003596 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003597 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003598 break;
3599 }
3600
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003601 iwl3945_activate_qos(priv, 0);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08003602
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003603 /* we have just associated, don't start scan too early */
3604 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08003605}
3606
Johannes Berge8975582008-10-09 12:18:51 +02003607static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003608
Zhu Yib481de92007-09-25 17:54:57 -07003609/*****************************************************************************
3610 *
3611 * mac80211 entry point functions
3612 *
3613 *****************************************************************************/
3614
Zhu Yi5a669262008-01-14 17:46:18 -08003615#define UCODE_READY_TIMEOUT (2 * HZ)
3616
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003617static int iwl3945_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003618{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003619 struct iwl_priv *priv = hw->priv;
Zhu Yi5a669262008-01-14 17:46:18 -08003620 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003621
Tomas Winklere1623442009-01-27 14:27:56 -08003622 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003623
3624 /* we should be verifying the device is ready to be opened */
3625 mutex_lock(&priv->mutex);
3626
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003627 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
Zhu Yi5a669262008-01-14 17:46:18 -08003628 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
3629 * ucode filename and max sizes are card-specific. */
3630
3631 if (!priv->ucode_code.len) {
3632 ret = iwl3945_read_ucode(priv);
3633 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003634 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a669262008-01-14 17:46:18 -08003635 mutex_unlock(&priv->mutex);
3636 goto out_release_irq;
3637 }
3638 }
3639
Zhu Yie655b9f2008-01-24 02:19:38 -08003640 ret = __iwl3945_up(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08003641
Zhu Yib481de92007-09-25 17:54:57 -07003642 mutex_unlock(&priv->mutex);
Zhu Yi5a669262008-01-14 17:46:18 -08003643
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003644 iwl_rfkill_set_hw_state(priv);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02003645
Zhu Yie655b9f2008-01-24 02:19:38 -08003646 if (ret)
3647 goto out_release_irq;
3648
Tomas Winklere1623442009-01-27 14:27:56 -08003649 IWL_DEBUG_INFO(priv, "Start UP work.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003650
3651 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
3652 return 0;
3653
Zhu Yi5a669262008-01-14 17:46:18 -08003654 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
3655 * mac80211 will not be run successfully. */
3656 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
3657 test_bit(STATUS_READY, &priv->status),
3658 UCODE_READY_TIMEOUT);
3659 if (!ret) {
3660 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003661 IWL_ERR(priv,
3662 "Wait for START_ALIVE timeout after %dms.\n",
3663 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Zhu Yi5a669262008-01-14 17:46:18 -08003664 ret = -ETIMEDOUT;
3665 goto out_release_irq;
3666 }
3667 }
3668
Helmut Schaa26635162009-01-15 09:38:44 +01003669 /* ucode is running and will send rfkill notifications,
3670 * no need to poll the killswitch state anymore */
3671 cancel_delayed_work(&priv->rfkill_poll);
3672
Zhu Yie655b9f2008-01-24 02:19:38 -08003673 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08003674 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003675 return 0;
Zhu Yi5a669262008-01-14 17:46:18 -08003676
3677out_release_irq:
Zhu Yie655b9f2008-01-24 02:19:38 -08003678 priv->is_open = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08003679 IWL_DEBUG_MAC80211(priv, "leave - failed\n");
Zhu Yi5a669262008-01-14 17:46:18 -08003680 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003681}
3682
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003683static void iwl3945_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003684{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003685 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003686
Tomas Winklere1623442009-01-27 14:27:56 -08003687 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003688
Zhu Yie655b9f2008-01-24 02:19:38 -08003689 if (!priv->is_open) {
Tomas Winklere1623442009-01-27 14:27:56 -08003690 IWL_DEBUG_MAC80211(priv, "leave - skip\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003691 return;
3692 }
3693
Zhu Yib481de92007-09-25 17:54:57 -07003694 priv->is_open = 0;
Zhu Yi5a669262008-01-14 17:46:18 -08003695
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003696 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08003697 /* stop mac, cancel any scan request and clear
3698 * RXON_FILTER_ASSOC_MSK BIT
3699 */
Zhu Yi5a669262008-01-14 17:46:18 -08003700 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003701 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003702 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003703 }
3704
Zhu Yi5a669262008-01-14 17:46:18 -08003705 iwl3945_down(priv);
3706
3707 flush_workqueue(priv->workqueue);
Helmut Schaa26635162009-01-15 09:38:44 +01003708
3709 /* start polling the killswitch state again */
3710 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3711 round_jiffies_relative(2 * HZ));
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003712
Tomas Winklere1623442009-01-27 14:27:56 -08003713 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003714}
3715
Johannes Berge039fa42008-05-15 12:55:29 +02003716static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003717{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003718 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003719
Tomas Winklere1623442009-01-27 14:27:56 -08003720 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003721
Tomas Winklere1623442009-01-27 14:27:56 -08003722 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02003723 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07003724
Johannes Berge039fa42008-05-15 12:55:29 +02003725 if (iwl3945_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07003726 dev_kfree_skb_any(skb);
3727
Tomas Winklere1623442009-01-27 14:27:56 -08003728 IWL_DEBUG_MAC80211(priv, "leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08003729 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07003730}
3731
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003732static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003733 struct ieee80211_if_init_conf *conf)
3734{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003735 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003736 unsigned long flags;
3737
Tomas Winklere1623442009-01-27 14:27:56 -08003738 IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07003739
Johannes Berg32bfd352007-12-19 01:31:26 +01003740 if (priv->vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08003741 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
Tomas Winkler864792e2007-11-27 21:00:52 +02003742 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07003743 }
3744
3745 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01003746 priv->vif = conf->vif;
Zhu, Yi60294de2008-10-29 14:05:45 -07003747 priv->iw_mode = conf->type;
Zhu Yib481de92007-09-25 17:54:57 -07003748
3749 spin_unlock_irqrestore(&priv->lock, flags);
3750
3751 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02003752
3753 if (conf->mac_addr) {
Tomas Winklere1623442009-01-27 14:27:56 -08003754 IWL_DEBUG_MAC80211(priv, "Set: %pM\n", conf->mac_addr);
Tomas Winkler864792e2007-11-27 21:00:52 +02003755 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
3756 }
3757
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003758 if (iwl_is_ready(priv))
Zhu Yi5a669262008-01-14 17:46:18 -08003759 iwl3945_set_mode(priv, conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07003760
Zhu Yib481de92007-09-25 17:54:57 -07003761 mutex_unlock(&priv->mutex);
3762
Tomas Winklere1623442009-01-27 14:27:56 -08003763 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003764 return 0;
3765}
3766
3767/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003768 * iwl3945_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07003769 *
3770 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
3771 * be set inappropriately and the driver currently sets the hardware up to
3772 * use it whenever needed.
3773 */
Johannes Berge8975582008-10-09 12:18:51 +02003774static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed)
Zhu Yib481de92007-09-25 17:54:57 -07003775{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003776 struct iwl_priv *priv = hw->priv;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08003777 const struct iwl_channel_info *ch_info;
Johannes Berge8975582008-10-09 12:18:51 +02003778 struct ieee80211_conf *conf = &hw->conf;
Zhu Yib481de92007-09-25 17:54:57 -07003779 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08003780 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003781
3782 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08003783 IWL_DEBUG_MAC80211(priv, "enter to channel %d\n",
3784 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07003785
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003786 if (!iwl_is_ready(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003787 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08003788 ret = -EIO;
3789 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003790 }
3791
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08003792 if (unlikely(!iwl3945_mod_params.disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07003793 test_bit(STATUS_SCANNING, &priv->status))) {
Tomas Winklere1623442009-01-27 14:27:56 -08003794 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
Zhu Yia0646472007-12-20 14:10:01 +08003795 set_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003796 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08003797 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07003798 }
3799
3800 spin_lock_irqsave(&priv->lock, flags);
3801
Samuel Ortize6148912009-01-23 13:45:15 -08003802 ch_info = iwl_get_channel_info(priv, conf->channel->band,
3803 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07003804 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003805 IWL_DEBUG_SCAN(priv,
3806 "Channel %d [%d] is INVALID for this band.\n",
3807 conf->channel->hw_value, conf->channel->band);
3808 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
Zhu Yib481de92007-09-25 17:54:57 -07003809 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003810 ret = -EINVAL;
3811 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003812 }
3813
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003814 iwl_set_rxon_channel(priv, conf->channel);
Zhu Yib481de92007-09-25 17:54:57 -07003815
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003816 iwl_set_flags_for_band(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07003817
3818 /* The list of supported rates and rate mask can be different
3819 * for each phymode; since the phymode may have changed, reset
3820 * the rate mask to what mac80211 lists */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003821 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003822
3823 spin_unlock_irqrestore(&priv->lock, flags);
3824
3825#ifdef IEEE80211_CONF_CHANNEL_SWITCH
3826 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003827 iwl3945_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003828 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003829 }
3830#endif
3831
Abhijeet Kolekar7dc45f22009-02-18 15:54:32 -08003832 if (conf->radio_enabled && iwl_radio_kill_sw_enable_radio(priv)) {
3833 IWL_DEBUG_MAC80211(priv, "leave - RF-KILL - waiting for uCode\n");
3834 goto out;
3835 }
Zhu Yib481de92007-09-25 17:54:57 -07003836
3837 if (!conf->radio_enabled) {
Abhijeet Kolekar7dc45f22009-02-18 15:54:32 -08003838 iwl_radio_kill_sw_disable_radio(priv);
Tomas Winklere1623442009-01-27 14:27:56 -08003839 IWL_DEBUG_MAC80211(priv, "leave - radio disabled\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08003840 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003841 }
3842
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003843 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003844 IWL_DEBUG_MAC80211(priv, "leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08003845 ret = -EIO;
3846 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003847 }
3848
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003849 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003850
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003851 if (memcmp(&priv->active_rxon,
3852 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003853 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003854 else
Tomas Winklere1623442009-01-27 14:27:56 -08003855 IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration\n");
Zhu Yib481de92007-09-25 17:54:57 -07003856
Tomas Winklere1623442009-01-27 14:27:56 -08003857 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003858
Zhu Yi76bb77e2007-11-22 10:53:22 +08003859out:
Zhu Yia0646472007-12-20 14:10:01 +08003860 clear_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003861 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003862 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003863}
3864
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003865static void iwl3945_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003866{
3867 int rc = 0;
3868
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08003869 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07003870 return;
3871
3872 /* The following should be done only at AP bring up */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003873 if (!(iwl_is_associated(priv))) {
Zhu Yib481de92007-09-25 17:54:57 -07003874
3875 /* RXON - unassoc (to set timing command) */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003876 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003877 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003878
3879 /* RXON Timing */
Tomas Winkler28afaf92008-12-19 10:37:06 +08003880 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003881 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003882 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
3883 sizeof(priv->rxon_timing),
3884 &priv->rxon_timing);
Zhu Yib481de92007-09-25 17:54:57 -07003885 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003886 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003887 "Attempting to continue.\n");
3888
3889 /* FIXME: what should be the assoc_id for AP? */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003890 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003891 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003892 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003893 RXON_FLG_SHORT_PREAMBLE_MSK;
3894 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003895 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003896 ~RXON_FLG_SHORT_PREAMBLE_MSK;
3897
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003898 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003899 if (priv->assoc_capability &
3900 WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003901 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003902 RXON_FLG_SHORT_SLOT_MSK;
3903 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003904 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003905 ~RXON_FLG_SHORT_SLOT_MSK;
3906
Johannes Berg05c914f2008-09-11 00:01:58 +02003907 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003908 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003909 ~RXON_FLG_SHORT_SLOT_MSK;
3910 }
3911 /* restore RXON assoc */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003912 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003913 iwl3945_commit_rxon(priv);
Kolekar, Abhijeetb5323d32008-12-19 10:37:22 +08003914 iwl3945_add_station(priv, iwl_bcast_addr, 0, 0);
Zhu Yi556f8db2007-09-27 11:27:33 +08003915 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003916 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003917
3918 /* FIXME - we need to add code here to detect a totally new
3919 * configuration, reset the AP, unassoc, rxon timing, assoc,
3920 * clear sta table, add BCAST sta... */
3921}
3922
Johannes Berg32bfd352007-12-19 01:31:26 +01003923static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
3924 struct ieee80211_vif *vif,
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003925 struct ieee80211_if_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07003926{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003927 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003928 int rc;
3929
3930 if (conf == NULL)
3931 return -EIO;
3932
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08003933 if (priv->vif != vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08003934 IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08003935 return 0;
3936 }
3937
Johannes Berg9d139c82008-07-09 14:40:37 +02003938 /* handle this temporarily here */
Johannes Berg05c914f2008-09-11 00:01:58 +02003939 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Johannes Berg9d139c82008-07-09 14:40:37 +02003940 conf->changed & IEEE80211_IFCC_BEACON) {
3941 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
3942 if (!beacon)
3943 return -ENOMEM;
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003944 mutex_lock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02003945 rc = iwl3945_mac_beacon_update(hw, beacon);
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003946 mutex_unlock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02003947 if (rc)
3948 return rc;
3949 }
3950
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003951 if (!iwl_is_alive(priv))
Zhu Yi5a669262008-01-14 17:46:18 -08003952 return -EAGAIN;
3953
Zhu Yib481de92007-09-25 17:54:57 -07003954 mutex_lock(&priv->mutex);
3955
Zhu Yib481de92007-09-25 17:54:57 -07003956 if (conf->bssid)
Tomas Winklere1623442009-01-27 14:27:56 -08003957 IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07003958
Johannes Berg4150c572007-09-17 01:29:23 -04003959/*
3960 * very dubious code was here; the probe filtering flag is never set:
3961 *
Zhu Yib481de92007-09-25 17:54:57 -07003962 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
3963 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04003964 */
Zhu Yib481de92007-09-25 17:54:57 -07003965
Johannes Berg05c914f2008-09-11 00:01:58 +02003966 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07003967 if (!conf->bssid) {
3968 conf->bssid = priv->mac_addr;
3969 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08003970 IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07003971 conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07003972 }
3973 if (priv->ibss_beacon)
3974 dev_kfree_skb(priv->ibss_beacon);
3975
Johannes Berg9d139c82008-07-09 14:40:37 +02003976 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
Zhu Yib481de92007-09-25 17:54:57 -07003977 }
3978
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003979 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08003980 goto done;
3981
Zhu Yib481de92007-09-25 17:54:57 -07003982 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
3983 !is_multicast_ether_addr(conf->bssid)) {
3984 /* If there is currently a HW scan going on in the background
3985 * then we need to cancel it else the RXON below will fail. */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003986 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003987 IWL_WARN(priv, "Aborted scan still in progress "
Zhu Yib481de92007-09-25 17:54:57 -07003988 "after 100ms\n");
Tomas Winklere1623442009-01-27 14:27:56 -08003989 IWL_DEBUG_MAC80211(priv, "leaving:scan abort failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07003990 mutex_unlock(&priv->mutex);
3991 return -EAGAIN;
3992 }
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003993 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07003994
3995 /* TODO: Audit driver for usage of these members and see
3996 * if mac80211 deprecates them (priv->bssid looks like it
3997 * shouldn't be there, but I haven't scanned the IBSS code
3998 * to verify) - jpk */
3999 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
4000
Johannes Berg05c914f2008-09-11 00:01:58 +02004001 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004002 iwl3945_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004003 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004004 rc = iwl3945_commit_rxon(priv);
Johannes Berg05c914f2008-09-11 00:01:58 +02004005 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004006 iwl3945_add_station(priv,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004007 priv->active_rxon.bssid_addr, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004008 }
4009
4010 } else {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004011 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004012 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004013 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004014 }
4015
Mohamed Abbasfde35712007-11-29 11:10:15 +08004016 done:
Tomas Winklere1623442009-01-27 14:27:56 -08004017 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004018 mutex_unlock(&priv->mutex);
4019
4020 return 0;
4021}
4022
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004023static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004024 struct ieee80211_if_init_conf *conf)
4025{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004026 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004027
Tomas Winklere1623442009-01-27 14:27:56 -08004028 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004029
4030 mutex_lock(&priv->mutex);
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004031
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004032 if (iwl_is_ready_rf(priv)) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004033 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004034 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Mohamed Abbasfde35712007-11-29 11:10:15 +08004035 iwl3945_commit_rxon(priv);
4036 }
Johannes Berg32bfd352007-12-19 01:31:26 +01004037 if (priv->vif == conf->vif) {
4038 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07004039 memset(priv->bssid, 0, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07004040 }
4041 mutex_unlock(&priv->mutex);
4042
Tomas Winklere1623442009-01-27 14:27:56 -08004043 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004044}
4045
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004046#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
4047
4048static void iwl3945_bss_info_changed(struct ieee80211_hw *hw,
4049 struct ieee80211_vif *vif,
4050 struct ieee80211_bss_conf *bss_conf,
4051 u32 changes)
4052{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004053 struct iwl_priv *priv = hw->priv;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004054
Tomas Winklere1623442009-01-27 14:27:56 -08004055 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004056
4057 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
Tomas Winklere1623442009-01-27 14:27:56 -08004058 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004059 bss_conf->use_short_preamble);
4060 if (bss_conf->use_short_preamble)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004061 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004062 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004063 priv->staging_rxon.flags &=
4064 ~RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004065 }
4066
4067 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
Tomas Winklere1623442009-01-27 14:27:56 -08004068 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n",
4069 bss_conf->use_cts_prot);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004070 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004071 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004072 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004073 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004074 }
4075
4076 if (changes & BSS_CHANGED_ASSOC) {
Tomas Winklere1623442009-01-27 14:27:56 -08004077 IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004078 /* This should never happen as this function should
4079 * never be called from interrupt context. */
4080 if (WARN_ON_ONCE(in_interrupt()))
4081 return;
4082 if (bss_conf->assoc) {
4083 priv->assoc_id = bss_conf->aid;
4084 priv->beacon_int = bss_conf->beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08004085 priv->timestamp = bss_conf->timestamp;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004086 priv->assoc_capability = bss_conf->assoc_capability;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08004087 priv->power_data.dtim_period = bss_conf->dtim_period;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004088 priv->next_scan_jiffies = jiffies +
4089 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
4090 mutex_lock(&priv->mutex);
4091 iwl3945_post_associate(priv);
4092 mutex_unlock(&priv->mutex);
4093 } else {
4094 priv->assoc_id = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08004095 IWL_DEBUG_MAC80211(priv,
4096 "DISASSOC %d\n", bss_conf->assoc);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004097 }
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004098 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
Tomas Winklere1623442009-01-27 14:27:56 -08004099 IWL_DEBUG_MAC80211(priv,
4100 "Associated Changes %d\n", changes);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004101 iwl3945_send_rxon_assoc(priv);
4102 }
4103
4104}
4105
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004106static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01004107 struct ieee80211_vif *vif,
4108 struct ieee80211_sta *sta,
4109 struct ieee80211_key_conf *key)
Zhu Yib481de92007-09-25 17:54:57 -07004110{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004111 struct iwl_priv *priv = hw->priv;
Johannes Bergdc822b52008-12-29 12:55:09 +01004112 const u8 *addr;
Winkler, Tomas42986792009-01-19 15:30:22 -08004113 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07004114 u8 sta_id;
4115
Tomas Winklere1623442009-01-27 14:27:56 -08004116 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004117
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004118 if (iwl3945_mod_params.sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08004119 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07004120 return -EOPNOTSUPP;
4121 }
4122
Winkler, Tomas42986792009-01-19 15:30:22 -08004123 addr = sta ? sta->addr : iwl_bcast_addr;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004124 sta_id = iwl3945_hw_find_station(priv, addr);
Zhu Yib481de92007-09-25 17:54:57 -07004125 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -08004126 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
Johannes Berge1749612008-10-27 15:59:26 -07004127 addr);
Zhu Yib481de92007-09-25 17:54:57 -07004128 return -EINVAL;
4129 }
4130
4131 mutex_lock(&priv->mutex);
4132
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004133 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004134
Zhu Yib481de92007-09-25 17:54:57 -07004135 switch (cmd) {
4136 case SET_KEY:
Winkler, Tomas42986792009-01-19 15:30:22 -08004137 ret = iwl3945_update_sta_key_info(priv, key, sta_id);
4138 if (!ret) {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004139 iwl_set_rxon_hwcrypto(priv, 1);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004140 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004141 key->hw_key_idx = sta_id;
Tomas Winklere1623442009-01-27 14:27:56 -08004142 IWL_DEBUG_MAC80211(priv,
4143 "set_key success, using hwcrypto\n");
Zhu Yib481de92007-09-25 17:54:57 -07004144 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
4145 }
4146 break;
4147 case DISABLE_KEY:
Winkler, Tomas42986792009-01-19 15:30:22 -08004148 ret = iwl3945_clear_sta_key_info(priv, sta_id);
4149 if (!ret) {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004150 iwl_set_rxon_hwcrypto(priv, 0);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004151 iwl3945_commit_rxon(priv);
Tomas Winklere1623442009-01-27 14:27:56 -08004152 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07004153 }
4154 break;
4155 default:
Winkler, Tomas42986792009-01-19 15:30:22 -08004156 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07004157 }
4158
Tomas Winklere1623442009-01-27 14:27:56 -08004159 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004160 mutex_unlock(&priv->mutex);
4161
Winkler, Tomas42986792009-01-19 15:30:22 -08004162 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004163}
4164
Johannes Berge100bb62008-04-30 18:51:21 +02004165static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
Zhu Yib481de92007-09-25 17:54:57 -07004166 const struct ieee80211_tx_queue_params *params)
4167{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004168 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004169 unsigned long flags;
4170 int q;
Zhu Yib481de92007-09-25 17:54:57 -07004171
Tomas Winklere1623442009-01-27 14:27:56 -08004172 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004173
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004174 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004175 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004176 return -EIO;
4177 }
4178
4179 if (queue >= AC_NUM) {
Tomas Winklere1623442009-01-27 14:27:56 -08004180 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
Zhu Yib481de92007-09-25 17:54:57 -07004181 return 0;
4182 }
4183
Zhu Yib481de92007-09-25 17:54:57 -07004184 q = AC_NUM - 1 - queue;
4185
4186 spin_lock_irqsave(&priv->lock, flags);
4187
4188 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
4189 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
4190 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
4191 priv->qos_data.def_qos_parm.ac[q].edca_txop =
Johannes Berg3330d7be2008-02-10 16:49:38 +01004192 cpu_to_le16((params->txop * 32));
Zhu Yib481de92007-09-25 17:54:57 -07004193
4194 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
4195 priv->qos_data.qos_active = 1;
4196
4197 spin_unlock_irqrestore(&priv->lock, flags);
4198
4199 mutex_lock(&priv->mutex);
Johannes Berg05c914f2008-09-11 00:01:58 +02004200 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004201 iwl3945_activate_qos(priv, 1);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004202 else if (priv->assoc_id && iwl_is_associated(priv))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004203 iwl3945_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004204
4205 mutex_unlock(&priv->mutex);
4206
Tomas Winklere1623442009-01-27 14:27:56 -08004207 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004208 return 0;
4209}
4210
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004211static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004212 struct ieee80211_tx_queue_stats *stats)
4213{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004214 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004215 int i, avail;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08004216 struct iwl_tx_queue *txq;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004217 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07004218 unsigned long flags;
4219
Tomas Winklere1623442009-01-27 14:27:56 -08004220 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004221
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004222 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004223 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004224 return -EIO;
4225 }
4226
4227 spin_lock_irqsave(&priv->lock, flags);
4228
4229 for (i = 0; i < AC_NUM; i++) {
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08004230 txq = &priv->txq[i];
Zhu Yib481de92007-09-25 17:54:57 -07004231 q = &txq->q;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004232 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07004233
Johannes Berg57ffc582008-04-29 17:18:59 +02004234 stats[i].len = q->n_window - avail;
4235 stats[i].limit = q->n_window - q->high_mark;
4236 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07004237
4238 }
4239 spin_unlock_irqrestore(&priv->lock, flags);
4240
Tomas Winklere1623442009-01-27 14:27:56 -08004241 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004242
4243 return 0;
4244}
4245
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004246static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07004247{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004248 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004249 unsigned long flags;
4250
4251 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08004252 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004253
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004254 iwl_reset_qos(priv);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08004255
Zhu Yib481de92007-09-25 17:54:57 -07004256 spin_lock_irqsave(&priv->lock, flags);
4257 priv->assoc_id = 0;
4258 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004259
4260 /* new association get rid of ibss beacon skb */
4261 if (priv->ibss_beacon)
4262 dev_kfree_skb(priv->ibss_beacon);
4263
4264 priv->ibss_beacon = NULL;
4265
4266 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08004267 priv->timestamp = 0;
Johannes Berg05c914f2008-09-11 00:01:58 +02004268 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
Zhu Yib481de92007-09-25 17:54:57 -07004269 priv->beacon_int = 0;
4270
4271 spin_unlock_irqrestore(&priv->lock, flags);
4272
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004273 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004274 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +08004275 mutex_unlock(&priv->mutex);
4276 return;
4277 }
4278
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004279 /* we are restarting association process
4280 * clear RXON_FILTER_ASSOC_MSK bit
4281 */
Johannes Berg05c914f2008-09-11 00:01:58 +02004282 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004283 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004284 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004285 iwl3945_commit_rxon(priv);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004286 }
4287
Zhu Yib481de92007-09-25 17:54:57 -07004288 /* Per mac80211.h: This is only used in IBSS mode... */
Johannes Berg05c914f2008-09-11 00:01:58 +02004289 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004290
Tomas Winklere1623442009-01-27 14:27:56 -08004291 IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07004292 mutex_unlock(&priv->mutex);
4293 return;
4294 }
4295
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004296 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004297
4298 mutex_unlock(&priv->mutex);
4299
Tomas Winklere1623442009-01-27 14:27:56 -08004300 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004301
4302}
4303
Johannes Berge039fa42008-05-15 12:55:29 +02004304static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07004305{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004306 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004307 unsigned long flags;
4308
Tomas Winklere1623442009-01-27 14:27:56 -08004309 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004310
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004311 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004312 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004313 return -EIO;
4314 }
4315
Johannes Berg05c914f2008-09-11 00:01:58 +02004316 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Tomas Winklere1623442009-01-27 14:27:56 -08004317 IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07004318 return -EIO;
4319 }
4320
4321 spin_lock_irqsave(&priv->lock, flags);
4322
4323 if (priv->ibss_beacon)
4324 dev_kfree_skb(priv->ibss_beacon);
4325
4326 priv->ibss_beacon = skb;
4327
4328 priv->assoc_id = 0;
4329
Tomas Winklere1623442009-01-27 14:27:56 -08004330 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004331 spin_unlock_irqrestore(&priv->lock, flags);
4332
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004333 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004334
Abhijeet Kolekardc4b1e72008-09-03 11:26:30 +08004335 iwl3945_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004336
Zhu Yib481de92007-09-25 17:54:57 -07004337
4338 return 0;
4339}
4340
4341/*****************************************************************************
4342 *
4343 * sysfs attributes
4344 *
4345 *****************************************************************************/
4346
Samuel Ortizd08853a2009-01-23 13:45:17 -08004347#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07004348
4349/*
4350 * The following adds a new attribute to the sysfs representation
4351 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
4352 * used for controlling the debug level.
4353 *
4354 * See the level definitions in iwl for details.
4355 */
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004356static ssize_t show_debug_level(struct device *d,
4357 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07004358{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004359 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004360
4361 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07004362}
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004363static ssize_t store_debug_level(struct device *d,
4364 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07004365 const char *buf, size_t count)
4366{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004367 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004368 unsigned long val;
4369 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07004370
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004371 ret = strict_strtoul(buf, 0, &val);
4372 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08004373 IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07004374 else
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004375 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07004376
4377 return strnlen(buf, count);
4378}
4379
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004380static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
4381 show_debug_level, store_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07004382
Samuel Ortizd08853a2009-01-23 13:45:17 -08004383#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07004384
Zhu Yib481de92007-09-25 17:54:57 -07004385static ssize_t show_temperature(struct device *d,
4386 struct device_attribute *attr, char *buf)
4387{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004388 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004389
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004390 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004391 return -EAGAIN;
4392
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004393 return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
Zhu Yib481de92007-09-25 17:54:57 -07004394}
4395
4396static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
4397
Zhu Yib481de92007-09-25 17:54:57 -07004398static ssize_t show_tx_power(struct device *d,
4399 struct device_attribute *attr, char *buf)
4400{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004401 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08004402 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07004403}
4404
4405static ssize_t store_tx_power(struct device *d,
4406 struct device_attribute *attr,
4407 const char *buf, size_t count)
4408{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004409 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004410 char *p = (char *)buf;
4411 u32 val;
4412
4413 val = simple_strtoul(p, &p, 10);
4414 if (p == buf)
Tomas Winkler978785a2008-12-19 10:37:31 +08004415 IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07004416 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004417 iwl3945_hw_reg_set_txpower(priv, val);
Zhu Yib481de92007-09-25 17:54:57 -07004418
4419 return count;
4420}
4421
4422static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
4423
4424static ssize_t show_flags(struct device *d,
4425 struct device_attribute *attr, char *buf)
4426{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004427 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004428
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004429 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
Zhu Yib481de92007-09-25 17:54:57 -07004430}
4431
4432static ssize_t store_flags(struct device *d,
4433 struct device_attribute *attr,
4434 const char *buf, size_t count)
4435{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004436 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004437 u32 flags = simple_strtoul(buf, NULL, 0);
4438
4439 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004440 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
Zhu Yib481de92007-09-25 17:54:57 -07004441 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004442 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004443 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004444 else {
Tomas Winklere1623442009-01-27 14:27:56 -08004445 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
Zhu Yib481de92007-09-25 17:54:57 -07004446 flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004447 priv->staging_rxon.flags = cpu_to_le32(flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004448 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004449 }
4450 }
4451 mutex_unlock(&priv->mutex);
4452
4453 return count;
4454}
4455
4456static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
4457
4458static ssize_t show_filter_flags(struct device *d,
4459 struct device_attribute *attr, char *buf)
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
4463 return sprintf(buf, "0x%04X\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004464 le32_to_cpu(priv->active_rxon.filter_flags));
Zhu Yib481de92007-09-25 17:54:57 -07004465}
4466
4467static ssize_t store_filter_flags(struct device *d,
4468 struct device_attribute *attr,
4469 const char *buf, size_t count)
4470{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004471 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004472 u32 filter_flags = simple_strtoul(buf, NULL, 0);
4473
4474 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004475 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
Zhu Yib481de92007-09-25 17:54:57 -07004476 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004477 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004478 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004479 else {
Tomas Winklere1623442009-01-27 14:27:56 -08004480 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
Zhu Yib481de92007-09-25 17:54:57 -07004481 "0x%04X\n", filter_flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004482 priv->staging_rxon.filter_flags =
Zhu Yib481de92007-09-25 17:54:57 -07004483 cpu_to_le32(filter_flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004484 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004485 }
4486 }
4487 mutex_unlock(&priv->mutex);
4488
4489 return count;
4490}
4491
4492static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
4493 store_filter_flags);
4494
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004495#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004496
4497static ssize_t show_measurement(struct device *d,
4498 struct device_attribute *attr, char *buf)
4499{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004500 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler600c0e12008-12-19 10:37:04 +08004501 struct iwl_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004502 u32 size = sizeof(measure_report), len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03004503 u8 *data = (u8 *)&measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004504 unsigned long flags;
4505
4506 spin_lock_irqsave(&priv->lock, flags);
4507 if (!(priv->measurement_status & MEASUREMENT_READY)) {
4508 spin_unlock_irqrestore(&priv->lock, flags);
4509 return 0;
4510 }
4511 memcpy(&measure_report, &priv->measure_report, size);
4512 priv->measurement_status = 0;
4513 spin_unlock_irqrestore(&priv->lock, flags);
4514
4515 while (size && (PAGE_SIZE - len)) {
4516 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4517 PAGE_SIZE - len, 1);
4518 len = strlen(buf);
4519 if (PAGE_SIZE - len)
4520 buf[len++] = '\n';
4521
4522 ofs += 16;
4523 size -= min(size, 16U);
4524 }
4525
4526 return len;
4527}
4528
4529static ssize_t store_measurement(struct device *d,
4530 struct device_attribute *attr,
4531 const char *buf, size_t count)
4532{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004533 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004534 struct ieee80211_measurement_params params = {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004535 .channel = le16_to_cpu(priv->active_rxon.channel),
Zhu Yib481de92007-09-25 17:54:57 -07004536 .start_time = cpu_to_le64(priv->last_tsf),
4537 .duration = cpu_to_le16(1),
4538 };
4539 u8 type = IWL_MEASURE_BASIC;
4540 u8 buffer[32];
4541 u8 channel;
4542
4543 if (count) {
4544 char *p = buffer;
4545 strncpy(buffer, buf, min(sizeof(buffer), count));
4546 channel = simple_strtoul(p, NULL, 0);
4547 if (channel)
4548 params.channel = channel;
4549
4550 p = buffer;
4551 while (*p && *p != ' ')
4552 p++;
4553 if (*p)
4554 type = simple_strtoul(p + 1, NULL, 0);
4555 }
4556
Tomas Winklere1623442009-01-27 14:27:56 -08004557 IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on "
Zhu Yib481de92007-09-25 17:54:57 -07004558 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004559 iwl3945_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07004560
4561 return count;
4562}
4563
4564static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
4565 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004566#endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07004567
Zhu Yib481de92007-09-25 17:54:57 -07004568static ssize_t store_retry_rate(struct device *d,
4569 struct device_attribute *attr,
4570 const char *buf, size_t count)
4571{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004572 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004573
4574 priv->retry_rate = simple_strtoul(buf, NULL, 0);
4575 if (priv->retry_rate <= 0)
4576 priv->retry_rate = 1;
4577
4578 return count;
4579}
4580
4581static ssize_t show_retry_rate(struct device *d,
4582 struct device_attribute *attr, char *buf)
4583{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004584 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004585 return sprintf(buf, "%d", priv->retry_rate);
4586}
4587
4588static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
4589 store_retry_rate);
4590
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004591
Zhu Yib481de92007-09-25 17:54:57 -07004592static ssize_t store_power_level(struct device *d,
4593 struct device_attribute *attr,
4594 const char *buf, size_t count)
4595{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004596 struct iwl_priv *priv = dev_get_drvdata(d);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004597 int ret;
4598 unsigned long mode;
Zhu Yib481de92007-09-25 17:54:57 -07004599
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004600
Zhu Yib481de92007-09-25 17:54:57 -07004601 mutex_lock(&priv->mutex);
4602
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004603 if (!iwl_is_ready(priv)) {
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004604 ret = -EAGAIN;
Zhu Yib481de92007-09-25 17:54:57 -07004605 goto out;
4606 }
4607
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004608 ret = strict_strtoul(buf, 10, &mode);
4609 if (ret)
4610 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004611
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004612 ret = iwl_power_set_user_mode(priv, mode);
4613 if (ret) {
4614 IWL_DEBUG_MAC80211(priv, "failed setting power mode.\n");
4615 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004616 }
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004617 ret = count;
Zhu Yib481de92007-09-25 17:54:57 -07004618
4619 out:
4620 mutex_unlock(&priv->mutex);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004621 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004622}
4623
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004624static ssize_t show_power_level(struct device *d,
4625 struct device_attribute *attr, char *buf)
4626{
4627 struct iwl_priv *priv = dev_get_drvdata(d);
4628 int mode = priv->power_data.user_power_setting;
4629 int system = priv->power_data.system_power_setting;
4630 int level = priv->power_data.power_mode;
4631 char *p = buf;
4632
4633 switch (system) {
4634 case IWL_POWER_SYS_AUTO:
4635 p += sprintf(p, "SYSTEM:auto");
4636 break;
4637 case IWL_POWER_SYS_AC:
4638 p += sprintf(p, "SYSTEM:ac");
4639 break;
4640 case IWL_POWER_SYS_BATTERY:
4641 p += sprintf(p, "SYSTEM:battery");
4642 break;
4643 }
4644
4645 p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
4646 "fixed" : "auto");
4647 p += sprintf(p, "\tINDEX:%d", level);
4648 p += sprintf(p, "\n");
4649 return p - buf + 1;
4650}
4651
4652static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR,
4653 show_power_level, store_power_level);
4654
Zhu Yib481de92007-09-25 17:54:57 -07004655#define MAX_WX_STRING 80
4656
4657/* Values are in microsecond */
4658static const s32 timeout_duration[] = {
4659 350000,
4660 250000,
4661 75000,
4662 37000,
4663 25000,
4664};
4665static const s32 period_duration[] = {
4666 400000,
4667 700000,
4668 1000000,
4669 1000000,
4670 1000000
4671};
4672
Zhu Yib481de92007-09-25 17:54:57 -07004673static ssize_t show_channels(struct device *d,
4674 struct device_attribute *attr, char *buf)
4675{
Johannes Berg8318d782008-01-24 19:38:38 +01004676 /* all this shit doesn't belong into sysfs anyway */
4677 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07004678}
4679
4680static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
4681
4682static ssize_t show_statistics(struct device *d,
4683 struct device_attribute *attr, char *buf)
4684{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004685 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004686 u32 size = sizeof(struct iwl3945_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07004687 u32 len = 0, ofs = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004688 u8 *data = (u8 *)&priv->statistics_39;
Zhu Yib481de92007-09-25 17:54:57 -07004689 int rc = 0;
4690
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004691 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004692 return -EAGAIN;
4693
4694 mutex_lock(&priv->mutex);
Samuel Ortiz17f841c2009-01-23 13:45:20 -08004695 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004696 mutex_unlock(&priv->mutex);
4697
4698 if (rc) {
4699 len = sprintf(buf,
4700 "Error sending statistics request: 0x%08X\n", rc);
4701 return len;
4702 }
4703
4704 while (size && (PAGE_SIZE - len)) {
4705 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4706 PAGE_SIZE - len, 1);
4707 len = strlen(buf);
4708 if (PAGE_SIZE - len)
4709 buf[len++] = '\n';
4710
4711 ofs += 16;
4712 size -= min(size, 16U);
4713 }
4714
4715 return len;
4716}
4717
4718static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
4719
4720static ssize_t show_antenna(struct device *d,
4721 struct device_attribute *attr, char *buf)
4722{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004723 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004724
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004725 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004726 return -EAGAIN;
4727
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08004728 return sprintf(buf, "%d\n", iwl3945_mod_params.antenna);
Zhu Yib481de92007-09-25 17:54:57 -07004729}
4730
4731static ssize_t store_antenna(struct device *d,
4732 struct device_attribute *attr,
4733 const char *buf, size_t count)
4734{
Winkler, Tomas7530f852009-01-27 14:27:53 -08004735 struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004736 int ant;
Zhu Yib481de92007-09-25 17:54:57 -07004737
4738 if (count == 0)
4739 return 0;
4740
4741 if (sscanf(buf, "%1i", &ant) != 1) {
Tomas Winklere1623442009-01-27 14:27:56 -08004742 IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004743 return count;
4744 }
4745
4746 if ((ant >= 0) && (ant <= 2)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004747 IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant);
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08004748 iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant;
Zhu Yib481de92007-09-25 17:54:57 -07004749 } else
Tomas Winklere1623442009-01-27 14:27:56 -08004750 IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant);
Zhu Yib481de92007-09-25 17:54:57 -07004751
4752
4753 return count;
4754}
4755
4756static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
4757
4758static ssize_t show_status(struct device *d,
4759 struct device_attribute *attr, char *buf)
4760{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004761 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004762 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004763 return -EAGAIN;
4764 return sprintf(buf, "0x%08x\n", (int)priv->status);
4765}
4766
4767static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
4768
4769static ssize_t dump_error_log(struct device *d,
4770 struct device_attribute *attr,
4771 const char *buf, size_t count)
4772{
4773 char *p = (char *)buf;
4774
4775 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004776 iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07004777
4778 return strnlen(buf, count);
4779}
4780
4781static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
4782
4783static ssize_t dump_event_log(struct device *d,
4784 struct device_attribute *attr,
4785 const char *buf, size_t count)
4786{
4787 char *p = (char *)buf;
4788
4789 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004790 iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07004791
4792 return strnlen(buf, count);
4793}
4794
4795static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
4796
4797/*****************************************************************************
4798 *
Tomas Winklera96a27f2008-10-23 23:48:56 -07004799 * driver setup and tear down
Zhu Yib481de92007-09-25 17:54:57 -07004800 *
4801 *****************************************************************************/
4802
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004803static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004804{
Reinette Chatred21050c2009-02-13 11:51:18 -08004805 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07004806
4807 init_waitqueue_head(&priv->wait_command_queue);
4808
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004809 INIT_WORK(&priv->up, iwl3945_bg_up);
4810 INIT_WORK(&priv->restart, iwl3945_bg_restart);
4811 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01004812 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004813 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004814 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
4815 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
Helmut Schaa26635162009-01-15 09:38:44 +01004816 INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll);
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08004817 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
4818 INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
4819 INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
4820 INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
Zhu Yib481de92007-09-25 17:54:57 -07004821
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004822 iwl3945_hw_setup_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004823
4824 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004825 iwl3945_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07004826}
4827
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004828static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004829{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004830 iwl3945_hw_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004831
Joonwoo Parke47eb6a2007-11-29 10:42:49 +09004832 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004833 cancel_delayed_work(&priv->scan_check);
4834 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004835 cancel_work_sync(&priv->beacon_update);
4836}
4837
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004838static struct attribute *iwl3945_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07004839 &dev_attr_antenna.attr,
4840 &dev_attr_channels.attr,
4841 &dev_attr_dump_errors.attr,
4842 &dev_attr_dump_events.attr,
4843 &dev_attr_flags.attr,
4844 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004845#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004846 &dev_attr_measurement.attr,
4847#endif
4848 &dev_attr_power_level.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004849 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004850 &dev_attr_statistics.attr,
4851 &dev_attr_status.attr,
4852 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004853 &dev_attr_tx_power.attr,
Samuel Ortizd08853a2009-01-23 13:45:17 -08004854#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004855 &dev_attr_debug_level.attr,
4856#endif
Zhu Yib481de92007-09-25 17:54:57 -07004857 NULL
4858};
4859
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004860static struct attribute_group iwl3945_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07004861 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004862 .attrs = iwl3945_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07004863};
4864
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004865static struct ieee80211_ops iwl3945_hw_ops = {
4866 .tx = iwl3945_mac_tx,
4867 .start = iwl3945_mac_start,
4868 .stop = iwl3945_mac_stop,
4869 .add_interface = iwl3945_mac_add_interface,
4870 .remove_interface = iwl3945_mac_remove_interface,
4871 .config = iwl3945_mac_config,
4872 .config_interface = iwl3945_mac_config_interface,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004873 .configure_filter = iwl_configure_filter,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004874 .set_key = iwl3945_mac_set_key,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004875 .get_tx_stats = iwl3945_mac_get_tx_stats,
4876 .conf_tx = iwl3945_mac_conf_tx,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004877 .reset_tsf = iwl3945_mac_reset_tsf,
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004878 .bss_info_changed = iwl3945_bss_info_changed,
Abhijeet Kolekare9dde6f62009-02-18 15:54:27 -08004879 .hw_scan = iwl_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07004880};
4881
Winkler, Tomase52119c2008-12-22 11:31:19 +08004882static int iwl3945_init_drv(struct iwl_priv *priv)
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004883{
4884 int ret;
Samuel Ortize6148912009-01-23 13:45:15 -08004885 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004886
4887 priv->retry_rate = 1;
4888 priv->ibss_beacon = NULL;
4889
4890 spin_lock_init(&priv->lock);
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08004891 spin_lock_init(&priv->power_data.lock);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004892 spin_lock_init(&priv->sta_lock);
4893 spin_lock_init(&priv->hcmd_lock);
4894
4895 INIT_LIST_HEAD(&priv->free_frames);
4896
4897 mutex_init(&priv->mutex);
4898
4899 /* Clear the driver's (not device's) station table */
4900 iwl3945_clear_stations_table(priv);
4901
4902 priv->data_retry_limit = -1;
4903 priv->ieee_channels = NULL;
4904 priv->ieee_rates = NULL;
4905 priv->band = IEEE80211_BAND_2GHZ;
4906
4907 priv->iw_mode = NL80211_IFTYPE_STATION;
4908
4909 iwl_reset_qos(priv);
4910
4911 priv->qos_data.qos_active = 0;
4912 priv->qos_data.qos_cap.val = 0;
4913
4914 priv->rates_mask = IWL_RATES_MASK;
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004915 /* If power management is turned on, default to CAM mode */
4916 priv->power_mode = IWL_POWER_MODE_CAM;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08004917 priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004918
Samuel Ortize6148912009-01-23 13:45:15 -08004919 if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
4920 IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
4921 eeprom->version);
4922 ret = -EINVAL;
4923 goto err;
4924 }
4925 ret = iwl_init_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004926 if (ret) {
4927 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
4928 goto err;
4929 }
4930
Samuel Ortize6148912009-01-23 13:45:15 -08004931 /* Set up txpower settings in driver for all channels */
4932 if (iwl3945_txpower_set_from_eeprom(priv)) {
4933 ret = -EIO;
4934 goto err_free_channel_map;
4935 }
4936
Samuel Ortiz534166d2009-01-23 13:45:16 -08004937 ret = iwlcore_init_geos(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004938 if (ret) {
4939 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
4940 goto err_free_channel_map;
4941 }
Samuel Ortiz534166d2009-01-23 13:45:16 -08004942 iwl3945_init_hw_rates(priv, priv->ieee_rates);
4943
4944 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
4945 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
4946 &priv->bands[IEEE80211_BAND_2GHZ];
4947 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
4948 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
4949 &priv->bands[IEEE80211_BAND_5GHZ];
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004950
4951 return 0;
4952
4953err_free_channel_map:
Samuel Ortize6148912009-01-23 13:45:15 -08004954 iwl_free_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004955err:
4956 return ret;
4957}
4958
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004959static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07004960{
4961 int err = 0;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004962 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07004963 struct ieee80211_hw *hw;
Kolekar, Abhijeetc0f20d92008-12-19 10:37:19 +08004964 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Samuel Ortize6148912009-01-23 13:45:15 -08004965 struct iwl3945_eeprom *eeprom;
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004966 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07004967
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004968 /***********************
4969 * 1. Allocating HW data
4970 * ********************/
4971
Zhu Yib481de92007-09-25 17:54:57 -07004972 /* mac80211 allocates memory for this device instance, including
4973 * space for this driver's private structure */
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004974 hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
Zhu Yib481de92007-09-25 17:54:57 -07004975 if (hw == NULL) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08004976 printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
Zhu Yib481de92007-09-25 17:54:57 -07004977 err = -ENOMEM;
4978 goto out;
4979 }
Zhu Yib481de92007-09-25 17:54:57 -07004980 priv = hw->priv;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004981 SET_IEEE80211_DEV(hw, &pdev->dev);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004982
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004983 if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) ||
4984 (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004985 IWL_ERR(priv,
4986 "invalid queues_num, should be between %d and %d\n",
4987 IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES);
Samuel Ortiza3139c52008-12-19 10:37:09 +08004988 err = -EINVAL;
4989 goto out;
4990 }
4991
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004992 /*
4993 * Disabling hardware scan means that mac80211 will perform scans
4994 * "the hard way", rather than using device's scan.
4995 */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004996 if (iwl3945_mod_params.disable_hw_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08004997 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004998 iwl3945_hw_ops.hw_scan = NULL;
4999 }
5000
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005001
Tomas Winklere1623442009-01-27 14:27:56 -08005002 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005003 priv->cfg = cfg;
5004 priv->pci_dev = pdev;
5005
Samuel Ortizd08853a2009-01-23 13:45:17 -08005006#ifdef CONFIG_IWLWIFI_DEBUG
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005007 priv->debug_level = iwl3945_mod_params.debug;
5008 atomic_set(&priv->restrict_refcnt, 0);
5009#endif
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005010 hw->rate_control_algorithm = "iwl-3945-rs";
5011 hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
5012
Bruno Randolf566bfe52008-05-08 19:15:40 +02005013 /* Tell mac80211 our characteristics */
Johannes Berg605a0bd2008-07-15 10:10:01 +02005014 hw->flags = IEEE80211_HW_SIGNAL_DBM |
Bruno Randolf566bfe52008-05-08 19:15:40 +02005015 IEEE80211_HW_NOISE_DBM;
Zhu Yib481de92007-09-25 17:54:57 -07005016
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -07005017 hw->wiphy->interface_modes =
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -07005018 BIT(NL80211_IFTYPE_STATION) |
5019 BIT(NL80211_IFTYPE_ADHOC);
5020
Luis R. Rodriguez2a44f912009-01-22 15:05:49 -08005021 hw->wiphy->custom_regulatory = true;
Luis R. Rodriguezea4a82dc2008-11-12 14:22:04 -08005022
Johannes Berg2a519312009-02-10 21:25:55 +01005023 hw->wiphy->max_scan_ssids = 1;
5024
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005025 /* 4 EDCA QOS priorities */
Zhu Yib481de92007-09-25 17:54:57 -07005026 hw->queues = 4;
5027
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005028 /***************************
5029 * 2. Initializing PCI bus
5030 * *************************/
Zhu Yib481de92007-09-25 17:54:57 -07005031 if (pci_enable_device(pdev)) {
5032 err = -ENODEV;
5033 goto out_ieee80211_free_hw;
5034 }
5035
5036 pci_set_master(pdev);
5037
Zhu Yib481de92007-09-25 17:54:57 -07005038 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
5039 if (!err)
5040 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
5041 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08005042 IWL_WARN(priv, "No suitable DMA available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07005043 goto out_pci_disable_device;
5044 }
5045
5046 pci_set_drvdata(pdev, priv);
5047 err = pci_request_regions(pdev, DRV_NAME);
5048 if (err)
5049 goto out_pci_disable_device;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005050
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005051 /***********************
5052 * 3. Read REV Register
5053 * ********************/
Zhu Yib481de92007-09-25 17:54:57 -07005054 priv->hw_base = pci_iomap(pdev, 0, 0);
5055 if (!priv->hw_base) {
5056 err = -ENODEV;
5057 goto out_pci_release_regions;
5058 }
5059
Tomas Winklere1623442009-01-27 14:27:56 -08005060 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Zhu Yib481de92007-09-25 17:54:57 -07005061 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08005062 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Zhu Yib481de92007-09-25 17:54:57 -07005063
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005064 /* We disable the RETRY_TIMEOUT register (0x41) to keep
5065 * PCI Tx retries from interfering with C3 CPU state */
5066 pci_write_config_byte(pdev, 0x41, 0x00);
Zhu Yib481de92007-09-25 17:54:57 -07005067
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005068 /* amp init */
5069 err = priv->cfg->ops->lib->apm_ops.init(priv);
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005070 if (err < 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08005071 IWL_DEBUG_INFO(priv, "Failed to init APMG\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005072 goto out_iounmap;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005073 }
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005074
5075 /***********************
5076 * 4. Read EEPROM
5077 * ********************/
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005078
Zhu Yi5a669262008-01-14 17:46:18 -08005079 /* Read the EEPROM */
Samuel Ortize6148912009-01-23 13:45:15 -08005080 err = iwl_eeprom_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005081 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005082 IWL_ERR(priv, "Unable to init EEPROM\n");
Zhu Yi5a669262008-01-14 17:46:18 -08005083 goto out_remove_sysfs;
5084 }
5085 /* MAC Address location in EEPROM same for 3945/4965 */
Samuel Ortize6148912009-01-23 13:45:15 -08005086 eeprom = (struct iwl3945_eeprom *)priv->eeprom;
5087 memcpy(priv->mac_addr, eeprom->mac_address, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08005088 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
Zhu Yi5a669262008-01-14 17:46:18 -08005089 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
5090
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005091 /***********************
5092 * 5. Setup HW Constants
5093 * ********************/
5094 /* Device-specific setup */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005095 if (iwl3945_hw_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005096 IWL_ERR(priv, "failed to set hw settings\n");
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005097 goto out_iounmap;
5098 }
5099
5100 /***********************
5101 * 6. Setup priv
5102 * ********************/
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005103
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005104 err = iwl3945_init_drv(priv);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005105 if (err) {
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005106 IWL_ERR(priv, "initializing driver failed\n");
5107 goto out_free_geos;
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005108 }
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005109
Tomas Winkler978785a2008-12-19 10:37:31 +08005110 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
5111 priv->cfg->name);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005112
5113 /***********************************
5114 * 7. Initialize Module Parameters
5115 * **********************************/
5116
5117 /* Initialize module parameter values here */
5118 /* Disable radio (SW RF KILL) via parameter when loading driver */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005119 if (iwl3945_mod_params.disable) {
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005120 set_bit(STATUS_RF_KILL_SW, &priv->status);
Tomas Winklere1623442009-01-27 14:27:56 -08005121 IWL_DEBUG_INFO(priv, "Radio disabled.\n");
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005122 }
5123
5124
5125 /***********************
5126 * 8. Setup Services
5127 * ********************/
5128
5129 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08005130 iwl_disable_interrupts(priv);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005131 spin_unlock_irqrestore(&priv->lock, flags);
5132
Helmut Schaa26635162009-01-15 09:38:44 +01005133 pci_enable_msi(priv->pci_dev);
5134
Abhijeet Kolekarf17d08a2009-02-18 15:54:31 -08005135 err = request_irq(priv->pci_dev->irq, iwl_isr, IRQF_SHARED,
Helmut Schaa26635162009-01-15 09:38:44 +01005136 DRV_NAME, priv);
5137 if (err) {
5138 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
5139 goto out_disable_msi;
5140 }
5141
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005142 err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
5143 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005144 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005145 goto out_release_irq;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005146 }
5147
Samuel Ortiz8ccde882009-01-27 14:27:52 -08005148 iwl_set_rxon_channel(priv,
5149 &priv->bands[IEEE80211_BAND_2GHZ].channels[5]);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005150 iwl3945_setup_deferred_work(priv);
5151 iwl3945_setup_rx_handlers(priv);
5152
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005153 /*********************************
Helmut Schaa26635162009-01-15 09:38:44 +01005154 * 9. Setup and Register mac80211
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005155 * *******************************/
5156
Zhu Yi5a669262008-01-14 17:46:18 -08005157 err = ieee80211_register_hw(priv->hw);
5158 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005159 IWL_ERR(priv, "Failed to register network device: %d\n", err);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005160 goto out_remove_sysfs;
Zhu Yib481de92007-09-25 17:54:57 -07005161 }
5162
Zhu Yi5a669262008-01-14 17:46:18 -08005163 priv->hw->conf.beacon_int = 100;
5164 priv->mac80211_registered = 1;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005165
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005166 err = iwl_rfkill_init(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005167 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08005168 IWL_ERR(priv, "Unable to initialize RFKILL system. "
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005169 "Ignoring error: %d\n", err);
5170
Helmut Schaa26635162009-01-15 09:38:44 +01005171 /* Start monitoring the killswitch */
5172 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
5173 2 * HZ);
5174
Zhu Yib481de92007-09-25 17:54:57 -07005175 return 0;
5176
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005177 out_remove_sysfs:
5178 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005179 out_free_geos:
Samuel Ortiz534166d2009-01-23 13:45:16 -08005180 iwlcore_free_geos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005181
5182 out_release_irq:
Helmut Schaa26635162009-01-15 09:38:44 +01005183 free_irq(priv->pci_dev->irq, priv);
Zhu Yib481de92007-09-25 17:54:57 -07005184 destroy_workqueue(priv->workqueue);
5185 priv->workqueue = NULL;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005186 iwl3945_unset_hw_params(priv);
Helmut Schaa26635162009-01-15 09:38:44 +01005187 out_disable_msi:
5188 pci_disable_msi(priv->pci_dev);
Zhu Yib481de92007-09-25 17:54:57 -07005189 out_iounmap:
5190 pci_iounmap(pdev, priv->hw_base);
5191 out_pci_release_regions:
5192 pci_release_regions(pdev);
5193 out_pci_disable_device:
5194 pci_disable_device(pdev);
5195 pci_set_drvdata(pdev, NULL);
5196 out_ieee80211_free_hw:
5197 ieee80211_free_hw(priv->hw);
5198 out:
5199 return err;
5200}
5201
Reinette Chatrec83dbf62008-03-21 13:53:41 -07005202static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07005203{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005204 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005205 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07005206
5207 if (!priv)
5208 return;
5209
Tomas Winklere1623442009-01-27 14:27:56 -08005210 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07005211
Zhu Yib481de92007-09-25 17:54:57 -07005212 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08005213
Kolekar, Abhijeetd552bfb2008-12-19 10:37:41 +08005214 if (priv->mac80211_registered) {
5215 ieee80211_unregister_hw(priv->hw);
5216 priv->mac80211_registered = 0;
5217 } else {
5218 iwl3945_down(priv);
5219 }
Zhu Yib481de92007-09-25 17:54:57 -07005220
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005221 /* make sure we flush any pending irq or
5222 * tasklet for the driver
5223 */
5224 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08005225 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005226 spin_unlock_irqrestore(&priv->lock, flags);
5227
5228 iwl_synchronize_irq(priv);
5229
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005230 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07005231
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005232 iwl_rfkill_unregister(priv);
Helmut Schaa26635162009-01-15 09:38:44 +01005233 cancel_delayed_work(&priv->rfkill_poll);
5234
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005235 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005236
5237 if (priv->rxq.bd)
Winkler, Tomas51af3d32008-12-22 11:31:23 +08005238 iwl_rx_queue_free(priv, &priv->rxq);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005239 iwl3945_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005240
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005241 iwl3945_unset_hw_params(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005242 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005243
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08005244 /*netif_stop_queue(dev); */
5245 flush_workqueue(priv->workqueue);
5246
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005247 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07005248 * priv->workqueue... so we can't take down the workqueue
5249 * until now... */
5250 destroy_workqueue(priv->workqueue);
5251 priv->workqueue = NULL;
5252
Helmut Schaa26635162009-01-15 09:38:44 +01005253 free_irq(pdev->irq, priv);
5254 pci_disable_msi(pdev);
5255
Zhu Yib481de92007-09-25 17:54:57 -07005256 pci_iounmap(pdev, priv->hw_base);
5257 pci_release_regions(pdev);
5258 pci_disable_device(pdev);
5259 pci_set_drvdata(pdev, NULL);
5260
Samuel Ortize6148912009-01-23 13:45:15 -08005261 iwl_free_channel_map(priv);
Samuel Ortiz534166d2009-01-23 13:45:16 -08005262 iwlcore_free_geos(priv);
Winkler, Tomas805cee52009-01-19 15:30:28 -08005263 kfree(priv->scan);
Zhu Yib481de92007-09-25 17:54:57 -07005264 if (priv->ibss_beacon)
5265 dev_kfree_skb(priv->ibss_beacon);
5266
5267 ieee80211_free_hw(priv->hw);
5268}
5269
5270#ifdef CONFIG_PM
5271
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005272static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07005273{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005274 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005275
Zhu Yie655b9f2008-01-24 02:19:38 -08005276 if (priv->is_open) {
5277 set_bit(STATUS_IN_SUSPEND, &priv->status);
5278 iwl3945_mac_stop(priv->hw);
5279 priv->is_open = 1;
5280 }
Helmut Schaa26635162009-01-15 09:38:44 +01005281 pci_save_state(pdev);
5282 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005283 pci_set_power_state(pdev, PCI_D3hot);
5284
Zhu Yib481de92007-09-25 17:54:57 -07005285 return 0;
5286}
5287
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005288static int iwl3945_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07005289{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005290 struct iwl_priv *priv = pci_get_drvdata(pdev);
Winkler, Tomas450154e2009-01-27 14:27:55 -08005291 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07005292
Zhu Yib481de92007-09-25 17:54:57 -07005293 pci_set_power_state(pdev, PCI_D0);
Winkler, Tomas450154e2009-01-27 14:27:55 -08005294 ret = pci_enable_device(pdev);
5295 if (ret)
5296 return ret;
Helmut Schaa26635162009-01-15 09:38:44 +01005297 pci_restore_state(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005298
Zhu Yie655b9f2008-01-24 02:19:38 -08005299 if (priv->is_open)
5300 iwl3945_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07005301
Zhu Yie655b9f2008-01-24 02:19:38 -08005302 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07005303 return 0;
5304}
5305
5306#endif /* CONFIG_PM */
5307
5308/*****************************************************************************
5309 *
5310 * driver and module entry point
5311 *
5312 *****************************************************************************/
5313
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005314static struct pci_driver iwl3945_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07005315 .name = DRV_NAME,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005316 .id_table = iwl3945_hw_card_ids,
5317 .probe = iwl3945_pci_probe,
5318 .remove = __devexit_p(iwl3945_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07005319#ifdef CONFIG_PM
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005320 .suspend = iwl3945_pci_suspend,
5321 .resume = iwl3945_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07005322#endif
5323};
5324
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005325static int __init iwl3945_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07005326{
5327
5328 int ret;
5329 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
5330 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005331
5332 ret = iwl3945_rate_control_register();
5333 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005334 printk(KERN_ERR DRV_NAME
5335 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005336 return ret;
5337 }
5338
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005339 ret = pci_register_driver(&iwl3945_driver);
Zhu Yib481de92007-09-25 17:54:57 -07005340 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005341 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005342 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07005343 }
Zhu Yib481de92007-09-25 17:54:57 -07005344
5345 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005346
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005347error_register:
5348 iwl3945_rate_control_unregister();
5349 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07005350}
5351
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005352static void __exit iwl3945_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07005353{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005354 pci_unregister_driver(&iwl3945_driver);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005355 iwl3945_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07005356}
5357
Reinette Chatrea0987a82008-12-02 12:14:06 -08005358MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
Zhu Yi25cb6ca2008-09-11 11:45:22 +08005359
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005360module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005361MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005362module_param_named(disable, iwl3945_mod_params.disable, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005363MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -08005364module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
5365MODULE_PARM_DESC(swcrypto,
5366 "using software crypto (default 1 [software])\n");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005367module_param_named(debug, iwl3945_mod_params.debug, uint, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005368MODULE_PARM_DESC(debug, "debug output mask");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005369module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005370MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
5371
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005372module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005373MODULE_PARM_DESC(queues_num, "number of hw queues.");
5374
Samuel Ortizaf48d042009-01-23 13:45:19 -08005375module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, 0444);
5376MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error");
5377
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005378module_exit(iwl3945_exit);
5379module_init(iwl3945_init);