blob: 97f8322e0661433466bc1e5d62f91410f796a8a3 [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
Zhu Yib481de92007-09-25 17:54:57 -070043#include <net/mac80211.h>
44
45#include <asm/div64.h>
46
Samuel Ortiza3139c52008-12-19 10:37:09 +080047#define DRV_NAME "iwlagn"
48
Assaf Krauss6bc913b2008-03-11 16:17:18 -070049#include "iwl-eeprom.h"
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070050#include "iwl-dev.h"
Tomas Winklerfee12472008-04-03 16:05:21 -070051#include "iwl-core.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070052#include "iwl-io.h"
Zhu Yib481de92007-09-25 17:54:57 -070053#include "iwl-helpers.h"
Emmanuel Grumbach6974e362008-04-14 21:16:06 -070054#include "iwl-sta.h"
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -070055#include "iwl-calib.h"
Zhu Yib481de92007-09-25 17:54:57 -070056
Christoph Hellwig416e1432007-10-25 17:15:49 +080057
Zhu Yib481de92007-09-25 17:54:57 -070058/******************************************************************************
59 *
60 * module boiler plate
61 *
62 ******************************************************************************/
63
Zhu Yib481de92007-09-25 17:54:57 -070064/*
65 * module name, copyright, version, etc.
Zhu Yib481de92007-09-25 17:54:57 -070066 */
Tomas Winklerd783b062008-07-18 13:53:02 +080067#define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
Zhu Yib481de92007-09-25 17:54:57 -070068
Tomas Winkler0a6857e2008-03-12 16:58:49 -070069#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070070#define VD "d"
71#else
72#define VD
73#endif
74
Reinette Chatre80bc5392009-02-13 11:51:19 -080075#ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -070076#define VS "s"
77#else
78#define VS
79#endif
80
Tomas Winklerdf48c322008-03-06 10:40:19 -080081#define DRV_VERSION IWLWIFI_VERSION VD VS
Zhu Yib481de92007-09-25 17:54:57 -070082
Zhu Yib481de92007-09-25 17:54:57 -070083
84MODULE_DESCRIPTION(DRV_DESCRIPTION);
85MODULE_VERSION(DRV_VERSION);
Tomas Winklera7b75202008-12-11 10:33:41 -080086MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
Zhu Yib481de92007-09-25 17:54:57 -070087MODULE_LICENSE("GPL");
Tomas Winkler4fc22b22008-07-21 18:54:42 +030088MODULE_ALIAS("iwl4965");
Zhu Yib481de92007-09-25 17:54:57 -070089
Zhu Yib481de92007-09-25 17:54:57 -070090/*************** STATION TABLE MANAGEMENT ****
Ben Cahill9fbab512007-11-29 11:09:47 +080091 * mac80211 should be examined to determine if sta_info is duplicating
Zhu Yib481de92007-09-25 17:54:57 -070092 * the functionality provided here
93 */
94
95/**************************************************************/
96
Zhu Yib481de92007-09-25 17:54:57 -070097/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -070098 * iwl_commit_rxon - commit staging_rxon to hardware
Zhu Yib481de92007-09-25 17:54:57 -070099 *
Ian Schram01ebd062007-10-25 17:15:22 +0800100 * The RXON command in staging_rxon is committed to the hardware and
Zhu Yib481de92007-09-25 17:54:57 -0700101 * the active_rxon structure is updated with the new data. This
102 * function correctly transitions out of the RXON_ASSOC_MSK state if
103 * a HW tune is required based on the RXON structure changes.
104 */
Abhijeet Kolekare0158e62009-04-08 11:26:37 -0700105int iwl_commit_rxon(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700106{
107 /* cast away the const for active_rxon in this function */
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800108 struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800109 int ret;
110 bool new_assoc =
111 !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK);
Zhu Yib481de92007-09-25 17:54:57 -0700112
Tomas Winklerfee12472008-04-03 16:05:21 -0700113 if (!iwl_is_alive(priv))
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800114 return -EBUSY;
Zhu Yib481de92007-09-25 17:54:57 -0700115
116 /* always get timestamp with Rx frame */
117 priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
Emmanuel Grumbacha326a5d2008-07-11 11:53:31 +0800118 /* allow CTS-to-self if possible. this is relevant only for
119 * 5000, but will not damage 4965 */
120 priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN;
Zhu Yib481de92007-09-25 17:54:57 -0700121
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800122 ret = iwl_check_rxon_cmd(priv);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800123 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800124 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700125 return -EINVAL;
126 }
127
128 /* If we don't need to send a full RXON, we can use
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700129 * iwl_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -0700130 * and other flags for the current radio configuration. */
Mohamed Abbas54559702008-09-03 11:18:44 +0800131 if (!iwl_full_rxon_required(priv)) {
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800132 ret = iwl_send_rxon_assoc(priv);
133 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800134 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800135 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700136 }
137
138 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700139 return 0;
140 }
141
142 /* station table will be cleared */
143 priv->assoc_station_added = 0;
144
Zhu Yib481de92007-09-25 17:54:57 -0700145 /* If we are currently associated and the new config requires
146 * an RXON_ASSOC and the new config wants the associated mask enabled,
147 * we must clear the associated from the active configuration
148 * before we apply the new config */
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800149 if (iwl_is_associated(priv) && new_assoc) {
Tomas Winklere1623442009-01-27 14:27:56 -0800150 IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
Zhu Yib481de92007-09-25 17:54:57 -0700151 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
152
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800153 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800154 sizeof(struct iwl_rxon_cmd),
Zhu Yib481de92007-09-25 17:54:57 -0700155 &priv->active_rxon);
156
157 /* If the mask clearing failed then we set
158 * active_rxon back to what it was previously */
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800159 if (ret) {
Zhu Yib481de92007-09-25 17:54:57 -0700160 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
Winkler, Tomas15b16872008-12-19 10:37:33 +0800161 IWL_ERR(priv, "Error clearing ASSOC_MSK (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800162 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700163 }
Zhu Yib481de92007-09-25 17:54:57 -0700164 }
165
Tomas Winklere1623442009-01-27 14:27:56 -0800166 IWL_DEBUG_INFO(priv, "Sending RXON\n"
Zhu Yib481de92007-09-25 17:54:57 -0700167 "* with%s RXON_FILTER_ASSOC_MSK\n"
168 "* channel = %d\n"
Johannes Berge1749612008-10-27 15:59:26 -0700169 "* bssid = %pM\n",
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800170 (new_assoc ? "" : "out"),
Zhu Yib481de92007-09-25 17:54:57 -0700171 le16_to_cpu(priv->staging_rxon.channel),
Johannes Berge1749612008-10-27 15:59:26 -0700172 priv->staging_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -0700173
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700174 iwl_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800175
176 /* Apply the new configuration
177 * RXON unassoc clears the station table in uCode, send it before
178 * we add the bcast station. If assoc bit is set, we will send RXON
179 * after having added the bcast and bssid station.
180 */
181 if (!new_assoc) {
182 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800183 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800184 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800185 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800186 return ret;
187 }
188 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700189 }
190
Abhijeet Kolekare11bc022009-04-08 11:26:41 -0700191 priv->cfg->ops->smgmt->clear_station_table(priv);
Zhu Yi556f8db2007-09-27 11:27:33 +0800192
Zhu Yib481de92007-09-25 17:54:57 -0700193 if (!priv->error_recovering)
194 priv->start_calib = 0;
195
Zhu Yib481de92007-09-25 17:54:57 -0700196 /* Add the broadcast address so we can send broadcast frames */
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800197 if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) ==
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800198 IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800199 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700200 return -EIO;
201 }
202
203 /* If we have set the ASSOC_MSK and we are in BSS mode then
204 * add the IWL_AP_ID to the station rate table */
Tomas Winkler91851592008-06-30 17:23:14 +0800205 if (new_assoc) {
Johannes Berg05c914fe2008-09-11 00:01:58 +0200206 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Tomas Winkler91851592008-06-30 17:23:14 +0800207 ret = iwl_rxon_add_station(priv,
208 priv->active_rxon.bssid_addr, 1);
209 if (ret == IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800210 IWL_ERR(priv,
211 "Error adding AP address for TX.\n");
Tomas Winkler91851592008-06-30 17:23:14 +0800212 return -EIO;
213 }
214 priv->assoc_station_added = 1;
215 if (priv->default_wep_key &&
216 iwl_send_static_wepkey_cmd(priv, 0))
Winkler, Tomas15b16872008-12-19 10:37:33 +0800217 IWL_ERR(priv,
218 "Could not send WEP static key.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700219 }
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800220
221 /* Apply the new configuration
222 * RXON assoc doesn't clear the station table in uCode,
223 */
224 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
225 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
226 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800227 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800228 return ret;
229 }
230 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700231 }
232
Zhu Yi36da7d72008-07-11 11:53:40 +0800233 iwl_init_sensitivity(priv);
234
235 /* If we issue a new RXON command which required a tune then we must
236 * send a new TXPOWER command or we won't be able to Tx any frames */
237 ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
238 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800239 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
Zhu Yi36da7d72008-07-11 11:53:40 +0800240 return ret;
241 }
242
Zhu Yib481de92007-09-25 17:54:57 -0700243 return 0;
244}
245
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700246void iwl_update_chain_flags(struct iwl_priv *priv)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700247{
248
Abhijeet Kolekar45823532009-04-08 11:26:44 -0700249 if (priv->cfg->ops->hcmd->set_rxon_chain)
250 priv->cfg->ops->hcmd->set_rxon_chain(priv);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -0700251 iwlcore_commit_rxon(priv);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700252}
253
Tomas Winklerfcab4232008-05-15 13:54:01 +0800254static void iwl_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700255{
256 struct list_head *element;
257
Tomas Winklere1623442009-01-27 14:27:56 -0800258 IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
Zhu Yib481de92007-09-25 17:54:57 -0700259 priv->frames_count);
260
261 while (!list_empty(&priv->free_frames)) {
262 element = priv->free_frames.next;
263 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800264 kfree(list_entry(element, struct iwl_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700265 priv->frames_count--;
266 }
267
268 if (priv->frames_count) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800269 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
Zhu Yib481de92007-09-25 17:54:57 -0700270 priv->frames_count);
271 priv->frames_count = 0;
272 }
273}
274
Tomas Winklerfcab4232008-05-15 13:54:01 +0800275static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700276{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800277 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700278 struct list_head *element;
279 if (list_empty(&priv->free_frames)) {
280 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
281 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800282 IWL_ERR(priv, "Could not allocate frame!\n");
Zhu Yib481de92007-09-25 17:54:57 -0700283 return NULL;
284 }
285
286 priv->frames_count++;
287 return frame;
288 }
289
290 element = priv->free_frames.next;
291 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800292 return list_entry(element, struct iwl_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700293}
294
Tomas Winklerfcab4232008-05-15 13:54:01 +0800295static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700296{
297 memset(frame, 0, sizeof(*frame));
298 list_add(&frame->list, &priv->free_frames);
299}
300
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800301static unsigned int iwl_fill_beacon_frame(struct iwl_priv *priv,
302 struct ieee80211_hdr *hdr,
Rami Rosen73ec1cc2008-12-16 09:37:07 +0200303 int left)
Zhu Yib481de92007-09-25 17:54:57 -0700304{
Tomas Winkler3109ece2008-03-28 16:33:35 -0700305 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
Johannes Berg05c914fe2008-09-11 00:01:58 +0200306 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
307 (priv->iw_mode != NL80211_IFTYPE_AP)))
Zhu Yib481de92007-09-25 17:54:57 -0700308 return 0;
309
310 if (priv->ibss_beacon->len > left)
311 return 0;
312
313 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
314
315 return priv->ibss_beacon->len;
316}
317
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700318static unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800319 struct iwl_frame *frame, u8 rate)
320{
321 struct iwl_tx_beacon_cmd *tx_beacon_cmd;
322 unsigned int frame_size;
323
324 tx_beacon_cmd = &frame->u.beacon;
325 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
326
327 tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id;
328 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
329
330 frame_size = iwl_fill_beacon_frame(priv, tx_beacon_cmd->frame,
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800331 sizeof(frame->u) - sizeof(*tx_beacon_cmd));
332
333 BUG_ON(frame_size > MAX_MPDU_SIZE);
334 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
335
336 if ((rate == IWL_RATE_1M_PLCP) || (rate >= IWL_RATE_2M_PLCP))
337 tx_beacon_cmd->tx.rate_n_flags =
338 iwl_hw_set_rate_n_flags(rate, RATE_MCS_CCK_MSK);
339 else
340 tx_beacon_cmd->tx.rate_n_flags =
341 iwl_hw_set_rate_n_flags(rate, 0);
342
343 tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
344 TX_CMD_FLG_TSF_MSK |
345 TX_CMD_FLG_STA_RATE_MSK;
346
347 return sizeof(*tx_beacon_cmd) + frame_size;
348}
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700349static int iwl_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700350{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800351 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700352 unsigned int frame_size;
353 int rc;
354 u8 rate;
355
Tomas Winklerfcab4232008-05-15 13:54:01 +0800356 frame = iwl_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700357
358 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800359 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
Zhu Yib481de92007-09-25 17:54:57 -0700360 "command.\n");
361 return -ENOMEM;
362 }
363
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700364 rate = iwl_rate_get_lowest_plcp(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700365
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700366 frame_size = iwl_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -0700367
Tomas Winkler857485c2008-03-21 13:53:44 -0700368 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700369 &frame->u.cmd[0]);
370
Tomas Winklerfcab4232008-05-15 13:54:01 +0800371 iwl_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700372
373 return rc;
374}
375
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800376static inline dma_addr_t iwl_tfd_tb_get_addr(struct iwl_tfd *tfd, u8 idx)
377{
378 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
379
380 dma_addr_t addr = get_unaligned_le32(&tb->lo);
381 if (sizeof(dma_addr_t) > sizeof(u32))
382 addr |=
383 ((dma_addr_t)(le16_to_cpu(tb->hi_n_len) & 0xF) << 16) << 16;
384
385 return addr;
386}
387
388static inline u16 iwl_tfd_tb_get_len(struct iwl_tfd *tfd, u8 idx)
389{
390 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
391
392 return le16_to_cpu(tb->hi_n_len) >> 4;
393}
394
395static inline void iwl_tfd_set_tb(struct iwl_tfd *tfd, u8 idx,
396 dma_addr_t addr, u16 len)
397{
398 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
399 u16 hi_n_len = len << 4;
400
401 put_unaligned_le32(addr, &tb->lo);
402 if (sizeof(dma_addr_t) > sizeof(u32))
403 hi_n_len |= ((addr >> 16) >> 16) & 0xF;
404
405 tb->hi_n_len = cpu_to_le16(hi_n_len);
406
407 tfd->num_tbs = idx + 1;
408}
409
410static inline u8 iwl_tfd_get_num_tbs(struct iwl_tfd *tfd)
411{
412 return tfd->num_tbs & 0x1f;
413}
414
415/**
416 * iwl_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
417 * @priv - driver private data
418 * @txq - tx queue
419 *
420 * Does NOT advance any TFD circular buffer read/write indexes
421 * Does NOT free the TFD itself (which is within circular buffer)
422 */
423void iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq)
424{
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800425 struct iwl_tfd *tfd_tmp = (struct iwl_tfd *)txq->tfds;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800426 struct iwl_tfd *tfd;
427 struct pci_dev *dev = priv->pci_dev;
428 int index = txq->q.read_ptr;
429 int i;
430 int num_tbs;
431
432 tfd = &tfd_tmp[index];
433
434 /* Sanity check on number of chunks */
435 num_tbs = iwl_tfd_get_num_tbs(tfd);
436
437 if (num_tbs >= IWL_NUM_OF_TBS) {
438 IWL_ERR(priv, "Too many chunks: %i\n", num_tbs);
439 /* @todo issue fatal error, it is quite serious situation */
440 return;
441 }
442
443 /* Unmap tx_cmd */
444 if (num_tbs)
445 pci_unmap_single(dev,
446 pci_unmap_addr(&txq->cmd[index]->meta, mapping),
447 pci_unmap_len(&txq->cmd[index]->meta, len),
Fenghua Yu96891ce2009-02-18 15:54:33 -0800448 PCI_DMA_BIDIRECTIONAL);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800449
450 /* Unmap chunks, if any. */
451 for (i = 1; i < num_tbs; i++) {
452 pci_unmap_single(dev, iwl_tfd_tb_get_addr(tfd, i),
453 iwl_tfd_tb_get_len(tfd, i), PCI_DMA_TODEVICE);
454
455 if (txq->txb) {
456 dev_kfree_skb(txq->txb[txq->q.read_ptr].skb[i - 1]);
457 txq->txb[txq->q.read_ptr].skb[i - 1] = NULL;
458 }
459 }
460}
461
462int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv,
463 struct iwl_tx_queue *txq,
464 dma_addr_t addr, u16 len,
465 u8 reset, u8 pad)
466{
467 struct iwl_queue *q;
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800468 struct iwl_tfd *tfd, *tfd_tmp;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800469 u32 num_tbs;
470
471 q = &txq->q;
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800472 tfd_tmp = (struct iwl_tfd *)txq->tfds;
473 tfd = &tfd_tmp[q->write_ptr];
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800474
475 if (reset)
476 memset(tfd, 0, sizeof(*tfd));
477
478 num_tbs = iwl_tfd_get_num_tbs(tfd);
479
480 /* Each TFD can point to a maximum 20 Tx buffers */
481 if (num_tbs >= IWL_NUM_OF_TBS) {
482 IWL_ERR(priv, "Error can not send more than %d chunks\n",
483 IWL_NUM_OF_TBS);
484 return -EINVAL;
485 }
486
487 BUG_ON(addr & ~DMA_BIT_MASK(36));
488 if (unlikely(addr & ~IWL_TX_DMA_MASK))
489 IWL_ERR(priv, "Unaligned address = %llx\n",
490 (unsigned long long)addr);
491
492 iwl_tfd_set_tb(tfd, num_tbs, addr, len);
493
494 return 0;
495}
496
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800497/*
498 * Tell nic where to find circular buffer of Tx Frame Descriptors for
499 * given Tx queue, and enable the DMA channel used for that queue.
500 *
501 * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
502 * channels supported in hardware.
503 */
504int iwl_hw_tx_queue_init(struct iwl_priv *priv,
505 struct iwl_tx_queue *txq)
506{
507 int ret;
508 unsigned long flags;
509 int txq_id = txq->q.id;
510
511 spin_lock_irqsave(&priv->lock, flags);
512 ret = iwl_grab_nic_access(priv);
513 if (ret) {
514 spin_unlock_irqrestore(&priv->lock, flags);
515 return ret;
516 }
517
518 /* Circular buffer (TFD queue in DRAM) physical base address */
519 iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id),
520 txq->q.dma_addr >> 8);
521
522 iwl_release_nic_access(priv);
523 spin_unlock_irqrestore(&priv->lock, flags);
524
525 return 0;
526}
527
528
Zhu Yib481de92007-09-25 17:54:57 -0700529/******************************************************************************
530 *
Zhu Yib481de92007-09-25 17:54:57 -0700531 * Misc. internal state and helper functions
532 *
533 ******************************************************************************/
Zhu Yib481de92007-09-25 17:54:57 -0700534
Zhu Yib481de92007-09-25 17:54:57 -0700535#define MAX_UCODE_BEACON_INTERVAL 4096
Zhu Yib481de92007-09-25 17:54:57 -0700536
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800537static u16 iwl_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -0700538{
539 u16 new_val = 0;
540 u16 beacon_factor = 0;
541
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800542 beacon_factor = (beacon_val + MAX_UCODE_BEACON_INTERVAL)
543 / MAX_UCODE_BEACON_INTERVAL;
Zhu Yib481de92007-09-25 17:54:57 -0700544 new_val = beacon_val / beacon_factor;
545
John W. Linville41d2f292009-02-20 19:03:31 -0500546 if (!new_val)
547 new_val = MAX_UCODE_BEACON_INTERVAL;
548
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800549 return new_val;
Zhu Yib481de92007-09-25 17:54:57 -0700550}
551
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800552static void iwl_setup_rxon_timing(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700553{
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800554 u64 tsf;
555 s32 interval_tm, rem;
Zhu Yib481de92007-09-25 17:54:57 -0700556 unsigned long flags;
557 struct ieee80211_conf *conf = NULL;
558 u16 beacon_int = 0;
559
560 conf = ieee80211_get_hw_conf(priv->hw);
561
562 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800563 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
Tomas Winklerb5d7be52008-07-19 04:41:24 +0300564 priv->rxon_timing.listen_interval = cpu_to_le16(conf->listen_interval);
Zhu Yib481de92007-09-25 17:54:57 -0700565
Johannes Berg05c914fe2008-09-11 00:01:58 +0200566 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800567 beacon_int = iwl_adjust_beacon_interval(priv->beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -0700568 priv->rxon_timing.atim_window = 0;
569 } else {
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800570 beacon_int = iwl_adjust_beacon_interval(conf->beacon_int);
571
Zhu Yib481de92007-09-25 17:54:57 -0700572 /* TODO: we need to get atim_window from upper stack
573 * for now we set to 0 */
574 priv->rxon_timing.atim_window = 0;
575 }
576
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800577 priv->rxon_timing.beacon_interval = cpu_to_le16(beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -0700578
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800579 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
580 interval_tm = beacon_int * 1024;
581 rem = do_div(tsf, interval_tm);
582 priv->rxon_timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
583
584 spin_unlock_irqrestore(&priv->lock, flags);
Tomas Winklere1623442009-01-27 14:27:56 -0800585 IWL_DEBUG_ASSOC(priv, "beacon interval %d beacon timer %d beacon tim %d\n",
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800586 le16_to_cpu(priv->rxon_timing.beacon_interval),
587 le32_to_cpu(priv->rxon_timing.beacon_init_val),
588 le16_to_cpu(priv->rxon_timing.atim_window));
Zhu Yib481de92007-09-25 17:54:57 -0700589}
590
Zhu Yib481de92007-09-25 17:54:57 -0700591/******************************************************************************
592 *
593 * Generic RX handler implementations
594 *
595 ******************************************************************************/
Tomas Winkler885ba202008-05-29 16:34:55 +0800596static void iwl_rx_reply_alive(struct iwl_priv *priv,
597 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700598{
Tomas Winklerdb11d632008-05-05 10:22:33 +0800599 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Tomas Winkler885ba202008-05-29 16:34:55 +0800600 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -0700601 struct delayed_work *pwork;
602
603 palive = &pkt->u.alive_frame;
604
Tomas Winklere1623442009-01-27 14:27:56 -0800605 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
Zhu Yib481de92007-09-25 17:54:57 -0700606 "0x%01X 0x%01X\n",
607 palive->is_valid, palive->ver_type,
608 palive->ver_subtype);
609
610 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
Tomas Winklere1623442009-01-27 14:27:56 -0800611 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700612 memcpy(&priv->card_alive_init,
613 &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +0800614 sizeof(struct iwl_init_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700615 pwork = &priv->init_alive_start;
616 } else {
Tomas Winklere1623442009-01-27 14:27:56 -0800617 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700618 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +0800619 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700620 pwork = &priv->alive_start;
621 }
622
623 /* We delay the ALIVE response by 5ms to
624 * give the HW RF Kill time to activate... */
625 if (palive->is_valid == UCODE_VALID_OK)
626 queue_delayed_work(priv->workqueue, pwork,
627 msecs_to_jiffies(5));
628 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800629 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700630}
631
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700632static void iwl_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -0700633{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700634 struct iwl_priv *priv =
635 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -0700636 struct sk_buff *beacon;
637
638 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +0200639 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -0700640
641 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800642 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -0700643 return;
644 }
645
646 mutex_lock(&priv->mutex);
647 /* new beacon skb is allocated every time; dispose previous.*/
648 if (priv->ibss_beacon)
649 dev_kfree_skb(priv->ibss_beacon);
650
651 priv->ibss_beacon = beacon;
652 mutex_unlock(&priv->mutex);
653
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700654 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700655}
656
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800657/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700658 * iwl_bg_statistics_periodic - Timer callback to queue statistics
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800659 *
660 * This callback is provided in order to send a statistics request.
661 *
662 * This timer function is continually reset to execute within
663 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
664 * was received. We need to ensure we receive the statistics in order
665 * to update the temperature used for calibrating the TXPOWER.
666 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700667static void iwl_bg_statistics_periodic(unsigned long data)
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800668{
669 struct iwl_priv *priv = (struct iwl_priv *)data;
670
671 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
672 return;
673
Mohamed Abbas61780ee2008-10-29 14:05:49 -0700674 /* dont send host command if rf-kill is on */
675 if (!iwl_is_ready_rf(priv))
676 return;
677
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800678 iwl_send_statistics_request(priv, CMD_ASYNC);
679}
680
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700681static void iwl_rx_beacon_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +0800682 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700683{
Tomas Winkler0a6857e2008-03-12 16:58:49 -0700684#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklerdb11d632008-05-05 10:22:33 +0800685 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Tomas Winkler2aa6ab82008-12-11 10:33:40 -0800686 struct iwl4965_beacon_notif *beacon =
687 (struct iwl4965_beacon_notif *)pkt->u.raw;
Tomas Winklere7d326a2008-06-12 09:47:11 +0800688 u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -0700689
Tomas Winklere1623442009-01-27 14:27:56 -0800690 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
Zhu Yib481de92007-09-25 17:54:57 -0700691 "tsf %d %d rate %d\n",
Tomas Winkler25a65722008-06-12 09:47:07 +0800692 le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
Zhu Yib481de92007-09-25 17:54:57 -0700693 beacon->beacon_notify_hdr.failure_frame,
694 le32_to_cpu(beacon->ibss_mgr_status),
695 le32_to_cpu(beacon->high_tsf),
696 le32_to_cpu(beacon->low_tsf), rate);
697#endif
698
Johannes Berg05c914fe2008-09-11 00:01:58 +0200699 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -0700700 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
701 queue_work(priv->workqueue, &priv->beacon_update);
702}
703
Zhu Yib481de92007-09-25 17:54:57 -0700704/* Handle notification from uCode that card's power state is changing
705 * due to software, hardware, or critical temperature RFKILL */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700706static void iwl_rx_card_state_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +0800707 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700708{
Tomas Winklerdb11d632008-05-05 10:22:33 +0800709 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700710 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
711 unsigned long status = priv->status;
712
Tomas Winklere1623442009-01-27 14:27:56 -0800713 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n",
Zhu Yib481de92007-09-25 17:54:57 -0700714 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
715 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
716
717 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
718 RF_CARD_DISABLED)) {
719
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700720 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -0700721 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
722
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700723 if (!iwl_grab_nic_access(priv)) {
724 iwl_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -0700725 priv, HBUS_TARG_MBX_C,
726 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
727
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700728 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700729 }
730
731 if (!(flags & RXON_CARD_DISABLED)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700732 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -0700733 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700734 if (!iwl_grab_nic_access(priv)) {
735 iwl_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -0700736 priv, HBUS_TARG_MBX_C,
737 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
738
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700739 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700740 }
741 }
742
743 if (flags & RF_CARD_DISABLED) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700744 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -0700745 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700746 iwl_read32(priv, CSR_UCODE_DRV_GP1);
747 if (!iwl_grab_nic_access(priv))
748 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700749 }
750 }
751
752 if (flags & HW_CARD_DISABLED)
753 set_bit(STATUS_RF_KILL_HW, &priv->status);
754 else
755 clear_bit(STATUS_RF_KILL_HW, &priv->status);
756
757
758 if (flags & SW_CARD_DISABLED)
759 set_bit(STATUS_RF_KILL_SW, &priv->status);
760 else
761 clear_bit(STATUS_RF_KILL_SW, &priv->status);
762
763 if (!(flags & RXON_CARD_DISABLED))
Tomas Winkler2a421b92008-06-12 09:47:10 +0800764 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700765
766 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
767 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
768 (test_bit(STATUS_RF_KILL_SW, &status) !=
769 test_bit(STATUS_RF_KILL_SW, &priv->status)))
770 queue_work(priv->workqueue, &priv->rf_kill);
771 else
772 wake_up_interruptible(&priv->wait_command_queue);
773}
774
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700775int iwl_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
Tomas Winklere2e3c572008-07-18 13:53:04 +0800776{
777 int ret;
778 unsigned long flags;
779
780 spin_lock_irqsave(&priv->lock, flags);
781 ret = iwl_grab_nic_access(priv);
782 if (ret)
783 goto err;
784
785 if (src == IWL_PWR_SRC_VAUX) {
Tomas Winkler3fdb68d2009-02-10 15:19:02 -0800786 if (pci_pme_capable(priv->pci_dev, PCI_D3cold))
Tomas Winklere2e3c572008-07-18 13:53:04 +0800787 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
788 APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
789 ~APMG_PS_CTRL_MSK_PWR_SRC);
790 } else {
791 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
792 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
793 ~APMG_PS_CTRL_MSK_PWR_SRC);
794 }
795
796 iwl_release_nic_access(priv);
797err:
798 spin_unlock_irqrestore(&priv->lock, flags);
799 return ret;
800}
801
Zhu Yib481de92007-09-25 17:54:57 -0700802/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700803 * iwl_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -0700804 *
805 * Setup the RX handlers for each of the reply types sent from the uCode
806 * to the host.
807 *
808 * This function chains into the hardware specific files for them to setup
809 * any hardware specific handlers as well.
810 */
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +0800811static void iwl_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700812{
Tomas Winkler885ba202008-05-29 16:34:55 +0800813 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700814 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
815 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700816 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700817 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700818 iwl_rx_pm_debug_statistics_notif;
819 priv->rx_handlers[BEACON_NOTIFICATION] = iwl_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700820
Ben Cahill9fbab512007-11-29 11:09:47 +0800821 /*
822 * The same handler is used for both the REPLY to a discrete
823 * statistics request from the host as well as for the periodic
824 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -0700825 */
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +0800826 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_rx_statistics;
827 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
Tomas Winkler2a421b92008-06-12 09:47:10 +0800828
Tomas Winkler21c339b2008-11-07 09:58:41 -0800829 iwl_setup_spectrum_handlers(priv);
Tomas Winkler2a421b92008-06-12 09:47:10 +0800830 iwl_setup_rx_scan_handlers(priv);
831
Ron Rindjunsky37a44212008-05-29 16:35:18 +0800832 /* status change handler */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700833 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700834
Tomas Winklerc1354752008-05-29 16:35:04 +0800835 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
836 iwl_rx_missed_beacon_notif;
Ron Rindjunsky37a44212008-05-29 16:35:18 +0800837 /* Rx handlers */
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800838 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl_rx_reply_rx_phy;
839 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl_rx_reply_rx;
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +0800840 /* block ack */
841 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl_rx_reply_compressed_ba;
Ben Cahill9fbab512007-11-29 11:09:47 +0800842 /* Set up hardware specific Rx handlers */
Emmanuel Grumbachd4789ef2008-04-24 11:55:20 -0700843 priv->cfg->ops->lib->rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700844}
845
Zhu Yib481de92007-09-25 17:54:57 -0700846/**
Tomas Winklera55360e2008-05-05 10:22:28 +0800847 * iwl_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -0700848 *
849 * Uses the priv->rx_handlers callback function array to invoke
850 * the appropriate handlers, including command responses,
851 * frame-received notifications, and other notifications.
852 */
Tomas Winklera55360e2008-05-05 10:22:28 +0800853void iwl_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700854{
Tomas Winklera55360e2008-05-05 10:22:28 +0800855 struct iwl_rx_mem_buffer *rxb;
Tomas Winklerdb11d632008-05-05 10:22:33 +0800856 struct iwl_rx_packet *pkt;
Tomas Winklera55360e2008-05-05 10:22:28 +0800857 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -0700858 u32 r, i;
859 int reclaim;
860 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800861 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -0800862 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -0700863
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800864 /* uCode's read index (stored in shared DRAM) indicates the last Rx
865 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8d864222008-11-07 09:58:39 -0800866 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -0700867 i = rxq->read;
868
869 /* Rx interrupt, but nothing sent from uCode */
870 if (i == r)
Tomas Winklere1623442009-01-27 14:27:56 -0800871 IWL_DEBUG_RX(priv, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -0700872
Tomas Winklera55360e2008-05-05 10:22:28 +0800873 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800874 fill_rx = 1;
875
Zhu Yib481de92007-09-25 17:54:57 -0700876 while (i != r) {
877 rxb = rxq->queue[i];
878
Ben Cahill9fbab512007-11-29 11:09:47 +0800879 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -0700880 * then a bug has been introduced in the queue refilling
881 * routines -- catch it here */
882 BUG_ON(rxb == NULL);
883
884 rxq->queue[i] = NULL;
885
Johannes Berge91af0a2008-11-19 01:22:51 +0100886 dma_sync_single_range_for_cpu(
887 &priv->pci_dev->dev, rxb->real_dma_addr,
888 rxb->aligned_dma_addr - rxb->real_dma_addr,
889 priv->hw_params.rx_buf_size,
890 PCI_DMA_FROMDEVICE);
Tomas Winklerdb11d632008-05-05 10:22:33 +0800891 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700892
893 /* Reclaim a command buffer only if this packet is a response
894 * to a (driver-originated) command.
895 * If the packet (e.g. Rx frame) originated from uCode,
896 * there is no command buffer to reclaim.
897 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
898 * but apparently a few don't get set; catch them here. */
899 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
900 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
Tomas Winkler857485c2008-03-21 13:53:44 -0700901 (pkt->hdr.cmd != REPLY_RX) &&
Daniel Halperin7dddaf12008-10-23 23:48:58 -0700902 (pkt->hdr.cmd != REPLY_RX_MPDU_CMD) &&
Zhu Yicfe01702007-09-27 11:27:31 +0800903 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
Zhu Yib481de92007-09-25 17:54:57 -0700904 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
905 (pkt->hdr.cmd != REPLY_TX);
906
907 /* Based on type of command response or notification,
908 * handle those that need handling via function in
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700909 * rx_handlers table. See iwl_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -0700910 if (priv->rx_handlers[pkt->hdr.cmd]) {
Tomas Winklere1623442009-01-27 14:27:56 -0800911 IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r,
Ester Kummerf3d67992008-05-06 11:05:12 +0800912 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700913 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
914 } else {
915 /* No handling needed */
Tomas Winklere1623442009-01-27 14:27:56 -0800916 IWL_DEBUG_RX(priv,
Zhu Yib481de92007-09-25 17:54:57 -0700917 "r %d i %d No handler needed for %s, 0x%02x\n",
918 r, i, get_cmd_string(pkt->hdr.cmd),
919 pkt->hdr.cmd);
920 }
921
922 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +0800923 /* Invoke any callbacks, transfer the skb to caller, and
Tomas Winkler857485c2008-03-21 13:53:44 -0700924 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -0700925 * as we reclaim the driver command queue */
926 if (rxb && rxb->skb)
Tomas Winkler17b88922008-05-29 16:35:12 +0800927 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -0700928 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800929 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -0700930 }
931
932 /* For now we just don't re-use anything. We can tweak this
933 * later to try and re-use notification packets and SKBs that
934 * fail to Rx correctly */
935 if (rxb->skb != NULL) {
936 priv->alloc_rxb_skb--;
937 dev_kfree_skb_any(rxb->skb);
938 rxb->skb = NULL;
939 }
940
Johannes Berg40185172008-11-18 01:47:21 +0100941 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
942 priv->hw_params.rx_buf_size + 256,
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +0200943 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -0700944 spin_lock_irqsave(&rxq->lock, flags);
945 list_add_tail(&rxb->list, &priv->rxq.rx_used);
946 spin_unlock_irqrestore(&rxq->lock, flags);
947 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800948 /* If there are a lot of unused frames,
949 * restock the Rx queue so ucode wont assert. */
950 if (fill_rx) {
951 count++;
952 if (count >= 8) {
953 priv->rxq.read = i;
Zhu Yif1bc4ac2008-12-17 16:52:33 +0800954 iwl_rx_queue_restock(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800955 count = 0;
956 }
957 }
Zhu Yib481de92007-09-25 17:54:57 -0700958 }
959
960 /* Backtrack one entry */
961 priv->rxq.read = i;
Tomas Winklera55360e2008-05-05 10:22:28 +0800962 iwl_rx_queue_restock(priv);
963}
Tomas Winklera55360e2008-05-05 10:22:28 +0800964
Mohamed Abbas0359fac2008-03-28 16:21:08 -0700965/* call this function to flush any scheduled tasklet */
966static inline void iwl_synchronize_irq(struct iwl_priv *priv)
967{
Tomas Winklera96a27f2008-10-23 23:48:56 -0700968 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -0700969 synchronize_irq(priv->pci_dev->irq);
970 tasklet_kill(&priv->irq_tasklet);
971}
972
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700973static void iwl_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700974{
975 unsigned long flags;
976
977 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
978 sizeof(priv->staging_rxon));
979 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -0700980 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700981
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800982 iwl_rxon_add_station(priv, priv->bssid, 1);
Zhu Yib481de92007-09-25 17:54:57 -0700983
984 spin_lock_irqsave(&priv->lock, flags);
985 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
986 priv->error_recovering = 0;
987 spin_unlock_irqrestore(&priv->lock, flags);
988}
989
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700990static void iwl_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700991{
992 u32 inta, handled = 0;
993 u32 inta_fh;
994 unsigned long flags;
Tomas Winkler0a6857e2008-03-12 16:58:49 -0700995#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -0700996 u32 inta_mask;
997#endif
998
999 spin_lock_irqsave(&priv->lock, flags);
1000
1001 /* Ack/clear/reset pending uCode interrupts.
1002 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1003 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001004 inta = iwl_read32(priv, CSR_INT);
1005 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07001006
1007 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
1008 * Any new interrupts that happen after this, either while we're
1009 * in this tasklet, or later, will show up in next ISR/tasklet. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001010 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1011 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001012
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001013#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001014 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001015 /* just for debug */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001016 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Tomas Winklere1623442009-01-27 14:27:56 -08001017 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07001018 inta, inta_mask, inta_fh);
1019 }
1020#endif
1021
1022 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
1023 * atomic, make sure that inta covers all the interrupts that
1024 * we've discovered, even if FH interrupt came in just after
1025 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001026 if (inta_fh & CSR49_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001027 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001028 if (inta_fh & CSR49_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001029 inta |= CSR_INT_BIT_FH_TX;
1030
1031 /* Now service all interrupt bits discovered above. */
1032 if (inta & CSR_INT_BIT_HW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001033 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001034
1035 /* Tell the device to stop sending interrupts */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001036 iwl_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001037
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001038 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001039
1040 handled |= CSR_INT_BIT_HW_ERR;
1041
1042 spin_unlock_irqrestore(&priv->lock, flags);
1043
1044 return;
1045 }
1046
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001047#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001048 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07001049 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001050 if (inta & CSR_INT_BIT_SCD)
Tomas Winklere1623442009-01-27 14:27:56 -08001051 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
Joonwoo Park25c03d82008-01-23 10:15:20 -08001052 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001053
1054 /* Alive notification via Rx interrupt will do the real work */
1055 if (inta & CSR_INT_BIT_ALIVE)
Tomas Winklere1623442009-01-27 14:27:56 -08001056 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07001057 }
1058#endif
1059 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001060 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07001061
Ben Cahill9fbab512007-11-29 11:09:47 +08001062 /* HW RF KILL switch toggled */
Zhu Yib481de92007-09-25 17:54:57 -07001063 if (inta & CSR_INT_BIT_RF_KILL) {
1064 int hw_rf_kill = 0;
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001065 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yib481de92007-09-25 17:54:57 -07001066 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
1067 hw_rf_kill = 1;
1068
Tomas Winklere1623442009-01-27 14:27:56 -08001069 IWL_DEBUG_RF_KILL(priv, "RF_KILL bit toggled to %s.\n",
Abhijeet Kolekarc3056062008-11-12 13:14:08 -08001070 hw_rf_kill ? "disable radio" : "enable radio");
Zhu Yib481de92007-09-25 17:54:57 -07001071
Emmanuel Grumbacha9efa652008-06-30 17:23:25 +08001072 /* driver only loads ucode once setting the interface up.
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01001073 * the driver allows loading the ucode even if the radio
1074 * is killed. Hence update the killswitch state here. The
1075 * rfkill handler will care about restarting if needed.
Emmanuel Grumbacha9efa652008-06-30 17:23:25 +08001076 */
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01001077 if (!test_bit(STATUS_ALIVE, &priv->status)) {
1078 if (hw_rf_kill)
1079 set_bit(STATUS_RF_KILL_HW, &priv->status);
1080 else
1081 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1082 queue_work(priv->workqueue, &priv->rf_kill);
Mohamed Abbasedb34222008-12-11 10:33:37 -08001083 }
Zhu Yib481de92007-09-25 17:54:57 -07001084
1085 handled |= CSR_INT_BIT_RF_KILL;
1086 }
1087
Ben Cahill9fbab512007-11-29 11:09:47 +08001088 /* Chip got too hot and stopped itself */
Zhu Yib481de92007-09-25 17:54:57 -07001089 if (inta & CSR_INT_BIT_CT_KILL) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001090 IWL_ERR(priv, "Microcode CT kill error detected.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001091 handled |= CSR_INT_BIT_CT_KILL;
1092 }
1093
1094 /* Error detected by uCode */
1095 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001096 IWL_ERR(priv, "Microcode SW error detected. "
1097 " Restarting 0x%X.\n", inta);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001098 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001099 handled |= CSR_INT_BIT_SW_ERR;
1100 }
1101
1102 /* uCode wakes up after power-down sleep */
1103 if (inta & CSR_INT_BIT_WAKEUP) {
Tomas Winklere1623442009-01-27 14:27:56 -08001104 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
Tomas Winklera55360e2008-05-05 10:22:28 +08001105 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Tomas Winklerbabcebf2008-05-15 13:54:00 +08001106 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
1107 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
1108 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
1109 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
1110 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1111 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07001112
1113 handled |= CSR_INT_BIT_WAKEUP;
1114 }
1115
1116 /* All uCode command responses, including Tx command responses,
1117 * Rx "responses" (frame-received notification), and other
1118 * notifications from uCode come through here*/
1119 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Tomas Winklera55360e2008-05-05 10:22:28 +08001120 iwl_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001121 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1122 }
1123
1124 if (inta & CSR_INT_BIT_FH_TX) {
Tomas Winklere1623442009-01-27 14:27:56 -08001125 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07001126 handled |= CSR_INT_BIT_FH_TX;
Ron Rindjunskydbb983b2008-05-15 13:54:12 +08001127 /* FH finished to write, send event */
1128 priv->ucode_write_complete = 1;
1129 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07001130 }
1131
1132 if (inta & ~handled)
Winkler, Tomas15b16872008-12-19 10:37:33 +08001133 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Zhu Yib481de92007-09-25 17:54:57 -07001134
1135 if (inta & ~CSR_INI_SET_MASK) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001136 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Zhu Yib481de92007-09-25 17:54:57 -07001137 inta & ~CSR_INI_SET_MASK);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001138 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001139 }
1140
1141 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001142 /* only Re-enable if diabled by irq */
1143 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001144 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001145
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001146#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001147 if (priv->debug_level & (IWL_DL_ISR)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001148 inta = iwl_read32(priv, CSR_INT);
1149 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1150 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Tomas Winklere1623442009-01-27 14:27:56 -08001151 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
Zhu Yib481de92007-09-25 17:54:57 -07001152 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
1153 }
1154#endif
1155 spin_unlock_irqrestore(&priv->lock, flags);
1156}
1157
Zhu Yib481de92007-09-25 17:54:57 -07001158/******************************************************************************
1159 *
1160 * uCode download functions
1161 *
1162 ******************************************************************************/
1163
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001164static void iwl_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001165{
Tomas Winkler98c92212008-01-14 17:46:20 -08001166 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
1167 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
1168 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
1169 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
1170 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1171 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001172}
1173
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001174static void iwl_nic_start(struct iwl_priv *priv)
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +08001175{
1176 /* Remove all resets to allow NIC to operate */
1177 iwl_write32(priv, CSR_RESET, 0);
1178}
1179
1180
Zhu Yib481de92007-09-25 17:54:57 -07001181/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001182 * iwl_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07001183 *
1184 * Copy into buffers for card to fetch via bus-mastering
1185 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001186static int iwl_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001187{
Ron Rindjunsky14b3d332008-06-13 15:44:54 +08001188 struct iwl_ucode *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08001189 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07001190 const struct firmware *ucode_raw;
Reinette Chatrea0987a82008-12-02 12:14:06 -08001191 const char *name_pre = priv->cfg->fw_name_pre;
1192 const unsigned int api_max = priv->cfg->ucode_api_max;
1193 const unsigned int api_min = priv->cfg->ucode_api_min;
1194 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07001195 u8 *src;
1196 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08001197 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07001198
1199 /* Ask kernel firmware_class module to get the boot firmware off disk.
1200 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08001201 for (index = api_max; index >= api_min; index--) {
1202 sprintf(buf, "%s%d%s", name_pre, index, ".ucode");
1203 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
1204 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001205 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001206 buf, ret);
1207 if (ret == -ENOENT)
1208 continue;
1209 else
1210 goto error;
1211 } else {
1212 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08001213 IWL_ERR(priv, "Loaded firmware %s, "
1214 "which is deprecated. "
1215 "Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001216 buf, api_max);
Winkler, Tomas15b16872008-12-19 10:37:33 +08001217
Tomas Winklere1623442009-01-27 14:27:56 -08001218 IWL_DEBUG_INFO(priv, "Got firmware '%s' file (%zd bytes) from disk\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001219 buf, ucode_raw->size);
1220 break;
1221 }
Zhu Yib481de92007-09-25 17:54:57 -07001222 }
1223
Reinette Chatrea0987a82008-12-02 12:14:06 -08001224 if (ret < 0)
1225 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07001226
1227 /* Make sure that we got at least our header! */
1228 if (ucode_raw->size < sizeof(*ucode)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001229 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001230 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001231 goto err_release;
1232 }
1233
1234 /* Data from ucode file: header followed by uCode images */
1235 ucode = (void *)ucode_raw->data;
1236
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08001237 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08001238 api_ver = IWL_UCODE_API(priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07001239 inst_size = le32_to_cpu(ucode->inst_size);
1240 data_size = le32_to_cpu(ucode->data_size);
1241 init_size = le32_to_cpu(ucode->init_size);
1242 init_data_size = le32_to_cpu(ucode->init_data_size);
1243 boot_size = le32_to_cpu(ucode->boot_size);
1244
Reinette Chatrea0987a82008-12-02 12:14:06 -08001245 /* api_ver should match the api version forming part of the
1246 * firmware filename ... but we don't check for that and only rely
Nick Andrew877d0312009-01-26 11:06:57 +01001247 * on the API version read from firmware header from here on forward */
Reinette Chatrea0987a82008-12-02 12:14:06 -08001248
1249 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001250 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08001251 "Driver supports v%u, firmware is v%u.\n",
1252 api_max, api_ver);
1253 priv->ucode_ver = 0;
1254 ret = -EINVAL;
1255 goto err_release;
1256 }
1257 if (api_ver != api_max)
Tomas Winkler978785a2008-12-19 10:37:31 +08001258 IWL_ERR(priv, "Firmware has old API version. Expected v%u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08001259 "got v%u. New firmware can be obtained "
1260 "from http://www.intellinuxwireless.org.\n",
1261 api_max, api_ver);
1262
Tomas Winkler978785a2008-12-19 10:37:31 +08001263 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
1264 IWL_UCODE_MAJOR(priv->ucode_ver),
1265 IWL_UCODE_MINOR(priv->ucode_ver),
1266 IWL_UCODE_API(priv->ucode_ver),
1267 IWL_UCODE_SERIAL(priv->ucode_ver));
Reinette Chatrea0987a82008-12-02 12:14:06 -08001268
Tomas Winklere1623442009-01-27 14:27:56 -08001269 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001270 priv->ucode_ver);
Tomas Winklere1623442009-01-27 14:27:56 -08001271 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
Zhu Yib481de92007-09-25 17:54:57 -07001272 inst_size);
Tomas Winklere1623442009-01-27 14:27:56 -08001273 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
Zhu Yib481de92007-09-25 17:54:57 -07001274 data_size);
Tomas Winklere1623442009-01-27 14:27:56 -08001275 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
Zhu Yib481de92007-09-25 17:54:57 -07001276 init_size);
Tomas Winklere1623442009-01-27 14:27:56 -08001277 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
Zhu Yib481de92007-09-25 17:54:57 -07001278 init_data_size);
Tomas Winklere1623442009-01-27 14:27:56 -08001279 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
Zhu Yib481de92007-09-25 17:54:57 -07001280 boot_size);
1281
1282 /* Verify size of file vs. image size info in file's header */
1283 if (ucode_raw->size < sizeof(*ucode) +
1284 inst_size + data_size + init_size +
1285 init_data_size + boot_size) {
1286
Tomas Winklere1623442009-01-27 14:27:56 -08001287 IWL_DEBUG_INFO(priv, "uCode file size %d too small\n",
Zhu Yib481de92007-09-25 17:54:57 -07001288 (int)ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001289 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001290 goto err_release;
1291 }
1292
1293 /* Verify that uCode images will fit in card's SRAM */
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001294 if (inst_size > priv->hw_params.max_inst_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08001295 IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08001296 inst_size);
1297 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001298 goto err_release;
1299 }
1300
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001301 if (data_size > priv->hw_params.max_data_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08001302 IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08001303 data_size);
1304 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001305 goto err_release;
1306 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001307 if (init_size > priv->hw_params.max_inst_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08001308 IWL_INFO(priv, "uCode init instr len %d too large to fit in\n",
1309 init_size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001310 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001311 goto err_release;
1312 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001313 if (init_data_size > priv->hw_params.max_data_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08001314 IWL_INFO(priv, "uCode init data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08001315 init_data_size);
1316 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001317 goto err_release;
1318 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001319 if (boot_size > priv->hw_params.max_bsm_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08001320 IWL_INFO(priv, "uCode boot instr len %d too large to fit in\n",
1321 boot_size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001322 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001323 goto err_release;
1324 }
1325
1326 /* Allocate ucode buffers for card's bus-master loading ... */
1327
1328 /* Runtime instructions and 2 copies of data:
1329 * 1) unmodified from disk
1330 * 2) backup cache for save/restore during power-downs */
1331 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001332 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07001333
1334 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001335 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07001336
1337 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001338 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07001339
Zhu, Yi1f304e42009-01-23 13:45:22 -08001340 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
1341 !priv->ucode_data_backup.v_addr)
1342 goto err_pci_alloc;
1343
Zhu Yib481de92007-09-25 17:54:57 -07001344 /* Initialization instructions and data */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001345 if (init_size && init_data_size) {
1346 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001347 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Zhu Yib481de92007-09-25 17:54:57 -07001348
Tomas Winkler90e759d2007-11-29 11:09:41 +08001349 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001350 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001351
1352 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
1353 goto err_pci_alloc;
1354 }
Zhu Yib481de92007-09-25 17:54:57 -07001355
1356 /* Bootstrap (instructions only, no data) */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001357 if (boot_size) {
1358 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001359 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001360
Tomas Winkler90e759d2007-11-29 11:09:41 +08001361 if (!priv->ucode_boot.v_addr)
1362 goto err_pci_alloc;
1363 }
Zhu Yib481de92007-09-25 17:54:57 -07001364
1365 /* Copy images into buffers for card's bus-master reads ... */
1366
1367 /* Runtime instructions (first block of data in file) */
1368 src = &ucode->data[0];
1369 len = priv->ucode_code.len;
Tomas Winklere1623442009-01-27 14:27:56 -08001370 IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001371 memcpy(priv->ucode_code.v_addr, src, len);
Tomas Winklere1623442009-01-27 14:27:56 -08001372 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07001373 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
1374
1375 /* Runtime data (2nd block)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001376 * NOTE: Copy into backup buffer will be done in iwl_up() */
Zhu Yib481de92007-09-25 17:54:57 -07001377 src = &ucode->data[inst_size];
1378 len = priv->ucode_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08001379 IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode data len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001380 memcpy(priv->ucode_data.v_addr, src, len);
1381 memcpy(priv->ucode_data_backup.v_addr, src, len);
1382
1383 /* Initialization instructions (3rd block) */
1384 if (init_size) {
1385 src = &ucode->data[inst_size + data_size];
1386 len = priv->ucode_init.len;
Tomas Winklere1623442009-01-27 14:27:56 -08001387 IWL_DEBUG_INFO(priv, "Copying (but not loading) init instr len %Zd\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08001388 len);
Zhu Yib481de92007-09-25 17:54:57 -07001389 memcpy(priv->ucode_init.v_addr, src, len);
1390 }
1391
1392 /* Initialization data (4th block) */
1393 if (init_data_size) {
1394 src = &ucode->data[inst_size + data_size + init_size];
1395 len = priv->ucode_init_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08001396 IWL_DEBUG_INFO(priv, "Copying (but not loading) init data len %Zd\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08001397 len);
Zhu Yib481de92007-09-25 17:54:57 -07001398 memcpy(priv->ucode_init_data.v_addr, src, len);
1399 }
1400
1401 /* Bootstrap instructions (5th block) */
1402 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
1403 len = priv->ucode_boot.len;
Tomas Winklere1623442009-01-27 14:27:56 -08001404 IWL_DEBUG_INFO(priv, "Copying (but not loading) boot instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001405 memcpy(priv->ucode_boot.v_addr, src, len);
1406
1407 /* We have our copies now, allow OS release its copies */
1408 release_firmware(ucode_raw);
1409 return 0;
1410
1411 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08001412 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001413 ret = -ENOMEM;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001414 iwl_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001415
1416 err_release:
1417 release_firmware(ucode_raw);
1418
1419 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08001420 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07001421}
1422
Zhu Yib481de92007-09-25 17:54:57 -07001423/**
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001424 * iwl_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07001425 * from protocol/runtime uCode (initialization uCode's
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001426 * Alive gets handled by iwl_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07001427 */
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001428static void iwl_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001429{
Tomas Winkler57aab752008-04-14 21:16:03 -07001430 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001431
Tomas Winklere1623442009-01-27 14:27:56 -08001432 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001433
1434 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
1435 /* We had an error bringing up the hardware, so take it
1436 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08001437 IWL_DEBUG_INFO(priv, "Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001438 goto restart;
1439 }
1440
1441 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
1442 * This is a paranoid check, because we would not have gotten the
1443 * "runtime" alive if code weren't properly loaded. */
Emmanuel Grumbachb0692f22008-04-24 11:55:18 -07001444 if (iwl_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001445 /* Runtime instruction load was bad;
1446 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08001447 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001448 goto restart;
1449 }
1450
Abhijeet Kolekare11bc022009-04-08 11:26:41 -07001451 priv->cfg->ops->smgmt->clear_station_table(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07001452 ret = priv->cfg->ops->lib->alive_notify(priv);
1453 if (ret) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001454 IWL_WARN(priv,
1455 "Could not complete ALIVE transition [ntf]: %d\n", ret);
Zhu Yib481de92007-09-25 17:54:57 -07001456 goto restart;
1457 }
1458
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001459 /* After the ALIVE response, we can send host commands to the uCode */
Zhu Yib481de92007-09-25 17:54:57 -07001460 set_bit(STATUS_ALIVE, &priv->status);
1461
Tomas Winklerfee12472008-04-03 16:05:21 -07001462 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001463 return;
1464
Johannes Berg36d68252008-05-15 12:55:26 +02001465 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07001466
1467 priv->active_rate = priv->rates_mask;
1468 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
1469
Tomas Winkler3109ece2008-03-28 16:33:35 -07001470 if (iwl_is_associated(priv)) {
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001471 struct iwl_rxon_cmd *active_rxon =
1472 (struct iwl_rxon_cmd *)&priv->active_rxon;
Mohamed Abbas019fb972009-03-17 21:59:18 -07001473 /* apply any changes in staging */
1474 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001475 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1476 } else {
1477 /* Initialize our rx_config data */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001478 iwl_connection_init_rx_config(priv, priv->iw_mode);
Abhijeet Kolekar45823532009-04-08 11:26:44 -07001479
1480 if (priv->cfg->ops->hcmd->set_rxon_chain)
1481 priv->cfg->ops->hcmd->set_rxon_chain(priv);
1482
Zhu Yib481de92007-09-25 17:54:57 -07001483 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
1484 }
1485
Ben Cahill9fbab512007-11-29 11:09:47 +08001486 /* Configure Bluetooth device coexistence support */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001487 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001488
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001489 iwl_reset_run_time_calib(priv);
1490
Zhu Yib481de92007-09-25 17:54:57 -07001491 /* Configure the adapter for unassociated operation */
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001492 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001493
1494 /* At this point, the NIC is initialized and operational */
Emmanuel Grumbach47f4a582008-06-12 09:47:13 +08001495 iwl_rf_kill_ct_config(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08001496
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07001497 iwl_leds_register(priv);
1498
Tomas Winklere1623442009-01-27 14:27:56 -08001499 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07001500 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08001501 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07001502
1503 if (priv->error_recovering)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001504 iwl_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001505
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08001506 iwl_power_update_mode(priv, 1);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08001507
Mohamed Abbasada17512008-11-07 09:58:34 -08001508 /* reassociate for ADHOC mode */
1509 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
1510 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
1511 priv->vif);
1512 if (beacon)
1513 iwl_mac_beacon_update(priv->hw, beacon);
1514 }
1515
1516
Assaf Kraussc46fbef2008-06-12 09:47:05 +08001517 if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001518 iwl_set_mode(priv, priv->iw_mode);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08001519
Zhu Yib481de92007-09-25 17:54:57 -07001520 return;
1521
1522 restart:
1523 queue_work(priv->workqueue, &priv->restart);
1524}
1525
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001526static void iwl_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07001527
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001528static void __iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001529{
1530 unsigned long flags;
1531 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07001532
Tomas Winklere1623442009-01-27 14:27:56 -08001533 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07001534
Zhu Yib481de92007-09-25 17:54:57 -07001535 if (!exit_pending)
1536 set_bit(STATUS_EXIT_PENDING, &priv->status);
1537
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07001538 iwl_leds_unregister(priv);
1539
Abhijeet Kolekare11bc022009-04-08 11:26:41 -07001540 priv->cfg->ops->smgmt->clear_station_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001541
1542 /* Unblock any waiting calls */
1543 wake_up_interruptible_all(&priv->wait_command_queue);
1544
Zhu Yib481de92007-09-25 17:54:57 -07001545 /* Wipe out the EXIT_PENDING status bit if we are not actually
1546 * exiting the module */
1547 if (!exit_pending)
1548 clear_bit(STATUS_EXIT_PENDING, &priv->status);
1549
1550 /* stop and reset the on-board processor */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001551 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07001552
1553 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001554 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001555 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001556 spin_unlock_irqrestore(&priv->lock, flags);
1557 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001558
1559 if (priv->mac80211_registered)
1560 ieee80211_stop_queues(priv->hw);
1561
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001562 /* If we have not previously called iwl_init() then
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07001563 * clear all bits but the RF Kill bits and return */
Tomas Winklerfee12472008-04-03 16:05:21 -07001564 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001565 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
1566 STATUS_RF_KILL_HW |
1567 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
1568 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08001569 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
1570 STATUS_GEO_CONFIGURED |
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08001571 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
1572 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07001573 goto exit;
1574 }
1575
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07001576 /* ...otherwise clear out all the status bits but the RF Kill
1577 * bits and continue taking the NIC down. */
Zhu Yib481de92007-09-25 17:54:57 -07001578 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
1579 STATUS_RF_KILL_HW |
1580 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
1581 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08001582 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
1583 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07001584 test_bit(STATUS_FW_ERROR, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08001585 STATUS_FW_ERROR |
1586 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
1587 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07001588
1589 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001590 iwl_clear_bit(priv, CSR_GP_CNTRL,
Ben Cahill9fbab512007-11-29 11:09:47 +08001591 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07001592 spin_unlock_irqrestore(&priv->lock, flags);
1593
Tomas Winklerda1bc452008-05-29 16:35:00 +08001594 iwl_txq_ctx_stop(priv);
Tomas Winklerb3bbacb2008-05-29 16:35:01 +08001595 iwl_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001596
1597 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001598 if (!iwl_grab_nic_access(priv)) {
1599 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07001600 APMG_CLK_VAL_DMA_CLK_RQT);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001601 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001602 }
1603 spin_unlock_irqrestore(&priv->lock, flags);
1604
1605 udelay(5);
1606
Tomas Winkler7f066102008-05-29 16:34:57 +08001607 /* FIXME: apm_ops.suspend(priv) */
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07001608 if (exit_pending)
Gregory Greenmand5353112008-09-03 11:18:49 +08001609 priv->cfg->ops->lib->apm_ops.stop(priv);
1610 else
1611 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001612 exit:
Tomas Winkler885ba202008-05-29 16:34:55 +08001613 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001614
1615 if (priv->ibss_beacon)
1616 dev_kfree_skb(priv->ibss_beacon);
1617 priv->ibss_beacon = NULL;
1618
1619 /* clear out any free frames */
Tomas Winklerfcab4232008-05-15 13:54:01 +08001620 iwl_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001621}
1622
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001623static void iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001624{
1625 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001626 __iwl_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001627 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08001628
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001629 iwl_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001630}
1631
1632#define MAX_HW_RESTARTS 5
1633
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001634static int __iwl_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001635{
Tomas Winkler57aab752008-04-14 21:16:03 -07001636 int i;
1637 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07001638
1639 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001640 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07001641 return -EIO;
1642 }
1643
Reinette Chatree903fbd2008-01-30 22:05:15 -08001644 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001645 IWL_ERR(priv, "ucode not available for device bringup\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08001646 return -EIO;
1647 }
1648
Zhu Yie655b9f2008-01-24 02:19:38 -08001649 /* If platform's RF_KILL switch is NOT set to KILL */
Tomas Winklerc1842d62008-08-04 16:00:43 +08001650 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
Zhu Yie655b9f2008-01-24 02:19:38 -08001651 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08001652 else
Zhu Yie655b9f2008-01-24 02:19:38 -08001653 set_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08001654
Tomas Winklerc1842d62008-08-04 16:00:43 +08001655 if (iwl_is_rfkill(priv)) {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001656 iwl_enable_interrupts(priv);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001657 IWL_WARN(priv, "Radio disabled by %s RF Kill switch\n",
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08001658 test_bit(STATUS_RF_KILL_HW, &priv->status) ? "HW" : "SW");
Tomas Winklerc1842d62008-08-04 16:00:43 +08001659 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07001660 }
1661
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001662 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07001663
Ron Rindjunsky1053d352008-05-05 10:22:43 +08001664 ret = iwl_hw_nic_init(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07001665 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001666 IWL_ERR(priv, "Unable to init nic\n");
Tomas Winkler57aab752008-04-14 21:16:03 -07001667 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07001668 }
1669
1670 /* make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001671 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
1672 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07001673 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1674
1675 /* clear (again), then enable host interrupts */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001676 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001677 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001678
1679 /* really make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001680 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
1681 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07001682
1683 /* Copy original ucode data image from disk into backup cache.
1684 * This will be used to initialize the on-board processor's
1685 * data SRAM for a clean start when the runtime program first loads. */
1686 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a66926a2008-01-14 17:46:18 -08001687 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07001688
Zhu Yib481de92007-09-25 17:54:57 -07001689 for (i = 0; i < MAX_HW_RESTARTS; i++) {
1690
Abhijeet Kolekare11bc022009-04-08 11:26:41 -07001691 priv->cfg->ops->smgmt->clear_station_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001692
1693 /* load bootstrap state machine,
1694 * load bootstrap program into processor's memory,
1695 * prepare to load the "initialize" uCode */
Tomas Winkler57aab752008-04-14 21:16:03 -07001696 ret = priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001697
Tomas Winkler57aab752008-04-14 21:16:03 -07001698 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001699 IWL_ERR(priv, "Unable to set up bootstrap uCode: %d\n",
1700 ret);
Zhu Yib481de92007-09-25 17:54:57 -07001701 continue;
1702 }
1703
Emmanuel Grumbachf3d5b452008-06-12 09:47:04 +08001704 /* Clear out the uCode error bit if it is set */
1705 clear_bit(STATUS_FW_ERROR, &priv->status);
1706
Zhu Yib481de92007-09-25 17:54:57 -07001707 /* start card; "initialize" will load runtime ucode */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001708 iwl_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001709
Tomas Winklere1623442009-01-27 14:27:56 -08001710 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
Zhu Yib481de92007-09-25 17:54:57 -07001711
1712 return 0;
1713 }
1714
1715 set_bit(STATUS_EXIT_PENDING, &priv->status);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001716 __iwl_down(priv);
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08001717 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07001718
1719 /* tried to restart and config the device for as long as our
1720 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08001721 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07001722 return -EIO;
1723}
1724
1725
1726/*****************************************************************************
1727 *
1728 * Workqueue callbacks
1729 *
1730 *****************************************************************************/
1731
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001732static void iwl_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07001733{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001734 struct iwl_priv *priv =
1735 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07001736
1737 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1738 return;
1739
1740 mutex_lock(&priv->mutex);
Emmanuel Grumbachf3ccc082008-05-05 10:22:45 +08001741 priv->cfg->ops->lib->init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001742 mutex_unlock(&priv->mutex);
1743}
1744
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001745static void iwl_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07001746{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001747 struct iwl_priv *priv =
1748 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07001749
1750 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1751 return;
1752
1753 mutex_lock(&priv->mutex);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001754 iwl_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001755 mutex_unlock(&priv->mutex);
1756}
1757
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08001758static void iwl_bg_run_time_calib_work(struct work_struct *work)
1759{
1760 struct iwl_priv *priv = container_of(work, struct iwl_priv,
1761 run_time_calib_work);
1762
1763 mutex_lock(&priv->mutex);
1764
1765 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
1766 test_bit(STATUS_SCANNING, &priv->status)) {
1767 mutex_unlock(&priv->mutex);
1768 return;
1769 }
1770
1771 if (priv->start_calib) {
1772 iwl_chain_noise_calibration(priv, &priv->statistics);
1773
1774 iwl_sensitivity_calibration(priv, &priv->statistics);
1775 }
1776
1777 mutex_unlock(&priv->mutex);
1778 return;
1779}
1780
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001781static void iwl_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07001782{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001783 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07001784
1785 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1786 return;
1787
1788 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001789 __iwl_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001790 mutex_unlock(&priv->mutex);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02001791 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001792}
1793
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001794static void iwl_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07001795{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001796 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07001797
1798 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1799 return;
1800
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001801 iwl_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001802 queue_work(priv->workqueue, &priv->up);
1803}
1804
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001805static void iwl_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07001806{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001807 struct iwl_priv *priv =
1808 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07001809
1810 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1811 return;
1812
1813 mutex_lock(&priv->mutex);
Tomas Winklera55360e2008-05-05 10:22:28 +08001814 iwl_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001815 mutex_unlock(&priv->mutex);
1816}
1817
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08001818#define IWL_DELAY_NEXT_SCAN (HZ*2)
1819
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07001820void iwl_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001821{
Zhu Yib481de92007-09-25 17:54:57 -07001822 struct ieee80211_conf *conf = NULL;
Tomas Winkler857485c2008-03-21 13:53:44 -07001823 int ret = 0;
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08001824 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07001825
Johannes Berg05c914fe2008-09-11 00:01:58 +02001826 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001827 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07001828 return;
1829 }
1830
Tomas Winklere1623442009-01-27 14:27:56 -08001831 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07001832 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07001833
1834
1835 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1836 return;
1837
Zhu Yib481de92007-09-25 17:54:57 -07001838
Reinette Chatre508e32e2008-04-14 21:16:13 -07001839 if (!priv->vif || !priv->is_open)
Mohamed Abbas948c1712007-10-25 17:15:45 +08001840 return;
Reinette Chatre508e32e2008-04-14 21:16:13 -07001841
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08001842 iwl_power_cancel_timeout(priv);
Tomas Winkler2a421b92008-06-12 09:47:10 +08001843 iwl_scan_cancel_timeout(priv, 200);
mabbas052c4b92007-10-25 17:15:43 +08001844
Zhu Yib481de92007-09-25 17:54:57 -07001845 conf = ieee80211_get_hw_conf(priv->hw);
1846
1847 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001848 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001849
Tomas Winkler3195c1f2008-10-08 09:37:30 +08001850 iwl_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07001851 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07001852 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07001853 if (ret)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001854 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07001855 "Attempting to continue.\n");
1856
1857 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
1858
Emmanuel Grumbach42eb7c62008-09-17 10:10:05 +08001859 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03001860
Abhijeet Kolekar45823532009-04-08 11:26:44 -07001861 if (priv->cfg->ops->hcmd->set_rxon_chain)
1862 priv->cfg->ops->hcmd->set_rxon_chain(priv);
1863
Zhu Yib481de92007-09-25 17:54:57 -07001864 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
1865
Tomas Winklere1623442009-01-27 14:27:56 -08001866 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07001867 priv->assoc_id, priv->beacon_int);
1868
1869 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1870 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
1871 else
1872 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
1873
1874 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
1875 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
1876 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
1877 else
1878 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
1879
Johannes Berg05c914fe2008-09-11 00:01:58 +02001880 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07001881 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
1882
1883 }
1884
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001885 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001886
1887 switch (priv->iw_mode) {
Johannes Berg05c914fe2008-09-11 00:01:58 +02001888 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -07001889 break;
1890
Johannes Berg05c914fe2008-09-11 00:01:58 +02001891 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07001892
Assaf Kraussc46fbef2008-06-12 09:47:05 +08001893 /* assume default assoc id */
1894 priv->assoc_id = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001895
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08001896 iwl_rxon_add_station(priv, priv->bssid, 0);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001897 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001898
1899 break;
1900
1901 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08001902 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001903 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07001904 break;
1905 }
1906
Johannes Berg05c914fe2008-09-11 00:01:58 +02001907 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07001908 priv->assoc_station_added = 1;
1909
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08001910 spin_lock_irqsave(&priv->lock, flags);
1911 iwl_activate_qos(priv, 0);
1912 spin_unlock_irqrestore(&priv->lock, flags);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08001913
Grumbach, Emmanuel04816442008-09-03 11:26:53 +08001914 /* the chain noise calibration will enabled PM upon completion
1915 * If chain noise has already been run, then we need to enable
1916 * power management here */
1917 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
1918 iwl_power_enable_management(priv);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08001919
1920 /* Enable Rx differential gain and sensitivity calibrations */
1921 iwl_chain_noise_reset(priv);
1922 priv->start_calib = 1;
1923
Reinette Chatre508e32e2008-04-14 21:16:13 -07001924}
1925
Zhu Yib481de92007-09-25 17:54:57 -07001926/*****************************************************************************
1927 *
1928 * mac80211 entry point functions
1929 *
1930 *****************************************************************************/
1931
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08001932#define UCODE_READY_TIMEOUT (4 * HZ)
Zhu Yi5a66926a2008-01-14 17:46:18 -08001933
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001934static int iwl_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07001935{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001936 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08001937 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07001938
Tomas Winklere1623442009-01-27 14:27:56 -08001939 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07001940
1941 /* we should be verifying the device is ready to be opened */
1942 mutex_lock(&priv->mutex);
1943
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001944 memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd));
Zhu Yi5a66926a2008-01-14 17:46:18 -08001945 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
1946 * ucode filename and max sizes are card-specific. */
1947
1948 if (!priv->ucode_code.len) {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001949 ret = iwl_read_ucode(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08001950 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001951 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a66926a2008-01-14 17:46:18 -08001952 mutex_unlock(&priv->mutex);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01001953 return ret;
Zhu Yi5a66926a2008-01-14 17:46:18 -08001954 }
1955 }
1956
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001957 ret = __iwl_up(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08001958
Zhu Yib481de92007-09-25 17:54:57 -07001959 mutex_unlock(&priv->mutex);
Zhu Yi5a66926a2008-01-14 17:46:18 -08001960
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02001961 iwl_rfkill_set_hw_state(priv);
1962
Zhu Yie655b9f2008-01-24 02:19:38 -08001963 if (ret)
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01001964 return ret;
Zhu Yie655b9f2008-01-24 02:19:38 -08001965
Tomas Winklerc1842d62008-08-04 16:00:43 +08001966 if (iwl_is_rfkill(priv))
1967 goto out;
1968
Tomas Winklere1623442009-01-27 14:27:56 -08001969 IWL_DEBUG_INFO(priv, "Start UP work done.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08001970
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08001971 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
Zhu Yi5a66926a2008-01-14 17:46:18 -08001972 * mac80211 will not be run successfully. */
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08001973 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
1974 test_bit(STATUS_READY, &priv->status),
1975 UCODE_READY_TIMEOUT);
1976 if (!ret) {
1977 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001978 IWL_ERR(priv, "START_ALIVE timeout after %dms.\n",
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08001979 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01001980 return -ETIMEDOUT;
Zhu Yi5a66926a2008-01-14 17:46:18 -08001981 }
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08001982 }
Tomas Winkler0a078ff2008-06-30 17:23:26 +08001983
Tomas Winklerc1842d62008-08-04 16:00:43 +08001984out:
Tomas Winkler0a078ff2008-06-30 17:23:26 +08001985 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08001986 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07001987 return 0;
1988}
1989
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001990static void iwl_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07001991{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001992 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07001993
Tomas Winklere1623442009-01-27 14:27:56 -08001994 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas948c1712007-10-25 17:15:45 +08001995
Zhu Yie655b9f2008-01-24 02:19:38 -08001996 if (!priv->is_open) {
Tomas Winklere1623442009-01-27 14:27:56 -08001997 IWL_DEBUG_MAC80211(priv, "leave - skip\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08001998 return;
1999 }
2000
Zhu Yib481de92007-09-25 17:54:57 -07002001 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002002
Tomas Winklerfee12472008-04-03 16:05:21 -07002003 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08002004 /* stop mac, cancel any scan request and clear
2005 * RXON_FILTER_ASSOC_MSK BIT
2006 */
Zhu Yi5a66926a2008-01-14 17:46:18 -08002007 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002008 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002009 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002010 }
2011
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002012 iwl_down(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002013
2014 flush_workqueue(priv->workqueue);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002015
2016 /* enable interrupts again in order to receive rfkill changes */
2017 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
2018 iwl_enable_interrupts(priv);
Mohamed Abbas948c1712007-10-25 17:15:45 +08002019
Tomas Winklere1623442009-01-27 14:27:56 -08002020 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002021}
2022
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002023static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07002024{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002025 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002026
Tomas Winklere1623442009-01-27 14:27:56 -08002027 IWL_DEBUG_MACDUMP(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002028
Tomas Winklere1623442009-01-27 14:27:56 -08002029 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02002030 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07002031
Johannes Berge039fa42008-05-15 12:55:29 +02002032 if (iwl_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07002033 dev_kfree_skb_any(skb);
2034
Tomas Winklere1623442009-01-27 14:27:56 -08002035 IWL_DEBUG_MACDUMP(priv, "leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08002036 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07002037}
2038
Abhijeet Kolekar60690a62009-04-08 11:26:49 -07002039void iwl_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002040{
Tomas Winkler857485c2008-03-21 13:53:44 -07002041 int ret = 0;
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002042 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07002043
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08002044 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07002045 return;
2046
2047 /* The following should be done only at AP bring up */
Tomas Winkler3195c1f2008-10-08 09:37:30 +08002048 if (!iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002049
2050 /* RXON - unassoc (to set timing command) */
2051 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002052 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002053
2054 /* RXON Timing */
Tomas Winkler3195c1f2008-10-08 09:37:30 +08002055 iwl_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07002056 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07002057 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07002058 if (ret)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002059 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07002060 "Attempting to continue.\n");
2061
Abhijeet Kolekar45823532009-04-08 11:26:44 -07002062 if (priv->cfg->ops->hcmd->set_rxon_chain)
2063 priv->cfg->ops->hcmd->set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002064
2065 /* FIXME: what should be the assoc_id for AP? */
2066 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2067 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2068 priv->staging_rxon.flags |=
2069 RXON_FLG_SHORT_PREAMBLE_MSK;
2070 else
2071 priv->staging_rxon.flags &=
2072 ~RXON_FLG_SHORT_PREAMBLE_MSK;
2073
2074 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2075 if (priv->assoc_capability &
2076 WLAN_CAPABILITY_SHORT_SLOT_TIME)
2077 priv->staging_rxon.flags |=
2078 RXON_FLG_SHORT_SLOT_MSK;
2079 else
2080 priv->staging_rxon.flags &=
2081 ~RXON_FLG_SHORT_SLOT_MSK;
2082
Johannes Berg05c914fe2008-09-11 00:01:58 +02002083 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002084 priv->staging_rxon.flags &=
2085 ~RXON_FLG_SHORT_SLOT_MSK;
2086 }
2087 /* restore RXON assoc */
2088 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002089 iwlcore_commit_rxon(priv);
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002090 spin_lock_irqsave(&priv->lock, flags);
2091 iwl_activate_qos(priv, 1);
2092 spin_unlock_irqrestore(&priv->lock, flags);
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002093 iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
Zhu Yie1493de2007-09-27 11:27:32 +08002094 }
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002095 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002096
2097 /* FIXME - we need to add code here to detect a totally new
2098 * configuration, reset the AP, unassoc, rxon timing, assoc,
2099 * clear sta table, add BCAST sta... */
2100}
2101
Johannes Berg9d139c82008-07-09 14:40:37 +02002102
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002103static int iwl_mac_config_interface(struct ieee80211_hw *hw,
Johannes Berg32bfd352007-12-19 01:31:26 +01002104 struct ieee80211_vif *vif,
Zhu Yib481de92007-09-25 17:54:57 -07002105 struct ieee80211_if_conf *conf)
2106{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002107 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002108 int rc;
2109
2110 if (conf == NULL)
2111 return -EIO;
2112
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08002113 if (priv->vif != vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08002114 IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08002115 return 0;
2116 }
2117
Johannes Berg05c914fe2008-09-11 00:01:58 +02002118 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Johannes Berg9d139c82008-07-09 14:40:37 +02002119 conf->changed & IEEE80211_IFCC_BEACON) {
2120 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
2121 if (!beacon)
2122 return -ENOMEM;
Mohamed Abbasada17512008-11-07 09:58:34 -08002123 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002124 rc = iwl_mac_beacon_update(hw, beacon);
Mohamed Abbasada17512008-11-07 09:58:34 -08002125 mutex_unlock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02002126 if (rc)
2127 return rc;
2128 }
2129
Tomas Winklerfee12472008-04-03 16:05:21 -07002130 if (!iwl_is_alive(priv))
Zhu Yi5a66926a2008-01-14 17:46:18 -08002131 return -EAGAIN;
2132
Zhu Yib481de92007-09-25 17:54:57 -07002133 mutex_lock(&priv->mutex);
2134
Zhu Yib481de92007-09-25 17:54:57 -07002135 if (conf->bssid)
Tomas Winklere1623442009-01-27 14:27:56 -08002136 IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07002137
Johannes Berg4150c572007-09-17 01:29:23 -04002138/*
2139 * very dubious code was here; the probe filtering flag is never set:
2140 *
Zhu Yib481de92007-09-25 17:54:57 -07002141 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
2142 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04002143 */
Zhu Yib481de92007-09-25 17:54:57 -07002144
Johannes Berg05c914fe2008-09-11 00:01:58 +02002145 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07002146 if (!conf->bssid) {
2147 conf->bssid = priv->mac_addr;
2148 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08002149 IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07002150 conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07002151 }
2152 if (priv->ibss_beacon)
2153 dev_kfree_skb(priv->ibss_beacon);
2154
Johannes Berg9d139c82008-07-09 14:40:37 +02002155 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
Zhu Yib481de92007-09-25 17:54:57 -07002156 }
2157
Tomas Winklerfee12472008-04-03 16:05:21 -07002158 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08002159 goto done;
2160
Zhu Yib481de92007-09-25 17:54:57 -07002161 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
2162 !is_multicast_ether_addr(conf->bssid)) {
2163 /* If there is currently a HW scan going on in the background
2164 * then we need to cancel it else the RXON below will fail. */
Tomas Winkler2a421b92008-06-12 09:47:10 +08002165 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002166 IWL_WARN(priv, "Aborted scan still in progress "
Zhu Yib481de92007-09-25 17:54:57 -07002167 "after 100ms\n");
Tomas Winklere1623442009-01-27 14:27:56 -08002168 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002169 mutex_unlock(&priv->mutex);
2170 return -EAGAIN;
2171 }
2172 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
2173
2174 /* TODO: Audit driver for usage of these members and see
2175 * if mac80211 deprecates them (priv->bssid looks like it
2176 * shouldn't be there, but I haven't scanned the IBSS code
2177 * to verify) - jpk */
2178 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
2179
Johannes Berg05c914fe2008-09-11 00:01:58 +02002180 if (priv->iw_mode == NL80211_IFTYPE_AP)
Abhijeet Kolekar60690a62009-04-08 11:26:49 -07002181 iwlcore_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002182 else {
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002183 rc = iwlcore_commit_rxon(priv);
Johannes Berg05c914fe2008-09-11 00:01:58 +02002184 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002185 iwl_rxon_add_station(
Zhu Yib481de92007-09-25 17:54:57 -07002186 priv, priv->active_rxon.bssid_addr, 1);
2187 }
2188
2189 } else {
Tomas Winkler2a421b92008-06-12 09:47:10 +08002190 iwl_scan_cancel_timeout(priv, 100);
Zhu Yib481de92007-09-25 17:54:57 -07002191 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002192 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002193 }
2194
Mohamed Abbasfde35712007-11-29 11:10:15 +08002195 done:
Tomas Winklere1623442009-01-27 14:27:56 -08002196 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002197 mutex_unlock(&priv->mutex);
2198
2199 return 0;
2200}
2201
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002202static void iwl_mac_update_tkip_key(struct ieee80211_hw *hw,
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002203 struct ieee80211_key_conf *keyconf, const u8 *addr,
2204 u32 iv32, u16 *phase1key)
2205{
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002206
Tomas Winkler9f586712008-11-12 13:14:05 -08002207 struct iwl_priv *priv = hw->priv;
Tomas Winklere1623442009-01-27 14:27:56 -08002208 IWL_DEBUG_MAC80211(priv, "enter\n");
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002209
Tomas Winkler9f586712008-11-12 13:14:05 -08002210 iwl_update_tkip_key(priv, keyconf, addr, iv32, phase1key);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002211
Tomas Winklere1623442009-01-27 14:27:56 -08002212 IWL_DEBUG_MAC80211(priv, "leave\n");
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002213}
2214
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002215static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01002216 struct ieee80211_vif *vif,
2217 struct ieee80211_sta *sta,
Zhu Yib481de92007-09-25 17:54:57 -07002218 struct ieee80211_key_conf *key)
2219{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002220 struct iwl_priv *priv = hw->priv;
Winkler, Tomas42986792009-01-19 15:30:22 -08002221 const u8 *addr;
2222 int ret;
2223 u8 sta_id;
2224 bool is_default_wep_key = false;
Zhu Yib481de92007-09-25 17:54:57 -07002225
Tomas Winklere1623442009-01-27 14:27:56 -08002226 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002227
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07002228 if (priv->hw_params.sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08002229 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07002230 return -EOPNOTSUPP;
2231 }
Winkler, Tomas42986792009-01-19 15:30:22 -08002232 addr = sta ? sta->addr : iwl_bcast_addr;
Abhijeet Kolekare11bc022009-04-08 11:26:41 -07002233 sta_id = priv->cfg->ops->smgmt->find_station(priv, addr);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002234 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -08002235 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
Johannes Berge1749612008-10-27 15:59:26 -07002236 addr);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002237 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002238
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002239 }
Zhu Yib481de92007-09-25 17:54:57 -07002240
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002241 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002242 iwl_scan_cancel_timeout(priv, 100);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002243 mutex_unlock(&priv->mutex);
2244
2245 /* If we are getting WEP group key and we didn't receive any key mapping
2246 * so far, we are in legacy wep mode (group key only), otherwise we are
2247 * in 1X mode.
2248 * In legacy wep mode, we use another host command to the uCode */
Tomas Winkler5425e492008-04-15 16:01:38 -07002249 if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
Johannes Berg05c914fe2008-09-11 00:01:58 +02002250 priv->iw_mode != NL80211_IFTYPE_AP) {
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002251 if (cmd == SET_KEY)
2252 is_default_wep_key = !priv->key_mapping_key;
2253 else
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +08002254 is_default_wep_key =
2255 (key->hw_key_idx == HW_KEY_DEFAULT);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002256 }
mabbas052c4b92007-10-25 17:15:43 +08002257
Zhu Yib481de92007-09-25 17:54:57 -07002258 switch (cmd) {
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002259 case SET_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002260 if (is_default_wep_key)
2261 ret = iwl_set_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002262 else
Emmanuel Grumbach74805132008-04-14 21:16:09 -07002263 ret = iwl_set_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002264
Tomas Winklere1623442009-01-27 14:27:56 -08002265 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07002266 break;
2267 case DISABLE_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002268 if (is_default_wep_key)
2269 ret = iwl_remove_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002270 else
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07002271 ret = iwl_remove_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002272
Tomas Winklere1623442009-01-27 14:27:56 -08002273 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07002274 break;
2275 default:
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002276 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002277 }
2278
Tomas Winklere1623442009-01-27 14:27:56 -08002279 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002280
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002281 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002282}
2283
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002284static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
Tomas Winklerd783b062008-07-18 13:53:02 +08002285 enum ieee80211_ampdu_mlme_action action,
Johannes Berg17741cd2008-09-11 00:02:02 +02002286 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
Tomas Winklerd783b062008-07-18 13:53:02 +08002287{
2288 struct iwl_priv *priv = hw->priv;
Wey-Yi Guy5c2207c2009-03-17 21:51:43 -07002289 int ret;
Tomas Winklerd783b062008-07-18 13:53:02 +08002290
Tomas Winklere1623442009-01-27 14:27:56 -08002291 IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
Johannes Berge1749612008-10-27 15:59:26 -07002292 sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08002293
2294 if (!(priv->cfg->sku & IWL_SKU_N))
2295 return -EACCES;
2296
2297 switch (action) {
2298 case IEEE80211_AMPDU_RX_START:
Tomas Winklere1623442009-01-27 14:27:56 -08002299 IWL_DEBUG_HT(priv, "start Rx\n");
Tomas Winkler9f586712008-11-12 13:14:05 -08002300 return iwl_sta_rx_agg_start(priv, sta->addr, tid, *ssn);
Tomas Winklerd783b062008-07-18 13:53:02 +08002301 case IEEE80211_AMPDU_RX_STOP:
Tomas Winklere1623442009-01-27 14:27:56 -08002302 IWL_DEBUG_HT(priv, "stop Rx\n");
Wey-Yi Guy5c2207c2009-03-17 21:51:43 -07002303 ret = iwl_sta_rx_agg_stop(priv, sta->addr, tid);
2304 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2305 return 0;
2306 else
2307 return ret;
Tomas Winklerd783b062008-07-18 13:53:02 +08002308 case IEEE80211_AMPDU_TX_START:
Tomas Winklere1623442009-01-27 14:27:56 -08002309 IWL_DEBUG_HT(priv, "start Tx\n");
Johannes Berg17741cd2008-09-11 00:02:02 +02002310 return iwl_tx_agg_start(priv, sta->addr, tid, ssn);
Tomas Winklerd783b062008-07-18 13:53:02 +08002311 case IEEE80211_AMPDU_TX_STOP:
Tomas Winklere1623442009-01-27 14:27:56 -08002312 IWL_DEBUG_HT(priv, "stop Tx\n");
Wey-Yi Guy5c2207c2009-03-17 21:51:43 -07002313 ret = iwl_tx_agg_stop(priv, sta->addr, tid);
2314 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2315 return 0;
2316 else
2317 return ret;
Tomas Winklerd783b062008-07-18 13:53:02 +08002318 default:
Tomas Winklere1623442009-01-27 14:27:56 -08002319 IWL_DEBUG_HT(priv, "unknown\n");
Tomas Winklerd783b062008-07-18 13:53:02 +08002320 return -EINVAL;
2321 break;
2322 }
2323 return 0;
2324}
Tomas Winkler9f586712008-11-12 13:14:05 -08002325
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002326static int iwl_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07002327 struct ieee80211_tx_queue_stats *stats)
2328{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002329 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002330 int i, avail;
Ron Rindjunsky16466902008-05-05 10:22:50 +08002331 struct iwl_tx_queue *txq;
Tomas Winkler443cfd42008-05-15 13:53:57 +08002332 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07002333 unsigned long flags;
2334
Tomas Winklere1623442009-01-27 14:27:56 -08002335 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002336
Tomas Winklerfee12472008-04-03 16:05:21 -07002337 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002338 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07002339 return -EIO;
2340 }
2341
2342 spin_lock_irqsave(&priv->lock, flags);
2343
2344 for (i = 0; i < AC_NUM; i++) {
2345 txq = &priv->txq[i];
2346 q = &txq->q;
Tomas Winkler443cfd42008-05-15 13:53:57 +08002347 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07002348
Johannes Berg57ffc582008-04-29 17:18:59 +02002349 stats[i].len = q->n_window - avail;
2350 stats[i].limit = q->n_window - q->high_mark;
2351 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07002352
2353 }
2354 spin_unlock_irqrestore(&priv->lock, flags);
2355
Tomas Winklere1623442009-01-27 14:27:56 -08002356 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002357
2358 return 0;
2359}
2360
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002361static int iwl_mac_get_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07002362 struct ieee80211_low_level_stats *stats)
2363{
Ester Kummerbf403db2008-05-05 10:22:40 +08002364 struct iwl_priv *priv = hw->priv;
2365
2366 priv = hw->priv;
Tomas Winklere1623442009-01-27 14:27:56 -08002367 IWL_DEBUG_MAC80211(priv, "enter\n");
2368 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002369
2370 return 0;
2371}
2372
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002373static void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002374{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002375 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002376 unsigned long flags;
2377
2378 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08002379 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002380
Zhu Yib481de92007-09-25 17:54:57 -07002381 spin_lock_irqsave(&priv->lock, flags);
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02002382 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
Zhu Yib481de92007-09-25 17:54:57 -07002383 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yib481de92007-09-25 17:54:57 -07002384
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07002385 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002386
Zhu Yib481de92007-09-25 17:54:57 -07002387 spin_lock_irqsave(&priv->lock, flags);
2388 priv->assoc_id = 0;
2389 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002390 priv->assoc_station_added = 0;
2391
2392 /* new association get rid of ibss beacon skb */
2393 if (priv->ibss_beacon)
2394 dev_kfree_skb(priv->ibss_beacon);
2395
2396 priv->ibss_beacon = NULL;
2397
2398 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler3109ece2008-03-28 16:33:35 -07002399 priv->timestamp = 0;
Johannes Berg05c914fe2008-09-11 00:01:58 +02002400 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
Zhu Yib481de92007-09-25 17:54:57 -07002401 priv->beacon_int = 0;
2402
2403 spin_unlock_irqrestore(&priv->lock, flags);
2404
Tomas Winklerfee12472008-04-03 16:05:21 -07002405 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002406 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +08002407 mutex_unlock(&priv->mutex);
2408 return;
2409 }
2410
mabbas052c4b92007-10-25 17:15:43 +08002411 /* we are restarting association process
2412 * clear RXON_FILTER_ASSOC_MSK bit
2413 */
Johannes Berg05c914fe2008-09-11 00:01:58 +02002414 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Tomas Winkler2a421b92008-06-12 09:47:10 +08002415 iwl_scan_cancel_timeout(priv, 100);
mabbas052c4b92007-10-25 17:15:43 +08002416 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002417 iwlcore_commit_rxon(priv);
mabbas052c4b92007-10-25 17:15:43 +08002418 }
2419
Mohamed Abbas5da4b552008-04-21 15:41:51 -07002420 iwl_power_update_mode(priv, 0);
2421
Zhu Yib481de92007-09-25 17:54:57 -07002422 /* Per mac80211.h: This is only used in IBSS mode... */
Johannes Berg05c914fe2008-09-11 00:01:58 +02002423 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
mabbas052c4b92007-10-25 17:15:43 +08002424
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08002425 /* switch to CAM during association period.
2426 * the ucode will block any association/authentication
2427 * frome during assiciation period if it can not hear
2428 * the AP because of PM. the timer enable PM back is
2429 * association do not complete
2430 */
2431 if (priv->hw->conf.channel->flags & (IEEE80211_CHAN_PASSIVE_SCAN |
2432 IEEE80211_CHAN_RADAR))
2433 iwl_power_disable_management(priv, 3000);
2434
Tomas Winklere1623442009-01-27 14:27:56 -08002435 IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07002436 mutex_unlock(&priv->mutex);
2437 return;
2438 }
2439
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002440 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002441
2442 mutex_unlock(&priv->mutex);
2443
Tomas Winklere1623442009-01-27 14:27:56 -08002444 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002445}
2446
Zhu Yib481de92007-09-25 17:54:57 -07002447
Zhu Yib481de92007-09-25 17:54:57 -07002448/*****************************************************************************
2449 *
2450 * sysfs attributes
2451 *
2452 *****************************************************************************/
2453
Tomas Winkler0a6857e2008-03-12 16:58:49 -07002454#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07002455
2456/*
2457 * The following adds a new attribute to the sysfs representation
Wu, Fengguangc3a739f2008-12-17 16:52:29 +08002458 * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
Zhu Yib481de92007-09-25 17:54:57 -07002459 * used for controlling the debug level.
2460 *
2461 * See the level definitions in iwl for details.
2462 */
2463
Ester Kummer8cf769c2008-05-06 11:05:11 +08002464static ssize_t show_debug_level(struct device *d,
2465 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07002466{
Ester Kummer8cf769c2008-05-06 11:05:11 +08002467 struct iwl_priv *priv = d->driver_data;
2468
2469 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07002470}
Ester Kummer8cf769c2008-05-06 11:05:11 +08002471static ssize_t store_debug_level(struct device *d,
2472 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07002473 const char *buf, size_t count)
2474{
Ester Kummer8cf769c2008-05-06 11:05:11 +08002475 struct iwl_priv *priv = d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08002476 unsigned long val;
2477 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002478
Tomas Winkler9257746f2008-09-03 11:26:32 +08002479 ret = strict_strtoul(buf, 0, &val);
2480 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08002481 IWL_ERR(priv, "%s is not in hex or decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07002482 else
Ester Kummer8cf769c2008-05-06 11:05:11 +08002483 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07002484
2485 return strnlen(buf, count);
2486}
2487
Ester Kummer8cf769c2008-05-06 11:05:11 +08002488static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
2489 show_debug_level, store_debug_level);
2490
Zhu Yib481de92007-09-25 17:54:57 -07002491
Tomas Winkler0a6857e2008-03-12 16:58:49 -07002492#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07002493
Zhu Yib481de92007-09-25 17:54:57 -07002494
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08002495static ssize_t show_version(struct device *d,
2496 struct device_attribute *attr, char *buf)
2497{
2498 struct iwl_priv *priv = d->driver_data;
Tomas Winkler885ba202008-05-29 16:34:55 +08002499 struct iwl_alive_resp *palive = &priv->card_alive;
Tomas Winklerf236a262008-06-30 17:23:02 +08002500 ssize_t pos = 0;
2501 u16 eeprom_ver;
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08002502
2503 if (palive->is_valid)
Tomas Winklerf236a262008-06-30 17:23:02 +08002504 pos += sprintf(buf + pos,
2505 "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n"
2506 "fw type: 0x%01X 0x%01X\n",
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08002507 palive->ucode_major, palive->ucode_minor,
2508 palive->sw_rev[0], palive->sw_rev[1],
2509 palive->ver_type, palive->ver_subtype);
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08002510 else
Tomas Winklerf236a262008-06-30 17:23:02 +08002511 pos += sprintf(buf + pos, "fw not loaded\n");
2512
2513 if (priv->eeprom) {
2514 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
2515 pos += sprintf(buf + pos, "EEPROM version: 0x%x\n",
2516 eeprom_ver);
2517 } else {
2518 pos += sprintf(buf + pos, "EEPROM not initialzed\n");
2519 }
2520
2521 return pos;
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08002522}
2523
2524static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL);
2525
Zhu Yib481de92007-09-25 17:54:57 -07002526static ssize_t show_temperature(struct device *d,
2527 struct device_attribute *attr, char *buf)
2528{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002529 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07002530
Tomas Winklerfee12472008-04-03 16:05:21 -07002531 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002532 return -EAGAIN;
2533
Emmanuel Grumbach91dbc5bd2008-06-12 09:47:14 +08002534 return sprintf(buf, "%d\n", priv->temperature);
Zhu Yib481de92007-09-25 17:54:57 -07002535}
2536
2537static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
2538
Zhu Yib481de92007-09-25 17:54:57 -07002539static ssize_t show_tx_power(struct device *d,
2540 struct device_attribute *attr, char *buf)
2541{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002542 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Jay Sternberg91f39e82008-12-17 16:52:34 +08002543
2544 if (!iwl_is_ready_rf(priv))
2545 return sprintf(buf, "off\n");
2546 else
2547 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07002548}
2549
2550static ssize_t store_tx_power(struct device *d,
2551 struct device_attribute *attr,
2552 const char *buf, size_t count)
2553{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002554 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08002555 unsigned long val;
2556 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002557
Tomas Winkler9257746f2008-09-03 11:26:32 +08002558 ret = strict_strtoul(buf, 10, &val);
2559 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08002560 IWL_INFO(priv, "%s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07002561 else
Tomas Winkler630fe9b2008-06-12 09:47:08 +08002562 iwl_set_tx_power(priv, val, false);
Zhu Yib481de92007-09-25 17:54:57 -07002563
2564 return count;
2565}
2566
2567static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
2568
2569static ssize_t show_flags(struct device *d,
2570 struct device_attribute *attr, char *buf)
2571{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002572 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07002573
2574 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
2575}
2576
2577static ssize_t store_flags(struct device *d,
2578 struct device_attribute *attr,
2579 const char *buf, size_t count)
2580{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002581 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08002582 unsigned long val;
2583 u32 flags;
2584 int ret = strict_strtoul(buf, 0, &val);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08002585 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08002586 return ret;
2587 flags = (u32)val;
Zhu Yib481de92007-09-25 17:54:57 -07002588
2589 mutex_lock(&priv->mutex);
2590 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
2591 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08002592 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002593 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002594 else {
Tomas Winklere1623442009-01-27 14:27:56 -08002595 IWL_DEBUG_INFO(priv, "Commit rxon.flags = 0x%04X\n", flags);
Zhu Yib481de92007-09-25 17:54:57 -07002596 priv->staging_rxon.flags = cpu_to_le32(flags);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002597 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002598 }
2599 }
2600 mutex_unlock(&priv->mutex);
2601
2602 return count;
2603}
2604
2605static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
2606
2607static ssize_t show_filter_flags(struct device *d,
2608 struct device_attribute *attr, char *buf)
2609{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002610 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07002611
2612 return sprintf(buf, "0x%04X\n",
2613 le32_to_cpu(priv->active_rxon.filter_flags));
2614}
2615
2616static ssize_t store_filter_flags(struct device *d,
2617 struct device_attribute *attr,
2618 const char *buf, size_t count)
2619{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002620 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08002621 unsigned long val;
2622 u32 filter_flags;
2623 int ret = strict_strtoul(buf, 0, &val);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08002624 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08002625 return ret;
2626 filter_flags = (u32)val;
Zhu Yib481de92007-09-25 17:54:57 -07002627
2628 mutex_lock(&priv->mutex);
2629 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
2630 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08002631 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002632 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002633 else {
Tomas Winklere1623442009-01-27 14:27:56 -08002634 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
Zhu Yib481de92007-09-25 17:54:57 -07002635 "0x%04X\n", filter_flags);
2636 priv->staging_rxon.filter_flags =
2637 cpu_to_le32(filter_flags);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002638 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002639 }
2640 }
2641 mutex_unlock(&priv->mutex);
2642
2643 return count;
2644}
2645
2646static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
2647 store_filter_flags);
2648
Zhu Yib481de92007-09-25 17:54:57 -07002649static ssize_t store_power_level(struct device *d,
2650 struct device_attribute *attr,
2651 const char *buf, size_t count)
2652{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002653 struct iwl_priv *priv = dev_get_drvdata(d);
Esti Kummer298df1f2008-07-18 13:52:58 +08002654 int ret;
Tomas Winkler9257746f2008-09-03 11:26:32 +08002655 unsigned long mode;
Zhu Yib481de92007-09-25 17:54:57 -07002656
Tomas Winkler9257746f2008-09-03 11:26:32 +08002657
Zhu Yib481de92007-09-25 17:54:57 -07002658 mutex_lock(&priv->mutex);
2659
Tomas Winkler9257746f2008-09-03 11:26:32 +08002660 ret = strict_strtoul(buf, 10, &mode);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08002661 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08002662 goto out;
2663
Esti Kummer298df1f2008-07-18 13:52:58 +08002664 ret = iwl_power_set_user_mode(priv, mode);
2665 if (ret) {
Tomas Winklere1623442009-01-27 14:27:56 -08002666 IWL_DEBUG_MAC80211(priv, "failed setting power mode.\n");
Mohamed Abbas5da4b552008-04-21 15:41:51 -07002667 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002668 }
Esti Kummer298df1f2008-07-18 13:52:58 +08002669 ret = count;
Zhu Yib481de92007-09-25 17:54:57 -07002670
2671 out:
2672 mutex_unlock(&priv->mutex);
Esti Kummer298df1f2008-07-18 13:52:58 +08002673 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002674}
2675
Zhu Yib481de92007-09-25 17:54:57 -07002676static ssize_t show_power_level(struct device *d,
2677 struct device_attribute *attr, char *buf)
2678{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002679 struct iwl_priv *priv = dev_get_drvdata(d);
Esti Kummer298df1f2008-07-18 13:52:58 +08002680 int mode = priv->power_data.user_power_setting;
2681 int system = priv->power_data.system_power_setting;
Mohamed Abbas5da4b552008-04-21 15:41:51 -07002682 int level = priv->power_data.power_mode;
Zhu Yib481de92007-09-25 17:54:57 -07002683 char *p = buf;
2684
Esti Kummer298df1f2008-07-18 13:52:58 +08002685 switch (system) {
2686 case IWL_POWER_SYS_AUTO:
2687 p += sprintf(p, "SYSTEM:auto");
Zhu Yib481de92007-09-25 17:54:57 -07002688 break;
Esti Kummer298df1f2008-07-18 13:52:58 +08002689 case IWL_POWER_SYS_AC:
2690 p += sprintf(p, "SYSTEM:ac");
Zhu Yib481de92007-09-25 17:54:57 -07002691 break;
Esti Kummer298df1f2008-07-18 13:52:58 +08002692 case IWL_POWER_SYS_BATTERY:
2693 p += sprintf(p, "SYSTEM:battery");
2694 break;
Zhu Yib481de92007-09-25 17:54:57 -07002695 }
Esti Kummer298df1f2008-07-18 13:52:58 +08002696
Abhijeet Kolekarc3056062008-11-12 13:14:08 -08002697 p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
2698 "fixed" : "auto");
Esti Kummer298df1f2008-07-18 13:52:58 +08002699 p += sprintf(p, "\tINDEX:%d", level);
2700 p += sprintf(p, "\n");
Tomas Winkler3ac7f142008-07-21 02:40:14 +03002701 return p - buf + 1;
Zhu Yib481de92007-09-25 17:54:57 -07002702}
2703
2704static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
2705 store_power_level);
2706
Zhu Yib481de92007-09-25 17:54:57 -07002707
2708static ssize_t show_statistics(struct device *d,
2709 struct device_attribute *attr, char *buf)
2710{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002711 struct iwl_priv *priv = dev_get_drvdata(d);
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08002712 u32 size = sizeof(struct iwl_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07002713 u32 len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03002714 u8 *data = (u8 *)&priv->statistics;
Zhu Yib481de92007-09-25 17:54:57 -07002715 int rc = 0;
2716
Tomas Winklerfee12472008-04-03 16:05:21 -07002717 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002718 return -EAGAIN;
2719
2720 mutex_lock(&priv->mutex);
Emmanuel Grumbach49ea8592008-04-15 16:01:37 -07002721 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002722 mutex_unlock(&priv->mutex);
2723
2724 if (rc) {
2725 len = sprintf(buf,
2726 "Error sending statistics request: 0x%08X\n", rc);
2727 return len;
2728 }
2729
2730 while (size && (PAGE_SIZE - len)) {
2731 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
2732 PAGE_SIZE - len, 1);
2733 len = strlen(buf);
2734 if (PAGE_SIZE - len)
2735 buf[len++] = '\n';
2736
2737 ofs += 16;
2738 size -= min(size, 16U);
2739 }
2740
2741 return len;
2742}
2743
2744static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
2745
Zhu Yib481de92007-09-25 17:54:57 -07002746
Zhu Yib481de92007-09-25 17:54:57 -07002747/*****************************************************************************
2748 *
2749 * driver setup and teardown
2750 *
2751 *****************************************************************************/
2752
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002753static void iwl_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002754{
Reinette Chatred21050c2009-02-13 11:51:18 -08002755 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07002756
2757 init_waitqueue_head(&priv->wait_command_queue);
2758
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002759 INIT_WORK(&priv->up, iwl_bg_up);
2760 INIT_WORK(&priv->restart, iwl_bg_restart);
2761 INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish);
2762 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
2763 INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08002764 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002765 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
2766 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002767
Tomas Winkler2a421b92008-06-12 09:47:10 +08002768 iwl_setup_scan_deferred_work(priv);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08002769 iwl_setup_power_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002770
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002771 if (priv->cfg->ops->lib->setup_deferred_work)
2772 priv->cfg->ops->lib->setup_deferred_work(priv);
2773
2774 init_timer(&priv->statistics_periodic);
2775 priv->statistics_periodic.data = (unsigned long)priv;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002776 priv->statistics_periodic.function = iwl_bg_statistics_periodic;
Zhu Yib481de92007-09-25 17:54:57 -07002777
2778 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002779 iwl_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07002780}
2781
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002782static void iwl_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002783{
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002784 if (priv->cfg->ops->lib->cancel_deferred_work)
2785 priv->cfg->ops->lib->cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002786
Joonwoo Park3ae6a052007-11-29 10:43:16 +09002787 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07002788 cancel_delayed_work(&priv->scan_check);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08002789 cancel_delayed_work_sync(&priv->set_power_save);
Zhu Yib481de92007-09-25 17:54:57 -07002790 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07002791 cancel_work_sync(&priv->beacon_update);
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002792 del_timer_sync(&priv->statistics_periodic);
Zhu Yib481de92007-09-25 17:54:57 -07002793}
2794
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002795static struct attribute *iwl_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07002796 &dev_attr_flags.attr,
2797 &dev_attr_filter_flags.attr,
Zhu Yib481de92007-09-25 17:54:57 -07002798 &dev_attr_power_level.attr,
Zhu Yib481de92007-09-25 17:54:57 -07002799 &dev_attr_statistics.attr,
Zhu Yib481de92007-09-25 17:54:57 -07002800 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07002801 &dev_attr_tx_power.attr,
Ester Kummer8cf769c2008-05-06 11:05:11 +08002802#ifdef CONFIG_IWLWIFI_DEBUG
2803 &dev_attr_debug_level.attr,
2804#endif
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08002805 &dev_attr_version.attr,
Zhu Yib481de92007-09-25 17:54:57 -07002806
2807 NULL
2808};
2809
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002810static struct attribute_group iwl_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07002811 .name = NULL, /* put in device directory */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002812 .attrs = iwl_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07002813};
2814
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002815static struct ieee80211_ops iwl_hw_ops = {
2816 .tx = iwl_mac_tx,
2817 .start = iwl_mac_start,
2818 .stop = iwl_mac_stop,
2819 .add_interface = iwl_mac_add_interface,
2820 .remove_interface = iwl_mac_remove_interface,
2821 .config = iwl_mac_config,
2822 .config_interface = iwl_mac_config_interface,
2823 .configure_filter = iwl_configure_filter,
2824 .set_key = iwl_mac_set_key,
2825 .update_tkip_key = iwl_mac_update_tkip_key,
2826 .get_stats = iwl_mac_get_stats,
2827 .get_tx_stats = iwl_mac_get_tx_stats,
2828 .conf_tx = iwl_mac_conf_tx,
2829 .reset_tsf = iwl_mac_reset_tsf,
2830 .bss_info_changed = iwl_bss_info_changed,
2831 .ampdu_action = iwl_mac_ampdu_action,
Tomas Winklercb43dc22008-09-03 11:26:23 +08002832 .hw_scan = iwl_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07002833};
2834
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002835static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07002836{
2837 int err = 0;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002838 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07002839 struct ieee80211_hw *hw;
Tomas Winkler82b9a122008-03-04 18:09:30 -08002840 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002841 unsigned long flags;
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002842 u16 pci_cmd;
Zhu Yib481de92007-09-25 17:54:57 -07002843
Assaf Krauss316c30d2008-03-14 10:38:46 -07002844 /************************
2845 * 1. Allocating HW data
2846 ************************/
2847
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002848 /* Disabling hardware scan means that mac80211 will perform scans
2849 * "the hard way", rather than using device's scan. */
Assaf Krauss1ea87392008-03-18 14:57:50 -07002850 if (cfg->mod_params->disable_hw_scan) {
Ester Kummerbf403db2008-05-05 10:22:40 +08002851 if (cfg->mod_params->debug & IWL_DL_INFO)
2852 dev_printk(KERN_DEBUG, &(pdev->dev),
2853 "Disabling hw_scan\n");
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002854 iwl_hw_ops.hw_scan = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07002855 }
2856
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002857 hw = iwl_alloc_all(cfg, &iwl_hw_ops);
Assaf Krauss1d0a0822008-03-14 10:38:48 -07002858 if (!hw) {
Zhu Yib481de92007-09-25 17:54:57 -07002859 err = -ENOMEM;
2860 goto out;
2861 }
Assaf Krauss1d0a0822008-03-14 10:38:48 -07002862 priv = hw->priv;
2863 /* At this point both hw and priv are allocated. */
2864
Zhu Yib481de92007-09-25 17:54:57 -07002865 SET_IEEE80211_DEV(hw, &pdev->dev);
2866
Tomas Winklere1623442009-01-27 14:27:56 -08002867 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Tomas Winkler82b9a122008-03-04 18:09:30 -08002868 priv->cfg = cfg;
Zhu Yib481de92007-09-25 17:54:57 -07002869 priv->pci_dev = pdev;
Assaf Krauss316c30d2008-03-14 10:38:46 -07002870
Tomas Winkler0a6857e2008-03-12 16:58:49 -07002871#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08002872 priv->debug_level = priv->cfg->mod_params->debug;
Zhu Yib481de92007-09-25 17:54:57 -07002873 atomic_set(&priv->restrict_refcnt, 0);
2874#endif
Zhu Yib481de92007-09-25 17:54:57 -07002875
Assaf Krauss316c30d2008-03-14 10:38:46 -07002876 /**************************
2877 * 2. Initializing PCI bus
2878 **************************/
2879 if (pci_enable_device(pdev)) {
2880 err = -ENODEV;
2881 goto out_ieee80211_free_hw;
2882 }
2883
2884 pci_set_master(pdev);
2885
Winkler, Tomas093d874c2008-09-26 15:09:34 +08002886 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
Assaf Krauss316c30d2008-03-14 10:38:46 -07002887 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08002888 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07002889 if (err) {
Winkler, Tomas093d874c2008-09-26 15:09:34 +08002890 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07002891 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08002892 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07002893 /* both attempts failed: */
Assaf Krauss316c30d2008-03-14 10:38:46 -07002894 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08002895 IWL_WARN(priv, "No suitable DMA available.\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07002896 goto out_pci_disable_device;
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07002897 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07002898 }
2899
2900 err = pci_request_regions(pdev, DRV_NAME);
2901 if (err)
2902 goto out_pci_disable_device;
2903
2904 pci_set_drvdata(pdev, priv);
2905
Assaf Krauss316c30d2008-03-14 10:38:46 -07002906
2907 /***********************
2908 * 3. Read REV register
2909 ***********************/
2910 priv->hw_base = pci_iomap(pdev, 0, 0);
2911 if (!priv->hw_base) {
2912 err = -ENODEV;
2913 goto out_pci_release_regions;
2914 }
2915
Tomas Winklere1623442009-01-27 14:27:56 -08002916 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Assaf Krauss316c30d2008-03-14 10:38:46 -07002917 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08002918 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Assaf Krauss316c30d2008-03-14 10:38:46 -07002919
Tomas Winklerb661c812008-04-23 17:14:54 -07002920 iwl_hw_detect(priv);
Tomas Winkler978785a2008-12-19 10:37:31 +08002921 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s REV=0x%X\n",
Tomas Winklerb661c812008-04-23 17:14:54 -07002922 priv->cfg->name, priv->hw_rev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07002923
Tomas Winklere7b63582008-09-03 11:26:49 +08002924 /* We disable the RETRY_TIMEOUT register (0x41) to keep
2925 * PCI Tx retries from interfering with C3 CPU state */
2926 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
2927
Tomas Winkler91238712008-04-23 17:14:53 -07002928 /* amp init */
2929 err = priv->cfg->ops->lib->apm_ops.init(priv);
2930 if (err < 0) {
Reinette Chatre808ff692009-03-11 11:18:01 -07002931 IWL_ERR(priv, "Failed to init APMG\n");
Tomas Winkler91238712008-04-23 17:14:53 -07002932 goto out_iounmap;
2933 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07002934 /*****************
2935 * 4. Read EEPROM
2936 *****************/
Assaf Krauss316c30d2008-03-14 10:38:46 -07002937 /* Read the EEPROM */
2938 err = iwl_eeprom_init(priv);
2939 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002940 IWL_ERR(priv, "Unable to init EEPROM\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07002941 goto out_iounmap;
2942 }
Tomas Winkler8614f362008-04-23 17:14:55 -07002943 err = iwl_eeprom_check_version(priv);
2944 if (err)
Reinette Chatrec8f16132009-02-27 16:21:22 -08002945 goto out_free_eeprom;
Tomas Winkler8614f362008-04-23 17:14:55 -07002946
Ron Rindjunsky02883012008-05-15 13:53:53 +08002947 /* extract MAC Address */
Assaf Krauss316c30d2008-03-14 10:38:46 -07002948 iwl_eeprom_get_mac(priv, priv->mac_addr);
Tomas Winklere1623442009-01-27 14:27:56 -08002949 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
Assaf Krauss316c30d2008-03-14 10:38:46 -07002950 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
2951
2952 /************************
2953 * 5. Setup HW constants
2954 ************************/
Ron Rindjunskyda154e302008-06-30 17:23:20 +08002955 if (iwl_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002956 IWL_ERR(priv, "failed to set hw parameters\n");
Tomas Winkler073d3f52008-04-21 15:41:52 -07002957 goto out_free_eeprom;
Assaf Krauss316c30d2008-03-14 10:38:46 -07002958 }
2959
2960 /*******************
Tomas Winkler6ba87952008-05-15 13:54:17 +08002961 * 6. Setup priv
Assaf Krauss316c30d2008-03-14 10:38:46 -07002962 *******************/
Zhu Yib481de92007-09-25 17:54:57 -07002963
Tomas Winkler6ba87952008-05-15 13:54:17 +08002964 err = iwl_init_drv(priv);
Assaf Kraussbf85ea42008-03-14 10:38:49 -07002965 if (err)
Ron Rindjunsky399f4902008-04-23 17:14:56 -07002966 goto out_free_eeprom;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07002967 /* At this point both hw and priv are initialized. */
Assaf Krauss316c30d2008-03-14 10:38:46 -07002968
2969 /**********************************
2970 * 7. Initialize module parameters
2971 **********************************/
2972
2973 /* Disable radio (SW RF KILL) via parameter when loading driver */
Assaf Krauss1ea87392008-03-18 14:57:50 -07002974 if (priv->cfg->mod_params->disable) {
Assaf Krauss316c30d2008-03-14 10:38:46 -07002975 set_bit(STATUS_RF_KILL_SW, &priv->status);
Tomas Winklere1623442009-01-27 14:27:56 -08002976 IWL_DEBUG_INFO(priv, "Radio disabled.\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07002977 }
2978
Assaf Krauss316c30d2008-03-14 10:38:46 -07002979 /********************
2980 * 8. Setup services
2981 ********************/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002982 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002983 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002984 spin_unlock_irqrestore(&priv->lock, flags);
Assaf Krauss316c30d2008-03-14 10:38:46 -07002985
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002986 pci_enable_msi(priv->pci_dev);
2987
2988 err = request_irq(priv->pci_dev->irq, iwl_isr, IRQF_SHARED,
2989 DRV_NAME, priv);
2990 if (err) {
2991 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
2992 goto out_disable_msi;
2993 }
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002994 err = sysfs_create_group(&pdev->dev.kobj, &iwl_attribute_group);
Assaf Krauss316c30d2008-03-14 10:38:46 -07002995 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002996 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Helmut Schaa795cc0a2009-02-12 18:51:03 +01002997 goto out_free_irq;
Assaf Krauss316c30d2008-03-14 10:38:46 -07002998 }
2999
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003000 iwl_setup_deferred_work(priv);
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08003001 iwl_setup_rx_handlers(priv);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003002
Tomas Winkler6ba87952008-05-15 13:54:17 +08003003 /**********************************
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003004 * 9. Setup and register mac80211
Tomas Winkler6ba87952008-05-15 13:54:17 +08003005 **********************************/
3006
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003007 /* enable interrupts if needed: hw bug w/a */
3008 pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pci_cmd);
3009 if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
3010 pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
3011 pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
3012 }
3013
3014 iwl_enable_interrupts(priv);
3015
Tomas Winkler6ba87952008-05-15 13:54:17 +08003016 err = iwl_setup_mac(priv);
3017 if (err)
3018 goto out_remove_sysfs;
3019
3020 err = iwl_dbgfs_register(priv, DRV_NAME);
3021 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08003022 IWL_ERR(priv, "failed to create debugfs files\n");
Tomas Winkler6ba87952008-05-15 13:54:17 +08003023
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003024 /* If platform's RF_KILL switch is NOT set to KILL */
3025 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3026 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3027 else
3028 set_bit(STATUS_RF_KILL_HW, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003029
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08003030 err = iwl_rfkill_init(priv);
3031 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08003032 IWL_ERR(priv, "Unable to initialize RFKILL system. "
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08003033 "Ignoring error: %d\n", err);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003034 else
3035 iwl_rfkill_set_hw_state(priv);
3036
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08003037 iwl_power_initialize(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003038 return 0;
3039
Assaf Krauss316c30d2008-03-14 10:38:46 -07003040 out_remove_sysfs:
Reinette Chatrec8f16132009-02-27 16:21:22 -08003041 destroy_workqueue(priv->workqueue);
3042 priv->workqueue = NULL;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003043 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
Helmut Schaa795cc0a2009-02-12 18:51:03 +01003044 out_free_irq:
3045 free_irq(priv->pci_dev->irq, priv);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003046 out_disable_msi:
3047 pci_disable_msi(priv->pci_dev);
Tomas Winkler6ba87952008-05-15 13:54:17 +08003048 iwl_uninit_drv(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07003049 out_free_eeprom:
3050 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003051 out_iounmap:
3052 pci_iounmap(pdev, priv->hw_base);
3053 out_pci_release_regions:
Assaf Krauss316c30d2008-03-14 10:38:46 -07003054 pci_set_drvdata(pdev, NULL);
Reinette Chatre623d5632009-03-03 11:37:04 -08003055 pci_release_regions(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07003056 out_pci_disable_device:
3057 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07003058 out_ieee80211_free_hw:
3059 ieee80211_free_hw(priv->hw);
3060 out:
3061 return err;
3062}
3063
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003064static void __devexit iwl_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07003065{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003066 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003067 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07003068
3069 if (!priv)
3070 return;
3071
Tomas Winklere1623442009-01-27 14:27:56 -08003072 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07003073
Emmanuel Grumbach67249622008-05-29 16:35:26 +08003074 iwl_dbgfs_unregister(priv);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003075 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
Emmanuel Grumbach67249622008-05-29 16:35:26 +08003076
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003077 /* ieee80211_unregister_hw call wil cause iwl_mac_stop to
3078 * to be called and iwl_down since we are removing the device
Gregory Greenman0b124c32008-09-03 11:18:50 +08003079 * we need to set STATUS_EXIT_PENDING bit.
3080 */
3081 set_bit(STATUS_EXIT_PENDING, &priv->status);
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07003082 if (priv->mac80211_registered) {
3083 ieee80211_unregister_hw(priv->hw);
3084 priv->mac80211_registered = 0;
Gregory Greenman0b124c32008-09-03 11:18:50 +08003085 } else {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003086 iwl_down(priv);
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07003087 }
3088
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003089 /* make sure we flush any pending irq or
3090 * tasklet for the driver
3091 */
3092 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003093 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003094 spin_unlock_irqrestore(&priv->lock, flags);
3095
3096 iwl_synchronize_irq(priv);
3097
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08003098 iwl_rfkill_unregister(priv);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003099 iwl_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003100
3101 if (priv->rxq.bd)
Tomas Winklera55360e2008-05-05 10:22:28 +08003102 iwl_rx_queue_free(priv, &priv->rxq);
Ron Rindjunsky1053d352008-05-05 10:22:43 +08003103 iwl_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003104
Abhijeet Kolekare11bc022009-04-08 11:26:41 -07003105 priv->cfg->ops->smgmt->clear_station_table(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07003106 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003107
Zhu Yib481de92007-09-25 17:54:57 -07003108
Mohamed Abbas948c1712007-10-25 17:15:45 +08003109 /*netif_stop_queue(dev); */
3110 flush_workqueue(priv->workqueue);
3111
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003112 /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07003113 * priv->workqueue... so we can't take down the workqueue
3114 * until now... */
3115 destroy_workqueue(priv->workqueue);
3116 priv->workqueue = NULL;
3117
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003118 free_irq(priv->pci_dev->irq, priv);
3119 pci_disable_msi(priv->pci_dev);
Zhu Yib481de92007-09-25 17:54:57 -07003120 pci_iounmap(pdev, priv->hw_base);
3121 pci_release_regions(pdev);
3122 pci_disable_device(pdev);
3123 pci_set_drvdata(pdev, NULL);
3124
Tomas Winkler6ba87952008-05-15 13:54:17 +08003125 iwl_uninit_drv(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003126
3127 if (priv->ibss_beacon)
3128 dev_kfree_skb(priv->ibss_beacon);
3129
3130 ieee80211_free_hw(priv->hw);
3131}
3132
Zhu Yib481de92007-09-25 17:54:57 -07003133
3134/*****************************************************************************
3135 *
3136 * driver and module entry point
3137 *
3138 *****************************************************************************/
3139
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003140/* Hardware specific file defines the PCI IDs table for that hardware module */
3141static struct pci_device_id iwl_hw_card_ids[] = {
Tomas Winkler4fc22b22008-07-21 18:54:42 +03003142#ifdef CONFIG_IWL4965
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003143 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
3144 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
Tomas Winkler4fc22b22008-07-21 18:54:42 +03003145#endif /* CONFIG_IWL4965 */
Tomas Winkler5a6a2562008-04-24 11:55:23 -07003146#ifdef CONFIG_IWL5000
Esti Kummer47408632008-07-11 11:53:30 +08003147 {IWL_PCI_DEVICE(0x4232, 0x1205, iwl5100_bg_cfg)},
3148 {IWL_PCI_DEVICE(0x4232, 0x1305, iwl5100_bg_cfg)},
3149 {IWL_PCI_DEVICE(0x4232, 0x1206, iwl5100_abg_cfg)},
3150 {IWL_PCI_DEVICE(0x4232, 0x1306, iwl5100_abg_cfg)},
3151 {IWL_PCI_DEVICE(0x4232, 0x1326, iwl5100_abg_cfg)},
3152 {IWL_PCI_DEVICE(0x4237, 0x1216, iwl5100_abg_cfg)},
Tomas Winkler5a6a2562008-04-24 11:55:23 -07003153 {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)},
Esti Kummer47408632008-07-11 11:53:30 +08003154 {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)},
3155 {IWL_PCI_DEVICE(0x4236, PCI_ANY_ID, iwl5300_agn_cfg)},
3156 {IWL_PCI_DEVICE(0x4237, PCI_ANY_ID, iwl5100_agn_cfg)},
Tomas Winklere96a8492008-09-11 11:45:20 +08003157/* 5350 WiFi/WiMax */
3158 {IWL_PCI_DEVICE(0x423A, 0x1001, iwl5350_agn_cfg)},
3159 {IWL_PCI_DEVICE(0x423A, 0x1021, iwl5350_agn_cfg)},
3160 {IWL_PCI_DEVICE(0x423B, 0x1011, iwl5350_agn_cfg)},
Tomas Winkler7100e922008-12-01 16:32:18 -08003161/* 5150 Wifi/WiMax */
3162 {IWL_PCI_DEVICE(0x423C, PCI_ANY_ID, iwl5150_agn_cfg)},
3163 {IWL_PCI_DEVICE(0x423D, PCI_ANY_ID, iwl5150_agn_cfg)},
Jay Sternberge1228372009-01-19 15:30:34 -08003164/* 6000/6050 Series */
3165 {IWL_PCI_DEVICE(0x0082, 0x1102, iwl6000_2ag_cfg)},
3166 {IWL_PCI_DEVICE(0x0085, 0x1112, iwl6000_2ag_cfg)},
3167 {IWL_PCI_DEVICE(0x0082, 0x1122, iwl6000_2ag_cfg)},
3168 {IWL_PCI_DEVICE(0x422B, PCI_ANY_ID, iwl6000_3agn_cfg)},
3169 {IWL_PCI_DEVICE(0x4238, PCI_ANY_ID, iwl6000_3agn_cfg)},
3170 {IWL_PCI_DEVICE(0x0082, PCI_ANY_ID, iwl6000_2agn_cfg)},
3171 {IWL_PCI_DEVICE(0x0085, PCI_ANY_ID, iwl6000_3agn_cfg)},
3172 {IWL_PCI_DEVICE(0x0086, PCI_ANY_ID, iwl6050_3agn_cfg)},
3173 {IWL_PCI_DEVICE(0x0087, PCI_ANY_ID, iwl6050_2agn_cfg)},
3174 {IWL_PCI_DEVICE(0x0088, PCI_ANY_ID, iwl6050_3agn_cfg)},
3175 {IWL_PCI_DEVICE(0x0089, PCI_ANY_ID, iwl6050_2agn_cfg)},
Jay Sternberg77dcb6a2009-03-06 13:52:55 -08003176/* 1000 Series WiFi */
3177 {IWL_PCI_DEVICE(0x0083, PCI_ANY_ID, iwl1000_bgn_cfg)},
3178 {IWL_PCI_DEVICE(0x0084, PCI_ANY_ID, iwl1000_bgn_cfg)},
Tomas Winkler5a6a2562008-04-24 11:55:23 -07003179#endif /* CONFIG_IWL5000 */
Tomas Winkler7100e922008-12-01 16:32:18 -08003180
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003181 {0}
3182};
3183MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
3184
3185static struct pci_driver iwl_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07003186 .name = DRV_NAME,
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003187 .id_table = iwl_hw_card_ids,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003188 .probe = iwl_pci_probe,
3189 .remove = __devexit_p(iwl_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07003190#ifdef CONFIG_PM
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003191 .suspend = iwl_pci_suspend,
3192 .resume = iwl_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07003193#endif
3194};
3195
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003196static int __init iwl_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07003197{
3198
3199 int ret;
3200 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
3201 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003202
Tomas Winklere227cea2008-07-18 13:53:05 +08003203 ret = iwlagn_rate_control_register();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003204 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08003205 printk(KERN_ERR DRV_NAME
3206 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003207 return ret;
3208 }
3209
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003210 ret = pci_register_driver(&iwl_driver);
Zhu Yib481de92007-09-25 17:54:57 -07003211 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08003212 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003213 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07003214 }
Zhu Yib481de92007-09-25 17:54:57 -07003215
3216 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003217
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003218error_register:
Tomas Winklere227cea2008-07-18 13:53:05 +08003219 iwlagn_rate_control_unregister();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003220 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003221}
3222
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003223static void __exit iwl_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07003224{
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003225 pci_unregister_driver(&iwl_driver);
Tomas Winklere227cea2008-07-18 13:53:05 +08003226 iwlagn_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07003227}
3228
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003229module_exit(iwl_exit);
3230module_init(iwl_init);