blob: e4ed479c36f57b3fd39ed455474f99dc7727d702 [file] [log] [blame]
James Ketrenos2c86c272005-03-23 17:32:29 -06001/******************************************************************************
2
Zhu Yi171e7b22006-02-15 07:17:56 +08003 Copyright(c) 2003 - 2006 Intel Corporation. All rights reserved.
James Ketrenos2c86c272005-03-23 17:32:29 -06004
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of version 2 of the GNU General Public License as
7 published by the Free Software Foundation.
8
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc., 59
16 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 The full GNU General Public License is included in this distribution in the
19 file called LICENSE.
20
21 Contact Information:
Reinette Chatrec1eb2c82009-08-21 13:34:26 -070022 Intel Linux Wireless <ilw@linux.intel.com>
James Ketrenos2c86c272005-03-23 17:32:29 -060023 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24
25 Portions of this file are based on the sample_* files provided by Wireless
26 Extensions 0.26 package and copyright (c) 1997-2003 Jean Tourrilhes
27 <jt@hpl.hp.com>
28
29 Portions of this file are based on the Host AP project,
30 Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
Jouni Malinen85d32e72007-03-24 17:15:30 -070031 <j@w1.fi>
32 Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
James Ketrenos2c86c272005-03-23 17:32:29 -060033
34 Portions of ipw2100_mod_firmware_load, ipw2100_do_mod_firmware_load, and
35 ipw2100_fw_load are loosely based on drivers/sound/sound_firmware.c
36 available in the 2.4.25 kernel sources, and are copyright (c) Alan Cox
37
38******************************************************************************/
39/*
40
41 Initial driver on which this is based was developed by Janusz Gorycki,
42 Maciej Urbaniak, and Maciej Sosnowski.
43
44 Promiscuous mode support added by Jacek Wysoczynski and Maciej Urbaniak.
45
46Theory of Operation
47
48Tx - Commands and Data
49
50Firmware and host share a circular queue of Transmit Buffer Descriptors (TBDs)
51Each TBD contains a pointer to the physical (dma_addr_t) address of data being
52sent to the firmware as well as the length of the data.
53
54The host writes to the TBD queue at the WRITE index. The WRITE index points
55to the _next_ packet to be written and is advanced when after the TBD has been
56filled.
57
58The firmware pulls from the TBD queue at the READ index. The READ index points
59to the currently being read entry, and is advanced once the firmware is
60done with a packet.
61
62When data is sent to the firmware, the first TBD is used to indicate to the
63firmware if a Command or Data is being sent. If it is Command, all of the
64command information is contained within the physical address referred to by the
65TBD. If it is Data, the first TBD indicates the type of data packet, number
66of fragments, etc. The next TBD then referrs to the actual packet location.
67
68The Tx flow cycle is as follows:
69
701) ipw2100_tx() is called by kernel with SKB to transmit
712) Packet is move from the tx_free_list and appended to the transmit pending
72 list (tx_pend_list)
733) work is scheduled to move pending packets into the shared circular queue.
744) when placing packet in the circular queue, the incoming SKB is DMA mapped
75 to a physical address. That address is entered into a TBD. Two TBDs are
76 filled out. The first indicating a data packet, the second referring to the
77 actual payload data.
785) the packet is removed from tx_pend_list and placed on the end of the
79 firmware pending list (fw_pend_list)
806) firmware is notified that the WRITE index has
817) Once the firmware has processed the TBD, INTA is triggered.
828) For each Tx interrupt received from the firmware, the READ index is checked
83 to see which TBDs are done being processed.
849) For each TBD that has been processed, the ISR pulls the oldest packet
85 from the fw_pend_list.
8610)The packet structure contained in the fw_pend_list is then used
87 to unmap the DMA address and to free the SKB originally passed to the driver
88 from the kernel.
8911)The packet structure is placed onto the tx_free_list
90
91The above steps are the same for commands, only the msg_free_list/msg_pend_list
92are used instead of tx_free_list/tx_pend_list
93
94...
95
96Critical Sections / Locking :
97
98There are two locks utilized. The first is the low level lock (priv->low_lock)
99that protects the following:
100
101- Access to the Tx/Rx queue lists via priv->low_lock. The lists are as follows:
102
103 tx_free_list : Holds pre-allocated Tx buffers.
104 TAIL modified in __ipw2100_tx_process()
105 HEAD modified in ipw2100_tx()
106
107 tx_pend_list : Holds used Tx buffers waiting to go into the TBD ring
108 TAIL modified ipw2100_tx()
Jiri Benc19f7f742005-08-25 20:02:10 -0400109 HEAD modified by ipw2100_tx_send_data()
James Ketrenos2c86c272005-03-23 17:32:29 -0600110
111 msg_free_list : Holds pre-allocated Msg (Command) buffers
112 TAIL modified in __ipw2100_tx_process()
113 HEAD modified in ipw2100_hw_send_command()
114
115 msg_pend_list : Holds used Msg buffers waiting to go into the TBD ring
116 TAIL modified in ipw2100_hw_send_command()
Jiri Benc19f7f742005-08-25 20:02:10 -0400117 HEAD modified in ipw2100_tx_send_commands()
James Ketrenos2c86c272005-03-23 17:32:29 -0600118
119 The flow of data on the TX side is as follows:
120
121 MSG_FREE_LIST + COMMAND => MSG_PEND_LIST => TBD => MSG_FREE_LIST
122 TX_FREE_LIST + DATA => TX_PEND_LIST => TBD => TX_FREE_LIST
123
124 The methods that work on the TBD ring are protected via priv->low_lock.
125
126- The internal data state of the device itself
127- Access to the firmware read/write indexes for the BD queues
128 and associated logic
129
130All external entry functions are locked with the priv->action_lock to ensure
131that only one external action is invoked at a time.
132
133
134*/
135
136#include <linux/compiler.h>
James Ketrenos2c86c272005-03-23 17:32:29 -0600137#include <linux/errno.h>
138#include <linux/if_arp.h>
139#include <linux/in6.h>
140#include <linux/in.h>
141#include <linux/ip.h>
142#include <linux/kernel.h>
143#include <linux/kmod.h>
144#include <linux/module.h>
145#include <linux/netdevice.h>
146#include <linux/ethtool.h>
147#include <linux/pci.h>
Tobias Klauser05743d12005-06-20 14:28:40 -0700148#include <linux/dma-mapping.h>
James Ketrenos2c86c272005-03-23 17:32:29 -0600149#include <linux/proc_fs.h>
150#include <linux/skbuff.h>
151#include <asm/uaccess.h>
152#include <asm/io.h>
James Ketrenos2c86c272005-03-23 17:32:29 -0600153#include <linux/fs.h>
154#include <linux/mm.h>
155#include <linux/slab.h>
156#include <linux/unistd.h>
157#include <linux/stringify.h>
158#include <linux/tcp.h>
159#include <linux/types.h>
James Ketrenos2c86c272005-03-23 17:32:29 -0600160#include <linux/time.h>
161#include <linux/firmware.h>
162#include <linux/acpi.h>
163#include <linux/ctype.h>
Mark Grossf011e2e2008-02-04 22:30:09 -0800164#include <linux/pm_qos_params.h>
James Ketrenos2c86c272005-03-23 17:32:29 -0600165
John W. Linville9387b7c2008-09-30 20:59:05 -0400166#include <net/lib80211.h>
167
James Ketrenos2c86c272005-03-23 17:32:29 -0600168#include "ipw2100.h"
169
Zhu Yicc8279f2006-02-21 18:46:15 +0800170#define IPW2100_VERSION "git-1.2.2"
James Ketrenos2c86c272005-03-23 17:32:29 -0600171
172#define DRV_NAME "ipw2100"
173#define DRV_VERSION IPW2100_VERSION
174#define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2100 Network Driver"
Zhu Yi171e7b22006-02-15 07:17:56 +0800175#define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation"
James Ketrenos2c86c272005-03-23 17:32:29 -0600176
John W. Linvilled267be32010-07-20 14:11:51 -0400177static struct pm_qos_request_list *ipw2100_pm_qos_req;
Mark Grossed771342010-05-06 01:59:26 +0200178
James Ketrenos2c86c272005-03-23 17:32:29 -0600179/* Debugging stuff */
Brice Goglin0f52bf92005-12-01 01:41:46 -0800180#ifdef CONFIG_IPW2100_DEBUG
Robert P. J. Dayae800312007-01-31 02:39:40 -0500181#define IPW2100_RX_DEBUG /* Reception debugging */
James Ketrenos2c86c272005-03-23 17:32:29 -0600182#endif
183
184MODULE_DESCRIPTION(DRV_DESCRIPTION);
185MODULE_VERSION(DRV_VERSION);
186MODULE_AUTHOR(DRV_COPYRIGHT);
187MODULE_LICENSE("GPL");
188
189static int debug = 0;
Reinette Chatre21f8a732009-08-18 10:25:05 -0700190static int network_mode = 0;
James Ketrenos2c86c272005-03-23 17:32:29 -0600191static int channel = 0;
Tim Gardner5c7f9b72008-10-14 10:38:03 -0600192static int associate = 0;
James Ketrenos2c86c272005-03-23 17:32:29 -0600193static int disable = 0;
194#ifdef CONFIG_PM
195static struct ipw2100_fw ipw2100_firmware;
196#endif
197
198#include <linux/moduleparam.h>
199module_param(debug, int, 0444);
Reinette Chatre21f8a732009-08-18 10:25:05 -0700200module_param_named(mode, network_mode, int, 0444);
James Ketrenos2c86c272005-03-23 17:32:29 -0600201module_param(channel, int, 0444);
202module_param(associate, int, 0444);
203module_param(disable, int, 0444);
204
205MODULE_PARM_DESC(debug, "debug level");
206MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
207MODULE_PARM_DESC(channel, "channel");
Tim Gardner5c7f9b72008-10-14 10:38:03 -0600208MODULE_PARM_DESC(associate, "auto associate when scanning (default off)");
James Ketrenos2c86c272005-03-23 17:32:29 -0600209MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
210
Jiri Bencc4aee8c2005-08-25 20:04:43 -0400211static u32 ipw2100_debug_level = IPW_DL_NONE;
212
Brice Goglin0f52bf92005-12-01 01:41:46 -0800213#ifdef CONFIG_IPW2100_DEBUG
Jiri Bencc4aee8c2005-08-25 20:04:43 -0400214#define IPW_DEBUG(level, message...) \
215do { \
216 if (ipw2100_debug_level & (level)) { \
217 printk(KERN_DEBUG "ipw2100: %c %s ", \
Harvey Harrisonc94c93d2008-07-28 23:01:34 -0700218 in_interrupt() ? 'I' : 'U', __func__); \
Jiri Bencc4aee8c2005-08-25 20:04:43 -0400219 printk(message); \
220 } \
221} while (0)
222#else
223#define IPW_DEBUG(level, message...) do {} while (0)
Brice Goglin0f52bf92005-12-01 01:41:46 -0800224#endif /* CONFIG_IPW2100_DEBUG */
James Ketrenos2c86c272005-03-23 17:32:29 -0600225
Brice Goglin0f52bf92005-12-01 01:41:46 -0800226#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -0600227static const char *command_types[] = {
228 "undefined",
James Ketrenosee8e3652005-09-14 09:47:29 -0500229 "unused", /* HOST_ATTENTION */
James Ketrenos2c86c272005-03-23 17:32:29 -0600230 "HOST_COMPLETE",
James Ketrenosee8e3652005-09-14 09:47:29 -0500231 "unused", /* SLEEP */
232 "unused", /* HOST_POWER_DOWN */
James Ketrenos2c86c272005-03-23 17:32:29 -0600233 "unused",
234 "SYSTEM_CONFIG",
James Ketrenosee8e3652005-09-14 09:47:29 -0500235 "unused", /* SET_IMR */
James Ketrenos2c86c272005-03-23 17:32:29 -0600236 "SSID",
237 "MANDATORY_BSSID",
238 "AUTHENTICATION_TYPE",
239 "ADAPTER_ADDRESS",
240 "PORT_TYPE",
241 "INTERNATIONAL_MODE",
242 "CHANNEL",
243 "RTS_THRESHOLD",
244 "FRAG_THRESHOLD",
245 "POWER_MODE",
246 "TX_RATES",
247 "BASIC_TX_RATES",
248 "WEP_KEY_INFO",
249 "unused",
250 "unused",
251 "unused",
252 "unused",
253 "WEP_KEY_INDEX",
254 "WEP_FLAGS",
255 "ADD_MULTICAST",
256 "CLEAR_ALL_MULTICAST",
257 "BEACON_INTERVAL",
258 "ATIM_WINDOW",
259 "CLEAR_STATISTICS",
260 "undefined",
261 "undefined",
262 "undefined",
263 "undefined",
264 "TX_POWER_INDEX",
265 "undefined",
266 "undefined",
267 "undefined",
268 "undefined",
269 "undefined",
270 "undefined",
271 "BROADCAST_SCAN",
272 "CARD_DISABLE",
273 "PREFERRED_BSSID",
274 "SET_SCAN_OPTIONS",
275 "SCAN_DWELL_TIME",
276 "SWEEP_TABLE",
277 "AP_OR_STATION_TABLE",
278 "GROUP_ORDINALS",
279 "SHORT_RETRY_LIMIT",
280 "LONG_RETRY_LIMIT",
James Ketrenosee8e3652005-09-14 09:47:29 -0500281 "unused", /* SAVE_CALIBRATION */
282 "unused", /* RESTORE_CALIBRATION */
James Ketrenos2c86c272005-03-23 17:32:29 -0600283 "undefined",
284 "undefined",
285 "undefined",
286 "HOST_PRE_POWER_DOWN",
James Ketrenosee8e3652005-09-14 09:47:29 -0500287 "unused", /* HOST_INTERRUPT_COALESCING */
James Ketrenos2c86c272005-03-23 17:32:29 -0600288 "undefined",
289 "CARD_DISABLE_PHY_OFF",
James Ketrenosee8e3652005-09-14 09:47:29 -0500290 "MSDU_TX_RATES" "undefined",
James Ketrenos2c86c272005-03-23 17:32:29 -0600291 "undefined",
292 "SET_STATION_STAT_BITS",
293 "CLEAR_STATIONS_STAT_BITS",
294 "LEAP_ROGUE_MODE",
295 "SET_SECURITY_INFORMATION",
296 "DISASSOCIATION_BSSID",
297 "SET_WPA_ASS_IE"
298};
299#endif
300
Matthew Garrettc26409a2009-11-11 14:36:30 -0500301#define WEXT_USECHANNELS 1
302
303static const long ipw2100_frequencies[] = {
304 2412, 2417, 2422, 2427,
305 2432, 2437, 2442, 2447,
306 2452, 2457, 2462, 2467,
307 2472, 2484
308};
309
310#define FREQ_COUNT ARRAY_SIZE(ipw2100_frequencies)
311
312static const long ipw2100_rates_11b[] = {
313 1000000,
314 2000000,
315 5500000,
316 11000000
317};
318
319static struct ieee80211_rate ipw2100_bg_rates[] = {
320 { .bitrate = 10 },
321 { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
322 { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
323 { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
324};
325
326#define RATE_COUNT ARRAY_SIZE(ipw2100_rates_11b)
327
James Ketrenos2c86c272005-03-23 17:32:29 -0600328/* Pre-decl until we get the code solid and then we can clean it up */
Jiri Benc19f7f742005-08-25 20:02:10 -0400329static void ipw2100_tx_send_commands(struct ipw2100_priv *priv);
330static void ipw2100_tx_send_data(struct ipw2100_priv *priv);
James Ketrenos2c86c272005-03-23 17:32:29 -0600331static int ipw2100_adapter_setup(struct ipw2100_priv *priv);
332
333static void ipw2100_queues_initialize(struct ipw2100_priv *priv);
334static void ipw2100_queues_free(struct ipw2100_priv *priv);
335static int ipw2100_queues_allocate(struct ipw2100_priv *priv);
336
Jiri Bencc4aee8c2005-08-25 20:04:43 -0400337static int ipw2100_fw_download(struct ipw2100_priv *priv,
338 struct ipw2100_fw *fw);
339static int ipw2100_get_firmware(struct ipw2100_priv *priv,
340 struct ipw2100_fw *fw);
341static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf,
342 size_t max);
343static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf,
344 size_t max);
345static void ipw2100_release_firmware(struct ipw2100_priv *priv,
346 struct ipw2100_fw *fw);
347static int ipw2100_ucode_download(struct ipw2100_priv *priv,
348 struct ipw2100_fw *fw);
David Howellsc4028952006-11-22 14:57:56 +0000349static void ipw2100_wx_event_work(struct work_struct *work);
James Ketrenosee8e3652005-09-14 09:47:29 -0500350static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device *dev);
Jiri Bencc4aee8c2005-08-25 20:04:43 -0400351static struct iw_handler_def ipw2100_wx_handler_def;
352
James Ketrenosee8e3652005-09-14 09:47:29 -0500353static inline void read_register(struct net_device *dev, u32 reg, u32 * val)
James Ketrenos2c86c272005-03-23 17:32:29 -0600354{
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +0100355 *val = readl((void __iomem *)(dev->base_addr + reg));
James Ketrenos2c86c272005-03-23 17:32:29 -0600356 IPW_DEBUG_IO("r: 0x%08X => 0x%08X\n", reg, *val);
357}
358
359static inline void write_register(struct net_device *dev, u32 reg, u32 val)
360{
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +0100361 writel(val, (void __iomem *)(dev->base_addr + reg));
James Ketrenos2c86c272005-03-23 17:32:29 -0600362 IPW_DEBUG_IO("w: 0x%08X <= 0x%08X\n", reg, val);
363}
364
James Ketrenosee8e3652005-09-14 09:47:29 -0500365static inline void read_register_word(struct net_device *dev, u32 reg,
366 u16 * val)
James Ketrenos2c86c272005-03-23 17:32:29 -0600367{
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +0100368 *val = readw((void __iomem *)(dev->base_addr + reg));
James Ketrenos2c86c272005-03-23 17:32:29 -0600369 IPW_DEBUG_IO("r: 0x%08X => %04X\n", reg, *val);
370}
371
James Ketrenosee8e3652005-09-14 09:47:29 -0500372static inline void read_register_byte(struct net_device *dev, u32 reg, u8 * val)
James Ketrenos2c86c272005-03-23 17:32:29 -0600373{
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +0100374 *val = readb((void __iomem *)(dev->base_addr + reg));
James Ketrenos2c86c272005-03-23 17:32:29 -0600375 IPW_DEBUG_IO("r: 0x%08X => %02X\n", reg, *val);
376}
377
378static inline void write_register_word(struct net_device *dev, u32 reg, u16 val)
379{
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +0100380 writew(val, (void __iomem *)(dev->base_addr + reg));
James Ketrenos2c86c272005-03-23 17:32:29 -0600381 IPW_DEBUG_IO("w: 0x%08X <= %04X\n", reg, val);
382}
383
James Ketrenos2c86c272005-03-23 17:32:29 -0600384static inline void write_register_byte(struct net_device *dev, u32 reg, u8 val)
385{
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +0100386 writeb(val, (void __iomem *)(dev->base_addr + reg));
James Ketrenos2c86c272005-03-23 17:32:29 -0600387 IPW_DEBUG_IO("w: 0x%08X =< %02X\n", reg, val);
388}
389
James Ketrenosee8e3652005-09-14 09:47:29 -0500390static inline void read_nic_dword(struct net_device *dev, u32 addr, u32 * val)
James Ketrenos2c86c272005-03-23 17:32:29 -0600391{
392 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
393 addr & IPW_REG_INDIRECT_ADDR_MASK);
394 read_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
395}
396
397static inline void write_nic_dword(struct net_device *dev, u32 addr, u32 val)
398{
399 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
400 addr & IPW_REG_INDIRECT_ADDR_MASK);
401 write_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
402}
403
James Ketrenosee8e3652005-09-14 09:47:29 -0500404static inline void read_nic_word(struct net_device *dev, u32 addr, u16 * val)
James Ketrenos2c86c272005-03-23 17:32:29 -0600405{
406 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
407 addr & IPW_REG_INDIRECT_ADDR_MASK);
408 read_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
409}
410
411static inline void write_nic_word(struct net_device *dev, u32 addr, u16 val)
412{
413 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
414 addr & IPW_REG_INDIRECT_ADDR_MASK);
415 write_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
416}
417
James Ketrenosee8e3652005-09-14 09:47:29 -0500418static inline void read_nic_byte(struct net_device *dev, u32 addr, u8 * val)
James Ketrenos2c86c272005-03-23 17:32:29 -0600419{
420 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
421 addr & IPW_REG_INDIRECT_ADDR_MASK);
422 read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
423}
424
425static inline void write_nic_byte(struct net_device *dev, u32 addr, u8 val)
426{
427 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
428 addr & IPW_REG_INDIRECT_ADDR_MASK);
429 write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
430}
431
432static inline void write_nic_auto_inc_address(struct net_device *dev, u32 addr)
433{
434 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS,
435 addr & IPW_REG_INDIRECT_ADDR_MASK);
436}
437
438static inline void write_nic_dword_auto_inc(struct net_device *dev, u32 val)
439{
440 write_register(dev, IPW_REG_AUTOINCREMENT_DATA, val);
441}
442
Arjan van de Ven858119e2006-01-14 13:20:43 -0800443static void write_nic_memory(struct net_device *dev, u32 addr, u32 len,
James Ketrenosee8e3652005-09-14 09:47:29 -0500444 const u8 * buf)
James Ketrenos2c86c272005-03-23 17:32:29 -0600445{
446 u32 aligned_addr;
447 u32 aligned_len;
448 u32 dif_len;
449 u32 i;
450
451 /* read first nibble byte by byte */
452 aligned_addr = addr & (~0x3);
453 dif_len = addr - aligned_addr;
454 if (dif_len) {
455 /* Start reading at aligned_addr + dif_len */
456 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
457 aligned_addr);
458 for (i = dif_len; i < 4; i++, buf++)
James Ketrenosee8e3652005-09-14 09:47:29 -0500459 write_register_byte(dev,
460 IPW_REG_INDIRECT_ACCESS_DATA + i,
461 *buf);
James Ketrenos2c86c272005-03-23 17:32:29 -0600462
463 len -= dif_len;
464 aligned_addr += 4;
465 }
466
467 /* read DWs through autoincrement registers */
James Ketrenosee8e3652005-09-14 09:47:29 -0500468 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS, aligned_addr);
James Ketrenos2c86c272005-03-23 17:32:29 -0600469 aligned_len = len & (~0x3);
470 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
James Ketrenosee8e3652005-09-14 09:47:29 -0500471 write_register(dev, IPW_REG_AUTOINCREMENT_DATA, *(u32 *) buf);
James Ketrenos2c86c272005-03-23 17:32:29 -0600472
473 /* copy the last nibble */
474 dif_len = len - aligned_len;
475 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr);
476 for (i = 0; i < dif_len; i++, buf++)
James Ketrenosee8e3652005-09-14 09:47:29 -0500477 write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA + i,
478 *buf);
James Ketrenos2c86c272005-03-23 17:32:29 -0600479}
480
Arjan van de Ven858119e2006-01-14 13:20:43 -0800481static void read_nic_memory(struct net_device *dev, u32 addr, u32 len,
James Ketrenosee8e3652005-09-14 09:47:29 -0500482 u8 * buf)
James Ketrenos2c86c272005-03-23 17:32:29 -0600483{
484 u32 aligned_addr;
485 u32 aligned_len;
486 u32 dif_len;
487 u32 i;
488
489 /* read first nibble byte by byte */
490 aligned_addr = addr & (~0x3);
491 dif_len = addr - aligned_addr;
492 if (dif_len) {
493 /* Start reading at aligned_addr + dif_len */
494 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
495 aligned_addr);
496 for (i = dif_len; i < 4; i++, buf++)
James Ketrenosee8e3652005-09-14 09:47:29 -0500497 read_register_byte(dev,
498 IPW_REG_INDIRECT_ACCESS_DATA + i,
499 buf);
James Ketrenos2c86c272005-03-23 17:32:29 -0600500
501 len -= dif_len;
502 aligned_addr += 4;
503 }
504
505 /* read DWs through autoincrement registers */
James Ketrenosee8e3652005-09-14 09:47:29 -0500506 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS, aligned_addr);
James Ketrenos2c86c272005-03-23 17:32:29 -0600507 aligned_len = len & (~0x3);
508 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
James Ketrenosee8e3652005-09-14 09:47:29 -0500509 read_register(dev, IPW_REG_AUTOINCREMENT_DATA, (u32 *) buf);
James Ketrenos2c86c272005-03-23 17:32:29 -0600510
511 /* copy the last nibble */
512 dif_len = len - aligned_len;
James Ketrenosee8e3652005-09-14 09:47:29 -0500513 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr);
James Ketrenos2c86c272005-03-23 17:32:29 -0600514 for (i = 0; i < dif_len; i++, buf++)
James Ketrenosee8e3652005-09-14 09:47:29 -0500515 read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA + i, buf);
James Ketrenos2c86c272005-03-23 17:32:29 -0600516}
517
518static inline int ipw2100_hw_is_adapter_in_system(struct net_device *dev)
519{
520 return (dev->base_addr &&
James Ketrenosee8e3652005-09-14 09:47:29 -0500521 (readl
522 ((void __iomem *)(dev->base_addr +
523 IPW_REG_DOA_DEBUG_AREA_START))
James Ketrenos2c86c272005-03-23 17:32:29 -0600524 == IPW_DATA_DOA_DEBUG_VALUE));
525}
526
Jiri Bencc4aee8c2005-08-25 20:04:43 -0400527static int ipw2100_get_ordinal(struct ipw2100_priv *priv, u32 ord,
James Ketrenosee8e3652005-09-14 09:47:29 -0500528 void *val, u32 * len)
James Ketrenos2c86c272005-03-23 17:32:29 -0600529{
530 struct ipw2100_ordinals *ordinals = &priv->ordinals;
531 u32 addr;
532 u32 field_info;
533 u16 field_len;
534 u16 field_count;
535 u32 total_length;
536
537 if (ordinals->table1_addr == 0) {
Jiri Benc797b4f72005-08-25 20:03:27 -0400538 printk(KERN_WARNING DRV_NAME ": attempt to use fw ordinals "
James Ketrenos2c86c272005-03-23 17:32:29 -0600539 "before they have been loaded.\n");
540 return -EINVAL;
541 }
542
543 if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
544 if (*len < IPW_ORD_TAB_1_ENTRY_SIZE) {
545 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
546
Jiri Benc797b4f72005-08-25 20:03:27 -0400547 printk(KERN_WARNING DRV_NAME
Jiri Bencaaa4d302005-06-07 14:58:41 +0200548 ": ordinal buffer length too small, need %zd\n",
James Ketrenos2c86c272005-03-23 17:32:29 -0600549 IPW_ORD_TAB_1_ENTRY_SIZE);
550
551 return -EINVAL;
552 }
553
James Ketrenosee8e3652005-09-14 09:47:29 -0500554 read_nic_dword(priv->net_dev,
555 ordinals->table1_addr + (ord << 2), &addr);
James Ketrenos2c86c272005-03-23 17:32:29 -0600556 read_nic_dword(priv->net_dev, addr, val);
557
558 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
559
560 return 0;
561 }
562
563 if (IS_ORDINAL_TABLE_TWO(ordinals, ord)) {
564
565 ord -= IPW_START_ORD_TAB_2;
566
567 /* get the address of statistic */
James Ketrenosee8e3652005-09-14 09:47:29 -0500568 read_nic_dword(priv->net_dev,
569 ordinals->table2_addr + (ord << 3), &addr);
James Ketrenos2c86c272005-03-23 17:32:29 -0600570
571 /* get the second DW of statistics ;
572 * two 16-bit words - first is length, second is count */
573 read_nic_dword(priv->net_dev,
574 ordinals->table2_addr + (ord << 3) + sizeof(u32),
575 &field_info);
576
577 /* get each entry length */
James Ketrenosee8e3652005-09-14 09:47:29 -0500578 field_len = *((u16 *) & field_info);
James Ketrenos2c86c272005-03-23 17:32:29 -0600579
580 /* get number of entries */
James Ketrenosee8e3652005-09-14 09:47:29 -0500581 field_count = *(((u16 *) & field_info) + 1);
James Ketrenos2c86c272005-03-23 17:32:29 -0600582
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200583 /* abort if no enough memory */
James Ketrenos2c86c272005-03-23 17:32:29 -0600584 total_length = field_len * field_count;
585 if (total_length > *len) {
586 *len = total_length;
587 return -EINVAL;
588 }
589
590 *len = total_length;
591 if (!total_length)
592 return 0;
593
594 /* read the ordinal data from the SRAM */
595 read_nic_memory(priv->net_dev, addr, total_length, val);
596
597 return 0;
598 }
599
Jiri Benc797b4f72005-08-25 20:03:27 -0400600 printk(KERN_WARNING DRV_NAME ": ordinal %d neither in table 1 nor "
James Ketrenos2c86c272005-03-23 17:32:29 -0600601 "in table 2\n", ord);
602
603 return -EINVAL;
604}
605
James Ketrenosee8e3652005-09-14 09:47:29 -0500606static int ipw2100_set_ordinal(struct ipw2100_priv *priv, u32 ord, u32 * val,
607 u32 * len)
James Ketrenos2c86c272005-03-23 17:32:29 -0600608{
609 struct ipw2100_ordinals *ordinals = &priv->ordinals;
610 u32 addr;
611
612 if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
613 if (*len != IPW_ORD_TAB_1_ENTRY_SIZE) {
614 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
615 IPW_DEBUG_INFO("wrong size\n");
616 return -EINVAL;
617 }
618
James Ketrenosee8e3652005-09-14 09:47:29 -0500619 read_nic_dword(priv->net_dev,
620 ordinals->table1_addr + (ord << 2), &addr);
James Ketrenos2c86c272005-03-23 17:32:29 -0600621
622 write_nic_dword(priv->net_dev, addr, *val);
623
624 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
625
626 return 0;
627 }
628
629 IPW_DEBUG_INFO("wrong table\n");
630 if (IS_ORDINAL_TABLE_TWO(ordinals, ord))
631 return -EINVAL;
632
633 return -EINVAL;
634}
635
636static char *snprint_line(char *buf, size_t count,
James Ketrenosee8e3652005-09-14 09:47:29 -0500637 const u8 * data, u32 len, u32 ofs)
James Ketrenos2c86c272005-03-23 17:32:29 -0600638{
639 int out, i, j, l;
640 char c;
641
642 out = snprintf(buf, count, "%08X", ofs);
643
644 for (l = 0, i = 0; i < 2; i++) {
645 out += snprintf(buf + out, count - out, " ");
646 for (j = 0; j < 8 && l < len; j++, l++)
647 out += snprintf(buf + out, count - out, "%02X ",
648 data[(i * 8 + j)]);
649 for (; j < 8; j++)
650 out += snprintf(buf + out, count - out, " ");
651 }
652
653 out += snprintf(buf + out, count - out, " ");
654 for (l = 0, i = 0; i < 2; i++) {
655 out += snprintf(buf + out, count - out, " ");
656 for (j = 0; j < 8 && l < len; j++, l++) {
657 c = data[(i * 8 + j)];
658 if (!isascii(c) || !isprint(c))
659 c = '.';
660
661 out += snprintf(buf + out, count - out, "%c", c);
662 }
663
664 for (; j < 8; j++)
665 out += snprintf(buf + out, count - out, " ");
666 }
667
668 return buf;
669}
670
James Ketrenosee8e3652005-09-14 09:47:29 -0500671static void printk_buf(int level, const u8 * data, u32 len)
James Ketrenos2c86c272005-03-23 17:32:29 -0600672{
673 char line[81];
674 u32 ofs = 0;
675 if (!(ipw2100_debug_level & level))
676 return;
677
678 while (len) {
679 printk(KERN_DEBUG "%s\n",
680 snprint_line(line, sizeof(line), &data[ofs],
681 min(len, 16U), ofs));
682 ofs += 16;
683 len -= min(len, 16U);
684 }
685}
686
James Ketrenos2c86c272005-03-23 17:32:29 -0600687#define MAX_RESET_BACKOFF 10
688
Arjan van de Ven858119e2006-01-14 13:20:43 -0800689static void schedule_reset(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -0600690{
691 unsigned long now = get_seconds();
692
693 /* If we haven't received a reset request within the backoff period,
694 * then we can reset the backoff interval so this reset occurs
695 * immediately */
696 if (priv->reset_backoff &&
697 (now - priv->last_reset > priv->reset_backoff))
698 priv->reset_backoff = 0;
699
700 priv->last_reset = get_seconds();
701
702 if (!(priv->status & STATUS_RESET_PENDING)) {
703 IPW_DEBUG_INFO("%s: Scheduling firmware restart (%ds).\n",
704 priv->net_dev->name, priv->reset_backoff);
705 netif_carrier_off(priv->net_dev);
706 netif_stop_queue(priv->net_dev);
707 priv->status |= STATUS_RESET_PENDING;
708 if (priv->reset_backoff)
709 queue_delayed_work(priv->workqueue, &priv->reset_work,
710 priv->reset_backoff * HZ);
711 else
David Howellsc4028952006-11-22 14:57:56 +0000712 queue_delayed_work(priv->workqueue, &priv->reset_work,
713 0);
James Ketrenos2c86c272005-03-23 17:32:29 -0600714
715 if (priv->reset_backoff < MAX_RESET_BACKOFF)
716 priv->reset_backoff++;
717
718 wake_up_interruptible(&priv->wait_command_queue);
719 } else
720 IPW_DEBUG_INFO("%s: Firmware restart already in progress.\n",
721 priv->net_dev->name);
722
723}
724
725#define HOST_COMPLETE_TIMEOUT (2 * HZ)
726static int ipw2100_hw_send_command(struct ipw2100_priv *priv,
James Ketrenosee8e3652005-09-14 09:47:29 -0500727 struct host_command *cmd)
James Ketrenos2c86c272005-03-23 17:32:29 -0600728{
729 struct list_head *element;
730 struct ipw2100_tx_packet *packet;
731 unsigned long flags;
732 int err = 0;
733
734 IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n",
735 command_types[cmd->host_command], cmd->host_command,
736 cmd->host_command_length);
James Ketrenosee8e3652005-09-14 09:47:29 -0500737 printk_buf(IPW_DL_HC, (u8 *) cmd->host_command_parameters,
James Ketrenos2c86c272005-03-23 17:32:29 -0600738 cmd->host_command_length);
739
740 spin_lock_irqsave(&priv->low_lock, flags);
741
742 if (priv->fatal_error) {
James Ketrenosee8e3652005-09-14 09:47:29 -0500743 IPW_DEBUG_INFO
744 ("Attempt to send command while hardware in fatal error condition.\n");
James Ketrenos2c86c272005-03-23 17:32:29 -0600745 err = -EIO;
746 goto fail_unlock;
747 }
748
749 if (!(priv->status & STATUS_RUNNING)) {
James Ketrenosee8e3652005-09-14 09:47:29 -0500750 IPW_DEBUG_INFO
751 ("Attempt to send command while hardware is not running.\n");
James Ketrenos2c86c272005-03-23 17:32:29 -0600752 err = -EIO;
753 goto fail_unlock;
754 }
755
756 if (priv->status & STATUS_CMD_ACTIVE) {
James Ketrenosee8e3652005-09-14 09:47:29 -0500757 IPW_DEBUG_INFO
758 ("Attempt to send command while another command is pending.\n");
James Ketrenos2c86c272005-03-23 17:32:29 -0600759 err = -EBUSY;
760 goto fail_unlock;
761 }
762
763 if (list_empty(&priv->msg_free_list)) {
764 IPW_DEBUG_INFO("no available msg buffers\n");
765 goto fail_unlock;
766 }
767
768 priv->status |= STATUS_CMD_ACTIVE;
769 priv->messages_sent++;
770
771 element = priv->msg_free_list.next;
772
773 packet = list_entry(element, struct ipw2100_tx_packet, list);
774 packet->jiffy_start = jiffies;
775
776 /* initialize the firmware command packet */
777 packet->info.c_struct.cmd->host_command_reg = cmd->host_command;
778 packet->info.c_struct.cmd->host_command_reg1 = cmd->host_command1;
James Ketrenosee8e3652005-09-14 09:47:29 -0500779 packet->info.c_struct.cmd->host_command_len_reg =
780 cmd->host_command_length;
James Ketrenos2c86c272005-03-23 17:32:29 -0600781 packet->info.c_struct.cmd->sequence = cmd->host_command_sequence;
782
783 memcpy(packet->info.c_struct.cmd->host_command_params_reg,
784 cmd->host_command_parameters,
785 sizeof(packet->info.c_struct.cmd->host_command_params_reg));
786
787 list_del(element);
788 DEC_STAT(&priv->msg_free_stat);
789
790 list_add_tail(element, &priv->msg_pend_list);
791 INC_STAT(&priv->msg_pend_stat);
792
Jiri Benc19f7f742005-08-25 20:02:10 -0400793 ipw2100_tx_send_commands(priv);
794 ipw2100_tx_send_data(priv);
James Ketrenos2c86c272005-03-23 17:32:29 -0600795
796 spin_unlock_irqrestore(&priv->low_lock, flags);
797
798 /*
799 * We must wait for this command to complete before another
800 * command can be sent... but if we wait more than 3 seconds
801 * then there is a problem.
802 */
803
James Ketrenosee8e3652005-09-14 09:47:29 -0500804 err =
805 wait_event_interruptible_timeout(priv->wait_command_queue,
806 !(priv->
807 status & STATUS_CMD_ACTIVE),
808 HOST_COMPLETE_TIMEOUT);
James Ketrenos2c86c272005-03-23 17:32:29 -0600809
810 if (err == 0) {
811 IPW_DEBUG_INFO("Command completion failed out after %dms.\n",
James Ketrenos82328352005-08-24 22:33:31 -0500812 1000 * (HOST_COMPLETE_TIMEOUT / HZ));
James Ketrenos2c86c272005-03-23 17:32:29 -0600813 priv->fatal_error = IPW2100_ERR_MSG_TIMEOUT;
814 priv->status &= ~STATUS_CMD_ACTIVE;
815 schedule_reset(priv);
816 return -EIO;
817 }
818
819 if (priv->fatal_error) {
Jiri Benc797b4f72005-08-25 20:03:27 -0400820 printk(KERN_WARNING DRV_NAME ": %s: firmware fatal error\n",
James Ketrenos2c86c272005-03-23 17:32:29 -0600821 priv->net_dev->name);
822 return -EIO;
823 }
824
825 /* !!!!! HACK TEST !!!!!
826 * When lots of debug trace statements are enabled, the driver
827 * doesn't seem to have as many firmware restart cycles...
828 *
829 * As a test, we're sticking in a 1/100s delay here */
Nishanth Aravamudan3173c892005-09-11 02:09:55 -0700830 schedule_timeout_uninterruptible(msecs_to_jiffies(10));
James Ketrenos2c86c272005-03-23 17:32:29 -0600831
832 return 0;
833
James Ketrenosee8e3652005-09-14 09:47:29 -0500834 fail_unlock:
James Ketrenos2c86c272005-03-23 17:32:29 -0600835 spin_unlock_irqrestore(&priv->low_lock, flags);
836
837 return err;
838}
839
James Ketrenos2c86c272005-03-23 17:32:29 -0600840/*
841 * Verify the values and data access of the hardware
842 * No locks needed or used. No functions called.
843 */
844static int ipw2100_verify(struct ipw2100_priv *priv)
845{
846 u32 data1, data2;
847 u32 address;
848
849 u32 val1 = 0x76543210;
850 u32 val2 = 0xFEDCBA98;
851
852 /* Domain 0 check - all values should be DOA_DEBUG */
853 for (address = IPW_REG_DOA_DEBUG_AREA_START;
James Ketrenosee8e3652005-09-14 09:47:29 -0500854 address < IPW_REG_DOA_DEBUG_AREA_END; address += sizeof(u32)) {
James Ketrenos2c86c272005-03-23 17:32:29 -0600855 read_register(priv->net_dev, address, &data1);
856 if (data1 != IPW_DATA_DOA_DEBUG_VALUE)
857 return -EIO;
858 }
859
860 /* Domain 1 check - use arbitrary read/write compare */
861 for (address = 0; address < 5; address++) {
862 /* The memory area is not used now */
863 write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
864 val1);
865 write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
866 val2);
867 read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
868 &data1);
869 read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
870 &data2);
871 if (val1 == data1 && val2 == data2)
872 return 0;
873 }
874
875 return -EIO;
876}
877
878/*
879 *
880 * Loop until the CARD_DISABLED bit is the same value as the
881 * supplied parameter
882 *
883 * TODO: See if it would be more efficient to do a wait/wake
884 * cycle and have the completion event trigger the wakeup
885 *
886 */
887#define IPW_CARD_DISABLE_COMPLETE_WAIT 100 // 100 milli
888static int ipw2100_wait_for_card_state(struct ipw2100_priv *priv, int state)
889{
890 int i;
891 u32 card_state;
892 u32 len = sizeof(card_state);
893 int err;
894
895 for (i = 0; i <= IPW_CARD_DISABLE_COMPLETE_WAIT * 1000; i += 50) {
896 err = ipw2100_get_ordinal(priv, IPW_ORD_CARD_DISABLED,
897 &card_state, &len);
898 if (err) {
899 IPW_DEBUG_INFO("Query of CARD_DISABLED ordinal "
900 "failed.\n");
901 return 0;
902 }
903
904 /* We'll break out if either the HW state says it is
905 * in the state we want, or if HOST_COMPLETE command
906 * finishes */
907 if ((card_state == state) ||
908 ((priv->status & STATUS_ENABLED) ?
909 IPW_HW_STATE_ENABLED : IPW_HW_STATE_DISABLED) == state) {
910 if (state == IPW_HW_STATE_ENABLED)
911 priv->status |= STATUS_ENABLED;
912 else
913 priv->status &= ~STATUS_ENABLED;
914
915 return 0;
916 }
917
918 udelay(50);
919 }
920
921 IPW_DEBUG_INFO("ipw2100_wait_for_card_state to %s state timed out\n",
922 state ? "DISABLED" : "ENABLED");
923 return -EIO;
924}
925
James Ketrenos2c86c272005-03-23 17:32:29 -0600926/*********************************************************************
927 Procedure : sw_reset_and_clock
928 Purpose : Asserts s/w reset, asserts clock initialization
929 and waits for clock stabilization
930 ********************************************************************/
931static int sw_reset_and_clock(struct ipw2100_priv *priv)
932{
933 int i;
934 u32 r;
935
936 // assert s/w reset
937 write_register(priv->net_dev, IPW_REG_RESET_REG,
938 IPW_AUX_HOST_RESET_REG_SW_RESET);
939
940 // wait for clock stabilization
941 for (i = 0; i < 1000; i++) {
942 udelay(IPW_WAIT_RESET_ARC_COMPLETE_DELAY);
943
944 // check clock ready bit
945 read_register(priv->net_dev, IPW_REG_RESET_REG, &r);
946 if (r & IPW_AUX_HOST_RESET_REG_PRINCETON_RESET)
947 break;
948 }
949
950 if (i == 1000)
951 return -EIO; // TODO: better error value
952
953 /* set "initialization complete" bit to move adapter to
954 * D0 state */
955 write_register(priv->net_dev, IPW_REG_GP_CNTRL,
956 IPW_AUX_HOST_GP_CNTRL_BIT_INIT_DONE);
957
958 /* wait for clock stabilization */
959 for (i = 0; i < 10000; i++) {
960 udelay(IPW_WAIT_CLOCK_STABILIZATION_DELAY * 4);
961
962 /* check clock ready bit */
963 read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
964 if (r & IPW_AUX_HOST_GP_CNTRL_BIT_CLOCK_READY)
965 break;
966 }
967
968 if (i == 10000)
969 return -EIO; /* TODO: better error value */
970
James Ketrenos2c86c272005-03-23 17:32:29 -0600971 /* set D0 standby bit */
972 read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
973 write_register(priv->net_dev, IPW_REG_GP_CNTRL,
974 r | IPW_AUX_HOST_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos2c86c272005-03-23 17:32:29 -0600975
976 return 0;
977}
978
979/*********************************************************************
Pavel Machek8724a112005-06-20 14:28:43 -0700980 Procedure : ipw2100_download_firmware
James Ketrenos2c86c272005-03-23 17:32:29 -0600981 Purpose : Initiaze adapter after power on.
982 The sequence is:
983 1. assert s/w reset first!
984 2. awake clocks & wait for clock stabilization
985 3. hold ARC (don't ask me why...)
986 4. load Dino ucode and reset/clock init again
987 5. zero-out shared mem
988 6. download f/w
989 *******************************************************************/
990static int ipw2100_download_firmware(struct ipw2100_priv *priv)
991{
992 u32 address;
993 int err;
994
995#ifndef CONFIG_PM
996 /* Fetch the firmware and microcode */
997 struct ipw2100_fw ipw2100_firmware;
998#endif
999
1000 if (priv->fatal_error) {
1001 IPW_DEBUG_ERROR("%s: ipw2100_download_firmware called after "
James Ketrenosee8e3652005-09-14 09:47:29 -05001002 "fatal error %d. Interface must be brought down.\n",
1003 priv->net_dev->name, priv->fatal_error);
James Ketrenos2c86c272005-03-23 17:32:29 -06001004 return -EINVAL;
1005 }
James Ketrenos2c86c272005-03-23 17:32:29 -06001006#ifdef CONFIG_PM
1007 if (!ipw2100_firmware.version) {
1008 err = ipw2100_get_firmware(priv, &ipw2100_firmware);
1009 if (err) {
1010 IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001011 priv->net_dev->name, err);
James Ketrenos2c86c272005-03-23 17:32:29 -06001012 priv->fatal_error = IPW2100_ERR_FW_LOAD;
1013 goto fail;
1014 }
1015 }
1016#else
1017 err = ipw2100_get_firmware(priv, &ipw2100_firmware);
1018 if (err) {
1019 IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001020 priv->net_dev->name, err);
James Ketrenos2c86c272005-03-23 17:32:29 -06001021 priv->fatal_error = IPW2100_ERR_FW_LOAD;
1022 goto fail;
1023 }
1024#endif
1025 priv->firmware_version = ipw2100_firmware.version;
1026
1027 /* s/w reset and clock stabilization */
1028 err = sw_reset_and_clock(priv);
1029 if (err) {
1030 IPW_DEBUG_ERROR("%s: sw_reset_and_clock failed: %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001031 priv->net_dev->name, err);
James Ketrenos2c86c272005-03-23 17:32:29 -06001032 goto fail;
1033 }
1034
1035 err = ipw2100_verify(priv);
1036 if (err) {
1037 IPW_DEBUG_ERROR("%s: ipw2100_verify failed: %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001038 priv->net_dev->name, err);
James Ketrenos2c86c272005-03-23 17:32:29 -06001039 goto fail;
1040 }
1041
1042 /* Hold ARC */
1043 write_nic_dword(priv->net_dev,
James Ketrenosee8e3652005-09-14 09:47:29 -05001044 IPW_INTERNAL_REGISTER_HALT_AND_RESET, 0x80000000);
James Ketrenos2c86c272005-03-23 17:32:29 -06001045
1046 /* allow ARC to run */
1047 write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
1048
1049 /* load microcode */
1050 err = ipw2100_ucode_download(priv, &ipw2100_firmware);
1051 if (err) {
Jiri Benc797b4f72005-08-25 20:03:27 -04001052 printk(KERN_ERR DRV_NAME ": %s: Error loading microcode: %d\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06001053 priv->net_dev->name, err);
1054 goto fail;
1055 }
1056
1057 /* release ARC */
1058 write_nic_dword(priv->net_dev,
James Ketrenosee8e3652005-09-14 09:47:29 -05001059 IPW_INTERNAL_REGISTER_HALT_AND_RESET, 0x00000000);
James Ketrenos2c86c272005-03-23 17:32:29 -06001060
1061 /* s/w reset and clock stabilization (again!!!) */
1062 err = sw_reset_and_clock(priv);
1063 if (err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001064 printk(KERN_ERR DRV_NAME
1065 ": %s: sw_reset_and_clock failed: %d\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06001066 priv->net_dev->name, err);
1067 goto fail;
1068 }
1069
1070 /* load f/w */
1071 err = ipw2100_fw_download(priv, &ipw2100_firmware);
1072 if (err) {
1073 IPW_DEBUG_ERROR("%s: Error loading firmware: %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001074 priv->net_dev->name, err);
James Ketrenos2c86c272005-03-23 17:32:29 -06001075 goto fail;
1076 }
James Ketrenos2c86c272005-03-23 17:32:29 -06001077#ifndef CONFIG_PM
1078 /*
1079 * When the .resume method of the driver is called, the other
1080 * part of the system, i.e. the ide driver could still stay in
1081 * the suspend stage. This prevents us from loading the firmware
1082 * from the disk. --YZ
1083 */
1084
1085 /* free any storage allocated for firmware image */
1086 ipw2100_release_firmware(priv, &ipw2100_firmware);
1087#endif
1088
1089 /* zero out Domain 1 area indirectly (Si requirement) */
1090 for (address = IPW_HOST_FW_SHARED_AREA0;
1091 address < IPW_HOST_FW_SHARED_AREA0_END; address += 4)
1092 write_nic_dword(priv->net_dev, address, 0);
1093 for (address = IPW_HOST_FW_SHARED_AREA1;
1094 address < IPW_HOST_FW_SHARED_AREA1_END; address += 4)
1095 write_nic_dword(priv->net_dev, address, 0);
1096 for (address = IPW_HOST_FW_SHARED_AREA2;
1097 address < IPW_HOST_FW_SHARED_AREA2_END; address += 4)
1098 write_nic_dword(priv->net_dev, address, 0);
1099 for (address = IPW_HOST_FW_SHARED_AREA3;
1100 address < IPW_HOST_FW_SHARED_AREA3_END; address += 4)
1101 write_nic_dword(priv->net_dev, address, 0);
1102 for (address = IPW_HOST_FW_INTERRUPT_AREA;
1103 address < IPW_HOST_FW_INTERRUPT_AREA_END; address += 4)
1104 write_nic_dword(priv->net_dev, address, 0);
1105
1106 return 0;
1107
James Ketrenosee8e3652005-09-14 09:47:29 -05001108 fail:
James Ketrenos2c86c272005-03-23 17:32:29 -06001109 ipw2100_release_firmware(priv, &ipw2100_firmware);
1110 return err;
1111}
1112
1113static inline void ipw2100_enable_interrupts(struct ipw2100_priv *priv)
1114{
1115 if (priv->status & STATUS_INT_ENABLED)
1116 return;
1117 priv->status |= STATUS_INT_ENABLED;
1118 write_register(priv->net_dev, IPW_REG_INTA_MASK, IPW_INTERRUPT_MASK);
1119}
1120
1121static inline void ipw2100_disable_interrupts(struct ipw2100_priv *priv)
1122{
1123 if (!(priv->status & STATUS_INT_ENABLED))
1124 return;
1125 priv->status &= ~STATUS_INT_ENABLED;
1126 write_register(priv->net_dev, IPW_REG_INTA_MASK, 0x0);
1127}
1128
James Ketrenos2c86c272005-03-23 17:32:29 -06001129static void ipw2100_initialize_ordinals(struct ipw2100_priv *priv)
1130{
1131 struct ipw2100_ordinals *ord = &priv->ordinals;
1132
1133 IPW_DEBUG_INFO("enter\n");
1134
1135 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_1,
1136 &ord->table1_addr);
1137
1138 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_2,
1139 &ord->table2_addr);
1140
1141 read_nic_dword(priv->net_dev, ord->table1_addr, &ord->table1_size);
1142 read_nic_dword(priv->net_dev, ord->table2_addr, &ord->table2_size);
1143
1144 ord->table2_size &= 0x0000FFFF;
1145
1146 IPW_DEBUG_INFO("table 1 size: %d\n", ord->table1_size);
1147 IPW_DEBUG_INFO("table 2 size: %d\n", ord->table2_size);
1148 IPW_DEBUG_INFO("exit\n");
1149}
1150
1151static inline void ipw2100_hw_set_gpio(struct ipw2100_priv *priv)
1152{
1153 u32 reg = 0;
1154 /*
1155 * Set GPIO 3 writable by FW; GPIO 1 writable
1156 * by driver and enable clock
1157 */
1158 reg = (IPW_BIT_GPIO_GPIO3_MASK | IPW_BIT_GPIO_GPIO1_ENABLE |
1159 IPW_BIT_GPIO_LED_OFF);
1160 write_register(priv->net_dev, IPW_REG_GPIO, reg);
1161}
1162
Arjan van de Ven858119e2006-01-14 13:20:43 -08001163static int rf_kill_active(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06001164{
1165#define MAX_RF_KILL_CHECKS 5
1166#define RF_KILL_CHECK_DELAY 40
James Ketrenos2c86c272005-03-23 17:32:29 -06001167
1168 unsigned short value = 0;
1169 u32 reg = 0;
1170 int i;
1171
1172 if (!(priv->hw_features & HW_FEATURE_RFKILL)) {
Matthew Garrettc26409a2009-11-11 14:36:30 -05001173 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, false);
James Ketrenos2c86c272005-03-23 17:32:29 -06001174 priv->status &= ~STATUS_RF_KILL_HW;
1175 return 0;
1176 }
1177
1178 for (i = 0; i < MAX_RF_KILL_CHECKS; i++) {
1179 udelay(RF_KILL_CHECK_DELAY);
1180 read_register(priv->net_dev, IPW_REG_GPIO, &reg);
1181 value = (value << 1) | ((reg & IPW_BIT_GPIO_RF_KILL) ? 0 : 1);
1182 }
1183
Matthew Garrettc26409a2009-11-11 14:36:30 -05001184 if (value == 0) {
1185 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
James Ketrenos2c86c272005-03-23 17:32:29 -06001186 priv->status |= STATUS_RF_KILL_HW;
Matthew Garrettc26409a2009-11-11 14:36:30 -05001187 } else {
1188 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, false);
James Ketrenos2c86c272005-03-23 17:32:29 -06001189 priv->status &= ~STATUS_RF_KILL_HW;
Matthew Garrettc26409a2009-11-11 14:36:30 -05001190 }
James Ketrenos2c86c272005-03-23 17:32:29 -06001191
1192 return (value == 0);
1193}
1194
1195static int ipw2100_get_hw_features(struct ipw2100_priv *priv)
1196{
1197 u32 addr, len;
1198 u32 val;
1199
1200 /*
1201 * EEPROM_SRAM_DB_START_ADDRESS using ordinal in ordinal table 1
1202 */
1203 len = sizeof(addr);
James Ketrenosee8e3652005-09-14 09:47:29 -05001204 if (ipw2100_get_ordinal
1205 (priv, IPW_ORD_EEPROM_SRAM_DB_BLOCK_START_ADDRESS, &addr, &len)) {
James Ketrenos2c86c272005-03-23 17:32:29 -06001206 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001207 __LINE__);
James Ketrenos2c86c272005-03-23 17:32:29 -06001208 return -EIO;
1209 }
1210
1211 IPW_DEBUG_INFO("EEPROM address: %08X\n", addr);
1212
1213 /*
1214 * EEPROM version is the byte at offset 0xfd in firmware
1215 * We read 4 bytes, then shift out the byte we actually want */
1216 read_nic_dword(priv->net_dev, addr + 0xFC, &val);
1217 priv->eeprom_version = (val >> 24) & 0xFF;
1218 IPW_DEBUG_INFO("EEPROM version: %d\n", priv->eeprom_version);
1219
James Ketrenosee8e3652005-09-14 09:47:29 -05001220 /*
James Ketrenos2c86c272005-03-23 17:32:29 -06001221 * HW RF Kill enable is bit 0 in byte at offset 0x21 in firmware
1222 *
1223 * notice that the EEPROM bit is reverse polarity, i.e.
1224 * bit = 0 signifies HW RF kill switch is supported
1225 * bit = 1 signifies HW RF kill switch is NOT supported
1226 */
1227 read_nic_dword(priv->net_dev, addr + 0x20, &val);
1228 if (!((val >> 24) & 0x01))
1229 priv->hw_features |= HW_FEATURE_RFKILL;
1230
1231 IPW_DEBUG_INFO("HW RF Kill: %ssupported.\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001232 (priv->hw_features & HW_FEATURE_RFKILL) ? "" : "not ");
James Ketrenos2c86c272005-03-23 17:32:29 -06001233
1234 return 0;
1235}
1236
1237/*
1238 * Start firmware execution after power on and intialization
1239 * The sequence is:
1240 * 1. Release ARC
1241 * 2. Wait for f/w initialization completes;
1242 */
1243static int ipw2100_start_adapter(struct ipw2100_priv *priv)
1244{
James Ketrenos2c86c272005-03-23 17:32:29 -06001245 int i;
1246 u32 inta, inta_mask, gpio;
1247
1248 IPW_DEBUG_INFO("enter\n");
1249
1250 if (priv->status & STATUS_RUNNING)
1251 return 0;
1252
1253 /*
1254 * Initialize the hw - drive adapter to DO state by setting
1255 * init_done bit. Wait for clk_ready bit and Download
1256 * fw & dino ucode
1257 */
1258 if (ipw2100_download_firmware(priv)) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001259 printk(KERN_ERR DRV_NAME
1260 ": %s: Failed to power on the adapter.\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06001261 priv->net_dev->name);
1262 return -EIO;
1263 }
1264
1265 /* Clear the Tx, Rx and Msg queues and the r/w indexes
1266 * in the firmware RBD and TBD ring queue */
1267 ipw2100_queues_initialize(priv);
1268
1269 ipw2100_hw_set_gpio(priv);
1270
1271 /* TODO -- Look at disabling interrupts here to make sure none
1272 * get fired during FW initialization */
1273
1274 /* Release ARC - clear reset bit */
1275 write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
1276
1277 /* wait for f/w intialization complete */
1278 IPW_DEBUG_FW("Waiting for f/w initialization to complete...\n");
1279 i = 5000;
1280 do {
Nishanth Aravamudan3173c892005-09-11 02:09:55 -07001281 schedule_timeout_uninterruptible(msecs_to_jiffies(40));
James Ketrenos2c86c272005-03-23 17:32:29 -06001282 /* Todo... wait for sync command ... */
1283
1284 read_register(priv->net_dev, IPW_REG_INTA, &inta);
1285
1286 /* check "init done" bit */
1287 if (inta & IPW2100_INTA_FW_INIT_DONE) {
1288 /* reset "init done" bit */
1289 write_register(priv->net_dev, IPW_REG_INTA,
1290 IPW2100_INTA_FW_INIT_DONE);
1291 break;
1292 }
1293
1294 /* check error conditions : we check these after the firmware
1295 * check so that if there is an error, the interrupt handler
1296 * will see it and the adapter will be reset */
1297 if (inta &
1298 (IPW2100_INTA_FATAL_ERROR | IPW2100_INTA_PARITY_ERROR)) {
1299 /* clear error conditions */
1300 write_register(priv->net_dev, IPW_REG_INTA,
1301 IPW2100_INTA_FATAL_ERROR |
1302 IPW2100_INTA_PARITY_ERROR);
1303 }
Roel Kluina2a1c3e2007-11-05 23:55:02 +01001304 } while (--i);
James Ketrenos2c86c272005-03-23 17:32:29 -06001305
1306 /* Clear out any pending INTAs since we aren't supposed to have
1307 * interrupts enabled at this point... */
1308 read_register(priv->net_dev, IPW_REG_INTA, &inta);
1309 read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
1310 inta &= IPW_INTERRUPT_MASK;
1311 /* Clear out any pending interrupts */
1312 if (inta & inta_mask)
1313 write_register(priv->net_dev, IPW_REG_INTA, inta);
1314
1315 IPW_DEBUG_FW("f/w initialization complete: %s\n",
1316 i ? "SUCCESS" : "FAILED");
1317
1318 if (!i) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001319 printk(KERN_WARNING DRV_NAME
1320 ": %s: Firmware did not initialize.\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06001321 priv->net_dev->name);
1322 return -EIO;
1323 }
1324
1325 /* allow firmware to write to GPIO1 & GPIO3 */
1326 read_register(priv->net_dev, IPW_REG_GPIO, &gpio);
1327
1328 gpio |= (IPW_BIT_GPIO_GPIO1_MASK | IPW_BIT_GPIO_GPIO3_MASK);
1329
1330 write_register(priv->net_dev, IPW_REG_GPIO, gpio);
1331
1332 /* Ready to receive commands */
1333 priv->status |= STATUS_RUNNING;
1334
1335 /* The adapter has been reset; we are not associated */
1336 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
1337
1338 IPW_DEBUG_INFO("exit\n");
1339
1340 return 0;
1341}
1342
1343static inline void ipw2100_reset_fatalerror(struct ipw2100_priv *priv)
1344{
1345 if (!priv->fatal_error)
1346 return;
1347
1348 priv->fatal_errors[priv->fatal_index++] = priv->fatal_error;
1349 priv->fatal_index %= IPW2100_ERROR_QUEUE;
1350 priv->fatal_error = 0;
1351}
1352
James Ketrenos2c86c272005-03-23 17:32:29 -06001353/* NOTE: Our interrupt is disabled when this method is called */
1354static int ipw2100_power_cycle_adapter(struct ipw2100_priv *priv)
1355{
1356 u32 reg;
1357 int i;
1358
1359 IPW_DEBUG_INFO("Power cycling the hardware.\n");
1360
1361 ipw2100_hw_set_gpio(priv);
1362
1363 /* Step 1. Stop Master Assert */
1364 write_register(priv->net_dev, IPW_REG_RESET_REG,
1365 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
1366
1367 /* Step 2. Wait for stop Master Assert
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02001368 * (not more than 50us, otherwise ret error */
James Ketrenos2c86c272005-03-23 17:32:29 -06001369 i = 5;
1370 do {
1371 udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
1372 read_register(priv->net_dev, IPW_REG_RESET_REG, &reg);
1373
1374 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
1375 break;
Roel Kluina2a1c3e2007-11-05 23:55:02 +01001376 } while (--i);
James Ketrenos2c86c272005-03-23 17:32:29 -06001377
1378 priv->status &= ~STATUS_RESET_PENDING;
1379
1380 if (!i) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001381 IPW_DEBUG_INFO
1382 ("exit - waited too long for master assert stop\n");
James Ketrenos2c86c272005-03-23 17:32:29 -06001383 return -EIO;
1384 }
1385
1386 write_register(priv->net_dev, IPW_REG_RESET_REG,
1387 IPW_AUX_HOST_RESET_REG_SW_RESET);
1388
James Ketrenos2c86c272005-03-23 17:32:29 -06001389 /* Reset any fatal_error conditions */
1390 ipw2100_reset_fatalerror(priv);
1391
1392 /* At this point, the adapter is now stopped and disabled */
1393 priv->status &= ~(STATUS_RUNNING | STATUS_ASSOCIATING |
1394 STATUS_ASSOCIATED | STATUS_ENABLED);
1395
1396 return 0;
1397}
1398
1399/*
1400 * Send the CARD_DISABLE_PHY_OFF comamnd to the card to disable it
1401 *
1402 * After disabling, if the card was associated, a STATUS_ASSN_LOST will be sent.
1403 *
1404 * STATUS_CARD_DISABLE_NOTIFICATION will be sent regardless of
1405 * if STATUS_ASSN_LOST is sent.
1406 */
1407static int ipw2100_hw_phy_off(struct ipw2100_priv *priv)
1408{
1409
1410#define HW_PHY_OFF_LOOP_DELAY (HZ / 5000)
1411
1412 struct host_command cmd = {
1413 .host_command = CARD_DISABLE_PHY_OFF,
1414 .host_command_sequence = 0,
1415 .host_command_length = 0,
1416 };
1417 int err, i;
1418 u32 val1, val2;
1419
1420 IPW_DEBUG_HC("CARD_DISABLE_PHY_OFF\n");
1421
1422 /* Turn off the radio */
1423 err = ipw2100_hw_send_command(priv, &cmd);
1424 if (err)
1425 return err;
1426
1427 for (i = 0; i < 2500; i++) {
1428 read_nic_dword(priv->net_dev, IPW2100_CONTROL_REG, &val1);
1429 read_nic_dword(priv->net_dev, IPW2100_COMMAND, &val2);
1430
1431 if ((val1 & IPW2100_CONTROL_PHY_OFF) &&
1432 (val2 & IPW2100_COMMAND_PHY_OFF))
1433 return 0;
1434
Nishanth Aravamudan3173c892005-09-11 02:09:55 -07001435 schedule_timeout_uninterruptible(HW_PHY_OFF_LOOP_DELAY);
James Ketrenos2c86c272005-03-23 17:32:29 -06001436 }
1437
1438 return -EIO;
1439}
1440
James Ketrenos2c86c272005-03-23 17:32:29 -06001441static int ipw2100_enable_adapter(struct ipw2100_priv *priv)
1442{
1443 struct host_command cmd = {
1444 .host_command = HOST_COMPLETE,
1445 .host_command_sequence = 0,
1446 .host_command_length = 0
1447 };
1448 int err = 0;
1449
1450 IPW_DEBUG_HC("HOST_COMPLETE\n");
1451
1452 if (priv->status & STATUS_ENABLED)
1453 return 0;
1454
Ingo Molnar752e3772006-02-28 07:20:54 +08001455 mutex_lock(&priv->adapter_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06001456
1457 if (rf_kill_active(priv)) {
1458 IPW_DEBUG_HC("Command aborted due to RF kill active.\n");
1459 goto fail_up;
1460 }
1461
1462 err = ipw2100_hw_send_command(priv, &cmd);
1463 if (err) {
1464 IPW_DEBUG_INFO("Failed to send HOST_COMPLETE command\n");
1465 goto fail_up;
1466 }
1467
1468 err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_ENABLED);
1469 if (err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001470 IPW_DEBUG_INFO("%s: card not responding to init command.\n",
1471 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001472 goto fail_up;
1473 }
1474
1475 if (priv->stop_hang_check) {
1476 priv->stop_hang_check = 0;
1477 queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2);
1478 }
1479
James Ketrenosee8e3652005-09-14 09:47:29 -05001480 fail_up:
Ingo Molnar752e3772006-02-28 07:20:54 +08001481 mutex_unlock(&priv->adapter_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06001482 return err;
1483}
1484
1485static int ipw2100_hw_stop_adapter(struct ipw2100_priv *priv)
1486{
Nishanth Aravamudan3173c892005-09-11 02:09:55 -07001487#define HW_POWER_DOWN_DELAY (msecs_to_jiffies(100))
James Ketrenos2c86c272005-03-23 17:32:29 -06001488
1489 struct host_command cmd = {
1490 .host_command = HOST_PRE_POWER_DOWN,
1491 .host_command_sequence = 0,
1492 .host_command_length = 0,
1493 };
1494 int err, i;
1495 u32 reg;
1496
1497 if (!(priv->status & STATUS_RUNNING))
1498 return 0;
1499
1500 priv->status |= STATUS_STOPPING;
1501
1502 /* We can only shut down the card if the firmware is operational. So,
1503 * if we haven't reset since a fatal_error, then we can not send the
1504 * shutdown commands. */
1505 if (!priv->fatal_error) {
1506 /* First, make sure the adapter is enabled so that the PHY_OFF
1507 * command can shut it down */
1508 ipw2100_enable_adapter(priv);
1509
1510 err = ipw2100_hw_phy_off(priv);
1511 if (err)
James Ketrenosee8e3652005-09-14 09:47:29 -05001512 printk(KERN_WARNING DRV_NAME
1513 ": Error disabling radio %d\n", err);
James Ketrenos2c86c272005-03-23 17:32:29 -06001514
1515 /*
1516 * If in D0-standby mode going directly to D3 may cause a
1517 * PCI bus violation. Therefore we must change out of the D0
1518 * state.
1519 *
1520 * Sending the PREPARE_FOR_POWER_DOWN will restrict the
1521 * hardware from going into standby mode and will transition
Andreas Mohrd6e05ed2006-06-26 18:35:02 +02001522 * out of D0-standby if it is already in that state.
James Ketrenos2c86c272005-03-23 17:32:29 -06001523 *
1524 * STATUS_PREPARE_POWER_DOWN_COMPLETE will be sent by the
1525 * driver upon completion. Once received, the driver can
1526 * proceed to the D3 state.
1527 *
1528 * Prepare for power down command to fw. This command would
1529 * take HW out of D0-standby and prepare it for D3 state.
1530 *
1531 * Currently FW does not support event notification for this
1532 * event. Therefore, skip waiting for it. Just wait a fixed
1533 * 100ms
1534 */
1535 IPW_DEBUG_HC("HOST_PRE_POWER_DOWN\n");
1536
1537 err = ipw2100_hw_send_command(priv, &cmd);
1538 if (err)
Jiri Benc797b4f72005-08-25 20:03:27 -04001539 printk(KERN_WARNING DRV_NAME ": "
James Ketrenos2c86c272005-03-23 17:32:29 -06001540 "%s: Power down command failed: Error %d\n",
1541 priv->net_dev->name, err);
Nishanth Aravamudan3173c892005-09-11 02:09:55 -07001542 else
1543 schedule_timeout_uninterruptible(HW_POWER_DOWN_DELAY);
James Ketrenos2c86c272005-03-23 17:32:29 -06001544 }
1545
1546 priv->status &= ~STATUS_ENABLED;
1547
1548 /*
1549 * Set GPIO 3 writable by FW; GPIO 1 writable
1550 * by driver and enable clock
1551 */
1552 ipw2100_hw_set_gpio(priv);
1553
1554 /*
1555 * Power down adapter. Sequence:
1556 * 1. Stop master assert (RESET_REG[9]=1)
1557 * 2. Wait for stop master (RESET_REG[8]==1)
1558 * 3. S/w reset assert (RESET_REG[7] = 1)
1559 */
1560
1561 /* Stop master assert */
1562 write_register(priv->net_dev, IPW_REG_RESET_REG,
1563 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
1564
1565 /* wait stop master not more than 50 usec.
1566 * Otherwise return error. */
1567 for (i = 5; i > 0; i--) {
1568 udelay(10);
1569
1570 /* Check master stop bit */
1571 read_register(priv->net_dev, IPW_REG_RESET_REG, &reg);
1572
1573 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
1574 break;
1575 }
1576
1577 if (i == 0)
Jiri Benc797b4f72005-08-25 20:03:27 -04001578 printk(KERN_WARNING DRV_NAME
James Ketrenos2c86c272005-03-23 17:32:29 -06001579 ": %s: Could now power down adapter.\n",
1580 priv->net_dev->name);
1581
1582 /* assert s/w reset */
1583 write_register(priv->net_dev, IPW_REG_RESET_REG,
1584 IPW_AUX_HOST_RESET_REG_SW_RESET);
1585
1586 priv->status &= ~(STATUS_RUNNING | STATUS_STOPPING);
1587
1588 return 0;
1589}
1590
James Ketrenos2c86c272005-03-23 17:32:29 -06001591static int ipw2100_disable_adapter(struct ipw2100_priv *priv)
1592{
1593 struct host_command cmd = {
1594 .host_command = CARD_DISABLE,
1595 .host_command_sequence = 0,
1596 .host_command_length = 0
1597 };
1598 int err = 0;
1599
1600 IPW_DEBUG_HC("CARD_DISABLE\n");
1601
1602 if (!(priv->status & STATUS_ENABLED))
1603 return 0;
1604
1605 /* Make sure we clear the associated state */
1606 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1607
1608 if (!priv->stop_hang_check) {
1609 priv->stop_hang_check = 1;
1610 cancel_delayed_work(&priv->hang_check);
1611 }
1612
Ingo Molnar752e3772006-02-28 07:20:54 +08001613 mutex_lock(&priv->adapter_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06001614
1615 err = ipw2100_hw_send_command(priv, &cmd);
1616 if (err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001617 printk(KERN_WARNING DRV_NAME
1618 ": exit - failed to send CARD_DISABLE command\n");
James Ketrenos2c86c272005-03-23 17:32:29 -06001619 goto fail_up;
1620 }
1621
1622 err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_DISABLED);
1623 if (err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001624 printk(KERN_WARNING DRV_NAME
1625 ": exit - card failed to change to DISABLED\n");
James Ketrenos2c86c272005-03-23 17:32:29 -06001626 goto fail_up;
1627 }
1628
1629 IPW_DEBUG_INFO("TODO: implement scan state machine\n");
1630
James Ketrenosee8e3652005-09-14 09:47:29 -05001631 fail_up:
Ingo Molnar752e3772006-02-28 07:20:54 +08001632 mutex_unlock(&priv->adapter_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06001633 return err;
1634}
1635
Jiri Bencc4aee8c2005-08-25 20:04:43 -04001636static int ipw2100_set_scan_options(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06001637{
1638 struct host_command cmd = {
1639 .host_command = SET_SCAN_OPTIONS,
1640 .host_command_sequence = 0,
1641 .host_command_length = 8
1642 };
1643 int err;
1644
1645 IPW_DEBUG_INFO("enter\n");
1646
1647 IPW_DEBUG_SCAN("setting scan options\n");
1648
1649 cmd.host_command_parameters[0] = 0;
1650
1651 if (!(priv->config & CFG_ASSOCIATE))
1652 cmd.host_command_parameters[0] |= IPW_SCAN_NOASSOCIATE;
25b645b2005-07-12 15:45:30 -05001653 if ((priv->ieee->sec.flags & SEC_ENABLED) && priv->ieee->sec.enabled)
James Ketrenos2c86c272005-03-23 17:32:29 -06001654 cmd.host_command_parameters[0] |= IPW_SCAN_MIXED_CELL;
1655 if (priv->config & CFG_PASSIVE_SCAN)
1656 cmd.host_command_parameters[0] |= IPW_SCAN_PASSIVE;
1657
1658 cmd.host_command_parameters[1] = priv->channel_mask;
1659
1660 err = ipw2100_hw_send_command(priv, &cmd);
1661
1662 IPW_DEBUG_HC("SET_SCAN_OPTIONS 0x%04X\n",
1663 cmd.host_command_parameters[0]);
1664
1665 return err;
1666}
1667
Jiri Bencc4aee8c2005-08-25 20:04:43 -04001668static int ipw2100_start_scan(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06001669{
1670 struct host_command cmd = {
1671 .host_command = BROADCAST_SCAN,
1672 .host_command_sequence = 0,
1673 .host_command_length = 4
1674 };
1675 int err;
1676
1677 IPW_DEBUG_HC("START_SCAN\n");
1678
1679 cmd.host_command_parameters[0] = 0;
1680
1681 /* No scanning if in monitor mode */
1682 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
1683 return 1;
1684
1685 if (priv->status & STATUS_SCANNING) {
1686 IPW_DEBUG_SCAN("Scan requested while already in scan...\n");
1687 return 0;
1688 }
1689
1690 IPW_DEBUG_INFO("enter\n");
1691
1692 /* Not clearing here; doing so makes iwlist always return nothing...
1693 *
1694 * We should modify the table logic to use aging tables vs. clearing
1695 * the table on each scan start.
1696 */
1697 IPW_DEBUG_SCAN("starting scan\n");
1698
1699 priv->status |= STATUS_SCANNING;
1700 err = ipw2100_hw_send_command(priv, &cmd);
1701 if (err)
1702 priv->status &= ~STATUS_SCANNING;
1703
1704 IPW_DEBUG_INFO("exit\n");
1705
1706 return err;
1707}
1708
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001709static const struct libipw_geo ipw_geos[] = {
Zhu Yibe6b3b12006-01-24 13:49:08 +08001710 { /* Restricted */
1711 "---",
1712 .bg_channels = 14,
1713 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
1714 {2427, 4}, {2432, 5}, {2437, 6},
1715 {2442, 7}, {2447, 8}, {2452, 9},
1716 {2457, 10}, {2462, 11}, {2467, 12},
1717 {2472, 13}, {2484, 14}},
1718 },
1719};
1720
James Ketrenos2c86c272005-03-23 17:32:29 -06001721static int ipw2100_up(struct ipw2100_priv *priv, int deferred)
1722{
1723 unsigned long flags;
1724 int rc = 0;
1725 u32 lock;
1726 u32 ord_len = sizeof(lock);
1727
Dan Williamsc3d72b92009-02-11 13:26:06 -05001728 /* Age scan list entries found before suspend */
1729 if (priv->suspend_time) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001730 libipw_networks_age(priv->ieee, priv->suspend_time);
Dan Williamsc3d72b92009-02-11 13:26:06 -05001731 priv->suspend_time = 0;
1732 }
1733
1734 /* Quiet if manually disabled. */
James Ketrenos2c86c272005-03-23 17:32:29 -06001735 if (priv->status & STATUS_RF_KILL_SW) {
1736 IPW_DEBUG_INFO("%s: Radio is disabled by Manual Disable "
1737 "switch\n", priv->net_dev->name);
1738 return 0;
1739 }
1740
Arjan van de Ven5c875792006-09-30 23:27:17 -07001741 /* the ipw2100 hardware really doesn't want power management delays
1742 * longer than 175usec
1743 */
Mark Grossed771342010-05-06 01:59:26 +02001744 pm_qos_update_request(ipw2100_pm_qos_req, 175);
Arjan van de Ven5c875792006-09-30 23:27:17 -07001745
James Ketrenos2c86c272005-03-23 17:32:29 -06001746 /* If the interrupt is enabled, turn it off... */
1747 spin_lock_irqsave(&priv->low_lock, flags);
1748 ipw2100_disable_interrupts(priv);
1749
1750 /* Reset any fatal_error conditions */
1751 ipw2100_reset_fatalerror(priv);
1752 spin_unlock_irqrestore(&priv->low_lock, flags);
1753
1754 if (priv->status & STATUS_POWERED ||
1755 (priv->status & STATUS_RESET_PENDING)) {
1756 /* Power cycle the card ... */
1757 if (ipw2100_power_cycle_adapter(priv)) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001758 printk(KERN_WARNING DRV_NAME
1759 ": %s: Could not cycle adapter.\n",
1760 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001761 rc = 1;
1762 goto exit;
1763 }
1764 } else
1765 priv->status |= STATUS_POWERED;
1766
Pavel Machek8724a112005-06-20 14:28:43 -07001767 /* Load the firmware, start the clocks, etc. */
James Ketrenos2c86c272005-03-23 17:32:29 -06001768 if (ipw2100_start_adapter(priv)) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001769 printk(KERN_ERR DRV_NAME
1770 ": %s: Failed to start the firmware.\n",
1771 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001772 rc = 1;
1773 goto exit;
1774 }
1775
1776 ipw2100_initialize_ordinals(priv);
1777
1778 /* Determine capabilities of this particular HW configuration */
1779 if (ipw2100_get_hw_features(priv)) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001780 printk(KERN_ERR DRV_NAME
1781 ": %s: Failed to determine HW features.\n",
1782 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001783 rc = 1;
1784 goto exit;
1785 }
1786
Zhu Yibe6b3b12006-01-24 13:49:08 +08001787 /* Initialize the geo */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001788 if (libipw_set_geo(priv->ieee, &ipw_geos[0])) {
Zhu Yibe6b3b12006-01-24 13:49:08 +08001789 printk(KERN_WARNING DRV_NAME "Could not set geo\n");
1790 return 0;
1791 }
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001792 priv->ieee->freq_band = LIBIPW_24GHZ_BAND;
Zhu Yibe6b3b12006-01-24 13:49:08 +08001793
James Ketrenos2c86c272005-03-23 17:32:29 -06001794 lock = LOCK_NONE;
1795 if (ipw2100_set_ordinal(priv, IPW_ORD_PERS_DB_LOCK, &lock, &ord_len)) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001796 printk(KERN_ERR DRV_NAME
1797 ": %s: Failed to clear ordinal lock.\n",
1798 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001799 rc = 1;
1800 goto exit;
1801 }
1802
1803 priv->status &= ~STATUS_SCANNING;
1804
1805 if (rf_kill_active(priv)) {
1806 printk(KERN_INFO "%s: Radio is disabled by RF switch.\n",
1807 priv->net_dev->name);
1808
1809 if (priv->stop_rf_kill) {
1810 priv->stop_rf_kill = 0;
Stephen Hemmingera62056f2007-06-22 21:46:50 -07001811 queue_delayed_work(priv->workqueue, &priv->rf_kill,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05001812 round_jiffies_relative(HZ));
James Ketrenos2c86c272005-03-23 17:32:29 -06001813 }
1814
1815 deferred = 1;
1816 }
1817
1818 /* Turn on the interrupt so that commands can be processed */
1819 ipw2100_enable_interrupts(priv);
1820
1821 /* Send all of the commands that must be sent prior to
1822 * HOST_COMPLETE */
1823 if (ipw2100_adapter_setup(priv)) {
Jiri Benc797b4f72005-08-25 20:03:27 -04001824 printk(KERN_ERR DRV_NAME ": %s: Failed to start the card.\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001825 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001826 rc = 1;
1827 goto exit;
1828 }
1829
1830 if (!deferred) {
1831 /* Enable the adapter - sends HOST_COMPLETE */
1832 if (ipw2100_enable_adapter(priv)) {
Jiri Benc797b4f72005-08-25 20:03:27 -04001833 printk(KERN_ERR DRV_NAME ": "
James Ketrenosee8e3652005-09-14 09:47:29 -05001834 "%s: failed in call to enable adapter.\n",
1835 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001836 ipw2100_hw_stop_adapter(priv);
1837 rc = 1;
1838 goto exit;
1839 }
1840
James Ketrenos2c86c272005-03-23 17:32:29 -06001841 /* Start a scan . . . */
1842 ipw2100_set_scan_options(priv);
1843 ipw2100_start_scan(priv);
1844 }
1845
James Ketrenosee8e3652005-09-14 09:47:29 -05001846 exit:
James Ketrenos2c86c272005-03-23 17:32:29 -06001847 return rc;
1848}
1849
James Ketrenos2c86c272005-03-23 17:32:29 -06001850static void ipw2100_down(struct ipw2100_priv *priv)
1851{
1852 unsigned long flags;
1853 union iwreq_data wrqu = {
1854 .ap_addr = {
James Ketrenosee8e3652005-09-14 09:47:29 -05001855 .sa_family = ARPHRD_ETHER}
James Ketrenos2c86c272005-03-23 17:32:29 -06001856 };
1857 int associated = priv->status & STATUS_ASSOCIATED;
1858
1859 /* Kill the RF switch timer */
1860 if (!priv->stop_rf_kill) {
1861 priv->stop_rf_kill = 1;
1862 cancel_delayed_work(&priv->rf_kill);
1863 }
1864
Nick Andrew44072452009-01-03 18:52:40 +11001865 /* Kill the firmware hang check timer */
James Ketrenos2c86c272005-03-23 17:32:29 -06001866 if (!priv->stop_hang_check) {
1867 priv->stop_hang_check = 1;
1868 cancel_delayed_work(&priv->hang_check);
1869 }
1870
1871 /* Kill any pending resets */
1872 if (priv->status & STATUS_RESET_PENDING)
1873 cancel_delayed_work(&priv->reset_work);
1874
1875 /* Make sure the interrupt is on so that FW commands will be
1876 * processed correctly */
1877 spin_lock_irqsave(&priv->low_lock, flags);
1878 ipw2100_enable_interrupts(priv);
1879 spin_unlock_irqrestore(&priv->low_lock, flags);
1880
1881 if (ipw2100_hw_stop_adapter(priv))
Jiri Benc797b4f72005-08-25 20:03:27 -04001882 printk(KERN_ERR DRV_NAME ": %s: Error stopping adapter.\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06001883 priv->net_dev->name);
1884
1885 /* Do not disable the interrupt until _after_ we disable
1886 * the adaptor. Otherwise the CARD_DISABLE command will never
1887 * be ack'd by the firmware */
1888 spin_lock_irqsave(&priv->low_lock, flags);
1889 ipw2100_disable_interrupts(priv);
1890 spin_unlock_irqrestore(&priv->low_lock, flags);
1891
Mark Grossed771342010-05-06 01:59:26 +02001892 pm_qos_update_request(ipw2100_pm_qos_req, PM_QOS_DEFAULT_VALUE);
Arjan van de Ven5c875792006-09-30 23:27:17 -07001893
James Ketrenos2c86c272005-03-23 17:32:29 -06001894 /* We have to signal any supplicant if we are disassociating */
1895 if (associated)
1896 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1897
1898 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1899 netif_carrier_off(priv->net_dev);
1900 netif_stop_queue(priv->net_dev);
1901}
1902
Matthew Garrettc26409a2009-11-11 14:36:30 -05001903/* Called by register_netdev() */
1904static int ipw2100_net_init(struct net_device *dev)
1905{
1906 struct ipw2100_priv *priv = libipw_priv(dev);
1907 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
1908 struct wireless_dev *wdev = &priv->ieee->wdev;
1909 int ret;
1910 int i;
1911
1912 ret = ipw2100_up(priv, 1);
1913 if (ret)
1914 return ret;
1915
1916 memcpy(wdev->wiphy->perm_addr, priv->mac_addr, ETH_ALEN);
1917
1918 /* fill-out priv->ieee->bg_band */
1919 if (geo->bg_channels) {
1920 struct ieee80211_supported_band *bg_band = &priv->ieee->bg_band;
1921
1922 bg_band->band = IEEE80211_BAND_2GHZ;
1923 bg_band->n_channels = geo->bg_channels;
1924 bg_band->channels =
1925 kzalloc(geo->bg_channels *
1926 sizeof(struct ieee80211_channel), GFP_KERNEL);
Christoph Fritz93c05842010-08-03 12:54:20 +02001927 if (!bg_band->channels) {
1928 ipw2100_down(priv);
1929 return -ENOMEM;
1930 }
Matthew Garrettc26409a2009-11-11 14:36:30 -05001931 /* translate geo->bg to bg_band.channels */
1932 for (i = 0; i < geo->bg_channels; i++) {
1933 bg_band->channels[i].band = IEEE80211_BAND_2GHZ;
1934 bg_band->channels[i].center_freq = geo->bg[i].freq;
1935 bg_band->channels[i].hw_value = geo->bg[i].channel;
1936 bg_band->channels[i].max_power = geo->bg[i].max_power;
1937 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY)
1938 bg_band->channels[i].flags |=
1939 IEEE80211_CHAN_PASSIVE_SCAN;
1940 if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS)
1941 bg_band->channels[i].flags |=
1942 IEEE80211_CHAN_NO_IBSS;
1943 if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)
1944 bg_band->channels[i].flags |=
1945 IEEE80211_CHAN_RADAR;
1946 /* No equivalent for LIBIPW_CH_80211H_RULES,
1947 LIBIPW_CH_UNIFORM_SPREADING, or
1948 LIBIPW_CH_B_ONLY... */
1949 }
1950 /* point at bitrate info */
1951 bg_band->bitrates = ipw2100_bg_rates;
1952 bg_band->n_bitrates = RATE_COUNT;
1953
1954 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = bg_band;
1955 }
1956
1957 set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev);
1958 if (wiphy_register(wdev->wiphy)) {
1959 ipw2100_down(priv);
1960 return -EIO;
1961 }
1962 return 0;
1963}
1964
David Howellsc4028952006-11-22 14:57:56 +00001965static void ipw2100_reset_adapter(struct work_struct *work)
James Ketrenos2c86c272005-03-23 17:32:29 -06001966{
David Howellsc4028952006-11-22 14:57:56 +00001967 struct ipw2100_priv *priv =
1968 container_of(work, struct ipw2100_priv, reset_work.work);
James Ketrenos2c86c272005-03-23 17:32:29 -06001969 unsigned long flags;
1970 union iwreq_data wrqu = {
1971 .ap_addr = {
James Ketrenosee8e3652005-09-14 09:47:29 -05001972 .sa_family = ARPHRD_ETHER}
James Ketrenos2c86c272005-03-23 17:32:29 -06001973 };
1974 int associated = priv->status & STATUS_ASSOCIATED;
1975
1976 spin_lock_irqsave(&priv->low_lock, flags);
Zhu Yia1e695a2005-07-04 14:06:00 +08001977 IPW_DEBUG_INFO(": %s: Restarting adapter.\n", priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001978 priv->resets++;
1979 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1980 priv->status |= STATUS_SECURITY_UPDATED;
1981
1982 /* Force a power cycle even if interface hasn't been opened
1983 * yet */
1984 cancel_delayed_work(&priv->reset_work);
1985 priv->status |= STATUS_RESET_PENDING;
1986 spin_unlock_irqrestore(&priv->low_lock, flags);
1987
Ingo Molnar752e3772006-02-28 07:20:54 +08001988 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06001989 /* stop timed checks so that they don't interfere with reset */
1990 priv->stop_hang_check = 1;
1991 cancel_delayed_work(&priv->hang_check);
1992
1993 /* We have to signal any supplicant if we are disassociating */
1994 if (associated)
1995 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1996
1997 ipw2100_up(priv, 0);
Ingo Molnar752e3772006-02-28 07:20:54 +08001998 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06001999
2000}
2001
James Ketrenos2c86c272005-03-23 17:32:29 -06002002static void isr_indicate_associated(struct ipw2100_priv *priv, u32 status)
2003{
2004
2005#define MAC_ASSOCIATION_READ_DELAY (HZ)
Hannes Ederb9da9e92009-02-14 11:50:26 +00002006 int ret;
2007 unsigned int len, essid_len;
James Ketrenos2c86c272005-03-23 17:32:29 -06002008 char essid[IW_ESSID_MAX_SIZE];
2009 u32 txrate;
2010 u32 chan;
2011 char *txratename;
James Ketrenosee8e3652005-09-14 09:47:29 -05002012 u8 bssid[ETH_ALEN];
John W. Linville9387b7c2008-09-30 20:59:05 -04002013 DECLARE_SSID_BUF(ssid);
James Ketrenos2c86c272005-03-23 17:32:29 -06002014
2015 /*
2016 * TBD: BSSID is usually 00:00:00:00:00:00 here and not
2017 * an actual MAC of the AP. Seems like FW sets this
2018 * address too late. Read it later and expose through
2019 * /proc or schedule a later task to query and update
2020 */
2021
2022 essid_len = IW_ESSID_MAX_SIZE;
2023 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID,
2024 essid, &essid_len);
2025 if (ret) {
2026 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05002027 __LINE__);
James Ketrenos2c86c272005-03-23 17:32:29 -06002028 return;
2029 }
2030
2031 len = sizeof(u32);
James Ketrenosee8e3652005-09-14 09:47:29 -05002032 ret = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &txrate, &len);
James Ketrenos2c86c272005-03-23 17:32:29 -06002033 if (ret) {
2034 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05002035 __LINE__);
James Ketrenos2c86c272005-03-23 17:32:29 -06002036 return;
2037 }
2038
2039 len = sizeof(u32);
2040 ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &len);
2041 if (ret) {
2042 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05002043 __LINE__);
James Ketrenos2c86c272005-03-23 17:32:29 -06002044 return;
2045 }
2046 len = ETH_ALEN;
James Ketrenosee8e3652005-09-14 09:47:29 -05002047 ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID, &bssid, &len);
James Ketrenos2c86c272005-03-23 17:32:29 -06002048 if (ret) {
2049 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05002050 __LINE__);
James Ketrenos2c86c272005-03-23 17:32:29 -06002051 return;
2052 }
2053 memcpy(priv->ieee->bssid, bssid, ETH_ALEN);
2054
James Ketrenos2c86c272005-03-23 17:32:29 -06002055 switch (txrate) {
2056 case TX_RATE_1_MBIT:
2057 txratename = "1Mbps";
2058 break;
2059 case TX_RATE_2_MBIT:
2060 txratename = "2Mbsp";
2061 break;
2062 case TX_RATE_5_5_MBIT:
2063 txratename = "5.5Mbps";
2064 break;
2065 case TX_RATE_11_MBIT:
2066 txratename = "11Mbps";
2067 break;
2068 default:
2069 IPW_DEBUG_INFO("Unknown rate: %d\n", txrate);
2070 txratename = "unknown rate";
2071 break;
2072 }
2073
Johannes Berge1749612008-10-27 15:59:26 -07002074 IPW_DEBUG_INFO("%s: Associated with '%s' at %s, channel %d (BSSID=%pM)\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04002075 priv->net_dev->name, print_ssid(ssid, essid, essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07002076 txratename, chan, bssid);
James Ketrenos2c86c272005-03-23 17:32:29 -06002077
2078 /* now we copy read ssid into dev */
2079 if (!(priv->config & CFG_STATIC_ESSID)) {
James Ketrenosee8e3652005-09-14 09:47:29 -05002080 priv->essid_len = min((u8) essid_len, (u8) IW_ESSID_MAX_SIZE);
James Ketrenos2c86c272005-03-23 17:32:29 -06002081 memcpy(priv->essid, essid, priv->essid_len);
2082 }
2083 priv->channel = chan;
2084 memcpy(priv->bssid, bssid, ETH_ALEN);
2085
2086 priv->status |= STATUS_ASSOCIATING;
2087 priv->connect_start = get_seconds();
2088
2089 queue_delayed_work(priv->workqueue, &priv->wx_event_work, HZ / 10);
2090}
2091
Jiri Bencc4aee8c2005-08-25 20:04:43 -04002092static int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid,
2093 int length, int batch_mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06002094{
2095 int ssid_len = min(length, IW_ESSID_MAX_SIZE);
2096 struct host_command cmd = {
2097 .host_command = SSID,
2098 .host_command_sequence = 0,
2099 .host_command_length = ssid_len
2100 };
2101 int err;
John W. Linville9387b7c2008-09-30 20:59:05 -04002102 DECLARE_SSID_BUF(ssid);
James Ketrenos2c86c272005-03-23 17:32:29 -06002103
John W. Linville9387b7c2008-09-30 20:59:05 -04002104 IPW_DEBUG_HC("SSID: '%s'\n", print_ssid(ssid, essid, ssid_len));
James Ketrenos2c86c272005-03-23 17:32:29 -06002105
2106 if (ssid_len)
James Ketrenos82328352005-08-24 22:33:31 -05002107 memcpy(cmd.host_command_parameters, essid, ssid_len);
James Ketrenos2c86c272005-03-23 17:32:29 -06002108
2109 if (!batch_mode) {
2110 err = ipw2100_disable_adapter(priv);
2111 if (err)
2112 return err;
2113 }
2114
2115 /* Bug in FW currently doesn't honor bit 0 in SET_SCAN_OPTIONS to
2116 * disable auto association -- so we cheat by setting a bogus SSID */
2117 if (!ssid_len && !(priv->config & CFG_ASSOCIATE)) {
2118 int i;
James Ketrenosee8e3652005-09-14 09:47:29 -05002119 u8 *bogus = (u8 *) cmd.host_command_parameters;
James Ketrenos2c86c272005-03-23 17:32:29 -06002120 for (i = 0; i < IW_ESSID_MAX_SIZE; i++)
2121 bogus[i] = 0x18 + i;
2122 cmd.host_command_length = IW_ESSID_MAX_SIZE;
2123 }
2124
2125 /* NOTE: We always send the SSID command even if the provided ESSID is
2126 * the same as what we currently think is set. */
2127
2128 err = ipw2100_hw_send_command(priv, &cmd);
2129 if (!err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05002130 memset(priv->essid + ssid_len, 0, IW_ESSID_MAX_SIZE - ssid_len);
James Ketrenos2c86c272005-03-23 17:32:29 -06002131 memcpy(priv->essid, essid, ssid_len);
2132 priv->essid_len = ssid_len;
2133 }
2134
2135 if (!batch_mode) {
2136 if (ipw2100_enable_adapter(priv))
2137 err = -EIO;
2138 }
2139
2140 return err;
2141}
2142
2143static void isr_indicate_association_lost(struct ipw2100_priv *priv, u32 status)
2144{
John W. Linville9387b7c2008-09-30 20:59:05 -04002145 DECLARE_SSID_BUF(ssid);
2146
James Ketrenos2c86c272005-03-23 17:32:29 -06002147 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
Frans Pop9fd1ea42010-03-24 19:46:31 +01002148 "disassociated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04002149 print_ssid(ssid, priv->essid, priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07002150 priv->bssid);
James Ketrenos2c86c272005-03-23 17:32:29 -06002151
2152 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
2153
2154 if (priv->status & STATUS_STOPPING) {
2155 IPW_DEBUG_INFO("Card is stopping itself, discard ASSN_LOST.\n");
2156 return;
2157 }
2158
2159 memset(priv->bssid, 0, ETH_ALEN);
2160 memset(priv->ieee->bssid, 0, ETH_ALEN);
2161
2162 netif_carrier_off(priv->net_dev);
2163 netif_stop_queue(priv->net_dev);
2164
2165 if (!(priv->status & STATUS_RUNNING))
2166 return;
2167
2168 if (priv->status & STATUS_SECURITY_UPDATED)
David Howellsc4028952006-11-22 14:57:56 +00002169 queue_delayed_work(priv->workqueue, &priv->security_work, 0);
James Ketrenos2c86c272005-03-23 17:32:29 -06002170
David Howellsc4028952006-11-22 14:57:56 +00002171 queue_delayed_work(priv->workqueue, &priv->wx_event_work, 0);
James Ketrenos2c86c272005-03-23 17:32:29 -06002172}
2173
2174static void isr_indicate_rf_kill(struct ipw2100_priv *priv, u32 status)
2175{
2176 IPW_DEBUG_INFO("%s: RF Kill state changed to radio OFF.\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05002177 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06002178
2179 /* RF_KILL is now enabled (else we wouldn't be here) */
Matthew Garrettc26409a2009-11-11 14:36:30 -05002180 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
James Ketrenos2c86c272005-03-23 17:32:29 -06002181 priv->status |= STATUS_RF_KILL_HW;
2182
James Ketrenos2c86c272005-03-23 17:32:29 -06002183 /* Make sure the RF Kill check timer is running */
2184 priv->stop_rf_kill = 0;
2185 cancel_delayed_work(&priv->rf_kill);
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05002186 queue_delayed_work(priv->workqueue, &priv->rf_kill,
2187 round_jiffies_relative(HZ));
James Ketrenos2c86c272005-03-23 17:32:29 -06002188}
2189
Dan Williamsd20c6782007-10-10 12:28:07 -04002190static void send_scan_event(void *data)
2191{
2192 struct ipw2100_priv *priv = data;
2193 union iwreq_data wrqu;
2194
2195 wrqu.data.length = 0;
2196 wrqu.data.flags = 0;
2197 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
2198}
2199
2200static void ipw2100_scan_event_later(struct work_struct *work)
2201{
2202 send_scan_event(container_of(work, struct ipw2100_priv,
2203 scan_event_later.work));
2204}
2205
2206static void ipw2100_scan_event_now(struct work_struct *work)
2207{
2208 send_scan_event(container_of(work, struct ipw2100_priv,
2209 scan_event_now));
2210}
2211
James Ketrenos2c86c272005-03-23 17:32:29 -06002212static void isr_scan_complete(struct ipw2100_priv *priv, u32 status)
2213{
2214 IPW_DEBUG_SCAN("scan complete\n");
2215 /* Age the scan results... */
2216 priv->ieee->scans++;
2217 priv->status &= ~STATUS_SCANNING;
Dan Williamsd20c6782007-10-10 12:28:07 -04002218
2219 /* Only userspace-requested scan completion events go out immediately */
2220 if (!priv->user_requested_scan) {
2221 if (!delayed_work_pending(&priv->scan_event_later))
2222 queue_delayed_work(priv->workqueue,
2223 &priv->scan_event_later,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05002224 round_jiffies_relative(msecs_to_jiffies(4000)));
Dan Williamsd20c6782007-10-10 12:28:07 -04002225 } else {
2226 priv->user_requested_scan = 0;
2227 cancel_delayed_work(&priv->scan_event_later);
2228 queue_work(priv->workqueue, &priv->scan_event_now);
2229 }
James Ketrenos2c86c272005-03-23 17:32:29 -06002230}
2231
Brice Goglin0f52bf92005-12-01 01:41:46 -08002232#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06002233#define IPW2100_HANDLER(v, f) { v, f, # v }
2234struct ipw2100_status_indicator {
2235 int status;
James Ketrenosee8e3652005-09-14 09:47:29 -05002236 void (*cb) (struct ipw2100_priv * priv, u32 status);
James Ketrenos2c86c272005-03-23 17:32:29 -06002237 char *name;
2238};
2239#else
2240#define IPW2100_HANDLER(v, f) { v, f }
2241struct ipw2100_status_indicator {
2242 int status;
James Ketrenosee8e3652005-09-14 09:47:29 -05002243 void (*cb) (struct ipw2100_priv * priv, u32 status);
James Ketrenos2c86c272005-03-23 17:32:29 -06002244};
Brice Goglin0f52bf92005-12-01 01:41:46 -08002245#endif /* CONFIG_IPW2100_DEBUG */
James Ketrenos2c86c272005-03-23 17:32:29 -06002246
2247static void isr_indicate_scanning(struct ipw2100_priv *priv, u32 status)
2248{
2249 IPW_DEBUG_SCAN("Scanning...\n");
2250 priv->status |= STATUS_SCANNING;
2251}
2252
Jiri Bencc4aee8c2005-08-25 20:04:43 -04002253static const struct ipw2100_status_indicator status_handlers[] = {
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01002254 IPW2100_HANDLER(IPW_STATE_INITIALIZED, NULL),
2255 IPW2100_HANDLER(IPW_STATE_COUNTRY_FOUND, NULL),
James Ketrenos2c86c272005-03-23 17:32:29 -06002256 IPW2100_HANDLER(IPW_STATE_ASSOCIATED, isr_indicate_associated),
2257 IPW2100_HANDLER(IPW_STATE_ASSN_LOST, isr_indicate_association_lost),
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01002258 IPW2100_HANDLER(IPW_STATE_ASSN_CHANGED, NULL),
James Ketrenos2c86c272005-03-23 17:32:29 -06002259 IPW2100_HANDLER(IPW_STATE_SCAN_COMPLETE, isr_scan_complete),
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01002260 IPW2100_HANDLER(IPW_STATE_ENTERED_PSP, NULL),
2261 IPW2100_HANDLER(IPW_STATE_LEFT_PSP, NULL),
James Ketrenos2c86c272005-03-23 17:32:29 -06002262 IPW2100_HANDLER(IPW_STATE_RF_KILL, isr_indicate_rf_kill),
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01002263 IPW2100_HANDLER(IPW_STATE_DISABLED, NULL),
2264 IPW2100_HANDLER(IPW_STATE_POWER_DOWN, NULL),
James Ketrenos2c86c272005-03-23 17:32:29 -06002265 IPW2100_HANDLER(IPW_STATE_SCANNING, isr_indicate_scanning),
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01002266 IPW2100_HANDLER(-1, NULL)
James Ketrenos2c86c272005-03-23 17:32:29 -06002267};
2268
James Ketrenos2c86c272005-03-23 17:32:29 -06002269static void isr_status_change(struct ipw2100_priv *priv, int status)
2270{
2271 int i;
2272
2273 if (status == IPW_STATE_SCANNING &&
2274 priv->status & STATUS_ASSOCIATED &&
2275 !(priv->status & STATUS_SCANNING)) {
2276 IPW_DEBUG_INFO("Scan detected while associated, with "
2277 "no scan request. Restarting firmware.\n");
2278
2279 /* Wake up any sleeping jobs */
2280 schedule_reset(priv);
2281 }
2282
2283 for (i = 0; status_handlers[i].status != -1; i++) {
2284 if (status == status_handlers[i].status) {
2285 IPW_DEBUG_NOTIF("Status change: %s\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05002286 status_handlers[i].name);
James Ketrenos2c86c272005-03-23 17:32:29 -06002287 if (status_handlers[i].cb)
2288 status_handlers[i].cb(priv, status);
2289 priv->wstats.status = status;
2290 return;
2291 }
2292 }
2293
2294 IPW_DEBUG_NOTIF("unknown status received: %04x\n", status);
2295}
2296
James Ketrenosee8e3652005-09-14 09:47:29 -05002297static void isr_rx_complete_command(struct ipw2100_priv *priv,
2298 struct ipw2100_cmd_header *cmd)
James Ketrenos2c86c272005-03-23 17:32:29 -06002299{
Brice Goglin0f52bf92005-12-01 01:41:46 -08002300#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06002301 if (cmd->host_command_reg < ARRAY_SIZE(command_types)) {
2302 IPW_DEBUG_HC("Command completed '%s (%d)'\n",
2303 command_types[cmd->host_command_reg],
2304 cmd->host_command_reg);
2305 }
2306#endif
2307 if (cmd->host_command_reg == HOST_COMPLETE)
2308 priv->status |= STATUS_ENABLED;
2309
2310 if (cmd->host_command_reg == CARD_DISABLE)
2311 priv->status &= ~STATUS_ENABLED;
2312
2313 priv->status &= ~STATUS_CMD_ACTIVE;
2314
2315 wake_up_interruptible(&priv->wait_command_queue);
2316}
2317
Brice Goglin0f52bf92005-12-01 01:41:46 -08002318#ifdef CONFIG_IPW2100_DEBUG
Jiri Bencc4aee8c2005-08-25 20:04:43 -04002319static const char *frame_types[] = {
James Ketrenos2c86c272005-03-23 17:32:29 -06002320 "COMMAND_STATUS_VAL",
2321 "STATUS_CHANGE_VAL",
2322 "P80211_DATA_VAL",
2323 "P8023_DATA_VAL",
2324 "HOST_NOTIFICATION_VAL"
2325};
2326#endif
2327
Arjan van de Ven858119e2006-01-14 13:20:43 -08002328static int ipw2100_alloc_skb(struct ipw2100_priv *priv,
James Ketrenosee8e3652005-09-14 09:47:29 -05002329 struct ipw2100_rx_packet *packet)
James Ketrenos2c86c272005-03-23 17:32:29 -06002330{
2331 packet->skb = dev_alloc_skb(sizeof(struct ipw2100_rx));
2332 if (!packet->skb)
2333 return -ENOMEM;
2334
2335 packet->rxp = (struct ipw2100_rx *)packet->skb->data;
2336 packet->dma_addr = pci_map_single(priv->pci_dev, packet->skb->data,
2337 sizeof(struct ipw2100_rx),
2338 PCI_DMA_FROMDEVICE);
2339 /* NOTE: pci_map_single does not return an error code, and 0 is a valid
2340 * dma_addr */
2341
2342 return 0;
2343}
2344
James Ketrenos2c86c272005-03-23 17:32:29 -06002345#define SEARCH_ERROR 0xffffffff
2346#define SEARCH_FAIL 0xfffffffe
2347#define SEARCH_SUCCESS 0xfffffff0
2348#define SEARCH_DISCARD 0
2349#define SEARCH_SNAPSHOT 1
2350
2351#define SNAPSHOT_ADDR(ofs) (priv->snapshot[((ofs) >> 12) & 0xff] + ((ofs) & 0xfff))
Zhu Yi3c5eca52006-01-24 13:49:26 +08002352static void ipw2100_snapshot_free(struct ipw2100_priv *priv)
2353{
2354 int i;
2355 if (!priv->snapshot[0])
2356 return;
2357 for (i = 0; i < 0x30; i++)
2358 kfree(priv->snapshot[i]);
2359 priv->snapshot[0] = NULL;
2360}
2361
Robert P. J. Dayae800312007-01-31 02:39:40 -05002362#ifdef IPW2100_DEBUG_C3
Arjan van de Ven858119e2006-01-14 13:20:43 -08002363static int ipw2100_snapshot_alloc(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06002364{
2365 int i;
2366 if (priv->snapshot[0])
2367 return 1;
2368 for (i = 0; i < 0x30; i++) {
Robert P. J. Day5cbded52006-12-13 00:35:56 -08002369 priv->snapshot[i] = kmalloc(0x1000, GFP_ATOMIC);
James Ketrenos2c86c272005-03-23 17:32:29 -06002370 if (!priv->snapshot[i]) {
2371 IPW_DEBUG_INFO("%s: Error allocating snapshot "
James Ketrenosee8e3652005-09-14 09:47:29 -05002372 "buffer %d\n", priv->net_dev->name, i);
James Ketrenos2c86c272005-03-23 17:32:29 -06002373 while (i > 0)
2374 kfree(priv->snapshot[--i]);
2375 priv->snapshot[0] = NULL;
2376 return 0;
2377 }
2378 }
2379
2380 return 1;
2381}
2382
Arjan van de Ven858119e2006-01-14 13:20:43 -08002383static u32 ipw2100_match_buf(struct ipw2100_priv *priv, u8 * in_buf,
James Ketrenos2c86c272005-03-23 17:32:29 -06002384 size_t len, int mode)
2385{
2386 u32 i, j;
2387 u32 tmp;
2388 u8 *s, *d;
2389 u32 ret;
2390
2391 s = in_buf;
2392 if (mode == SEARCH_SNAPSHOT) {
2393 if (!ipw2100_snapshot_alloc(priv))
2394 mode = SEARCH_DISCARD;
2395 }
2396
2397 for (ret = SEARCH_FAIL, i = 0; i < 0x30000; i += 4) {
2398 read_nic_dword(priv->net_dev, i, &tmp);
2399 if (mode == SEARCH_SNAPSHOT)
James Ketrenosee8e3652005-09-14 09:47:29 -05002400 *(u32 *) SNAPSHOT_ADDR(i) = tmp;
James Ketrenos2c86c272005-03-23 17:32:29 -06002401 if (ret == SEARCH_FAIL) {
James Ketrenosee8e3652005-09-14 09:47:29 -05002402 d = (u8 *) & tmp;
James Ketrenos2c86c272005-03-23 17:32:29 -06002403 for (j = 0; j < 4; j++) {
2404 if (*s != *d) {
2405 s = in_buf;
2406 continue;
2407 }
2408
2409 s++;
2410 d++;
2411
2412 if ((s - in_buf) == len)
2413 ret = (i + j) - len + 1;
2414 }
2415 } else if (mode == SEARCH_DISCARD)
2416 return ret;
2417 }
2418
2419 return ret;
2420}
Zhu Yi3c5eca52006-01-24 13:49:26 +08002421#endif
James Ketrenos2c86c272005-03-23 17:32:29 -06002422
2423/*
2424 *
2425 * 0) Disconnect the SKB from the firmware (just unmap)
2426 * 1) Pack the ETH header into the SKB
2427 * 2) Pass the SKB to the network stack
2428 *
2429 * When packet is provided by the firmware, it contains the following:
2430 *
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002431 * . libipw_hdr
2432 * . libipw_snap_hdr
James Ketrenos2c86c272005-03-23 17:32:29 -06002433 *
2434 * The size of the constructed ethernet
2435 *
2436 */
Robert P. J. Dayae800312007-01-31 02:39:40 -05002437#ifdef IPW2100_RX_DEBUG
Jiri Bencc4aee8c2005-08-25 20:04:43 -04002438static u8 packet_data[IPW_RX_NIC_BUFFER_LENGTH];
James Ketrenos2c86c272005-03-23 17:32:29 -06002439#endif
2440
Arjan van de Ven858119e2006-01-14 13:20:43 -08002441static void ipw2100_corruption_detected(struct ipw2100_priv *priv, int i)
James Ketrenos2c86c272005-03-23 17:32:29 -06002442{
Robert P. J. Dayae800312007-01-31 02:39:40 -05002443#ifdef IPW2100_DEBUG_C3
James Ketrenos2c86c272005-03-23 17:32:29 -06002444 struct ipw2100_status *status = &priv->status_queue.drv[i];
2445 u32 match, reg;
2446 int j;
2447#endif
James Ketrenos2c86c272005-03-23 17:32:29 -06002448
Zhu Yia1e695a2005-07-04 14:06:00 +08002449 IPW_DEBUG_INFO(": PCI latency error detected at 0x%04zX.\n",
2450 i * sizeof(struct ipw2100_status));
James Ketrenos2c86c272005-03-23 17:32:29 -06002451
Robert P. J. Dayae800312007-01-31 02:39:40 -05002452#ifdef IPW2100_DEBUG_C3
Nick Andrew877d0312009-01-26 11:06:57 +01002453 /* Halt the firmware so we can get a good image */
James Ketrenos2c86c272005-03-23 17:32:29 -06002454 write_register(priv->net_dev, IPW_REG_RESET_REG,
2455 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
2456 j = 5;
2457 do {
2458 udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
2459 read_register(priv->net_dev, IPW_REG_RESET_REG, &reg);
2460
2461 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
2462 break;
James Ketrenosee8e3652005-09-14 09:47:29 -05002463 } while (j--);
James Ketrenos2c86c272005-03-23 17:32:29 -06002464
James Ketrenosee8e3652005-09-14 09:47:29 -05002465 match = ipw2100_match_buf(priv, (u8 *) status,
James Ketrenos2c86c272005-03-23 17:32:29 -06002466 sizeof(struct ipw2100_status),
2467 SEARCH_SNAPSHOT);
2468 if (match < SEARCH_SUCCESS)
2469 IPW_DEBUG_INFO("%s: DMA status match in Firmware at "
2470 "offset 0x%06X, length %d:\n",
2471 priv->net_dev->name, match,
2472 sizeof(struct ipw2100_status));
2473 else
2474 IPW_DEBUG_INFO("%s: No DMA status match in "
2475 "Firmware.\n", priv->net_dev->name);
2476
James Ketrenosee8e3652005-09-14 09:47:29 -05002477 printk_buf((u8 *) priv->status_queue.drv,
James Ketrenos2c86c272005-03-23 17:32:29 -06002478 sizeof(struct ipw2100_status) * RX_QUEUE_LENGTH);
2479#endif
2480
2481 priv->fatal_error = IPW2100_ERR_C3_CORRUPTION;
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002482 priv->net_dev->stats.rx_errors++;
James Ketrenos2c86c272005-03-23 17:32:29 -06002483 schedule_reset(priv);
2484}
2485
Arjan van de Ven858119e2006-01-14 13:20:43 -08002486static void isr_rx(struct ipw2100_priv *priv, int i,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002487 struct libipw_rx_stats *stats)
James Ketrenos2c86c272005-03-23 17:32:29 -06002488{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002489 struct net_device *dev = priv->net_dev;
James Ketrenos2c86c272005-03-23 17:32:29 -06002490 struct ipw2100_status *status = &priv->status_queue.drv[i];
2491 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
2492
2493 IPW_DEBUG_RX("Handler...\n");
2494
2495 if (unlikely(status->frame_size > skb_tailroom(packet->skb))) {
2496 IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!"
2497 " Dropping.\n",
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002498 dev->name,
James Ketrenos2c86c272005-03-23 17:32:29 -06002499 status->frame_size, skb_tailroom(packet->skb));
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002500 dev->stats.rx_errors++;
James Ketrenos2c86c272005-03-23 17:32:29 -06002501 return;
2502 }
2503
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002504 if (unlikely(!netif_running(dev))) {
2505 dev->stats.rx_errors++;
James Ketrenos2c86c272005-03-23 17:32:29 -06002506 priv->wstats.discard.misc++;
2507 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
2508 return;
2509 }
James Ketrenos2c86c272005-03-23 17:32:29 -06002510
2511 if (unlikely(priv->ieee->iw_mode != IW_MODE_MONITOR &&
James Ketrenosee8e3652005-09-14 09:47:29 -05002512 !(priv->status & STATUS_ASSOCIATED))) {
James Ketrenos2c86c272005-03-23 17:32:29 -06002513 IPW_DEBUG_DROP("Dropping packet while not associated.\n");
2514 priv->wstats.discard.misc++;
2515 return;
2516 }
2517
James Ketrenos2c86c272005-03-23 17:32:29 -06002518 pci_unmap_single(priv->pci_dev,
2519 packet->dma_addr,
James Ketrenosee8e3652005-09-14 09:47:29 -05002520 sizeof(struct ipw2100_rx), PCI_DMA_FROMDEVICE);
James Ketrenos2c86c272005-03-23 17:32:29 -06002521
2522 skb_put(packet->skb, status->frame_size);
2523
Robert P. J. Dayae800312007-01-31 02:39:40 -05002524#ifdef IPW2100_RX_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06002525 /* Make a copy of the frame so we can dump it to the logs if
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002526 * libipw_rx fails */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002527 skb_copy_from_linear_data(packet->skb, packet_data,
2528 min_t(u32, status->frame_size,
2529 IPW_RX_NIC_BUFFER_LENGTH));
James Ketrenos2c86c272005-03-23 17:32:29 -06002530#endif
2531
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002532 if (!libipw_rx(priv->ieee, packet->skb, stats)) {
Robert P. J. Dayae800312007-01-31 02:39:40 -05002533#ifdef IPW2100_RX_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06002534 IPW_DEBUG_DROP("%s: Non consumed packet:\n",
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002535 dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06002536 printk_buf(IPW_DL_DROP, packet_data, status->frame_size);
2537#endif
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002538 dev->stats.rx_errors++;
James Ketrenos2c86c272005-03-23 17:32:29 -06002539
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002540 /* libipw_rx failed, so it didn't free the SKB */
James Ketrenos2c86c272005-03-23 17:32:29 -06002541 dev_kfree_skb_any(packet->skb);
2542 packet->skb = NULL;
2543 }
2544
2545 /* We need to allocate a new SKB and attach it to the RDB. */
2546 if (unlikely(ipw2100_alloc_skb(priv, packet))) {
Jiri Benc797b4f72005-08-25 20:03:27 -04002547 printk(KERN_WARNING DRV_NAME ": "
James Ketrenosee8e3652005-09-14 09:47:29 -05002548 "%s: Unable to allocate SKB onto RBD ring - disabling "
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002549 "adapter.\n", dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06002550 /* TODO: schedule adapter shutdown */
2551 IPW_DEBUG_INFO("TODO: Shutdown adapter...\n");
2552 }
2553
2554 /* Update the RDB entry */
2555 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
2556}
2557
Stefan Rompf15745a72006-02-21 18:36:17 +08002558#ifdef CONFIG_IPW2100_MONITOR
2559
2560static void isr_rx_monitor(struct ipw2100_priv *priv, int i,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002561 struct libipw_rx_stats *stats)
Stefan Rompf15745a72006-02-21 18:36:17 +08002562{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002563 struct net_device *dev = priv->net_dev;
Stefan Rompf15745a72006-02-21 18:36:17 +08002564 struct ipw2100_status *status = &priv->status_queue.drv[i];
2565 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
2566
Stefan Rompf15745a72006-02-21 18:36:17 +08002567 /* Magic struct that slots into the radiotap header -- no reason
2568 * to build this manually element by element, we can write it much
2569 * more efficiently than we can parse it. ORDER MATTERS HERE */
2570 struct ipw_rt_hdr {
2571 struct ieee80211_radiotap_header rt_hdr;
2572 s8 rt_dbmsignal; /* signal in dbM, kluged to signed */
2573 } *ipw_rt;
2574
Zhu Yicae16292006-02-21 18:41:14 +08002575 IPW_DEBUG_RX("Handler...\n");
2576
2577 if (unlikely(status->frame_size > skb_tailroom(packet->skb) -
2578 sizeof(struct ipw_rt_hdr))) {
Stefan Rompf15745a72006-02-21 18:36:17 +08002579 IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!"
2580 " Dropping.\n",
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002581 dev->name,
Zhu Yicae16292006-02-21 18:41:14 +08002582 status->frame_size,
2583 skb_tailroom(packet->skb));
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002584 dev->stats.rx_errors++;
Stefan Rompf15745a72006-02-21 18:36:17 +08002585 return;
2586 }
2587
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002588 if (unlikely(!netif_running(dev))) {
2589 dev->stats.rx_errors++;
Stefan Rompf15745a72006-02-21 18:36:17 +08002590 priv->wstats.discard.misc++;
2591 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
2592 return;
2593 }
2594
2595 if (unlikely(priv->config & CFG_CRC_CHECK &&
2596 status->flags & IPW_STATUS_FLAG_CRC_ERROR)) {
2597 IPW_DEBUG_RX("CRC error in packet. Dropping.\n");
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002598 dev->stats.rx_errors++;
Stefan Rompf15745a72006-02-21 18:36:17 +08002599 return;
2600 }
2601
Zhu Yicae16292006-02-21 18:41:14 +08002602 pci_unmap_single(priv->pci_dev, packet->dma_addr,
Stefan Rompf15745a72006-02-21 18:36:17 +08002603 sizeof(struct ipw2100_rx), PCI_DMA_FROMDEVICE);
2604 memmove(packet->skb->data + sizeof(struct ipw_rt_hdr),
2605 packet->skb->data, status->frame_size);
2606
2607 ipw_rt = (struct ipw_rt_hdr *) packet->skb->data;
2608
2609 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
2610 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
Al Viro1edd3a52007-12-21 00:15:18 -05002611 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total hdr+data */
Stefan Rompf15745a72006-02-21 18:36:17 +08002612
Al Viro1edd3a52007-12-21 00:15:18 -05002613 ipw_rt->rt_hdr.it_present = cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
Stefan Rompf15745a72006-02-21 18:36:17 +08002614
2615 ipw_rt->rt_dbmsignal = status->rssi + IPW2100_RSSI_TO_DBM;
2616
2617 skb_put(packet->skb, status->frame_size + sizeof(struct ipw_rt_hdr));
2618
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002619 if (!libipw_rx(priv->ieee, packet->skb, stats)) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002620 dev->stats.rx_errors++;
Stefan Rompf15745a72006-02-21 18:36:17 +08002621
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002622 /* libipw_rx failed, so it didn't free the SKB */
Stefan Rompf15745a72006-02-21 18:36:17 +08002623 dev_kfree_skb_any(packet->skb);
2624 packet->skb = NULL;
2625 }
2626
2627 /* We need to allocate a new SKB and attach it to the RDB. */
2628 if (unlikely(ipw2100_alloc_skb(priv, packet))) {
2629 IPW_DEBUG_WARNING(
2630 "%s: Unable to allocate SKB onto RBD ring - disabling "
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002631 "adapter.\n", dev->name);
Stefan Rompf15745a72006-02-21 18:36:17 +08002632 /* TODO: schedule adapter shutdown */
2633 IPW_DEBUG_INFO("TODO: Shutdown adapter...\n");
2634 }
2635
2636 /* Update the RDB entry */
2637 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
2638}
2639
2640#endif
2641
Arjan van de Ven858119e2006-01-14 13:20:43 -08002642static int ipw2100_corruption_check(struct ipw2100_priv *priv, int i)
James Ketrenos2c86c272005-03-23 17:32:29 -06002643{
2644 struct ipw2100_status *status = &priv->status_queue.drv[i];
2645 struct ipw2100_rx *u = priv->rx_buffers[i].rxp;
2646 u16 frame_type = status->status_fields & STATUS_TYPE_MASK;
2647
2648 switch (frame_type) {
2649 case COMMAND_STATUS_VAL:
2650 return (status->frame_size != sizeof(u->rx_data.command));
2651 case STATUS_CHANGE_VAL:
2652 return (status->frame_size != sizeof(u->rx_data.status));
2653 case HOST_NOTIFICATION_VAL:
2654 return (status->frame_size < sizeof(u->rx_data.notification));
2655 case P80211_DATA_VAL:
2656 case P8023_DATA_VAL:
2657#ifdef CONFIG_IPW2100_MONITOR
2658 return 0;
2659#else
Al Viro1edd3a52007-12-21 00:15:18 -05002660 switch (WLAN_FC_GET_TYPE(le16_to_cpu(u->rx_data.header.frame_ctl))) {
James Ketrenos2c86c272005-03-23 17:32:29 -06002661 case IEEE80211_FTYPE_MGMT:
2662 case IEEE80211_FTYPE_CTL:
2663 return 0;
2664 case IEEE80211_FTYPE_DATA:
2665 return (status->frame_size >
2666 IPW_MAX_802_11_PAYLOAD_LENGTH);
2667 }
2668#endif
2669 }
2670
2671 return 1;
2672}
2673
2674/*
2675 * ipw2100 interrupts are disabled at this point, and the ISR
2676 * is the only code that calls this method. So, we do not need
2677 * to play with any locks.
2678 *
2679 * RX Queue works as follows:
2680 *
2681 * Read index - firmware places packet in entry identified by the
2682 * Read index and advances Read index. In this manner,
2683 * Read index will always point to the next packet to
2684 * be filled--but not yet valid.
2685 *
2686 * Write index - driver fills this entry with an unused RBD entry.
2687 * This entry has not filled by the firmware yet.
2688 *
2689 * In between the W and R indexes are the RBDs that have been received
2690 * but not yet processed.
2691 *
2692 * The process of handling packets will start at WRITE + 1 and advance
2693 * until it reaches the READ index.
2694 *
2695 * The WRITE index is cached in the variable 'priv->rx_queue.next'.
2696 *
2697 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002698static void __ipw2100_rx_process(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06002699{
2700 struct ipw2100_bd_queue *rxq = &priv->rx_queue;
2701 struct ipw2100_status_queue *sq = &priv->status_queue;
2702 struct ipw2100_rx_packet *packet;
2703 u16 frame_type;
2704 u32 r, w, i, s;
2705 struct ipw2100_rx *u;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002706 struct libipw_rx_stats stats = {
James Ketrenos2c86c272005-03-23 17:32:29 -06002707 .mac_time = jiffies,
2708 };
2709
2710 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_READ_INDEX, &r);
2711 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, &w);
2712
2713 if (r >= rxq->entries) {
2714 IPW_DEBUG_RX("exit - bad read index\n");
2715 return;
2716 }
2717
2718 i = (rxq->next + 1) % rxq->entries;
2719 s = i;
2720 while (i != r) {
2721 /* IPW_DEBUG_RX("r = %d : w = %d : processing = %d\n",
2722 r, rxq->next, i); */
2723
2724 packet = &priv->rx_buffers[i];
2725
2726 /* Sync the DMA for the STATUS buffer so CPU is sure to get
2727 * the correct values */
James Ketrenosee8e3652005-09-14 09:47:29 -05002728 pci_dma_sync_single_for_cpu(priv->pci_dev,
2729 sq->nic +
2730 sizeof(struct ipw2100_status) * i,
2731 sizeof(struct ipw2100_status),
2732 PCI_DMA_FROMDEVICE);
James Ketrenos2c86c272005-03-23 17:32:29 -06002733
2734 /* Sync the DMA for the RX buffer so CPU is sure to get
2735 * the correct values */
2736 pci_dma_sync_single_for_cpu(priv->pci_dev, packet->dma_addr,
2737 sizeof(struct ipw2100_rx),
2738 PCI_DMA_FROMDEVICE);
2739
2740 if (unlikely(ipw2100_corruption_check(priv, i))) {
2741 ipw2100_corruption_detected(priv, i);
2742 goto increment;
2743 }
2744
2745 u = packet->rxp;
James Ketrenosee8e3652005-09-14 09:47:29 -05002746 frame_type = sq->drv[i].status_fields & STATUS_TYPE_MASK;
James Ketrenos2c86c272005-03-23 17:32:29 -06002747 stats.rssi = sq->drv[i].rssi + IPW2100_RSSI_TO_DBM;
2748 stats.len = sq->drv[i].frame_size;
2749
2750 stats.mask = 0;
2751 if (stats.rssi != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002752 stats.mask |= LIBIPW_STATMASK_RSSI;
2753 stats.freq = LIBIPW_24GHZ_BAND;
James Ketrenos2c86c272005-03-23 17:32:29 -06002754
James Ketrenosee8e3652005-09-14 09:47:29 -05002755 IPW_DEBUG_RX("%s: '%s' frame type received (%d).\n",
2756 priv->net_dev->name, frame_types[frame_type],
2757 stats.len);
James Ketrenos2c86c272005-03-23 17:32:29 -06002758
2759 switch (frame_type) {
2760 case COMMAND_STATUS_VAL:
2761 /* Reset Rx watchdog */
James Ketrenosee8e3652005-09-14 09:47:29 -05002762 isr_rx_complete_command(priv, &u->rx_data.command);
James Ketrenos2c86c272005-03-23 17:32:29 -06002763 break;
2764
2765 case STATUS_CHANGE_VAL:
2766 isr_status_change(priv, u->rx_data.status);
2767 break;
2768
2769 case P80211_DATA_VAL:
2770 case P8023_DATA_VAL:
2771#ifdef CONFIG_IPW2100_MONITOR
2772 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Stefan Rompf15745a72006-02-21 18:36:17 +08002773 isr_rx_monitor(priv, i, &stats);
James Ketrenos2c86c272005-03-23 17:32:29 -06002774 break;
2775 }
2776#endif
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002777 if (stats.len < sizeof(struct libipw_hdr_3addr))
James Ketrenos2c86c272005-03-23 17:32:29 -06002778 break;
Al Viro1edd3a52007-12-21 00:15:18 -05002779 switch (WLAN_FC_GET_TYPE(le16_to_cpu(u->rx_data.header.frame_ctl))) {
James Ketrenos2c86c272005-03-23 17:32:29 -06002780 case IEEE80211_FTYPE_MGMT:
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002781 libipw_rx_mgt(priv->ieee,
James Ketrenosee8e3652005-09-14 09:47:29 -05002782 &u->rx_data.header, &stats);
James Ketrenos2c86c272005-03-23 17:32:29 -06002783 break;
2784
2785 case IEEE80211_FTYPE_CTL:
2786 break;
2787
2788 case IEEE80211_FTYPE_DATA:
2789 isr_rx(priv, i, &stats);
2790 break;
2791
2792 }
2793 break;
2794 }
2795
James Ketrenosee8e3652005-09-14 09:47:29 -05002796 increment:
James Ketrenos2c86c272005-03-23 17:32:29 -06002797 /* clear status field associated with this RBD */
2798 rxq->drv[i].status.info.field = 0;
2799
2800 i = (i + 1) % rxq->entries;
2801 }
2802
2803 if (i != s) {
2804 /* backtrack one entry, wrapping to end if at 0 */
2805 rxq->next = (i ? i : rxq->entries) - 1;
2806
2807 write_register(priv->net_dev,
James Ketrenosee8e3652005-09-14 09:47:29 -05002808 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, rxq->next);
James Ketrenos2c86c272005-03-23 17:32:29 -06002809 }
2810}
2811
James Ketrenos2c86c272005-03-23 17:32:29 -06002812/*
2813 * __ipw2100_tx_process
2814 *
2815 * This routine will determine whether the next packet on
2816 * the fw_pend_list has been processed by the firmware yet.
2817 *
2818 * If not, then it does nothing and returns.
2819 *
2820 * If so, then it removes the item from the fw_pend_list, frees
2821 * any associated storage, and places the item back on the
2822 * free list of its source (either msg_free_list or tx_free_list)
2823 *
2824 * TX Queue works as follows:
2825 *
2826 * Read index - points to the next TBD that the firmware will
2827 * process. The firmware will read the data, and once
2828 * done processing, it will advance the Read index.
2829 *
2830 * Write index - driver fills this entry with an constructed TBD
2831 * entry. The Write index is not advanced until the
2832 * packet has been configured.
2833 *
2834 * In between the W and R indexes are the TBDs that have NOT been
2835 * processed. Lagging behind the R index are packets that have
2836 * been processed but have not been freed by the driver.
2837 *
2838 * In order to free old storage, an internal index will be maintained
2839 * that points to the next packet to be freed. When all used
2840 * packets have been freed, the oldest index will be the same as the
2841 * firmware's read index.
2842 *
2843 * The OLDEST index is cached in the variable 'priv->tx_queue.oldest'
2844 *
2845 * Because the TBD structure can not contain arbitrary data, the
2846 * driver must keep an internal queue of cached allocations such that
2847 * it can put that data back into the tx_free_list and msg_free_list
2848 * for use by future command and data packets.
2849 *
2850 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002851static int __ipw2100_tx_process(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06002852{
2853 struct ipw2100_bd_queue *txq = &priv->tx_queue;
James Ketrenosee8e3652005-09-14 09:47:29 -05002854 struct ipw2100_bd *tbd;
James Ketrenos2c86c272005-03-23 17:32:29 -06002855 struct list_head *element;
2856 struct ipw2100_tx_packet *packet;
2857 int descriptors_used;
2858 int e, i;
2859 u32 r, w, frag_num = 0;
2860
2861 if (list_empty(&priv->fw_pend_list))
2862 return 0;
2863
2864 element = priv->fw_pend_list.next;
2865
2866 packet = list_entry(element, struct ipw2100_tx_packet, list);
James Ketrenosee8e3652005-09-14 09:47:29 -05002867 tbd = &txq->drv[packet->index];
James Ketrenos2c86c272005-03-23 17:32:29 -06002868
2869 /* Determine how many TBD entries must be finished... */
2870 switch (packet->type) {
2871 case COMMAND:
2872 /* COMMAND uses only one slot; don't advance */
2873 descriptors_used = 1;
2874 e = txq->oldest;
2875 break;
2876
2877 case DATA:
2878 /* DATA uses two slots; advance and loop position. */
2879 descriptors_used = tbd->num_fragments;
James Ketrenosee8e3652005-09-14 09:47:29 -05002880 frag_num = tbd->num_fragments - 1;
James Ketrenos2c86c272005-03-23 17:32:29 -06002881 e = txq->oldest + frag_num;
2882 e %= txq->entries;
2883 break;
2884
2885 default:
Jiri Benc797b4f72005-08-25 20:03:27 -04002886 printk(KERN_WARNING DRV_NAME ": %s: Bad fw_pend_list entry!\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05002887 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06002888 return 0;
2889 }
2890
2891 /* if the last TBD is not done by NIC yet, then packet is
2892 * not ready to be released.
2893 *
2894 */
2895 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
2896 &r);
2897 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
2898 &w);
2899 if (w != txq->next)
Jiri Benc797b4f72005-08-25 20:03:27 -04002900 printk(KERN_WARNING DRV_NAME ": %s: write index mismatch\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06002901 priv->net_dev->name);
2902
James Ketrenosee8e3652005-09-14 09:47:29 -05002903 /*
James Ketrenos2c86c272005-03-23 17:32:29 -06002904 * txq->next is the index of the last packet written txq->oldest is
2905 * the index of the r is the index of the next packet to be read by
2906 * firmware
2907 */
2908
James Ketrenos2c86c272005-03-23 17:32:29 -06002909 /*
2910 * Quick graphic to help you visualize the following
2911 * if / else statement
2912 *
2913 * ===>| s---->|===============
2914 * e>|
2915 * | a | b | c | d | e | f | g | h | i | j | k | l
2916 * r---->|
2917 * w
2918 *
2919 * w - updated by driver
2920 * r - updated by firmware
2921 * s - start of oldest BD entry (txq->oldest)
2922 * e - end of oldest BD entry
2923 *
2924 */
2925 if (!((r <= w && (e < r || e >= w)) || (e < r && e >= w))) {
2926 IPW_DEBUG_TX("exit - no processed packets ready to release.\n");
2927 return 0;
2928 }
2929
2930 list_del(element);
2931 DEC_STAT(&priv->fw_pend_stat);
2932
Brice Goglin0f52bf92005-12-01 01:41:46 -08002933#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06002934 {
Reinette Chatre21f8a732009-08-18 10:25:05 -07002935 i = txq->oldest;
James Ketrenosee8e3652005-09-14 09:47:29 -05002936 IPW_DEBUG_TX("TX%d V=%p P=%04X T=%04X L=%d\n", i,
2937 &txq->drv[i],
2938 (u32) (txq->nic + i * sizeof(struct ipw2100_bd)),
2939 txq->drv[i].host_addr, txq->drv[i].buf_length);
James Ketrenos2c86c272005-03-23 17:32:29 -06002940
2941 if (packet->type == DATA) {
2942 i = (i + 1) % txq->entries;
2943
James Ketrenosee8e3652005-09-14 09:47:29 -05002944 IPW_DEBUG_TX("TX%d V=%p P=%04X T=%04X L=%d\n", i,
2945 &txq->drv[i],
2946 (u32) (txq->nic + i *
2947 sizeof(struct ipw2100_bd)),
2948 (u32) txq->drv[i].host_addr,
2949 txq->drv[i].buf_length);
James Ketrenos2c86c272005-03-23 17:32:29 -06002950 }
2951 }
2952#endif
2953
2954 switch (packet->type) {
2955 case DATA:
2956 if (txq->drv[txq->oldest].status.info.fields.txType != 0)
Jiri Benc797b4f72005-08-25 20:03:27 -04002957 printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch. "
James Ketrenos2c86c272005-03-23 17:32:29 -06002958 "Expecting DATA TBD but pulled "
2959 "something else: ids %d=%d.\n",
2960 priv->net_dev->name, txq->oldest, packet->index);
2961
2962 /* DATA packet; we have to unmap and free the SKB */
James Ketrenos2c86c272005-03-23 17:32:29 -06002963 for (i = 0; i < frag_num; i++) {
James Ketrenosee8e3652005-09-14 09:47:29 -05002964 tbd = &txq->drv[(packet->index + 1 + i) % txq->entries];
James Ketrenos2c86c272005-03-23 17:32:29 -06002965
James Ketrenosee8e3652005-09-14 09:47:29 -05002966 IPW_DEBUG_TX("TX%d P=%08x L=%d\n",
2967 (packet->index + 1 + i) % txq->entries,
2968 tbd->host_addr, tbd->buf_length);
James Ketrenos2c86c272005-03-23 17:32:29 -06002969
2970 pci_unmap_single(priv->pci_dev,
2971 tbd->host_addr,
James Ketrenosee8e3652005-09-14 09:47:29 -05002972 tbd->buf_length, PCI_DMA_TODEVICE);
James Ketrenos2c86c272005-03-23 17:32:29 -06002973 }
2974
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002975 libipw_txb_free(packet->info.d_struct.txb);
James Ketrenos2c86c272005-03-23 17:32:29 -06002976 packet->info.d_struct.txb = NULL;
2977
2978 list_add_tail(element, &priv->tx_free_list);
2979 INC_STAT(&priv->tx_free_stat);
2980
2981 /* We have a free slot in the Tx queue, so wake up the
2982 * transmit layer if it is stopped. */
James Ketrenos82328352005-08-24 22:33:31 -05002983 if (priv->status & STATUS_ASSOCIATED)
James Ketrenos2c86c272005-03-23 17:32:29 -06002984 netif_wake_queue(priv->net_dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06002985
2986 /* A packet was processed by the hardware, so update the
2987 * watchdog */
2988 priv->net_dev->trans_start = jiffies;
2989
2990 break;
2991
2992 case COMMAND:
2993 if (txq->drv[txq->oldest].status.info.fields.txType != 1)
Jiri Benc797b4f72005-08-25 20:03:27 -04002994 printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch. "
James Ketrenos2c86c272005-03-23 17:32:29 -06002995 "Expecting COMMAND TBD but pulled "
2996 "something else: ids %d=%d.\n",
2997 priv->net_dev->name, txq->oldest, packet->index);
2998
Brice Goglin0f52bf92005-12-01 01:41:46 -08002999#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06003000 if (packet->info.c_struct.cmd->host_command_reg <
Ahmed S. Darwish22d57432007-02-05 18:56:22 +02003001 ARRAY_SIZE(command_types))
James Ketrenosee8e3652005-09-14 09:47:29 -05003002 IPW_DEBUG_TX("Command '%s (%d)' processed: %d.\n",
3003 command_types[packet->info.c_struct.cmd->
3004 host_command_reg],
3005 packet->info.c_struct.cmd->
3006 host_command_reg,
3007 packet->info.c_struct.cmd->cmd_status_reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06003008#endif
3009
3010 list_add_tail(element, &priv->msg_free_list);
3011 INC_STAT(&priv->msg_free_stat);
3012 break;
3013 }
3014
3015 /* advance oldest used TBD pointer to start of next entry */
3016 txq->oldest = (e + 1) % txq->entries;
3017 /* increase available TBDs number */
3018 txq->available += descriptors_used;
3019 SET_STAT(&priv->txq_stat, txq->available);
3020
3021 IPW_DEBUG_TX("packet latency (send to process) %ld jiffies\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05003022 jiffies - packet->jiffy_start);
James Ketrenos2c86c272005-03-23 17:32:29 -06003023
3024 return (!list_empty(&priv->fw_pend_list));
3025}
3026
James Ketrenos2c86c272005-03-23 17:32:29 -06003027static inline void __ipw2100_tx_complete(struct ipw2100_priv *priv)
3028{
3029 int i = 0;
3030
James Ketrenosee8e3652005-09-14 09:47:29 -05003031 while (__ipw2100_tx_process(priv) && i < 200)
3032 i++;
James Ketrenos2c86c272005-03-23 17:32:29 -06003033
3034 if (i == 200) {
Jiri Benc19f7f742005-08-25 20:02:10 -04003035 printk(KERN_WARNING DRV_NAME ": "
James Ketrenos2c86c272005-03-23 17:32:29 -06003036 "%s: Driver is running slow (%d iters).\n",
3037 priv->net_dev->name, i);
3038 }
3039}
3040
Jiri Benc19f7f742005-08-25 20:02:10 -04003041static void ipw2100_tx_send_commands(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06003042{
3043 struct list_head *element;
3044 struct ipw2100_tx_packet *packet;
3045 struct ipw2100_bd_queue *txq = &priv->tx_queue;
3046 struct ipw2100_bd *tbd;
3047 int next = txq->next;
3048
3049 while (!list_empty(&priv->msg_pend_list)) {
3050 /* if there isn't enough space in TBD queue, then
3051 * don't stuff a new one in.
3052 * NOTE: 3 are needed as a command will take one,
3053 * and there is a minimum of 2 that must be
3054 * maintained between the r and w indexes
3055 */
3056 if (txq->available <= 3) {
3057 IPW_DEBUG_TX("no room in tx_queue\n");
3058 break;
3059 }
3060
3061 element = priv->msg_pend_list.next;
3062 list_del(element);
3063 DEC_STAT(&priv->msg_pend_stat);
3064
James Ketrenosee8e3652005-09-14 09:47:29 -05003065 packet = list_entry(element, struct ipw2100_tx_packet, list);
James Ketrenos2c86c272005-03-23 17:32:29 -06003066
John W. Linvilleaa0d52c2010-08-10 13:08:11 -04003067 IPW_DEBUG_TX("using TBD at virt=%p, phys=%04X\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05003068 &txq->drv[txq->next],
John W. Linvilleaa0d52c2010-08-10 13:08:11 -04003069 (u32) (txq->nic + txq->next *
James Ketrenosee8e3652005-09-14 09:47:29 -05003070 sizeof(struct ipw2100_bd)));
James Ketrenos2c86c272005-03-23 17:32:29 -06003071
3072 packet->index = txq->next;
3073
3074 tbd = &txq->drv[txq->next];
3075
3076 /* initialize TBD */
3077 tbd->host_addr = packet->info.c_struct.cmd_phys;
3078 tbd->buf_length = sizeof(struct ipw2100_cmd_header);
3079 /* not marking number of fragments causes problems
3080 * with f/w debug version */
3081 tbd->num_fragments = 1;
3082 tbd->status.info.field =
James Ketrenosee8e3652005-09-14 09:47:29 -05003083 IPW_BD_STATUS_TX_FRAME_COMMAND |
3084 IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
James Ketrenos2c86c272005-03-23 17:32:29 -06003085
3086 /* update TBD queue counters */
3087 txq->next++;
3088 txq->next %= txq->entries;
3089 txq->available--;
3090 DEC_STAT(&priv->txq_stat);
3091
3092 list_add_tail(element, &priv->fw_pend_list);
3093 INC_STAT(&priv->fw_pend_stat);
3094 }
3095
3096 if (txq->next != next) {
3097 /* kick off the DMA by notifying firmware the
3098 * write index has moved; make sure TBD stores are sync'd */
3099 wmb();
3100 write_register(priv->net_dev,
3101 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
3102 txq->next);
3103 }
3104}
3105
James Ketrenos2c86c272005-03-23 17:32:29 -06003106/*
Jiri Benc19f7f742005-08-25 20:02:10 -04003107 * ipw2100_tx_send_data
James Ketrenos2c86c272005-03-23 17:32:29 -06003108 *
3109 */
Jiri Benc19f7f742005-08-25 20:02:10 -04003110static void ipw2100_tx_send_data(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06003111{
3112 struct list_head *element;
3113 struct ipw2100_tx_packet *packet;
3114 struct ipw2100_bd_queue *txq = &priv->tx_queue;
3115 struct ipw2100_bd *tbd;
3116 int next = txq->next;
James Ketrenosee8e3652005-09-14 09:47:29 -05003117 int i = 0;
James Ketrenos2c86c272005-03-23 17:32:29 -06003118 struct ipw2100_data_header *ipw_hdr;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003119 struct libipw_hdr_3addr *hdr;
James Ketrenos2c86c272005-03-23 17:32:29 -06003120
3121 while (!list_empty(&priv->tx_pend_list)) {
3122 /* if there isn't enough space in TBD queue, then
3123 * don't stuff a new one in.
3124 * NOTE: 4 are needed as a data will take two,
3125 * and there is a minimum of 2 that must be
3126 * maintained between the r and w indexes
3127 */
3128 element = priv->tx_pend_list.next;
James Ketrenosee8e3652005-09-14 09:47:29 -05003129 packet = list_entry(element, struct ipw2100_tx_packet, list);
James Ketrenos2c86c272005-03-23 17:32:29 -06003130
3131 if (unlikely(1 + packet->info.d_struct.txb->nr_frags >
3132 IPW_MAX_BDS)) {
3133 /* TODO: Support merging buffers if more than
3134 * IPW_MAX_BDS are used */
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02003135 IPW_DEBUG_INFO("%s: Maximum BD threshold exceeded. "
James Ketrenosee8e3652005-09-14 09:47:29 -05003136 "Increase fragmentation level.\n",
3137 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06003138 }
3139
James Ketrenosee8e3652005-09-14 09:47:29 -05003140 if (txq->available <= 3 + packet->info.d_struct.txb->nr_frags) {
James Ketrenos2c86c272005-03-23 17:32:29 -06003141 IPW_DEBUG_TX("no room in tx_queue\n");
3142 break;
3143 }
3144
3145 list_del(element);
3146 DEC_STAT(&priv->tx_pend_stat);
3147
3148 tbd = &txq->drv[txq->next];
3149
3150 packet->index = txq->next;
3151
3152 ipw_hdr = packet->info.d_struct.data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003153 hdr = (struct libipw_hdr_3addr *)packet->info.d_struct.txb->
James Ketrenosee8e3652005-09-14 09:47:29 -05003154 fragments[0]->data;
James Ketrenos2c86c272005-03-23 17:32:29 -06003155
3156 if (priv->ieee->iw_mode == IW_MODE_INFRA) {
3157 /* To DS: Addr1 = BSSID, Addr2 = SA,
3158 Addr3 = DA */
3159 memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
3160 memcpy(ipw_hdr->dst_addr, hdr->addr3, ETH_ALEN);
3161 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
3162 /* not From/To DS: Addr1 = DA, Addr2 = SA,
3163 Addr3 = BSSID */
3164 memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
3165 memcpy(ipw_hdr->dst_addr, hdr->addr1, ETH_ALEN);
3166 }
3167
3168 ipw_hdr->host_command_reg = SEND;
3169 ipw_hdr->host_command_reg1 = 0;
3170
3171 /* For now we only support host based encryption */
3172 ipw_hdr->needs_encryption = 0;
3173 ipw_hdr->encrypted = packet->info.d_struct.txb->encrypted;
3174 if (packet->info.d_struct.txb->nr_frags > 1)
3175 ipw_hdr->fragment_size =
James Ketrenosee8e3652005-09-14 09:47:29 -05003176 packet->info.d_struct.txb->frag_size -
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003177 LIBIPW_3ADDR_LEN;
James Ketrenos2c86c272005-03-23 17:32:29 -06003178 else
3179 ipw_hdr->fragment_size = 0;
3180
3181 tbd->host_addr = packet->info.d_struct.data_phys;
3182 tbd->buf_length = sizeof(struct ipw2100_data_header);
3183 tbd->num_fragments = 1 + packet->info.d_struct.txb->nr_frags;
3184 tbd->status.info.field =
James Ketrenosee8e3652005-09-14 09:47:29 -05003185 IPW_BD_STATUS_TX_FRAME_802_3 |
3186 IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
James Ketrenos2c86c272005-03-23 17:32:29 -06003187 txq->next++;
3188 txq->next %= txq->entries;
3189
James Ketrenosee8e3652005-09-14 09:47:29 -05003190 IPW_DEBUG_TX("data header tbd TX%d P=%08x L=%d\n",
3191 packet->index, tbd->host_addr, tbd->buf_length);
Brice Goglin0f52bf92005-12-01 01:41:46 -08003192#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06003193 if (packet->info.d_struct.txb->nr_frags > 1)
3194 IPW_DEBUG_FRAG("fragment Tx: %d frames\n",
3195 packet->info.d_struct.txb->nr_frags);
3196#endif
3197
James Ketrenosee8e3652005-09-14 09:47:29 -05003198 for (i = 0; i < packet->info.d_struct.txb->nr_frags; i++) {
3199 tbd = &txq->drv[txq->next];
James Ketrenos2c86c272005-03-23 17:32:29 -06003200 if (i == packet->info.d_struct.txb->nr_frags - 1)
3201 tbd->status.info.field =
James Ketrenosee8e3652005-09-14 09:47:29 -05003202 IPW_BD_STATUS_TX_FRAME_802_3 |
3203 IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
James Ketrenos2c86c272005-03-23 17:32:29 -06003204 else
3205 tbd->status.info.field =
James Ketrenosee8e3652005-09-14 09:47:29 -05003206 IPW_BD_STATUS_TX_FRAME_802_3 |
3207 IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
James Ketrenos2c86c272005-03-23 17:32:29 -06003208
3209 tbd->buf_length = packet->info.d_struct.txb->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003210 fragments[i]->len - LIBIPW_3ADDR_LEN;
James Ketrenos2c86c272005-03-23 17:32:29 -06003211
James Ketrenosee8e3652005-09-14 09:47:29 -05003212 tbd->host_addr = pci_map_single(priv->pci_dev,
3213 packet->info.d_struct.
3214 txb->fragments[i]->
3215 data +
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003216 LIBIPW_3ADDR_LEN,
James Ketrenosee8e3652005-09-14 09:47:29 -05003217 tbd->buf_length,
3218 PCI_DMA_TODEVICE);
James Ketrenos2c86c272005-03-23 17:32:29 -06003219
James Ketrenosee8e3652005-09-14 09:47:29 -05003220 IPW_DEBUG_TX("data frag tbd TX%d P=%08x L=%d\n",
3221 txq->next, tbd->host_addr,
3222 tbd->buf_length);
James Ketrenos2c86c272005-03-23 17:32:29 -06003223
James Ketrenosee8e3652005-09-14 09:47:29 -05003224 pci_dma_sync_single_for_device(priv->pci_dev,
3225 tbd->host_addr,
3226 tbd->buf_length,
3227 PCI_DMA_TODEVICE);
James Ketrenos2c86c272005-03-23 17:32:29 -06003228
3229 txq->next++;
3230 txq->next %= txq->entries;
James Ketrenosee8e3652005-09-14 09:47:29 -05003231 }
James Ketrenos2c86c272005-03-23 17:32:29 -06003232
3233 txq->available -= 1 + packet->info.d_struct.txb->nr_frags;
3234 SET_STAT(&priv->txq_stat, txq->available);
3235
3236 list_add_tail(element, &priv->fw_pend_list);
3237 INC_STAT(&priv->fw_pend_stat);
3238 }
3239
3240 if (txq->next != next) {
3241 /* kick off the DMA by notifying firmware the
3242 * write index has moved; make sure TBD stores are sync'd */
3243 write_register(priv->net_dev,
3244 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
3245 txq->next);
3246 }
James Ketrenos2c86c272005-03-23 17:32:29 -06003247}
3248
3249static void ipw2100_irq_tasklet(struct ipw2100_priv *priv)
3250{
3251 struct net_device *dev = priv->net_dev;
3252 unsigned long flags;
3253 u32 inta, tmp;
3254
3255 spin_lock_irqsave(&priv->low_lock, flags);
3256 ipw2100_disable_interrupts(priv);
3257
3258 read_register(dev, IPW_REG_INTA, &inta);
3259
3260 IPW_DEBUG_ISR("enter - INTA: 0x%08lX\n",
3261 (unsigned long)inta & IPW_INTERRUPT_MASK);
3262
3263 priv->in_isr++;
3264 priv->interrupts++;
3265
3266 /* We do not loop and keep polling for more interrupts as this
3267 * is frowned upon and doesn't play nicely with other potentially
3268 * chained IRQs */
3269 IPW_DEBUG_ISR("INTA: 0x%08lX\n",
3270 (unsigned long)inta & IPW_INTERRUPT_MASK);
3271
3272 if (inta & IPW2100_INTA_FATAL_ERROR) {
Jiri Benc797b4f72005-08-25 20:03:27 -04003273 printk(KERN_WARNING DRV_NAME
James Ketrenosee8e3652005-09-14 09:47:29 -05003274 ": Fatal interrupt. Scheduling firmware restart.\n");
James Ketrenos2c86c272005-03-23 17:32:29 -06003275 priv->inta_other++;
James Ketrenosee8e3652005-09-14 09:47:29 -05003276 write_register(dev, IPW_REG_INTA, IPW2100_INTA_FATAL_ERROR);
James Ketrenos2c86c272005-03-23 17:32:29 -06003277
3278 read_nic_dword(dev, IPW_NIC_FATAL_ERROR, &priv->fatal_error);
3279 IPW_DEBUG_INFO("%s: Fatal error value: 0x%08X\n",
3280 priv->net_dev->name, priv->fatal_error);
3281
3282 read_nic_dword(dev, IPW_ERROR_ADDR(priv->fatal_error), &tmp);
3283 IPW_DEBUG_INFO("%s: Fatal error address value: 0x%08X\n",
3284 priv->net_dev->name, tmp);
3285
3286 /* Wake up any sleeping jobs */
3287 schedule_reset(priv);
3288 }
3289
3290 if (inta & IPW2100_INTA_PARITY_ERROR) {
James Ketrenosee8e3652005-09-14 09:47:29 -05003291 printk(KERN_ERR DRV_NAME
Frans Pop9fd1ea42010-03-24 19:46:31 +01003292 ": ***** PARITY ERROR INTERRUPT !!!!\n");
James Ketrenos2c86c272005-03-23 17:32:29 -06003293 priv->inta_other++;
James Ketrenosee8e3652005-09-14 09:47:29 -05003294 write_register(dev, IPW_REG_INTA, IPW2100_INTA_PARITY_ERROR);
James Ketrenos2c86c272005-03-23 17:32:29 -06003295 }
3296
3297 if (inta & IPW2100_INTA_RX_TRANSFER) {
3298 IPW_DEBUG_ISR("RX interrupt\n");
3299
3300 priv->rx_interrupts++;
3301
James Ketrenosee8e3652005-09-14 09:47:29 -05003302 write_register(dev, IPW_REG_INTA, IPW2100_INTA_RX_TRANSFER);
James Ketrenos2c86c272005-03-23 17:32:29 -06003303
3304 __ipw2100_rx_process(priv);
3305 __ipw2100_tx_complete(priv);
3306 }
3307
3308 if (inta & IPW2100_INTA_TX_TRANSFER) {
3309 IPW_DEBUG_ISR("TX interrupt\n");
3310
3311 priv->tx_interrupts++;
3312
James Ketrenosee8e3652005-09-14 09:47:29 -05003313 write_register(dev, IPW_REG_INTA, IPW2100_INTA_TX_TRANSFER);
James Ketrenos2c86c272005-03-23 17:32:29 -06003314
3315 __ipw2100_tx_complete(priv);
Jiri Benc19f7f742005-08-25 20:02:10 -04003316 ipw2100_tx_send_commands(priv);
3317 ipw2100_tx_send_data(priv);
James Ketrenos2c86c272005-03-23 17:32:29 -06003318 }
3319
3320 if (inta & IPW2100_INTA_TX_COMPLETE) {
3321 IPW_DEBUG_ISR("TX complete\n");
3322 priv->inta_other++;
James Ketrenosee8e3652005-09-14 09:47:29 -05003323 write_register(dev, IPW_REG_INTA, IPW2100_INTA_TX_COMPLETE);
James Ketrenos2c86c272005-03-23 17:32:29 -06003324
3325 __ipw2100_tx_complete(priv);
3326 }
3327
3328 if (inta & IPW2100_INTA_EVENT_INTERRUPT) {
3329 /* ipw2100_handle_event(dev); */
3330 priv->inta_other++;
James Ketrenosee8e3652005-09-14 09:47:29 -05003331 write_register(dev, IPW_REG_INTA, IPW2100_INTA_EVENT_INTERRUPT);
James Ketrenos2c86c272005-03-23 17:32:29 -06003332 }
3333
3334 if (inta & IPW2100_INTA_FW_INIT_DONE) {
3335 IPW_DEBUG_ISR("FW init done interrupt\n");
3336 priv->inta_other++;
3337
3338 read_register(dev, IPW_REG_INTA, &tmp);
3339 if (tmp & (IPW2100_INTA_FATAL_ERROR |
3340 IPW2100_INTA_PARITY_ERROR)) {
James Ketrenosee8e3652005-09-14 09:47:29 -05003341 write_register(dev, IPW_REG_INTA,
3342 IPW2100_INTA_FATAL_ERROR |
3343 IPW2100_INTA_PARITY_ERROR);
James Ketrenos2c86c272005-03-23 17:32:29 -06003344 }
3345
James Ketrenosee8e3652005-09-14 09:47:29 -05003346 write_register(dev, IPW_REG_INTA, IPW2100_INTA_FW_INIT_DONE);
James Ketrenos2c86c272005-03-23 17:32:29 -06003347 }
3348
3349 if (inta & IPW2100_INTA_STATUS_CHANGE) {
3350 IPW_DEBUG_ISR("Status change interrupt\n");
3351 priv->inta_other++;
James Ketrenosee8e3652005-09-14 09:47:29 -05003352 write_register(dev, IPW_REG_INTA, IPW2100_INTA_STATUS_CHANGE);
James Ketrenos2c86c272005-03-23 17:32:29 -06003353 }
3354
3355 if (inta & IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE) {
3356 IPW_DEBUG_ISR("slave host mode interrupt\n");
3357 priv->inta_other++;
James Ketrenosee8e3652005-09-14 09:47:29 -05003358 write_register(dev, IPW_REG_INTA,
3359 IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE);
James Ketrenos2c86c272005-03-23 17:32:29 -06003360 }
3361
3362 priv->in_isr--;
3363 ipw2100_enable_interrupts(priv);
3364
3365 spin_unlock_irqrestore(&priv->low_lock, flags);
3366
3367 IPW_DEBUG_ISR("exit\n");
3368}
3369
David Howells7d12e782006-10-05 14:55:46 +01003370static irqreturn_t ipw2100_interrupt(int irq, void *data)
James Ketrenos2c86c272005-03-23 17:32:29 -06003371{
3372 struct ipw2100_priv *priv = data;
3373 u32 inta, inta_mask;
3374
3375 if (!data)
3376 return IRQ_NONE;
3377
James Ketrenosee8e3652005-09-14 09:47:29 -05003378 spin_lock(&priv->low_lock);
James Ketrenos2c86c272005-03-23 17:32:29 -06003379
3380 /* We check to see if we should be ignoring interrupts before
3381 * we touch the hardware. During ucode load if we try and handle
3382 * an interrupt we can cause keyboard problems as well as cause
3383 * the ucode to fail to initialize */
3384 if (!(priv->status & STATUS_INT_ENABLED)) {
3385 /* Shared IRQ */
3386 goto none;
3387 }
3388
3389 read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
3390 read_register(priv->net_dev, IPW_REG_INTA, &inta);
3391
3392 if (inta == 0xFFFFFFFF) {
3393 /* Hardware disappeared */
Jiri Benc797b4f72005-08-25 20:03:27 -04003394 printk(KERN_WARNING DRV_NAME ": IRQ INTA == 0xFFFFFFFF\n");
James Ketrenos2c86c272005-03-23 17:32:29 -06003395 goto none;
3396 }
3397
3398 inta &= IPW_INTERRUPT_MASK;
3399
3400 if (!(inta & inta_mask)) {
3401 /* Shared interrupt */
3402 goto none;
3403 }
3404
3405 /* We disable the hardware interrupt here just to prevent unneeded
3406 * calls to be made. We disable this again within the actual
3407 * work tasklet, so if another part of the code re-enables the
3408 * interrupt, that is fine */
3409 ipw2100_disable_interrupts(priv);
3410
3411 tasklet_schedule(&priv->irq_tasklet);
James Ketrenosee8e3652005-09-14 09:47:29 -05003412 spin_unlock(&priv->low_lock);
James Ketrenos2c86c272005-03-23 17:32:29 -06003413
3414 return IRQ_HANDLED;
James Ketrenosee8e3652005-09-14 09:47:29 -05003415 none:
James Ketrenos2c86c272005-03-23 17:32:29 -06003416 spin_unlock(&priv->low_lock);
3417 return IRQ_NONE;
3418}
3419
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +00003420static netdev_tx_t ipw2100_tx(struct libipw_txb *txb,
3421 struct net_device *dev, int pri)
James Ketrenos2c86c272005-03-23 17:32:29 -06003422{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003423 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06003424 struct list_head *element;
3425 struct ipw2100_tx_packet *packet;
3426 unsigned long flags;
3427
3428 spin_lock_irqsave(&priv->low_lock, flags);
3429
3430 if (!(priv->status & STATUS_ASSOCIATED)) {
3431 IPW_DEBUG_INFO("Can not transmit when not connected.\n");
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00003432 priv->net_dev->stats.tx_carrier_errors++;
James Ketrenos2c86c272005-03-23 17:32:29 -06003433 netif_stop_queue(dev);
3434 goto fail_unlock;
3435 }
3436
3437 if (list_empty(&priv->tx_free_list))
3438 goto fail_unlock;
3439
3440 element = priv->tx_free_list.next;
3441 packet = list_entry(element, struct ipw2100_tx_packet, list);
3442
3443 packet->info.d_struct.txb = txb;
3444
James Ketrenosee8e3652005-09-14 09:47:29 -05003445 IPW_DEBUG_TX("Sending fragment (%d bytes):\n", txb->fragments[0]->len);
3446 printk_buf(IPW_DL_TX, txb->fragments[0]->data, txb->fragments[0]->len);
James Ketrenos2c86c272005-03-23 17:32:29 -06003447
3448 packet->jiffy_start = jiffies;
3449
3450 list_del(element);
3451 DEC_STAT(&priv->tx_free_stat);
3452
3453 list_add_tail(element, &priv->tx_pend_list);
3454 INC_STAT(&priv->tx_pend_stat);
3455
Jiri Benc19f7f742005-08-25 20:02:10 -04003456 ipw2100_tx_send_data(priv);
James Ketrenos2c86c272005-03-23 17:32:29 -06003457
3458 spin_unlock_irqrestore(&priv->low_lock, flags);
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +00003459 return NETDEV_TX_OK;
James Ketrenos2c86c272005-03-23 17:32:29 -06003460
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +00003461fail_unlock:
James Ketrenos2c86c272005-03-23 17:32:29 -06003462 netif_stop_queue(dev);
3463 spin_unlock_irqrestore(&priv->low_lock, flags);
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +00003464 return NETDEV_TX_BUSY;
James Ketrenos2c86c272005-03-23 17:32:29 -06003465}
3466
James Ketrenos2c86c272005-03-23 17:32:29 -06003467static int ipw2100_msg_allocate(struct ipw2100_priv *priv)
3468{
3469 int i, j, err = -EINVAL;
3470 void *v;
3471 dma_addr_t p;
3472
James Ketrenosee8e3652005-09-14 09:47:29 -05003473 priv->msg_buffers =
Joe Perchesefe4c452010-05-31 20:23:15 -07003474 kmalloc(IPW_COMMAND_POOL_SIZE * sizeof(struct ipw2100_tx_packet),
3475 GFP_KERNEL);
James Ketrenos2c86c272005-03-23 17:32:29 -06003476 if (!priv->msg_buffers) {
Jiri Benc797b4f72005-08-25 20:03:27 -04003477 printk(KERN_ERR DRV_NAME ": %s: PCI alloc failed for msg "
James Ketrenos2c86c272005-03-23 17:32:29 -06003478 "buffers.\n", priv->net_dev->name);
3479 return -ENOMEM;
3480 }
3481
3482 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
James Ketrenosee8e3652005-09-14 09:47:29 -05003483 v = pci_alloc_consistent(priv->pci_dev,
3484 sizeof(struct ipw2100_cmd_header), &p);
James Ketrenos2c86c272005-03-23 17:32:29 -06003485 if (!v) {
Jiri Benc797b4f72005-08-25 20:03:27 -04003486 printk(KERN_ERR DRV_NAME ": "
James Ketrenos2c86c272005-03-23 17:32:29 -06003487 "%s: PCI alloc failed for msg "
James Ketrenosee8e3652005-09-14 09:47:29 -05003488 "buffers.\n", priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06003489 err = -ENOMEM;
3490 break;
3491 }
3492
3493 memset(v, 0, sizeof(struct ipw2100_cmd_header));
3494
3495 priv->msg_buffers[i].type = COMMAND;
3496 priv->msg_buffers[i].info.c_struct.cmd =
James Ketrenosee8e3652005-09-14 09:47:29 -05003497 (struct ipw2100_cmd_header *)v;
James Ketrenos2c86c272005-03-23 17:32:29 -06003498 priv->msg_buffers[i].info.c_struct.cmd_phys = p;
3499 }
3500
3501 if (i == IPW_COMMAND_POOL_SIZE)
3502 return 0;
3503
3504 for (j = 0; j < i; j++) {
James Ketrenosee8e3652005-09-14 09:47:29 -05003505 pci_free_consistent(priv->pci_dev,
3506 sizeof(struct ipw2100_cmd_header),
3507 priv->msg_buffers[j].info.c_struct.cmd,
3508 priv->msg_buffers[j].info.c_struct.
3509 cmd_phys);
James Ketrenos2c86c272005-03-23 17:32:29 -06003510 }
3511
3512 kfree(priv->msg_buffers);
3513 priv->msg_buffers = NULL;
3514
3515 return err;
3516}
3517
3518static int ipw2100_msg_initialize(struct ipw2100_priv *priv)
3519{
3520 int i;
3521
3522 INIT_LIST_HEAD(&priv->msg_free_list);
3523 INIT_LIST_HEAD(&priv->msg_pend_list);
3524
3525 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++)
3526 list_add_tail(&priv->msg_buffers[i].list, &priv->msg_free_list);
3527 SET_STAT(&priv->msg_free_stat, i);
3528
3529 return 0;
3530}
3531
3532static void ipw2100_msg_free(struct ipw2100_priv *priv)
3533{
3534 int i;
3535
3536 if (!priv->msg_buffers)
3537 return;
3538
3539 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
3540 pci_free_consistent(priv->pci_dev,
3541 sizeof(struct ipw2100_cmd_header),
3542 priv->msg_buffers[i].info.c_struct.cmd,
James Ketrenosee8e3652005-09-14 09:47:29 -05003543 priv->msg_buffers[i].info.c_struct.
3544 cmd_phys);
James Ketrenos2c86c272005-03-23 17:32:29 -06003545 }
3546
3547 kfree(priv->msg_buffers);
3548 priv->msg_buffers = NULL;
3549}
3550
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003551static ssize_t show_pci(struct device *d, struct device_attribute *attr,
3552 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003553{
3554 struct pci_dev *pci_dev = container_of(d, struct pci_dev, dev);
3555 char *out = buf;
3556 int i, j;
3557 u32 val;
3558
3559 for (i = 0; i < 16; i++) {
3560 out += sprintf(out, "[%08X] ", i * 16);
3561 for (j = 0; j < 16; j += 4) {
3562 pci_read_config_dword(pci_dev, i * 16 + j, &val);
3563 out += sprintf(out, "%08X ", val);
3564 }
3565 out += sprintf(out, "\n");
3566 }
3567
3568 return out - buf;
3569}
James Ketrenosee8e3652005-09-14 09:47:29 -05003570
James Ketrenos2c86c272005-03-23 17:32:29 -06003571static DEVICE_ATTR(pci, S_IRUGO, show_pci, NULL);
3572
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003573static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
3574 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003575{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003576 struct ipw2100_priv *p = dev_get_drvdata(d);
James Ketrenos2c86c272005-03-23 17:32:29 -06003577 return sprintf(buf, "0x%08x\n", (int)p->config);
3578}
James Ketrenosee8e3652005-09-14 09:47:29 -05003579
James Ketrenos2c86c272005-03-23 17:32:29 -06003580static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
3581
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003582static ssize_t show_status(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05003583 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003584{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003585 struct ipw2100_priv *p = dev_get_drvdata(d);
James Ketrenos2c86c272005-03-23 17:32:29 -06003586 return sprintf(buf, "0x%08x\n", (int)p->status);
3587}
James Ketrenosee8e3652005-09-14 09:47:29 -05003588
James Ketrenos2c86c272005-03-23 17:32:29 -06003589static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
3590
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003591static ssize_t show_capability(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05003592 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003593{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003594 struct ipw2100_priv *p = dev_get_drvdata(d);
James Ketrenos2c86c272005-03-23 17:32:29 -06003595 return sprintf(buf, "0x%08x\n", (int)p->capability);
3596}
James Ketrenos2c86c272005-03-23 17:32:29 -06003597
James Ketrenosee8e3652005-09-14 09:47:29 -05003598static DEVICE_ATTR(capability, S_IRUGO, show_capability, NULL);
James Ketrenos2c86c272005-03-23 17:32:29 -06003599
3600#define IPW2100_REG(x) { IPW_ ##x, #x }
Jiri Bencc4aee8c2005-08-25 20:04:43 -04003601static const struct {
James Ketrenos2c86c272005-03-23 17:32:29 -06003602 u32 addr;
3603 const char *name;
3604} hw_data[] = {
James Ketrenosee8e3652005-09-14 09:47:29 -05003605IPW2100_REG(REG_GP_CNTRL),
3606 IPW2100_REG(REG_GPIO),
3607 IPW2100_REG(REG_INTA),
3608 IPW2100_REG(REG_INTA_MASK), IPW2100_REG(REG_RESET_REG),};
James Ketrenos2c86c272005-03-23 17:32:29 -06003609#define IPW2100_NIC(x, s) { x, #x, s }
Jiri Bencc4aee8c2005-08-25 20:04:43 -04003610static const struct {
James Ketrenos2c86c272005-03-23 17:32:29 -06003611 u32 addr;
3612 const char *name;
3613 size_t size;
3614} nic_data[] = {
James Ketrenosee8e3652005-09-14 09:47:29 -05003615IPW2100_NIC(IPW2100_CONTROL_REG, 2),
3616 IPW2100_NIC(0x210014, 1), IPW2100_NIC(0x210000, 1),};
James Ketrenos2c86c272005-03-23 17:32:29 -06003617#define IPW2100_ORD(x, d) { IPW_ORD_ ##x, #x, d }
Jiri Bencc4aee8c2005-08-25 20:04:43 -04003618static const struct {
James Ketrenos2c86c272005-03-23 17:32:29 -06003619 u8 index;
3620 const char *name;
3621 const char *desc;
3622} ord_data[] = {
James Ketrenosee8e3652005-09-14 09:47:29 -05003623IPW2100_ORD(STAT_TX_HOST_REQUESTS, "requested Host Tx's (MSDU)"),
3624 IPW2100_ORD(STAT_TX_HOST_COMPLETE,
3625 "successful Host Tx's (MSDU)"),
3626 IPW2100_ORD(STAT_TX_DIR_DATA,
3627 "successful Directed Tx's (MSDU)"),
3628 IPW2100_ORD(STAT_TX_DIR_DATA1,
3629 "successful Directed Tx's (MSDU) @ 1MB"),
3630 IPW2100_ORD(STAT_TX_DIR_DATA2,
3631 "successful Directed Tx's (MSDU) @ 2MB"),
3632 IPW2100_ORD(STAT_TX_DIR_DATA5_5,
3633 "successful Directed Tx's (MSDU) @ 5_5MB"),
3634 IPW2100_ORD(STAT_TX_DIR_DATA11,
3635 "successful Directed Tx's (MSDU) @ 11MB"),
3636 IPW2100_ORD(STAT_TX_NODIR_DATA1,
3637 "successful Non_Directed Tx's (MSDU) @ 1MB"),
3638 IPW2100_ORD(STAT_TX_NODIR_DATA2,
3639 "successful Non_Directed Tx's (MSDU) @ 2MB"),
3640 IPW2100_ORD(STAT_TX_NODIR_DATA5_5,
3641 "successful Non_Directed Tx's (MSDU) @ 5.5MB"),
3642 IPW2100_ORD(STAT_TX_NODIR_DATA11,
3643 "successful Non_Directed Tx's (MSDU) @ 11MB"),
3644 IPW2100_ORD(STAT_NULL_DATA, "successful NULL data Tx's"),
3645 IPW2100_ORD(STAT_TX_RTS, "successful Tx RTS"),
3646 IPW2100_ORD(STAT_TX_CTS, "successful Tx CTS"),
3647 IPW2100_ORD(STAT_TX_ACK, "successful Tx ACK"),
3648 IPW2100_ORD(STAT_TX_ASSN, "successful Association Tx's"),
3649 IPW2100_ORD(STAT_TX_ASSN_RESP,
3650 "successful Association response Tx's"),
3651 IPW2100_ORD(STAT_TX_REASSN,
3652 "successful Reassociation Tx's"),
3653 IPW2100_ORD(STAT_TX_REASSN_RESP,
3654 "successful Reassociation response Tx's"),
3655 IPW2100_ORD(STAT_TX_PROBE,
3656 "probes successfully transmitted"),
3657 IPW2100_ORD(STAT_TX_PROBE_RESP,
3658 "probe responses successfully transmitted"),
3659 IPW2100_ORD(STAT_TX_BEACON, "tx beacon"),
3660 IPW2100_ORD(STAT_TX_ATIM, "Tx ATIM"),
3661 IPW2100_ORD(STAT_TX_DISASSN,
3662 "successful Disassociation TX"),
3663 IPW2100_ORD(STAT_TX_AUTH, "successful Authentication Tx"),
3664 IPW2100_ORD(STAT_TX_DEAUTH,
3665 "successful Deauthentication TX"),
3666 IPW2100_ORD(STAT_TX_TOTAL_BYTES,
3667 "Total successful Tx data bytes"),
3668 IPW2100_ORD(STAT_TX_RETRIES, "Tx retries"),
3669 IPW2100_ORD(STAT_TX_RETRY1, "Tx retries at 1MBPS"),
3670 IPW2100_ORD(STAT_TX_RETRY2, "Tx retries at 2MBPS"),
3671 IPW2100_ORD(STAT_TX_RETRY5_5, "Tx retries at 5.5MBPS"),
3672 IPW2100_ORD(STAT_TX_RETRY11, "Tx retries at 11MBPS"),
3673 IPW2100_ORD(STAT_TX_FAILURES, "Tx Failures"),
3674 IPW2100_ORD(STAT_TX_MAX_TRIES_IN_HOP,
3675 "times max tries in a hop failed"),
3676 IPW2100_ORD(STAT_TX_DISASSN_FAIL,
3677 "times disassociation failed"),
3678 IPW2100_ORD(STAT_TX_ERR_CTS, "missed/bad CTS frames"),
3679 IPW2100_ORD(STAT_TX_ERR_ACK, "tx err due to acks"),
3680 IPW2100_ORD(STAT_RX_HOST, "packets passed to host"),
3681 IPW2100_ORD(STAT_RX_DIR_DATA, "directed packets"),
3682 IPW2100_ORD(STAT_RX_DIR_DATA1, "directed packets at 1MB"),
3683 IPW2100_ORD(STAT_RX_DIR_DATA2, "directed packets at 2MB"),
3684 IPW2100_ORD(STAT_RX_DIR_DATA5_5,
3685 "directed packets at 5.5MB"),
3686 IPW2100_ORD(STAT_RX_DIR_DATA11, "directed packets at 11MB"),
3687 IPW2100_ORD(STAT_RX_NODIR_DATA, "nondirected packets"),
3688 IPW2100_ORD(STAT_RX_NODIR_DATA1,
3689 "nondirected packets at 1MB"),
3690 IPW2100_ORD(STAT_RX_NODIR_DATA2,
3691 "nondirected packets at 2MB"),
3692 IPW2100_ORD(STAT_RX_NODIR_DATA5_5,
3693 "nondirected packets at 5.5MB"),
3694 IPW2100_ORD(STAT_RX_NODIR_DATA11,
3695 "nondirected packets at 11MB"),
3696 IPW2100_ORD(STAT_RX_NULL_DATA, "null data rx's"),
3697 IPW2100_ORD(STAT_RX_RTS, "Rx RTS"), IPW2100_ORD(STAT_RX_CTS,
3698 "Rx CTS"),
3699 IPW2100_ORD(STAT_RX_ACK, "Rx ACK"),
3700 IPW2100_ORD(STAT_RX_CFEND, "Rx CF End"),
3701 IPW2100_ORD(STAT_RX_CFEND_ACK, "Rx CF End + CF Ack"),
3702 IPW2100_ORD(STAT_RX_ASSN, "Association Rx's"),
3703 IPW2100_ORD(STAT_RX_ASSN_RESP, "Association response Rx's"),
3704 IPW2100_ORD(STAT_RX_REASSN, "Reassociation Rx's"),
3705 IPW2100_ORD(STAT_RX_REASSN_RESP,
3706 "Reassociation response Rx's"),
3707 IPW2100_ORD(STAT_RX_PROBE, "probe Rx's"),
3708 IPW2100_ORD(STAT_RX_PROBE_RESP, "probe response Rx's"),
3709 IPW2100_ORD(STAT_RX_BEACON, "Rx beacon"),
3710 IPW2100_ORD(STAT_RX_ATIM, "Rx ATIM"),
3711 IPW2100_ORD(STAT_RX_DISASSN, "disassociation Rx"),
3712 IPW2100_ORD(STAT_RX_AUTH, "authentication Rx"),
3713 IPW2100_ORD(STAT_RX_DEAUTH, "deauthentication Rx"),
3714 IPW2100_ORD(STAT_RX_TOTAL_BYTES,
3715 "Total rx data bytes received"),
3716 IPW2100_ORD(STAT_RX_ERR_CRC, "packets with Rx CRC error"),
3717 IPW2100_ORD(STAT_RX_ERR_CRC1, "Rx CRC errors at 1MB"),
3718 IPW2100_ORD(STAT_RX_ERR_CRC2, "Rx CRC errors at 2MB"),
3719 IPW2100_ORD(STAT_RX_ERR_CRC5_5, "Rx CRC errors at 5.5MB"),
3720 IPW2100_ORD(STAT_RX_ERR_CRC11, "Rx CRC errors at 11MB"),
3721 IPW2100_ORD(STAT_RX_DUPLICATE1,
3722 "duplicate rx packets at 1MB"),
3723 IPW2100_ORD(STAT_RX_DUPLICATE2,
3724 "duplicate rx packets at 2MB"),
3725 IPW2100_ORD(STAT_RX_DUPLICATE5_5,
3726 "duplicate rx packets at 5.5MB"),
3727 IPW2100_ORD(STAT_RX_DUPLICATE11,
3728 "duplicate rx packets at 11MB"),
3729 IPW2100_ORD(STAT_RX_DUPLICATE, "duplicate rx packets"),
3730 IPW2100_ORD(PERS_DB_LOCK, "locking fw permanent db"),
3731 IPW2100_ORD(PERS_DB_SIZE, "size of fw permanent db"),
3732 IPW2100_ORD(PERS_DB_ADDR, "address of fw permanent db"),
3733 IPW2100_ORD(STAT_RX_INVALID_PROTOCOL,
3734 "rx frames with invalid protocol"),
3735 IPW2100_ORD(SYS_BOOT_TIME, "Boot time"),
3736 IPW2100_ORD(STAT_RX_NO_BUFFER,
3737 "rx frames rejected due to no buffer"),
3738 IPW2100_ORD(STAT_RX_MISSING_FRAG,
3739 "rx frames dropped due to missing fragment"),
3740 IPW2100_ORD(STAT_RX_ORPHAN_FRAG,
3741 "rx frames dropped due to non-sequential fragment"),
3742 IPW2100_ORD(STAT_RX_ORPHAN_FRAME,
3743 "rx frames dropped due to unmatched 1st frame"),
3744 IPW2100_ORD(STAT_RX_FRAG_AGEOUT,
3745 "rx frames dropped due to uncompleted frame"),
3746 IPW2100_ORD(STAT_RX_ICV_ERRORS,
3747 "ICV errors during decryption"),
3748 IPW2100_ORD(STAT_PSP_SUSPENSION, "times adapter suspended"),
3749 IPW2100_ORD(STAT_PSP_BCN_TIMEOUT, "beacon timeout"),
3750 IPW2100_ORD(STAT_PSP_POLL_TIMEOUT,
3751 "poll response timeouts"),
3752 IPW2100_ORD(STAT_PSP_NONDIR_TIMEOUT,
3753 "timeouts waiting for last {broad,multi}cast pkt"),
3754 IPW2100_ORD(STAT_PSP_RX_DTIMS, "PSP DTIMs received"),
3755 IPW2100_ORD(STAT_PSP_RX_TIMS, "PSP TIMs received"),
3756 IPW2100_ORD(STAT_PSP_STATION_ID, "PSP Station ID"),
3757 IPW2100_ORD(LAST_ASSN_TIME, "RTC time of last association"),
3758 IPW2100_ORD(STAT_PERCENT_MISSED_BCNS,
3759 "current calculation of % missed beacons"),
3760 IPW2100_ORD(STAT_PERCENT_RETRIES,
3761 "current calculation of % missed tx retries"),
3762 IPW2100_ORD(ASSOCIATED_AP_PTR,
3763 "0 if not associated, else pointer to AP table entry"),
3764 IPW2100_ORD(AVAILABLE_AP_CNT,
3765 "AP's decsribed in the AP table"),
3766 IPW2100_ORD(AP_LIST_PTR, "Ptr to list of available APs"),
3767 IPW2100_ORD(STAT_AP_ASSNS, "associations"),
3768 IPW2100_ORD(STAT_ASSN_FAIL, "association failures"),
3769 IPW2100_ORD(STAT_ASSN_RESP_FAIL,
3770 "failures due to response fail"),
3771 IPW2100_ORD(STAT_FULL_SCANS, "full scans"),
3772 IPW2100_ORD(CARD_DISABLED, "Card Disabled"),
3773 IPW2100_ORD(STAT_ROAM_INHIBIT,
3774 "times roaming was inhibited due to activity"),
3775 IPW2100_ORD(RSSI_AT_ASSN,
3776 "RSSI of associated AP at time of association"),
3777 IPW2100_ORD(STAT_ASSN_CAUSE1,
3778 "reassociation: no probe response or TX on hop"),
3779 IPW2100_ORD(STAT_ASSN_CAUSE2,
3780 "reassociation: poor tx/rx quality"),
3781 IPW2100_ORD(STAT_ASSN_CAUSE3,
3782 "reassociation: tx/rx quality (excessive AP load"),
3783 IPW2100_ORD(STAT_ASSN_CAUSE4,
3784 "reassociation: AP RSSI level"),
3785 IPW2100_ORD(STAT_ASSN_CAUSE5,
3786 "reassociations due to load leveling"),
3787 IPW2100_ORD(STAT_AUTH_FAIL, "times authentication failed"),
3788 IPW2100_ORD(STAT_AUTH_RESP_FAIL,
3789 "times authentication response failed"),
3790 IPW2100_ORD(STATION_TABLE_CNT,
3791 "entries in association table"),
3792 IPW2100_ORD(RSSI_AVG_CURR, "Current avg RSSI"),
3793 IPW2100_ORD(POWER_MGMT_MODE, "Power mode - 0=CAM, 1=PSP"),
3794 IPW2100_ORD(COUNTRY_CODE,
3795 "IEEE country code as recv'd from beacon"),
3796 IPW2100_ORD(COUNTRY_CHANNELS,
3797 "channels suported by country"),
3798 IPW2100_ORD(RESET_CNT, "adapter resets (warm)"),
3799 IPW2100_ORD(BEACON_INTERVAL, "Beacon interval"),
3800 IPW2100_ORD(ANTENNA_DIVERSITY,
3801 "TRUE if antenna diversity is disabled"),
3802 IPW2100_ORD(DTIM_PERIOD, "beacon intervals between DTIMs"),
3803 IPW2100_ORD(OUR_FREQ,
3804 "current radio freq lower digits - channel ID"),
3805 IPW2100_ORD(RTC_TIME, "current RTC time"),
3806 IPW2100_ORD(PORT_TYPE, "operating mode"),
3807 IPW2100_ORD(CURRENT_TX_RATE, "current tx rate"),
3808 IPW2100_ORD(SUPPORTED_RATES, "supported tx rates"),
3809 IPW2100_ORD(ATIM_WINDOW, "current ATIM Window"),
3810 IPW2100_ORD(BASIC_RATES, "basic tx rates"),
3811 IPW2100_ORD(NIC_HIGHEST_RATE, "NIC highest tx rate"),
3812 IPW2100_ORD(AP_HIGHEST_RATE, "AP highest tx rate"),
3813 IPW2100_ORD(CAPABILITIES,
3814 "Management frame capability field"),
3815 IPW2100_ORD(AUTH_TYPE, "Type of authentication"),
3816 IPW2100_ORD(RADIO_TYPE, "Adapter card platform type"),
3817 IPW2100_ORD(RTS_THRESHOLD,
3818 "Min packet length for RTS handshaking"),
3819 IPW2100_ORD(INT_MODE, "International mode"),
3820 IPW2100_ORD(FRAGMENTATION_THRESHOLD,
3821 "protocol frag threshold"),
3822 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_START_ADDRESS,
3823 "EEPROM offset in SRAM"),
3824 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_SIZE,
3825 "EEPROM size in SRAM"),
3826 IPW2100_ORD(EEPROM_SKU_CAPABILITY, "EEPROM SKU Capability"),
3827 IPW2100_ORD(EEPROM_IBSS_11B_CHANNELS,
3828 "EEPROM IBSS 11b channel set"),
3829 IPW2100_ORD(MAC_VERSION, "MAC Version"),
3830 IPW2100_ORD(MAC_REVISION, "MAC Revision"),
3831 IPW2100_ORD(RADIO_VERSION, "Radio Version"),
3832 IPW2100_ORD(NIC_MANF_DATE_TIME, "MANF Date/Time STAMP"),
3833 IPW2100_ORD(UCODE_VERSION, "Ucode Version"),};
James Ketrenos2c86c272005-03-23 17:32:29 -06003834
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003835static ssize_t show_registers(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05003836 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003837{
3838 int i;
3839 struct ipw2100_priv *priv = dev_get_drvdata(d);
3840 struct net_device *dev = priv->net_dev;
James Ketrenosee8e3652005-09-14 09:47:29 -05003841 char *out = buf;
James Ketrenos2c86c272005-03-23 17:32:29 -06003842 u32 val = 0;
3843
3844 out += sprintf(out, "%30s [Address ] : Hex\n", "Register");
3845
Ahmed S. Darwish22d57432007-02-05 18:56:22 +02003846 for (i = 0; i < ARRAY_SIZE(hw_data); i++) {
James Ketrenos2c86c272005-03-23 17:32:29 -06003847 read_register(dev, hw_data[i].addr, &val);
3848 out += sprintf(out, "%30s [%08X] : %08X\n",
3849 hw_data[i].name, hw_data[i].addr, val);
3850 }
3851
3852 return out - buf;
3853}
James Ketrenosee8e3652005-09-14 09:47:29 -05003854
James Ketrenos2c86c272005-03-23 17:32:29 -06003855static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL);
3856
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003857static ssize_t show_hardware(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05003858 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003859{
3860 struct ipw2100_priv *priv = dev_get_drvdata(d);
3861 struct net_device *dev = priv->net_dev;
James Ketrenosee8e3652005-09-14 09:47:29 -05003862 char *out = buf;
James Ketrenos2c86c272005-03-23 17:32:29 -06003863 int i;
3864
3865 out += sprintf(out, "%30s [Address ] : Hex\n", "NIC entry");
3866
Ahmed S. Darwish22d57432007-02-05 18:56:22 +02003867 for (i = 0; i < ARRAY_SIZE(nic_data); i++) {
James Ketrenos2c86c272005-03-23 17:32:29 -06003868 u8 tmp8;
3869 u16 tmp16;
3870 u32 tmp32;
3871
3872 switch (nic_data[i].size) {
3873 case 1:
3874 read_nic_byte(dev, nic_data[i].addr, &tmp8);
3875 out += sprintf(out, "%30s [%08X] : %02X\n",
3876 nic_data[i].name, nic_data[i].addr,
3877 tmp8);
3878 break;
3879 case 2:
3880 read_nic_word(dev, nic_data[i].addr, &tmp16);
3881 out += sprintf(out, "%30s [%08X] : %04X\n",
3882 nic_data[i].name, nic_data[i].addr,
3883 tmp16);
3884 break;
3885 case 4:
3886 read_nic_dword(dev, nic_data[i].addr, &tmp32);
3887 out += sprintf(out, "%30s [%08X] : %08X\n",
3888 nic_data[i].name, nic_data[i].addr,
3889 tmp32);
3890 break;
3891 }
3892 }
3893 return out - buf;
3894}
James Ketrenosee8e3652005-09-14 09:47:29 -05003895
James Ketrenos2c86c272005-03-23 17:32:29 -06003896static DEVICE_ATTR(hardware, S_IRUGO, show_hardware, NULL);
3897
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003898static ssize_t show_memory(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05003899 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003900{
3901 struct ipw2100_priv *priv = dev_get_drvdata(d);
3902 struct net_device *dev = priv->net_dev;
3903 static unsigned long loop = 0;
3904 int len = 0;
3905 u32 buffer[4];
3906 int i;
3907 char line[81];
3908
3909 if (loop >= 0x30000)
3910 loop = 0;
3911
3912 /* sysfs provides us PAGE_SIZE buffer */
3913 while (len < PAGE_SIZE - 128 && loop < 0x30000) {
3914
James Ketrenosee8e3652005-09-14 09:47:29 -05003915 if (priv->snapshot[0])
3916 for (i = 0; i < 4; i++)
3917 buffer[i] =
3918 *(u32 *) SNAPSHOT_ADDR(loop + i * 4);
3919 else
3920 for (i = 0; i < 4; i++)
3921 read_nic_dword(dev, loop + i * 4, &buffer[i]);
James Ketrenos2c86c272005-03-23 17:32:29 -06003922
3923 if (priv->dump_raw)
3924 len += sprintf(buf + len,
3925 "%c%c%c%c"
3926 "%c%c%c%c"
3927 "%c%c%c%c"
3928 "%c%c%c%c",
James Ketrenosee8e3652005-09-14 09:47:29 -05003929 ((u8 *) buffer)[0x0],
3930 ((u8 *) buffer)[0x1],
3931 ((u8 *) buffer)[0x2],
3932 ((u8 *) buffer)[0x3],
3933 ((u8 *) buffer)[0x4],
3934 ((u8 *) buffer)[0x5],
3935 ((u8 *) buffer)[0x6],
3936 ((u8 *) buffer)[0x7],
3937 ((u8 *) buffer)[0x8],
3938 ((u8 *) buffer)[0x9],
3939 ((u8 *) buffer)[0xa],
3940 ((u8 *) buffer)[0xb],
3941 ((u8 *) buffer)[0xc],
3942 ((u8 *) buffer)[0xd],
3943 ((u8 *) buffer)[0xe],
3944 ((u8 *) buffer)[0xf]);
James Ketrenos2c86c272005-03-23 17:32:29 -06003945 else
3946 len += sprintf(buf + len, "%s\n",
3947 snprint_line(line, sizeof(line),
James Ketrenosee8e3652005-09-14 09:47:29 -05003948 (u8 *) buffer, 16, loop));
James Ketrenos2c86c272005-03-23 17:32:29 -06003949 loop += 16;
3950 }
3951
3952 return len;
3953}
3954
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003955static ssize_t store_memory(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05003956 const char *buf, size_t count)
James Ketrenos2c86c272005-03-23 17:32:29 -06003957{
3958 struct ipw2100_priv *priv = dev_get_drvdata(d);
3959 struct net_device *dev = priv->net_dev;
3960 const char *p = buf;
3961
Zhu Yi8ed55a42006-01-24 13:49:20 +08003962 (void)dev; /* kill unused-var warning for debug-only code */
Jeff Garzikc2a8fad2005-11-09 00:49:38 -05003963
James Ketrenos2c86c272005-03-23 17:32:29 -06003964 if (count < 1)
3965 return count;
3966
3967 if (p[0] == '1' ||
3968 (count >= 2 && tolower(p[0]) == 'o' && tolower(p[1]) == 'n')) {
3969 IPW_DEBUG_INFO("%s: Setting memory dump to RAW mode.\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05003970 dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06003971 priv->dump_raw = 1;
3972
3973 } else if (p[0] == '0' || (count >= 2 && tolower(p[0]) == 'o' &&
James Ketrenosee8e3652005-09-14 09:47:29 -05003974 tolower(p[1]) == 'f')) {
James Ketrenos2c86c272005-03-23 17:32:29 -06003975 IPW_DEBUG_INFO("%s: Setting memory dump to HEX mode.\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05003976 dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06003977 priv->dump_raw = 0;
3978
3979 } else if (tolower(p[0]) == 'r') {
James Ketrenosee8e3652005-09-14 09:47:29 -05003980 IPW_DEBUG_INFO("%s: Resetting firmware snapshot.\n", dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06003981 ipw2100_snapshot_free(priv);
3982
3983 } else
3984 IPW_DEBUG_INFO("%s: Usage: 0|on = HEX, 1|off = RAW, "
James Ketrenosee8e3652005-09-14 09:47:29 -05003985 "reset = clear memory snapshot\n", dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06003986
3987 return count;
3988}
James Ketrenos2c86c272005-03-23 17:32:29 -06003989
James Ketrenosee8e3652005-09-14 09:47:29 -05003990static DEVICE_ATTR(memory, S_IWUSR | S_IRUGO, show_memory, store_memory);
James Ketrenos2c86c272005-03-23 17:32:29 -06003991
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003992static ssize_t show_ordinals(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05003993 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003994{
3995 struct ipw2100_priv *priv = dev_get_drvdata(d);
3996 u32 val = 0;
3997 int len = 0;
3998 u32 val_len;
3999 static int loop = 0;
4000
James Ketrenos82328352005-08-24 22:33:31 -05004001 if (priv->status & STATUS_RF_KILL_MASK)
4002 return 0;
4003
Ahmed S. Darwish22d57432007-02-05 18:56:22 +02004004 if (loop >= ARRAY_SIZE(ord_data))
James Ketrenos2c86c272005-03-23 17:32:29 -06004005 loop = 0;
4006
4007 /* sysfs provides us PAGE_SIZE buffer */
Ahmed S. Darwish22d57432007-02-05 18:56:22 +02004008 while (len < PAGE_SIZE - 128 && loop < ARRAY_SIZE(ord_data)) {
James Ketrenos2c86c272005-03-23 17:32:29 -06004009 val_len = sizeof(u32);
4010
4011 if (ipw2100_get_ordinal(priv, ord_data[loop].index, &val,
4012 &val_len))
4013 len += sprintf(buf + len, "[0x%02X] = ERROR %s\n",
4014 ord_data[loop].index,
4015 ord_data[loop].desc);
4016 else
4017 len += sprintf(buf + len, "[0x%02X] = 0x%08X %s\n",
4018 ord_data[loop].index, val,
4019 ord_data[loop].desc);
4020 loop++;
4021 }
4022
4023 return len;
4024}
James Ketrenosee8e3652005-09-14 09:47:29 -05004025
James Ketrenos2c86c272005-03-23 17:32:29 -06004026static DEVICE_ATTR(ordinals, S_IRUGO, show_ordinals, NULL);
4027
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004028static ssize_t show_stats(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05004029 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06004030{
4031 struct ipw2100_priv *priv = dev_get_drvdata(d);
James Ketrenosee8e3652005-09-14 09:47:29 -05004032 char *out = buf;
James Ketrenos2c86c272005-03-23 17:32:29 -06004033
4034 out += sprintf(out, "interrupts: %d {tx: %d, rx: %d, other: %d}\n",
4035 priv->interrupts, priv->tx_interrupts,
4036 priv->rx_interrupts, priv->inta_other);
4037 out += sprintf(out, "firmware resets: %d\n", priv->resets);
4038 out += sprintf(out, "firmware hangs: %d\n", priv->hangs);
Brice Goglin0f52bf92005-12-01 01:41:46 -08004039#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06004040 out += sprintf(out, "packet mismatch image: %s\n",
4041 priv->snapshot[0] ? "YES" : "NO");
4042#endif
4043
4044 return out - buf;
4045}
James Ketrenos2c86c272005-03-23 17:32:29 -06004046
James Ketrenosee8e3652005-09-14 09:47:29 -05004047static DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
James Ketrenos2c86c272005-03-23 17:32:29 -06004048
Jiri Bencc4aee8c2005-08-25 20:04:43 -04004049static int ipw2100_switch_mode(struct ipw2100_priv *priv, u32 mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06004050{
4051 int err;
4052
4053 if (mode == priv->ieee->iw_mode)
4054 return 0;
4055
4056 err = ipw2100_disable_adapter(priv);
4057 if (err) {
Jiri Benc797b4f72005-08-25 20:03:27 -04004058 printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06004059 priv->net_dev->name, err);
4060 return err;
4061 }
4062
4063 switch (mode) {
4064 case IW_MODE_INFRA:
4065 priv->net_dev->type = ARPHRD_ETHER;
4066 break;
4067 case IW_MODE_ADHOC:
4068 priv->net_dev->type = ARPHRD_ETHER;
4069 break;
4070#ifdef CONFIG_IPW2100_MONITOR
4071 case IW_MODE_MONITOR:
4072 priv->last_mode = priv->ieee->iw_mode;
Stefan Rompf15745a72006-02-21 18:36:17 +08004073 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
James Ketrenos2c86c272005-03-23 17:32:29 -06004074 break;
James Ketrenosee8e3652005-09-14 09:47:29 -05004075#endif /* CONFIG_IPW2100_MONITOR */
James Ketrenos2c86c272005-03-23 17:32:29 -06004076 }
4077
4078 priv->ieee->iw_mode = mode;
4079
4080#ifdef CONFIG_PM
James Ketrenosee8e3652005-09-14 09:47:29 -05004081 /* Indicate ipw2100_download_firmware download firmware
James Ketrenos2c86c272005-03-23 17:32:29 -06004082 * from disk instead of memory. */
4083 ipw2100_firmware.version = 0;
4084#endif
4085
James Ketrenosee8e3652005-09-14 09:47:29 -05004086 printk(KERN_INFO "%s: Reseting on mode change.\n", priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06004087 priv->reset_backoff = 0;
4088 schedule_reset(priv);
4089
4090 return 0;
4091}
4092
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004093static ssize_t show_internals(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05004094 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06004095{
4096 struct ipw2100_priv *priv = dev_get_drvdata(d);
4097 int len = 0;
4098
James Ketrenosee8e3652005-09-14 09:47:29 -05004099#define DUMP_VAR(x,y) len += sprintf(buf + len, # x ": %" y "\n", priv-> x)
James Ketrenos2c86c272005-03-23 17:32:29 -06004100
4101 if (priv->status & STATUS_ASSOCIATED)
4102 len += sprintf(buf + len, "connected: %lu\n",
4103 get_seconds() - priv->connect_start);
4104 else
4105 len += sprintf(buf + len, "not connected\n");
4106
John W. Linville274bfb82008-10-29 11:35:05 -04004107 DUMP_VAR(ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx], "p");
James Ketrenosee8e3652005-09-14 09:47:29 -05004108 DUMP_VAR(status, "08lx");
4109 DUMP_VAR(config, "08lx");
4110 DUMP_VAR(capability, "08lx");
James Ketrenos2c86c272005-03-23 17:32:29 -06004111
James Ketrenosee8e3652005-09-14 09:47:29 -05004112 len +=
4113 sprintf(buf + len, "last_rtc: %lu\n",
4114 (unsigned long)priv->last_rtc);
James Ketrenos2c86c272005-03-23 17:32:29 -06004115
James Ketrenosee8e3652005-09-14 09:47:29 -05004116 DUMP_VAR(fatal_error, "d");
4117 DUMP_VAR(stop_hang_check, "d");
4118 DUMP_VAR(stop_rf_kill, "d");
4119 DUMP_VAR(messages_sent, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004120
James Ketrenosee8e3652005-09-14 09:47:29 -05004121 DUMP_VAR(tx_pend_stat.value, "d");
4122 DUMP_VAR(tx_pend_stat.hi, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004123
James Ketrenosee8e3652005-09-14 09:47:29 -05004124 DUMP_VAR(tx_free_stat.value, "d");
4125 DUMP_VAR(tx_free_stat.lo, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004126
James Ketrenosee8e3652005-09-14 09:47:29 -05004127 DUMP_VAR(msg_free_stat.value, "d");
4128 DUMP_VAR(msg_free_stat.lo, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004129
James Ketrenosee8e3652005-09-14 09:47:29 -05004130 DUMP_VAR(msg_pend_stat.value, "d");
4131 DUMP_VAR(msg_pend_stat.hi, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004132
James Ketrenosee8e3652005-09-14 09:47:29 -05004133 DUMP_VAR(fw_pend_stat.value, "d");
4134 DUMP_VAR(fw_pend_stat.hi, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004135
James Ketrenosee8e3652005-09-14 09:47:29 -05004136 DUMP_VAR(txq_stat.value, "d");
4137 DUMP_VAR(txq_stat.lo, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004138
James Ketrenosee8e3652005-09-14 09:47:29 -05004139 DUMP_VAR(ieee->scans, "d");
4140 DUMP_VAR(reset_backoff, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004141
4142 return len;
4143}
James Ketrenosee8e3652005-09-14 09:47:29 -05004144
James Ketrenos2c86c272005-03-23 17:32:29 -06004145static DEVICE_ATTR(internals, S_IRUGO, show_internals, NULL);
4146
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004147static ssize_t show_bssinfo(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05004148 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06004149{
4150 struct ipw2100_priv *priv = dev_get_drvdata(d);
4151 char essid[IW_ESSID_MAX_SIZE + 1];
4152 u8 bssid[ETH_ALEN];
4153 u32 chan = 0;
James Ketrenosee8e3652005-09-14 09:47:29 -05004154 char *out = buf;
Hannes Ederb9da9e92009-02-14 11:50:26 +00004155 unsigned int length;
James Ketrenos2c86c272005-03-23 17:32:29 -06004156 int ret;
4157
James Ketrenos82328352005-08-24 22:33:31 -05004158 if (priv->status & STATUS_RF_KILL_MASK)
4159 return 0;
4160
James Ketrenos2c86c272005-03-23 17:32:29 -06004161 memset(essid, 0, sizeof(essid));
4162 memset(bssid, 0, sizeof(bssid));
4163
4164 length = IW_ESSID_MAX_SIZE;
4165 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID, essid, &length);
4166 if (ret)
4167 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4168 __LINE__);
4169
4170 length = sizeof(bssid);
4171 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
4172 bssid, &length);
4173 if (ret)
4174 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4175 __LINE__);
4176
4177 length = sizeof(u32);
4178 ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &length);
4179 if (ret)
4180 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4181 __LINE__);
4182
4183 out += sprintf(out, "ESSID: %s\n", essid);
Johannes Berge1749612008-10-27 15:59:26 -07004184 out += sprintf(out, "BSSID: %pM\n", bssid);
James Ketrenos2c86c272005-03-23 17:32:29 -06004185 out += sprintf(out, "Channel: %d\n", chan);
4186
4187 return out - buf;
4188}
James Ketrenos2c86c272005-03-23 17:32:29 -06004189
James Ketrenosee8e3652005-09-14 09:47:29 -05004190static DEVICE_ATTR(bssinfo, S_IRUGO, show_bssinfo, NULL);
James Ketrenos2c86c272005-03-23 17:32:29 -06004191
Brice Goglin0f52bf92005-12-01 01:41:46 -08004192#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06004193static ssize_t show_debug_level(struct device_driver *d, char *buf)
4194{
4195 return sprintf(buf, "0x%08X\n", ipw2100_debug_level);
4196}
4197
James Ketrenos82328352005-08-24 22:33:31 -05004198static ssize_t store_debug_level(struct device_driver *d,
4199 const char *buf, size_t count)
James Ketrenos2c86c272005-03-23 17:32:29 -06004200{
4201 char *p = (char *)buf;
4202 u32 val;
4203
4204 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
4205 p++;
4206 if (p[0] == 'x' || p[0] == 'X')
4207 p++;
4208 val = simple_strtoul(p, &p, 16);
4209 } else
4210 val = simple_strtoul(p, &p, 10);
4211 if (p == buf)
Zhu Yia1e695a2005-07-04 14:06:00 +08004212 IPW_DEBUG_INFO(": %s is not in hex or decimal form.\n", buf);
James Ketrenos2c86c272005-03-23 17:32:29 -06004213 else
4214 ipw2100_debug_level = val;
4215
4216 return strnlen(buf, count);
4217}
James Ketrenosee8e3652005-09-14 09:47:29 -05004218
James Ketrenos2c86c272005-03-23 17:32:29 -06004219static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, show_debug_level,
4220 store_debug_level);
Brice Goglin0f52bf92005-12-01 01:41:46 -08004221#endif /* CONFIG_IPW2100_DEBUG */
James Ketrenos2c86c272005-03-23 17:32:29 -06004222
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004223static ssize_t show_fatal_error(struct device *d,
James Ketrenosee8e3652005-09-14 09:47:29 -05004224 struct device_attribute *attr, char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06004225{
4226 struct ipw2100_priv *priv = dev_get_drvdata(d);
4227 char *out = buf;
4228 int i;
4229
4230 if (priv->fatal_error)
James Ketrenosee8e3652005-09-14 09:47:29 -05004231 out += sprintf(out, "0x%08X\n", priv->fatal_error);
James Ketrenos2c86c272005-03-23 17:32:29 -06004232 else
4233 out += sprintf(out, "0\n");
4234
4235 for (i = 1; i <= IPW2100_ERROR_QUEUE; i++) {
4236 if (!priv->fatal_errors[(priv->fatal_index - i) %
4237 IPW2100_ERROR_QUEUE])
4238 continue;
4239
4240 out += sprintf(out, "%d. 0x%08X\n", i,
4241 priv->fatal_errors[(priv->fatal_index - i) %
4242 IPW2100_ERROR_QUEUE]);
4243 }
4244
4245 return out - buf;
4246}
4247
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004248static ssize_t store_fatal_error(struct device *d,
James Ketrenosee8e3652005-09-14 09:47:29 -05004249 struct device_attribute *attr, const char *buf,
4250 size_t count)
James Ketrenos2c86c272005-03-23 17:32:29 -06004251{
4252 struct ipw2100_priv *priv = dev_get_drvdata(d);
4253 schedule_reset(priv);
4254 return count;
4255}
James Ketrenos2c86c272005-03-23 17:32:29 -06004256
James Ketrenosee8e3652005-09-14 09:47:29 -05004257static DEVICE_ATTR(fatal_error, S_IWUSR | S_IRUGO, show_fatal_error,
4258 store_fatal_error);
James Ketrenos2c86c272005-03-23 17:32:29 -06004259
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004260static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05004261 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06004262{
4263 struct ipw2100_priv *priv = dev_get_drvdata(d);
4264 return sprintf(buf, "%d\n", priv->ieee->scan_age);
4265}
4266
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004267static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05004268 const char *buf, size_t count)
James Ketrenos2c86c272005-03-23 17:32:29 -06004269{
4270 struct ipw2100_priv *priv = dev_get_drvdata(d);
4271 struct net_device *dev = priv->net_dev;
4272 char buffer[] = "00000000";
4273 unsigned long len =
4274 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
4275 unsigned long val;
4276 char *p = buffer;
4277
Zhu Yi8ed55a42006-01-24 13:49:20 +08004278 (void)dev; /* kill unused-var warning for debug-only code */
Jeff Garzikc2a8fad2005-11-09 00:49:38 -05004279
James Ketrenos2c86c272005-03-23 17:32:29 -06004280 IPW_DEBUG_INFO("enter\n");
4281
4282 strncpy(buffer, buf, len);
4283 buffer[len] = 0;
4284
4285 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
4286 p++;
4287 if (p[0] == 'x' || p[0] == 'X')
4288 p++;
4289 val = simple_strtoul(p, &p, 16);
4290 } else
4291 val = simple_strtoul(p, &p, 10);
4292 if (p == buffer) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004293 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06004294 } else {
4295 priv->ieee->scan_age = val;
4296 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
4297 }
4298
4299 IPW_DEBUG_INFO("exit\n");
4300 return len;
4301}
James Ketrenosee8e3652005-09-14 09:47:29 -05004302
James Ketrenos2c86c272005-03-23 17:32:29 -06004303static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
4304
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004305static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05004306 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06004307{
4308 /* 0 - RF kill not enabled
4309 1 - SW based RF kill active (sysfs)
4310 2 - HW based RF kill active
4311 3 - Both HW and SW baed RF kill active */
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07004312 struct ipw2100_priv *priv = dev_get_drvdata(d);
James Ketrenos2c86c272005-03-23 17:32:29 -06004313 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
James Ketrenosee8e3652005-09-14 09:47:29 -05004314 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos2c86c272005-03-23 17:32:29 -06004315 return sprintf(buf, "%i\n", val);
4316}
4317
4318static int ipw_radio_kill_sw(struct ipw2100_priv *priv, int disable_radio)
4319{
4320 if ((disable_radio ? 1 : 0) ==
4321 (priv->status & STATUS_RF_KILL_SW ? 1 : 0))
James Ketrenosee8e3652005-09-14 09:47:29 -05004322 return 0;
James Ketrenos2c86c272005-03-23 17:32:29 -06004323
4324 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
4325 disable_radio ? "OFF" : "ON");
4326
Ingo Molnar752e3772006-02-28 07:20:54 +08004327 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06004328
4329 if (disable_radio) {
4330 priv->status |= STATUS_RF_KILL_SW;
4331 ipw2100_down(priv);
4332 } else {
4333 priv->status &= ~STATUS_RF_KILL_SW;
4334 if (rf_kill_active(priv)) {
4335 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
4336 "disabled by HW switch\n");
4337 /* Make sure the RF_KILL check timer is running */
4338 priv->stop_rf_kill = 0;
4339 cancel_delayed_work(&priv->rf_kill);
Stephen Hemmingera62056f2007-06-22 21:46:50 -07004340 queue_delayed_work(priv->workqueue, &priv->rf_kill,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05004341 round_jiffies_relative(HZ));
James Ketrenos2c86c272005-03-23 17:32:29 -06004342 } else
4343 schedule_reset(priv);
4344 }
4345
Ingo Molnar752e3772006-02-28 07:20:54 +08004346 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06004347 return 1;
4348}
4349
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004350static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05004351 const char *buf, size_t count)
James Ketrenos2c86c272005-03-23 17:32:29 -06004352{
4353 struct ipw2100_priv *priv = dev_get_drvdata(d);
4354 ipw_radio_kill_sw(priv, buf[0] == '1');
4355 return count;
4356}
James Ketrenos2c86c272005-03-23 17:32:29 -06004357
James Ketrenosee8e3652005-09-14 09:47:29 -05004358static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos2c86c272005-03-23 17:32:29 -06004359
4360static struct attribute *ipw2100_sysfs_entries[] = {
4361 &dev_attr_hardware.attr,
4362 &dev_attr_registers.attr,
4363 &dev_attr_ordinals.attr,
4364 &dev_attr_pci.attr,
4365 &dev_attr_stats.attr,
4366 &dev_attr_internals.attr,
4367 &dev_attr_bssinfo.attr,
4368 &dev_attr_memory.attr,
4369 &dev_attr_scan_age.attr,
4370 &dev_attr_fatal_error.attr,
4371 &dev_attr_rf_kill.attr,
4372 &dev_attr_cfg.attr,
4373 &dev_attr_status.attr,
4374 &dev_attr_capability.attr,
4375 NULL,
4376};
4377
4378static struct attribute_group ipw2100_attribute_group = {
4379 .attrs = ipw2100_sysfs_entries,
4380};
4381
James Ketrenos2c86c272005-03-23 17:32:29 -06004382static int status_queue_allocate(struct ipw2100_priv *priv, int entries)
4383{
4384 struct ipw2100_status_queue *q = &priv->status_queue;
4385
4386 IPW_DEBUG_INFO("enter\n");
4387
4388 q->size = entries * sizeof(struct ipw2100_status);
James Ketrenosee8e3652005-09-14 09:47:29 -05004389 q->drv =
4390 (struct ipw2100_status *)pci_alloc_consistent(priv->pci_dev,
4391 q->size, &q->nic);
James Ketrenos2c86c272005-03-23 17:32:29 -06004392 if (!q->drv) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004393 IPW_DEBUG_WARNING("Can not allocate status queue.\n");
James Ketrenos2c86c272005-03-23 17:32:29 -06004394 return -ENOMEM;
4395 }
4396
4397 memset(q->drv, 0, q->size);
4398
4399 IPW_DEBUG_INFO("exit\n");
4400
4401 return 0;
4402}
4403
4404static void status_queue_free(struct ipw2100_priv *priv)
4405{
4406 IPW_DEBUG_INFO("enter\n");
4407
4408 if (priv->status_queue.drv) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004409 pci_free_consistent(priv->pci_dev, priv->status_queue.size,
4410 priv->status_queue.drv,
4411 priv->status_queue.nic);
James Ketrenos2c86c272005-03-23 17:32:29 -06004412 priv->status_queue.drv = NULL;
4413 }
4414
4415 IPW_DEBUG_INFO("exit\n");
4416}
4417
4418static int bd_queue_allocate(struct ipw2100_priv *priv,
4419 struct ipw2100_bd_queue *q, int entries)
4420{
4421 IPW_DEBUG_INFO("enter\n");
4422
4423 memset(q, 0, sizeof(struct ipw2100_bd_queue));
4424
4425 q->entries = entries;
4426 q->size = entries * sizeof(struct ipw2100_bd);
4427 q->drv = pci_alloc_consistent(priv->pci_dev, q->size, &q->nic);
4428 if (!q->drv) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004429 IPW_DEBUG_INFO
4430 ("can't allocate shared memory for buffer descriptors\n");
James Ketrenos2c86c272005-03-23 17:32:29 -06004431 return -ENOMEM;
4432 }
4433 memset(q->drv, 0, q->size);
4434
4435 IPW_DEBUG_INFO("exit\n");
4436
4437 return 0;
4438}
4439
James Ketrenosee8e3652005-09-14 09:47:29 -05004440static void bd_queue_free(struct ipw2100_priv *priv, struct ipw2100_bd_queue *q)
James Ketrenos2c86c272005-03-23 17:32:29 -06004441{
4442 IPW_DEBUG_INFO("enter\n");
4443
4444 if (!q)
4445 return;
4446
4447 if (q->drv) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004448 pci_free_consistent(priv->pci_dev, q->size, q->drv, q->nic);
James Ketrenos2c86c272005-03-23 17:32:29 -06004449 q->drv = NULL;
4450 }
4451
4452 IPW_DEBUG_INFO("exit\n");
4453}
4454
James Ketrenosee8e3652005-09-14 09:47:29 -05004455static void bd_queue_initialize(struct ipw2100_priv *priv,
4456 struct ipw2100_bd_queue *q, u32 base, u32 size,
4457 u32 r, u32 w)
James Ketrenos2c86c272005-03-23 17:32:29 -06004458{
4459 IPW_DEBUG_INFO("enter\n");
4460
James Ketrenosee8e3652005-09-14 09:47:29 -05004461 IPW_DEBUG_INFO("initializing bd queue at virt=%p, phys=%08x\n", q->drv,
4462 (u32) q->nic);
James Ketrenos2c86c272005-03-23 17:32:29 -06004463
4464 write_register(priv->net_dev, base, q->nic);
4465 write_register(priv->net_dev, size, q->entries);
4466 write_register(priv->net_dev, r, q->oldest);
4467 write_register(priv->net_dev, w, q->next);
4468
4469 IPW_DEBUG_INFO("exit\n");
4470}
4471
4472static void ipw2100_kill_workqueue(struct ipw2100_priv *priv)
4473{
4474 if (priv->workqueue) {
4475 priv->stop_rf_kill = 1;
4476 priv->stop_hang_check = 1;
4477 cancel_delayed_work(&priv->reset_work);
4478 cancel_delayed_work(&priv->security_work);
4479 cancel_delayed_work(&priv->wx_event_work);
4480 cancel_delayed_work(&priv->hang_check);
4481 cancel_delayed_work(&priv->rf_kill);
Dan Williamsd20c6782007-10-10 12:28:07 -04004482 cancel_delayed_work(&priv->scan_event_later);
James Ketrenos2c86c272005-03-23 17:32:29 -06004483 destroy_workqueue(priv->workqueue);
4484 priv->workqueue = NULL;
4485 }
4486}
4487
4488static int ipw2100_tx_allocate(struct ipw2100_priv *priv)
4489{
4490 int i, j, err = -EINVAL;
4491 void *v;
4492 dma_addr_t p;
4493
4494 IPW_DEBUG_INFO("enter\n");
4495
4496 err = bd_queue_allocate(priv, &priv->tx_queue, TX_QUEUE_LENGTH);
4497 if (err) {
4498 IPW_DEBUG_ERROR("%s: failed bd_queue_allocate\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05004499 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06004500 return err;
4501 }
4502
James Ketrenosee8e3652005-09-14 09:47:29 -05004503 priv->tx_buffers =
Joe Perchesefe4c452010-05-31 20:23:15 -07004504 kmalloc(TX_PENDED_QUEUE_LENGTH * sizeof(struct ipw2100_tx_packet),
4505 GFP_ATOMIC);
James Ketrenos2c86c272005-03-23 17:32:29 -06004506 if (!priv->tx_buffers) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004507 printk(KERN_ERR DRV_NAME
4508 ": %s: alloc failed form tx buffers.\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06004509 priv->net_dev->name);
4510 bd_queue_free(priv, &priv->tx_queue);
4511 return -ENOMEM;
4512 }
4513
4514 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004515 v = pci_alloc_consistent(priv->pci_dev,
4516 sizeof(struct ipw2100_data_header),
4517 &p);
James Ketrenos2c86c272005-03-23 17:32:29 -06004518 if (!v) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004519 printk(KERN_ERR DRV_NAME
4520 ": %s: PCI alloc failed for tx " "buffers.\n",
4521 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06004522 err = -ENOMEM;
4523 break;
4524 }
4525
4526 priv->tx_buffers[i].type = DATA;
James Ketrenosee8e3652005-09-14 09:47:29 -05004527 priv->tx_buffers[i].info.d_struct.data =
4528 (struct ipw2100_data_header *)v;
James Ketrenos2c86c272005-03-23 17:32:29 -06004529 priv->tx_buffers[i].info.d_struct.data_phys = p;
4530 priv->tx_buffers[i].info.d_struct.txb = NULL;
4531 }
4532
4533 if (i == TX_PENDED_QUEUE_LENGTH)
4534 return 0;
4535
4536 for (j = 0; j < i; j++) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004537 pci_free_consistent(priv->pci_dev,
4538 sizeof(struct ipw2100_data_header),
4539 priv->tx_buffers[j].info.d_struct.data,
4540 priv->tx_buffers[j].info.d_struct.
4541 data_phys);
James Ketrenos2c86c272005-03-23 17:32:29 -06004542 }
4543
4544 kfree(priv->tx_buffers);
4545 priv->tx_buffers = NULL;
4546
4547 return err;
4548}
4549
4550static void ipw2100_tx_initialize(struct ipw2100_priv *priv)
4551{
4552 int i;
4553
4554 IPW_DEBUG_INFO("enter\n");
4555
4556 /*
4557 * reinitialize packet info lists
4558 */
4559 INIT_LIST_HEAD(&priv->fw_pend_list);
4560 INIT_STAT(&priv->fw_pend_stat);
4561
4562 /*
4563 * reinitialize lists
4564 */
4565 INIT_LIST_HEAD(&priv->tx_pend_list);
4566 INIT_LIST_HEAD(&priv->tx_free_list);
4567 INIT_STAT(&priv->tx_pend_stat);
4568 INIT_STAT(&priv->tx_free_stat);
4569
4570 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4571 /* We simply drop any SKBs that have been queued for
4572 * transmit */
4573 if (priv->tx_buffers[i].info.d_struct.txb) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004574 libipw_txb_free(priv->tx_buffers[i].info.d_struct.
James Ketrenosee8e3652005-09-14 09:47:29 -05004575 txb);
James Ketrenos2c86c272005-03-23 17:32:29 -06004576 priv->tx_buffers[i].info.d_struct.txb = NULL;
4577 }
4578
4579 list_add_tail(&priv->tx_buffers[i].list, &priv->tx_free_list);
4580 }
4581
4582 SET_STAT(&priv->tx_free_stat, i);
4583
4584 priv->tx_queue.oldest = 0;
4585 priv->tx_queue.available = priv->tx_queue.entries;
4586 priv->tx_queue.next = 0;
4587 INIT_STAT(&priv->txq_stat);
4588 SET_STAT(&priv->txq_stat, priv->tx_queue.available);
4589
4590 bd_queue_initialize(priv, &priv->tx_queue,
4591 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_BASE,
4592 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_SIZE,
4593 IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
4594 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX);
4595
4596 IPW_DEBUG_INFO("exit\n");
4597
4598}
4599
4600static void ipw2100_tx_free(struct ipw2100_priv *priv)
4601{
4602 int i;
4603
4604 IPW_DEBUG_INFO("enter\n");
4605
4606 bd_queue_free(priv, &priv->tx_queue);
4607
4608 if (!priv->tx_buffers)
4609 return;
4610
4611 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4612 if (priv->tx_buffers[i].info.d_struct.txb) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004613 libipw_txb_free(priv->tx_buffers[i].info.d_struct.
James Ketrenosee8e3652005-09-14 09:47:29 -05004614 txb);
James Ketrenos2c86c272005-03-23 17:32:29 -06004615 priv->tx_buffers[i].info.d_struct.txb = NULL;
4616 }
4617 if (priv->tx_buffers[i].info.d_struct.data)
James Ketrenosee8e3652005-09-14 09:47:29 -05004618 pci_free_consistent(priv->pci_dev,
4619 sizeof(struct ipw2100_data_header),
4620 priv->tx_buffers[i].info.d_struct.
4621 data,
4622 priv->tx_buffers[i].info.d_struct.
4623 data_phys);
James Ketrenos2c86c272005-03-23 17:32:29 -06004624 }
4625
4626 kfree(priv->tx_buffers);
4627 priv->tx_buffers = NULL;
4628
4629 IPW_DEBUG_INFO("exit\n");
4630}
4631
James Ketrenos2c86c272005-03-23 17:32:29 -06004632static int ipw2100_rx_allocate(struct ipw2100_priv *priv)
4633{
4634 int i, j, err = -EINVAL;
4635
4636 IPW_DEBUG_INFO("enter\n");
4637
4638 err = bd_queue_allocate(priv, &priv->rx_queue, RX_QUEUE_LENGTH);
4639 if (err) {
4640 IPW_DEBUG_INFO("failed bd_queue_allocate\n");
4641 return err;
4642 }
4643
4644 err = status_queue_allocate(priv, RX_QUEUE_LENGTH);
4645 if (err) {
4646 IPW_DEBUG_INFO("failed status_queue_allocate\n");
4647 bd_queue_free(priv, &priv->rx_queue);
4648 return err;
4649 }
4650
4651 /*
4652 * allocate packets
4653 */
Joe Perchesefe4c452010-05-31 20:23:15 -07004654 priv->rx_buffers = kmalloc(RX_QUEUE_LENGTH *
4655 sizeof(struct ipw2100_rx_packet),
4656 GFP_KERNEL);
James Ketrenos2c86c272005-03-23 17:32:29 -06004657 if (!priv->rx_buffers) {
4658 IPW_DEBUG_INFO("can't allocate rx packet buffer table\n");
4659
4660 bd_queue_free(priv, &priv->rx_queue);
4661
4662 status_queue_free(priv);
4663
4664 return -ENOMEM;
4665 }
4666
4667 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4668 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
4669
4670 err = ipw2100_alloc_skb(priv, packet);
4671 if (unlikely(err)) {
4672 err = -ENOMEM;
4673 break;
4674 }
4675
4676 /* The BD holds the cache aligned address */
4677 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
4678 priv->rx_queue.drv[i].buf_length = IPW_RX_NIC_BUFFER_LENGTH;
4679 priv->status_queue.drv[i].status_fields = 0;
4680 }
4681
4682 if (i == RX_QUEUE_LENGTH)
4683 return 0;
4684
4685 for (j = 0; j < i; j++) {
4686 pci_unmap_single(priv->pci_dev, priv->rx_buffers[j].dma_addr,
4687 sizeof(struct ipw2100_rx_packet),
4688 PCI_DMA_FROMDEVICE);
4689 dev_kfree_skb(priv->rx_buffers[j].skb);
4690 }
4691
4692 kfree(priv->rx_buffers);
4693 priv->rx_buffers = NULL;
4694
4695 bd_queue_free(priv, &priv->rx_queue);
4696
4697 status_queue_free(priv);
4698
4699 return err;
4700}
4701
4702static void ipw2100_rx_initialize(struct ipw2100_priv *priv)
4703{
4704 IPW_DEBUG_INFO("enter\n");
4705
4706 priv->rx_queue.oldest = 0;
4707 priv->rx_queue.available = priv->rx_queue.entries - 1;
4708 priv->rx_queue.next = priv->rx_queue.entries - 1;
4709
4710 INIT_STAT(&priv->rxq_stat);
4711 SET_STAT(&priv->rxq_stat, priv->rx_queue.available);
4712
4713 bd_queue_initialize(priv, &priv->rx_queue,
4714 IPW_MEM_HOST_SHARED_RX_BD_BASE,
4715 IPW_MEM_HOST_SHARED_RX_BD_SIZE,
4716 IPW_MEM_HOST_SHARED_RX_READ_INDEX,
4717 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX);
4718
4719 /* set up the status queue */
4720 write_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_STATUS_BASE,
4721 priv->status_queue.nic);
4722
4723 IPW_DEBUG_INFO("exit\n");
4724}
4725
4726static void ipw2100_rx_free(struct ipw2100_priv *priv)
4727{
4728 int i;
4729
4730 IPW_DEBUG_INFO("enter\n");
4731
4732 bd_queue_free(priv, &priv->rx_queue);
4733 status_queue_free(priv);
4734
4735 if (!priv->rx_buffers)
4736 return;
4737
4738 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4739 if (priv->rx_buffers[i].rxp) {
4740 pci_unmap_single(priv->pci_dev,
4741 priv->rx_buffers[i].dma_addr,
4742 sizeof(struct ipw2100_rx),
4743 PCI_DMA_FROMDEVICE);
4744 dev_kfree_skb(priv->rx_buffers[i].skb);
4745 }
4746 }
4747
4748 kfree(priv->rx_buffers);
4749 priv->rx_buffers = NULL;
4750
4751 IPW_DEBUG_INFO("exit\n");
4752}
4753
4754static int ipw2100_read_mac_address(struct ipw2100_priv *priv)
4755{
4756 u32 length = ETH_ALEN;
Joe Perches0795af52007-10-03 17:59:30 -07004757 u8 addr[ETH_ALEN];
James Ketrenos2c86c272005-03-23 17:32:29 -06004758
4759 int err;
4760
Joe Perches0795af52007-10-03 17:59:30 -07004761 err = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ADAPTER_MAC, addr, &length);
James Ketrenos2c86c272005-03-23 17:32:29 -06004762 if (err) {
4763 IPW_DEBUG_INFO("MAC address read failed\n");
4764 return -EIO;
4765 }
James Ketrenos2c86c272005-03-23 17:32:29 -06004766
Joe Perches0795af52007-10-03 17:59:30 -07004767 memcpy(priv->net_dev->dev_addr, addr, ETH_ALEN);
Johannes Berge1749612008-10-27 15:59:26 -07004768 IPW_DEBUG_INFO("card MAC is %pM\n", priv->net_dev->dev_addr);
James Ketrenos2c86c272005-03-23 17:32:29 -06004769
4770 return 0;
4771}
4772
4773/********************************************************************
4774 *
4775 * Firmware Commands
4776 *
4777 ********************************************************************/
4778
Jiri Bencc4aee8c2005-08-25 20:04:43 -04004779static int ipw2100_set_mac_address(struct ipw2100_priv *priv, int batch_mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06004780{
4781 struct host_command cmd = {
4782 .host_command = ADAPTER_ADDRESS,
4783 .host_command_sequence = 0,
4784 .host_command_length = ETH_ALEN
4785 };
4786 int err;
4787
4788 IPW_DEBUG_HC("SET_MAC_ADDRESS\n");
4789
4790 IPW_DEBUG_INFO("enter\n");
4791
4792 if (priv->config & CFG_CUSTOM_MAC) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004793 memcpy(cmd.host_command_parameters, priv->mac_addr, ETH_ALEN);
James Ketrenos2c86c272005-03-23 17:32:29 -06004794 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
4795 } else
4796 memcpy(cmd.host_command_parameters, priv->net_dev->dev_addr,
4797 ETH_ALEN);
4798
4799 err = ipw2100_hw_send_command(priv, &cmd);
4800
4801 IPW_DEBUG_INFO("exit\n");
4802 return err;
4803}
4804
Jiri Bencc4aee8c2005-08-25 20:04:43 -04004805static int ipw2100_set_port_type(struct ipw2100_priv *priv, u32 port_type,
James Ketrenos2c86c272005-03-23 17:32:29 -06004806 int batch_mode)
4807{
4808 struct host_command cmd = {
4809 .host_command = PORT_TYPE,
4810 .host_command_sequence = 0,
4811 .host_command_length = sizeof(u32)
4812 };
4813 int err;
4814
4815 switch (port_type) {
4816 case IW_MODE_INFRA:
4817 cmd.host_command_parameters[0] = IPW_BSS;
4818 break;
4819 case IW_MODE_ADHOC:
4820 cmd.host_command_parameters[0] = IPW_IBSS;
4821 break;
4822 }
4823
4824 IPW_DEBUG_HC("PORT_TYPE: %s\n",
4825 port_type == IPW_IBSS ? "Ad-Hoc" : "Managed");
4826
4827 if (!batch_mode) {
4828 err = ipw2100_disable_adapter(priv);
4829 if (err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004830 printk(KERN_ERR DRV_NAME
4831 ": %s: Could not disable adapter %d\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06004832 priv->net_dev->name, err);
4833 return err;
4834 }
4835 }
4836
4837 /* send cmd to firmware */
4838 err = ipw2100_hw_send_command(priv, &cmd);
4839
4840 if (!batch_mode)
4841 ipw2100_enable_adapter(priv);
4842
4843 return err;
4844}
4845
Jiri Bencc4aee8c2005-08-25 20:04:43 -04004846static int ipw2100_set_channel(struct ipw2100_priv *priv, u32 channel,
4847 int batch_mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06004848{
4849 struct host_command cmd = {
4850 .host_command = CHANNEL,
4851 .host_command_sequence = 0,
4852 .host_command_length = sizeof(u32)
4853 };
4854 int err;
4855
4856 cmd.host_command_parameters[0] = channel;
4857
4858 IPW_DEBUG_HC("CHANNEL: %d\n", channel);
4859
4860 /* If BSS then we don't support channel selection */
4861 if (priv->ieee->iw_mode == IW_MODE_INFRA)
4862 return 0;
4863
4864 if ((channel != 0) &&
4865 ((channel < REG_MIN_CHANNEL) || (channel > REG_MAX_CHANNEL)))
4866 return -EINVAL;
4867
4868 if (!batch_mode) {
4869 err = ipw2100_disable_adapter(priv);
4870 if (err)
4871 return err;
4872 }
4873
4874 err = ipw2100_hw_send_command(priv, &cmd);
4875 if (err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004876 IPW_DEBUG_INFO("Failed to set channel to %d", channel);
James Ketrenos2c86c272005-03-23 17:32:29 -06004877 return err;
4878 }
4879
4880 if (channel)
4881 priv->config |= CFG_STATIC_CHANNEL;
4882 else
4883 priv->config &= ~CFG_STATIC_CHANNEL;
4884
4885 priv->channel = channel;
4886
4887 if (!batch_mode) {
4888 err = ipw2100_enable_adapter(priv);
4889 if (err)
4890 return err;
4891 }
4892
4893 return 0;
4894}
4895
Jiri Bencc4aee8c2005-08-25 20:04:43 -04004896static int ipw2100_system_config(struct ipw2100_priv *priv, int batch_mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06004897{
4898 struct host_command cmd = {
4899 .host_command = SYSTEM_CONFIG,
4900 .host_command_sequence = 0,
4901 .host_command_length = 12,
4902 };
4903 u32 ibss_mask, len = sizeof(u32);
4904 int err;
4905
4906 /* Set system configuration */
4907
4908 if (!batch_mode) {
4909 err = ipw2100_disable_adapter(priv);
4910 if (err)
4911 return err;
4912 }
4913
4914 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
4915 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_AUTO_START;
4916
4917 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_MASK |
James Ketrenosee8e3652005-09-14 09:47:29 -05004918 IPW_CFG_BSS_MASK | IPW_CFG_802_1x_ENABLE;
James Ketrenos2c86c272005-03-23 17:32:29 -06004919
4920 if (!(priv->config & CFG_LONG_PREAMBLE))
4921 cmd.host_command_parameters[0] |= IPW_CFG_PREAMBLE_AUTO;
4922
4923 err = ipw2100_get_ordinal(priv,
4924 IPW_ORD_EEPROM_IBSS_11B_CHANNELS,
James Ketrenosee8e3652005-09-14 09:47:29 -05004925 &ibss_mask, &len);
James Ketrenos2c86c272005-03-23 17:32:29 -06004926 if (err)
4927 ibss_mask = IPW_IBSS_11B_DEFAULT_MASK;
4928
4929 cmd.host_command_parameters[1] = REG_CHANNEL_MASK;
4930 cmd.host_command_parameters[2] = REG_CHANNEL_MASK & ibss_mask;
4931
4932 /* 11b only */
James Ketrenosee8e3652005-09-14 09:47:29 -05004933 /*cmd.host_command_parameters[0] |= DIVERSITY_ANTENNA_A; */
James Ketrenos2c86c272005-03-23 17:32:29 -06004934
4935 err = ipw2100_hw_send_command(priv, &cmd);
4936 if (err)
4937 return err;
4938
4939/* If IPv6 is configured in the kernel then we don't want to filter out all
4940 * of the multicast packets as IPv6 needs some. */
4941#if !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
4942 cmd.host_command = ADD_MULTICAST;
4943 cmd.host_command_sequence = 0;
4944 cmd.host_command_length = 0;
4945
4946 ipw2100_hw_send_command(priv, &cmd);
4947#endif
4948 if (!batch_mode) {
4949 err = ipw2100_enable_adapter(priv);
4950 if (err)
4951 return err;
4952 }
4953
4954 return 0;
4955}
4956
Jiri Bencc4aee8c2005-08-25 20:04:43 -04004957static int ipw2100_set_tx_rates(struct ipw2100_priv *priv, u32 rate,
4958 int batch_mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06004959{
4960 struct host_command cmd = {
4961 .host_command = BASIC_TX_RATES,
4962 .host_command_sequence = 0,
4963 .host_command_length = 4
4964 };
4965 int err;
4966
4967 cmd.host_command_parameters[0] = rate & TX_RATE_MASK;
4968
4969 if (!batch_mode) {
4970 err = ipw2100_disable_adapter(priv);
4971 if (err)
4972 return err;
4973 }
4974
4975 /* Set BASIC TX Rate first */
4976 ipw2100_hw_send_command(priv, &cmd);
4977
4978 /* Set TX Rate */
4979 cmd.host_command = TX_RATES;
4980 ipw2100_hw_send_command(priv, &cmd);
4981
4982 /* Set MSDU TX Rate */
4983 cmd.host_command = MSDU_TX_RATES;
4984 ipw2100_hw_send_command(priv, &cmd);
4985
4986 if (!batch_mode) {
4987 err = ipw2100_enable_adapter(priv);
4988 if (err)
4989 return err;
4990 }
4991
4992 priv->tx_rates = rate;
4993
4994 return 0;
4995}
4996
James Ketrenosee8e3652005-09-14 09:47:29 -05004997static int ipw2100_set_power_mode(struct ipw2100_priv *priv, int power_level)
James Ketrenos2c86c272005-03-23 17:32:29 -06004998{
4999 struct host_command cmd = {
5000 .host_command = POWER_MODE,
5001 .host_command_sequence = 0,
5002 .host_command_length = 4
5003 };
5004 int err;
5005
5006 cmd.host_command_parameters[0] = power_level;
5007
5008 err = ipw2100_hw_send_command(priv, &cmd);
5009 if (err)
5010 return err;
5011
5012 if (power_level == IPW_POWER_MODE_CAM)
5013 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
5014 else
5015 priv->power_mode = IPW_POWER_ENABLED | power_level;
5016
Robert P. J. Dayae800312007-01-31 02:39:40 -05005017#ifdef IPW2100_TX_POWER
James Ketrenosee8e3652005-09-14 09:47:29 -05005018 if (priv->port_type == IBSS && priv->adhoc_power != DFTL_IBSS_TX_POWER) {
James Ketrenos2c86c272005-03-23 17:32:29 -06005019 /* Set beacon interval */
5020 cmd.host_command = TX_POWER_INDEX;
James Ketrenosee8e3652005-09-14 09:47:29 -05005021 cmd.host_command_parameters[0] = (u32) priv->adhoc_power;
James Ketrenos2c86c272005-03-23 17:32:29 -06005022
5023 err = ipw2100_hw_send_command(priv, &cmd);
5024 if (err)
5025 return err;
5026 }
5027#endif
5028
5029 return 0;
5030}
5031
Jiri Bencc4aee8c2005-08-25 20:04:43 -04005032static int ipw2100_set_rts_threshold(struct ipw2100_priv *priv, u32 threshold)
James Ketrenos2c86c272005-03-23 17:32:29 -06005033{
5034 struct host_command cmd = {
5035 .host_command = RTS_THRESHOLD,
5036 .host_command_sequence = 0,
5037 .host_command_length = 4
5038 };
5039 int err;
5040
5041 if (threshold & RTS_DISABLED)
5042 cmd.host_command_parameters[0] = MAX_RTS_THRESHOLD;
5043 else
5044 cmd.host_command_parameters[0] = threshold & ~RTS_DISABLED;
5045
5046 err = ipw2100_hw_send_command(priv, &cmd);
5047 if (err)
5048 return err;
5049
5050 priv->rts_threshold = threshold;
5051
5052 return 0;
5053}
5054
5055#if 0
5056int ipw2100_set_fragmentation_threshold(struct ipw2100_priv *priv,
5057 u32 threshold, int batch_mode)
5058{
5059 struct host_command cmd = {
5060 .host_command = FRAG_THRESHOLD,
5061 .host_command_sequence = 0,
5062 .host_command_length = 4,
5063 .host_command_parameters[0] = 0,
5064 };
5065 int err;
5066
5067 if (!batch_mode) {
5068 err = ipw2100_disable_adapter(priv);
5069 if (err)
5070 return err;
5071 }
5072
5073 if (threshold == 0)
5074 threshold = DEFAULT_FRAG_THRESHOLD;
5075 else {
5076 threshold = max(threshold, MIN_FRAG_THRESHOLD);
5077 threshold = min(threshold, MAX_FRAG_THRESHOLD);
5078 }
5079
5080 cmd.host_command_parameters[0] = threshold;
5081
5082 IPW_DEBUG_HC("FRAG_THRESHOLD: %u\n", threshold);
5083
5084 err = ipw2100_hw_send_command(priv, &cmd);
5085
5086 if (!batch_mode)
5087 ipw2100_enable_adapter(priv);
5088
5089 if (!err)
5090 priv->frag_threshold = threshold;
5091
5092 return err;
5093}
5094#endif
5095
Jiri Bencc4aee8c2005-08-25 20:04:43 -04005096static int ipw2100_set_short_retry(struct ipw2100_priv *priv, u32 retry)
James Ketrenos2c86c272005-03-23 17:32:29 -06005097{
5098 struct host_command cmd = {
5099 .host_command = SHORT_RETRY_LIMIT,
5100 .host_command_sequence = 0,
5101 .host_command_length = 4
5102 };
5103 int err;
5104
5105 cmd.host_command_parameters[0] = retry;
5106
5107 err = ipw2100_hw_send_command(priv, &cmd);
5108 if (err)
5109 return err;
5110
5111 priv->short_retry_limit = retry;
5112
5113 return 0;
5114}
5115
Jiri Bencc4aee8c2005-08-25 20:04:43 -04005116static int ipw2100_set_long_retry(struct ipw2100_priv *priv, u32 retry)
James Ketrenos2c86c272005-03-23 17:32:29 -06005117{
5118 struct host_command cmd = {
5119 .host_command = LONG_RETRY_LIMIT,
5120 .host_command_sequence = 0,
5121 .host_command_length = 4
5122 };
5123 int err;
5124
5125 cmd.host_command_parameters[0] = retry;
5126
5127 err = ipw2100_hw_send_command(priv, &cmd);
5128 if (err)
5129 return err;
5130
5131 priv->long_retry_limit = retry;
5132
5133 return 0;
5134}
5135
James Ketrenosee8e3652005-09-14 09:47:29 -05005136static int ipw2100_set_mandatory_bssid(struct ipw2100_priv *priv, u8 * bssid,
Jiri Bencc4aee8c2005-08-25 20:04:43 -04005137 int batch_mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06005138{
5139 struct host_command cmd = {
5140 .host_command = MANDATORY_BSSID,
5141 .host_command_sequence = 0,
5142 .host_command_length = (bssid == NULL) ? 0 : ETH_ALEN
5143 };
5144 int err;
5145
Brice Goglin0f52bf92005-12-01 01:41:46 -08005146#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06005147 if (bssid != NULL)
Johannes Berge1749612008-10-27 15:59:26 -07005148 IPW_DEBUG_HC("MANDATORY_BSSID: %pM\n", bssid);
James Ketrenos2c86c272005-03-23 17:32:29 -06005149 else
5150 IPW_DEBUG_HC("MANDATORY_BSSID: <clear>\n");
5151#endif
5152 /* if BSSID is empty then we disable mandatory bssid mode */
5153 if (bssid != NULL)
James Ketrenos82328352005-08-24 22:33:31 -05005154 memcpy(cmd.host_command_parameters, bssid, ETH_ALEN);
James Ketrenos2c86c272005-03-23 17:32:29 -06005155
5156 if (!batch_mode) {
5157 err = ipw2100_disable_adapter(priv);
5158 if (err)
5159 return err;
5160 }
5161
5162 err = ipw2100_hw_send_command(priv, &cmd);
5163
5164 if (!batch_mode)
5165 ipw2100_enable_adapter(priv);
5166
5167 return err;
5168}
5169
James Ketrenos2c86c272005-03-23 17:32:29 -06005170static int ipw2100_disassociate_bssid(struct ipw2100_priv *priv)
5171{
5172 struct host_command cmd = {
5173 .host_command = DISASSOCIATION_BSSID,
5174 .host_command_sequence = 0,
5175 .host_command_length = ETH_ALEN
5176 };
5177 int err;
5178 int len;
5179
5180 IPW_DEBUG_HC("DISASSOCIATION_BSSID\n");
5181
5182 len = ETH_ALEN;
5183 /* The Firmware currently ignores the BSSID and just disassociates from
5184 * the currently associated AP -- but in the off chance that a future
5185 * firmware does use the BSSID provided here, we go ahead and try and
5186 * set it to the currently associated AP's BSSID */
5187 memcpy(cmd.host_command_parameters, priv->bssid, ETH_ALEN);
5188
5189 err = ipw2100_hw_send_command(priv, &cmd);
5190
5191 return err;
5192}
James Ketrenos2c86c272005-03-23 17:32:29 -06005193
5194static int ipw2100_set_wpa_ie(struct ipw2100_priv *,
5195 struct ipw2100_wpa_assoc_frame *, int)
James Ketrenosee8e3652005-09-14 09:47:29 -05005196 __attribute__ ((unused));
James Ketrenos2c86c272005-03-23 17:32:29 -06005197
5198static int ipw2100_set_wpa_ie(struct ipw2100_priv *priv,
5199 struct ipw2100_wpa_assoc_frame *wpa_frame,
5200 int batch_mode)
5201{
5202 struct host_command cmd = {
5203 .host_command = SET_WPA_IE,
5204 .host_command_sequence = 0,
5205 .host_command_length = sizeof(struct ipw2100_wpa_assoc_frame),
5206 };
5207 int err;
5208
5209 IPW_DEBUG_HC("SET_WPA_IE\n");
5210
5211 if (!batch_mode) {
5212 err = ipw2100_disable_adapter(priv);
5213 if (err)
5214 return err;
5215 }
5216
5217 memcpy(cmd.host_command_parameters, wpa_frame,
5218 sizeof(struct ipw2100_wpa_assoc_frame));
5219
5220 err = ipw2100_hw_send_command(priv, &cmd);
5221
5222 if (!batch_mode) {
5223 if (ipw2100_enable_adapter(priv))
5224 err = -EIO;
5225 }
5226
5227 return err;
5228}
5229
5230struct security_info_params {
5231 u32 allowed_ciphers;
5232 u16 version;
5233 u8 auth_mode;
5234 u8 replay_counters_number;
5235 u8 unicast_using_group;
Eric Dumazetba2d3582010-06-02 18:10:09 +00005236} __packed;
James Ketrenos2c86c272005-03-23 17:32:29 -06005237
Jiri Bencc4aee8c2005-08-25 20:04:43 -04005238static int ipw2100_set_security_information(struct ipw2100_priv *priv,
5239 int auth_mode,
5240 int security_level,
5241 int unicast_using_group,
5242 int batch_mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06005243{
5244 struct host_command cmd = {
5245 .host_command = SET_SECURITY_INFORMATION,
5246 .host_command_sequence = 0,
5247 .host_command_length = sizeof(struct security_info_params)
5248 };
5249 struct security_info_params *security =
James Ketrenosee8e3652005-09-14 09:47:29 -05005250 (struct security_info_params *)&cmd.host_command_parameters;
James Ketrenos2c86c272005-03-23 17:32:29 -06005251 int err;
5252 memset(security, 0, sizeof(*security));
5253
5254 /* If shared key AP authentication is turned on, then we need to
5255 * configure the firmware to try and use it.
5256 *
5257 * Actual data encryption/decryption is handled by the host. */
5258 security->auth_mode = auth_mode;
5259 security->unicast_using_group = unicast_using_group;
5260
5261 switch (security_level) {
5262 default:
5263 case SEC_LEVEL_0:
5264 security->allowed_ciphers = IPW_NONE_CIPHER;
5265 break;
5266 case SEC_LEVEL_1:
5267 security->allowed_ciphers = IPW_WEP40_CIPHER |
James Ketrenosee8e3652005-09-14 09:47:29 -05005268 IPW_WEP104_CIPHER;
James Ketrenos2c86c272005-03-23 17:32:29 -06005269 break;
5270 case SEC_LEVEL_2:
5271 security->allowed_ciphers = IPW_WEP40_CIPHER |
James Ketrenosee8e3652005-09-14 09:47:29 -05005272 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER;
James Ketrenos2c86c272005-03-23 17:32:29 -06005273 break;
5274 case SEC_LEVEL_2_CKIP:
5275 security->allowed_ciphers = IPW_WEP40_CIPHER |
James Ketrenosee8e3652005-09-14 09:47:29 -05005276 IPW_WEP104_CIPHER | IPW_CKIP_CIPHER;
James Ketrenos2c86c272005-03-23 17:32:29 -06005277 break;
5278 case SEC_LEVEL_3:
5279 security->allowed_ciphers = IPW_WEP40_CIPHER |
James Ketrenosee8e3652005-09-14 09:47:29 -05005280 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER | IPW_CCMP_CIPHER;
James Ketrenos2c86c272005-03-23 17:32:29 -06005281 break;
5282 }
5283
James Ketrenosee8e3652005-09-14 09:47:29 -05005284 IPW_DEBUG_HC
5285 ("SET_SECURITY_INFORMATION: auth:%d cipher:0x%02X (level %d)\n",
5286 security->auth_mode, security->allowed_ciphers, security_level);
James Ketrenos2c86c272005-03-23 17:32:29 -06005287
5288 security->replay_counters_number = 0;
5289
5290 if (!batch_mode) {
5291 err = ipw2100_disable_adapter(priv);
5292 if (err)
5293 return err;
5294 }
5295
5296 err = ipw2100_hw_send_command(priv, &cmd);
5297
5298 if (!batch_mode)
5299 ipw2100_enable_adapter(priv);
5300
5301 return err;
5302}
5303
James Ketrenosee8e3652005-09-14 09:47:29 -05005304static int ipw2100_set_tx_power(struct ipw2100_priv *priv, u32 tx_power)
James Ketrenos2c86c272005-03-23 17:32:29 -06005305{
5306 struct host_command cmd = {
5307 .host_command = TX_POWER_INDEX,
5308 .host_command_sequence = 0,
5309 .host_command_length = 4
5310 };
5311 int err = 0;
Zhu Yi3173ca02006-01-24 13:49:01 +08005312 u32 tmp = tx_power;
James Ketrenos2c86c272005-03-23 17:32:29 -06005313
Liu Hongf75459e2005-07-13 12:29:21 -05005314 if (tx_power != IPW_TX_POWER_DEFAULT)
Zhu Yi3173ca02006-01-24 13:49:01 +08005315 tmp = (tx_power - IPW_TX_POWER_MIN_DBM) * 16 /
5316 (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM);
Liu Hongf75459e2005-07-13 12:29:21 -05005317
Zhu Yi3173ca02006-01-24 13:49:01 +08005318 cmd.host_command_parameters[0] = tmp;
James Ketrenos2c86c272005-03-23 17:32:29 -06005319
5320 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
5321 err = ipw2100_hw_send_command(priv, &cmd);
5322 if (!err)
5323 priv->tx_power = tx_power;
5324
5325 return 0;
5326}
5327
Jiri Bencc4aee8c2005-08-25 20:04:43 -04005328static int ipw2100_set_ibss_beacon_interval(struct ipw2100_priv *priv,
5329 u32 interval, int batch_mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06005330{
5331 struct host_command cmd = {
5332 .host_command = BEACON_INTERVAL,
5333 .host_command_sequence = 0,
5334 .host_command_length = 4
5335 };
5336 int err;
5337
5338 cmd.host_command_parameters[0] = interval;
5339
5340 IPW_DEBUG_INFO("enter\n");
5341
5342 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5343 if (!batch_mode) {
5344 err = ipw2100_disable_adapter(priv);
5345 if (err)
5346 return err;
5347 }
5348
5349 ipw2100_hw_send_command(priv, &cmd);
5350
5351 if (!batch_mode) {
5352 err = ipw2100_enable_adapter(priv);
5353 if (err)
5354 return err;
5355 }
5356 }
5357
5358 IPW_DEBUG_INFO("exit\n");
5359
5360 return 0;
5361}
5362
Hannes Edera3d1fd22008-12-26 00:14:41 -08005363static void ipw2100_queues_initialize(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06005364{
5365 ipw2100_tx_initialize(priv);
5366 ipw2100_rx_initialize(priv);
5367 ipw2100_msg_initialize(priv);
5368}
5369
Hannes Edera3d1fd22008-12-26 00:14:41 -08005370static void ipw2100_queues_free(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06005371{
5372 ipw2100_tx_free(priv);
5373 ipw2100_rx_free(priv);
5374 ipw2100_msg_free(priv);
5375}
5376
Hannes Edera3d1fd22008-12-26 00:14:41 -08005377static int ipw2100_queues_allocate(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06005378{
5379 if (ipw2100_tx_allocate(priv) ||
James Ketrenosee8e3652005-09-14 09:47:29 -05005380 ipw2100_rx_allocate(priv) || ipw2100_msg_allocate(priv))
James Ketrenos2c86c272005-03-23 17:32:29 -06005381 goto fail;
5382
5383 return 0;
5384
James Ketrenosee8e3652005-09-14 09:47:29 -05005385 fail:
James Ketrenos2c86c272005-03-23 17:32:29 -06005386 ipw2100_tx_free(priv);
5387 ipw2100_rx_free(priv);
5388 ipw2100_msg_free(priv);
5389 return -ENOMEM;
5390}
5391
5392#define IPW_PRIVACY_CAPABLE 0x0008
5393
5394static int ipw2100_set_wep_flags(struct ipw2100_priv *priv, u32 flags,
5395 int batch_mode)
5396{
5397 struct host_command cmd = {
5398 .host_command = WEP_FLAGS,
5399 .host_command_sequence = 0,
5400 .host_command_length = 4
5401 };
5402 int err;
5403
5404 cmd.host_command_parameters[0] = flags;
5405
5406 IPW_DEBUG_HC("WEP_FLAGS: flags = 0x%08X\n", flags);
5407
5408 if (!batch_mode) {
5409 err = ipw2100_disable_adapter(priv);
5410 if (err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05005411 printk(KERN_ERR DRV_NAME
5412 ": %s: Could not disable adapter %d\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06005413 priv->net_dev->name, err);
5414 return err;
5415 }
5416 }
5417
5418 /* send cmd to firmware */
5419 err = ipw2100_hw_send_command(priv, &cmd);
5420
5421 if (!batch_mode)
5422 ipw2100_enable_adapter(priv);
5423
5424 return err;
5425}
5426
5427struct ipw2100_wep_key {
5428 u8 idx;
5429 u8 len;
5430 u8 key[13];
5431};
5432
5433/* Macros to ease up priting WEP keys */
5434#define WEP_FMT_64 "%02X%02X%02X%02X-%02X"
5435#define WEP_FMT_128 "%02X%02X%02X%02X-%02X%02X%02X%02X-%02X%02X%02X"
5436#define WEP_STR_64(x) x[0],x[1],x[2],x[3],x[4]
5437#define WEP_STR_128(x) x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],x[8],x[9],x[10]
5438
James Ketrenos2c86c272005-03-23 17:32:29 -06005439/**
5440 * Set a the wep key
5441 *
5442 * @priv: struct to work on
5443 * @idx: index of the key we want to set
5444 * @key: ptr to the key data to set
5445 * @len: length of the buffer at @key
5446 * @batch_mode: FIXME perform the operation in batch mode, not
5447 * disabling the device.
5448 *
5449 * @returns 0 if OK, < 0 errno code on error.
5450 *
5451 * Fill out a command structure with the new wep key, length an
5452 * index and send it down the wire.
5453 */
5454static int ipw2100_set_key(struct ipw2100_priv *priv,
5455 int idx, char *key, int len, int batch_mode)
5456{
5457 int keylen = len ? (len <= 5 ? 5 : 13) : 0;
5458 struct host_command cmd = {
5459 .host_command = WEP_KEY_INFO,
5460 .host_command_sequence = 0,
5461 .host_command_length = sizeof(struct ipw2100_wep_key),
5462 };
James Ketrenosee8e3652005-09-14 09:47:29 -05005463 struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
James Ketrenos2c86c272005-03-23 17:32:29 -06005464 int err;
5465
5466 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05005467 idx, keylen, len);
James Ketrenos2c86c272005-03-23 17:32:29 -06005468
5469 /* NOTE: We don't check cached values in case the firmware was reset
Adrian Bunk80f72282006-06-30 18:27:16 +02005470 * or some other problem is occurring. If the user is setting the key,
James Ketrenos2c86c272005-03-23 17:32:29 -06005471 * then we push the change */
5472
5473 wep_key->idx = idx;
5474 wep_key->len = keylen;
5475
5476 if (keylen) {
5477 memcpy(wep_key->key, key, len);
5478 memset(wep_key->key + len, 0, keylen - len);
5479 }
5480
5481 /* Will be optimized out on debug not being configured in */
5482 if (keylen == 0)
5483 IPW_DEBUG_WEP("%s: Clearing key %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05005484 priv->net_dev->name, wep_key->idx);
James Ketrenos2c86c272005-03-23 17:32:29 -06005485 else if (keylen == 5)
5486 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_64 "\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05005487 priv->net_dev->name, wep_key->idx, wep_key->len,
5488 WEP_STR_64(wep_key->key));
James Ketrenos2c86c272005-03-23 17:32:29 -06005489 else
5490 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_128
James Ketrenosee8e3652005-09-14 09:47:29 -05005491 "\n",
5492 priv->net_dev->name, wep_key->idx, wep_key->len,
5493 WEP_STR_128(wep_key->key));
James Ketrenos2c86c272005-03-23 17:32:29 -06005494
5495 if (!batch_mode) {
5496 err = ipw2100_disable_adapter(priv);
5497 /* FIXME: IPG: shouldn't this prink be in _disable_adapter()? */
5498 if (err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05005499 printk(KERN_ERR DRV_NAME
5500 ": %s: Could not disable adapter %d\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06005501 priv->net_dev->name, err);
5502 return err;
5503 }
5504 }
5505
5506 /* send cmd to firmware */
5507 err = ipw2100_hw_send_command(priv, &cmd);
5508
5509 if (!batch_mode) {
5510 int err2 = ipw2100_enable_adapter(priv);
5511 if (err == 0)
5512 err = err2;
5513 }
5514 return err;
5515}
5516
5517static int ipw2100_set_key_index(struct ipw2100_priv *priv,
5518 int idx, int batch_mode)
5519{
5520 struct host_command cmd = {
5521 .host_command = WEP_KEY_INDEX,
5522 .host_command_sequence = 0,
5523 .host_command_length = 4,
James Ketrenosee8e3652005-09-14 09:47:29 -05005524 .host_command_parameters = {idx},
James Ketrenos2c86c272005-03-23 17:32:29 -06005525 };
5526 int err;
5527
5528 IPW_DEBUG_HC("WEP_KEY_INDEX: index = %d\n", idx);
5529
5530 if (idx < 0 || idx > 3)
5531 return -EINVAL;
5532
5533 if (!batch_mode) {
5534 err = ipw2100_disable_adapter(priv);
5535 if (err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05005536 printk(KERN_ERR DRV_NAME
5537 ": %s: Could not disable adapter %d\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06005538 priv->net_dev->name, err);
5539 return err;
5540 }
5541 }
5542
5543 /* send cmd to firmware */
5544 err = ipw2100_hw_send_command(priv, &cmd);
5545
5546 if (!batch_mode)
5547 ipw2100_enable_adapter(priv);
5548
5549 return err;
5550}
5551
James Ketrenosee8e3652005-09-14 09:47:29 -05005552static int ipw2100_configure_security(struct ipw2100_priv *priv, int batch_mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06005553{
5554 int i, err, auth_mode, sec_level, use_group;
5555
5556 if (!(priv->status & STATUS_RUNNING))
5557 return 0;
5558
5559 if (!batch_mode) {
5560 err = ipw2100_disable_adapter(priv);
5561 if (err)
5562 return err;
5563 }
5564
25b645b2005-07-12 15:45:30 -05005565 if (!priv->ieee->sec.enabled) {
James Ketrenosee8e3652005-09-14 09:47:29 -05005566 err =
5567 ipw2100_set_security_information(priv, IPW_AUTH_OPEN,
5568 SEC_LEVEL_0, 0, 1);
James Ketrenos2c86c272005-03-23 17:32:29 -06005569 } else {
5570 auth_mode = IPW_AUTH_OPEN;
Zhu Yicbbdd032006-01-24 13:48:53 +08005571 if (priv->ieee->sec.flags & SEC_AUTH_MODE) {
5572 if (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)
5573 auth_mode = IPW_AUTH_SHARED;
5574 else if (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP)
5575 auth_mode = IPW_AUTH_LEAP_CISCO_ID;
5576 }
James Ketrenos2c86c272005-03-23 17:32:29 -06005577
5578 sec_level = SEC_LEVEL_0;
25b645b2005-07-12 15:45:30 -05005579 if (priv->ieee->sec.flags & SEC_LEVEL)
5580 sec_level = priv->ieee->sec.level;
James Ketrenos2c86c272005-03-23 17:32:29 -06005581
5582 use_group = 0;
25b645b2005-07-12 15:45:30 -05005583 if (priv->ieee->sec.flags & SEC_UNICAST_GROUP)
5584 use_group = priv->ieee->sec.unicast_uses_group;
James Ketrenos2c86c272005-03-23 17:32:29 -06005585
James Ketrenosee8e3652005-09-14 09:47:29 -05005586 err =
5587 ipw2100_set_security_information(priv, auth_mode, sec_level,
5588 use_group, 1);
James Ketrenos2c86c272005-03-23 17:32:29 -06005589 }
5590
5591 if (err)
5592 goto exit;
5593
25b645b2005-07-12 15:45:30 -05005594 if (priv->ieee->sec.enabled) {
James Ketrenos2c86c272005-03-23 17:32:29 -06005595 for (i = 0; i < 4; i++) {
25b645b2005-07-12 15:45:30 -05005596 if (!(priv->ieee->sec.flags & (1 << i))) {
5597 memset(priv->ieee->sec.keys[i], 0, WEP_KEY_LEN);
5598 priv->ieee->sec.key_sizes[i] = 0;
James Ketrenos2c86c272005-03-23 17:32:29 -06005599 } else {
5600 err = ipw2100_set_key(priv, i,
25b645b2005-07-12 15:45:30 -05005601 priv->ieee->sec.keys[i],
5602 priv->ieee->sec.
5603 key_sizes[i], 1);
James Ketrenos2c86c272005-03-23 17:32:29 -06005604 if (err)
5605 goto exit;
5606 }
5607 }
5608
John W. Linville274bfb82008-10-29 11:35:05 -04005609 ipw2100_set_key_index(priv, priv->ieee->crypt_info.tx_keyidx, 1);
James Ketrenos2c86c272005-03-23 17:32:29 -06005610 }
5611
5612 /* Always enable privacy so the Host can filter WEP packets if
5613 * encrypted data is sent up */
James Ketrenosee8e3652005-09-14 09:47:29 -05005614 err =
5615 ipw2100_set_wep_flags(priv,
25b645b2005-07-12 15:45:30 -05005616 priv->ieee->sec.
5617 enabled ? IPW_PRIVACY_CAPABLE : 0, 1);
James Ketrenos2c86c272005-03-23 17:32:29 -06005618 if (err)
5619 goto exit;
5620
5621 priv->status &= ~STATUS_SECURITY_UPDATED;
5622
James Ketrenosee8e3652005-09-14 09:47:29 -05005623 exit:
James Ketrenos2c86c272005-03-23 17:32:29 -06005624 if (!batch_mode)
5625 ipw2100_enable_adapter(priv);
5626
5627 return err;
5628}
5629
David Howellsc4028952006-11-22 14:57:56 +00005630static void ipw2100_security_work(struct work_struct *work)
James Ketrenos2c86c272005-03-23 17:32:29 -06005631{
David Howellsc4028952006-11-22 14:57:56 +00005632 struct ipw2100_priv *priv =
5633 container_of(work, struct ipw2100_priv, security_work.work);
5634
James Ketrenos2c86c272005-03-23 17:32:29 -06005635 /* If we happen to have reconnected before we get a chance to
5636 * process this, then update the security settings--which causes
5637 * a disassociation to occur */
5638 if (!(priv->status & STATUS_ASSOCIATED) &&
5639 priv->status & STATUS_SECURITY_UPDATED)
5640 ipw2100_configure_security(priv, 0);
5641}
5642
5643static void shim__set_security(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005644 struct libipw_security *sec)
James Ketrenos2c86c272005-03-23 17:32:29 -06005645{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005646 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06005647 int i, force_update = 0;
5648
Ingo Molnar752e3772006-02-28 07:20:54 +08005649 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06005650 if (!(priv->status & STATUS_INITIALIZED))
5651 goto done;
5652
5653 for (i = 0; i < 4; i++) {
5654 if (sec->flags & (1 << i)) {
25b645b2005-07-12 15:45:30 -05005655 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos2c86c272005-03-23 17:32:29 -06005656 if (sec->key_sizes[i] == 0)
25b645b2005-07-12 15:45:30 -05005657 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos2c86c272005-03-23 17:32:29 -06005658 else
25b645b2005-07-12 15:45:30 -05005659 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos2c86c272005-03-23 17:32:29 -06005660 sec->key_sizes[i]);
Hong Liu054b08d2005-08-25 17:45:49 +08005661 if (sec->level == SEC_LEVEL_1) {
5662 priv->ieee->sec.flags |= (1 << i);
5663 priv->status |= STATUS_SECURITY_UPDATED;
5664 } else
5665 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos2c86c272005-03-23 17:32:29 -06005666 }
5667 }
5668
5669 if ((sec->flags & SEC_ACTIVE_KEY) &&
25b645b2005-07-12 15:45:30 -05005670 priv->ieee->sec.active_key != sec->active_key) {
James Ketrenos2c86c272005-03-23 17:32:29 -06005671 if (sec->active_key <= 3) {
25b645b2005-07-12 15:45:30 -05005672 priv->ieee->sec.active_key = sec->active_key;
5673 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
James Ketrenos2c86c272005-03-23 17:32:29 -06005674 } else
25b645b2005-07-12 15:45:30 -05005675 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos2c86c272005-03-23 17:32:29 -06005676
5677 priv->status |= STATUS_SECURITY_UPDATED;
5678 }
5679
5680 if ((sec->flags & SEC_AUTH_MODE) &&
25b645b2005-07-12 15:45:30 -05005681 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
5682 priv->ieee->sec.auth_mode = sec->auth_mode;
5683 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos2c86c272005-03-23 17:32:29 -06005684 priv->status |= STATUS_SECURITY_UPDATED;
5685 }
5686
25b645b2005-07-12 15:45:30 -05005687 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
5688 priv->ieee->sec.flags |= SEC_ENABLED;
5689 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos2c86c272005-03-23 17:32:29 -06005690 priv->status |= STATUS_SECURITY_UPDATED;
5691 force_update = 1;
5692 }
5693
25b645b2005-07-12 15:45:30 -05005694 if (sec->flags & SEC_ENCRYPT)
5695 priv->ieee->sec.encrypt = sec->encrypt;
5696
5697 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
5698 priv->ieee->sec.level = sec->level;
5699 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos2c86c272005-03-23 17:32:29 -06005700 priv->status |= STATUS_SECURITY_UPDATED;
5701 }
5702
5703 IPW_DEBUG_WEP("Security flags: %c %c%c%c%c %c%c%c%c\n",
25b645b2005-07-12 15:45:30 -05005704 priv->ieee->sec.flags & (1 << 8) ? '1' : '0',
5705 priv->ieee->sec.flags & (1 << 7) ? '1' : '0',
5706 priv->ieee->sec.flags & (1 << 6) ? '1' : '0',
5707 priv->ieee->sec.flags & (1 << 5) ? '1' : '0',
5708 priv->ieee->sec.flags & (1 << 4) ? '1' : '0',
5709 priv->ieee->sec.flags & (1 << 3) ? '1' : '0',
5710 priv->ieee->sec.flags & (1 << 2) ? '1' : '0',
5711 priv->ieee->sec.flags & (1 << 1) ? '1' : '0',
5712 priv->ieee->sec.flags & (1 << 0) ? '1' : '0');
James Ketrenos2c86c272005-03-23 17:32:29 -06005713
5714/* As a temporary work around to enable WPA until we figure out why
5715 * wpa_supplicant toggles the security capability of the driver, which
5716 * forces a disassocation with force_update...
5717 *
5718 * if (force_update || !(priv->status & STATUS_ASSOCIATED))*/
5719 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
5720 ipw2100_configure_security(priv, 0);
James Ketrenosee8e3652005-09-14 09:47:29 -05005721 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08005722 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06005723}
5724
5725static int ipw2100_adapter_setup(struct ipw2100_priv *priv)
5726{
5727 int err;
5728 int batch_mode = 1;
5729 u8 *bssid;
5730
5731 IPW_DEBUG_INFO("enter\n");
5732
5733 err = ipw2100_disable_adapter(priv);
5734 if (err)
5735 return err;
5736#ifdef CONFIG_IPW2100_MONITOR
5737 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
5738 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5739 if (err)
5740 return err;
5741
5742 IPW_DEBUG_INFO("exit\n");
5743
5744 return 0;
5745 }
James Ketrenosee8e3652005-09-14 09:47:29 -05005746#endif /* CONFIG_IPW2100_MONITOR */
James Ketrenos2c86c272005-03-23 17:32:29 -06005747
5748 err = ipw2100_read_mac_address(priv);
5749 if (err)
5750 return -EIO;
5751
5752 err = ipw2100_set_mac_address(priv, batch_mode);
5753 if (err)
5754 return err;
5755
5756 err = ipw2100_set_port_type(priv, priv->ieee->iw_mode, batch_mode);
5757 if (err)
5758 return err;
5759
5760 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5761 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5762 if (err)
5763 return err;
5764 }
5765
James Ketrenosee8e3652005-09-14 09:47:29 -05005766 err = ipw2100_system_config(priv, batch_mode);
James Ketrenos2c86c272005-03-23 17:32:29 -06005767 if (err)
5768 return err;
5769
5770 err = ipw2100_set_tx_rates(priv, priv->tx_rates, batch_mode);
5771 if (err)
5772 return err;
5773
5774 /* Default to power mode OFF */
5775 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
5776 if (err)
5777 return err;
5778
5779 err = ipw2100_set_rts_threshold(priv, priv->rts_threshold);
5780 if (err)
5781 return err;
5782
5783 if (priv->config & CFG_STATIC_BSSID)
5784 bssid = priv->bssid;
5785 else
5786 bssid = NULL;
5787 err = ipw2100_set_mandatory_bssid(priv, bssid, batch_mode);
5788 if (err)
5789 return err;
5790
5791 if (priv->config & CFG_STATIC_ESSID)
5792 err = ipw2100_set_essid(priv, priv->essid, priv->essid_len,
5793 batch_mode);
5794 else
5795 err = ipw2100_set_essid(priv, NULL, 0, batch_mode);
5796 if (err)
5797 return err;
5798
5799 err = ipw2100_configure_security(priv, batch_mode);
5800 if (err)
5801 return err;
5802
5803 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosee8e3652005-09-14 09:47:29 -05005804 err =
5805 ipw2100_set_ibss_beacon_interval(priv,
5806 priv->beacon_interval,
5807 batch_mode);
James Ketrenos2c86c272005-03-23 17:32:29 -06005808 if (err)
5809 return err;
5810
5811 err = ipw2100_set_tx_power(priv, priv->tx_power);
5812 if (err)
5813 return err;
5814 }
5815
5816 /*
James Ketrenosee8e3652005-09-14 09:47:29 -05005817 err = ipw2100_set_fragmentation_threshold(
5818 priv, priv->frag_threshold, batch_mode);
5819 if (err)
5820 return err;
5821 */
James Ketrenos2c86c272005-03-23 17:32:29 -06005822
5823 IPW_DEBUG_INFO("exit\n");
5824
5825 return 0;
5826}
5827
James Ketrenos2c86c272005-03-23 17:32:29 -06005828/*************************************************************************
5829 *
5830 * EXTERNALLY CALLED METHODS
5831 *
5832 *************************************************************************/
5833
5834/* This method is called by the network layer -- not to be confused with
5835 * ipw2100_set_mac_address() declared above called by this driver (and this
5836 * method as well) to talk to the firmware */
5837static int ipw2100_set_address(struct net_device *dev, void *p)
5838{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005839 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06005840 struct sockaddr *addr = p;
5841 int err = 0;
5842
5843 if (!is_valid_ether_addr(addr->sa_data))
5844 return -EADDRNOTAVAIL;
5845
Ingo Molnar752e3772006-02-28 07:20:54 +08005846 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06005847
5848 priv->config |= CFG_CUSTOM_MAC;
5849 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
5850
5851 err = ipw2100_set_mac_address(priv, 0);
5852 if (err)
5853 goto done;
5854
5855 priv->reset_backoff = 0;
Ingo Molnar752e3772006-02-28 07:20:54 +08005856 mutex_unlock(&priv->action_mutex);
David Howellsc4028952006-11-22 14:57:56 +00005857 ipw2100_reset_adapter(&priv->reset_work.work);
James Ketrenos2c86c272005-03-23 17:32:29 -06005858 return 0;
5859
James Ketrenosee8e3652005-09-14 09:47:29 -05005860 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08005861 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06005862 return err;
5863}
5864
5865static int ipw2100_open(struct net_device *dev)
5866{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005867 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06005868 unsigned long flags;
5869 IPW_DEBUG_INFO("dev->open\n");
5870
5871 spin_lock_irqsave(&priv->low_lock, flags);
Jiri Benc3ce329c2005-08-25 20:07:01 -04005872 if (priv->status & STATUS_ASSOCIATED) {
5873 netif_carrier_on(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06005874 netif_start_queue(dev);
Jiri Benc3ce329c2005-08-25 20:07:01 -04005875 }
James Ketrenos2c86c272005-03-23 17:32:29 -06005876 spin_unlock_irqrestore(&priv->low_lock, flags);
5877
5878 return 0;
5879}
5880
5881static int ipw2100_close(struct net_device *dev)
5882{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005883 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06005884 unsigned long flags;
5885 struct list_head *element;
5886 struct ipw2100_tx_packet *packet;
5887
5888 IPW_DEBUG_INFO("enter\n");
5889
5890 spin_lock_irqsave(&priv->low_lock, flags);
5891
5892 if (priv->status & STATUS_ASSOCIATED)
5893 netif_carrier_off(dev);
5894 netif_stop_queue(dev);
5895
5896 /* Flush the TX queue ... */
5897 while (!list_empty(&priv->tx_pend_list)) {
5898 element = priv->tx_pend_list.next;
James Ketrenosee8e3652005-09-14 09:47:29 -05005899 packet = list_entry(element, struct ipw2100_tx_packet, list);
James Ketrenos2c86c272005-03-23 17:32:29 -06005900
5901 list_del(element);
5902 DEC_STAT(&priv->tx_pend_stat);
5903
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005904 libipw_txb_free(packet->info.d_struct.txb);
James Ketrenos2c86c272005-03-23 17:32:29 -06005905 packet->info.d_struct.txb = NULL;
5906
5907 list_add_tail(element, &priv->tx_free_list);
5908 INC_STAT(&priv->tx_free_stat);
5909 }
5910 spin_unlock_irqrestore(&priv->low_lock, flags);
5911
5912 IPW_DEBUG_INFO("exit\n");
5913
5914 return 0;
5915}
5916
James Ketrenos2c86c272005-03-23 17:32:29 -06005917/*
5918 * TODO: Fix this function... its just wrong
5919 */
5920static void ipw2100_tx_timeout(struct net_device *dev)
5921{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005922 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06005923
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00005924 dev->stats.tx_errors++;
James Ketrenos2c86c272005-03-23 17:32:29 -06005925
5926#ifdef CONFIG_IPW2100_MONITOR
5927 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
5928 return;
5929#endif
5930
5931 IPW_DEBUG_INFO("%s: TX timed out. Scheduling firmware restart.\n",
5932 dev->name);
5933 schedule_reset(priv);
5934}
5935
James Ketrenosee8e3652005-09-14 09:47:29 -05005936static int ipw2100_wpa_enable(struct ipw2100_priv *priv, int value)
5937{
James Ketrenos82328352005-08-24 22:33:31 -05005938 /* This is called when wpa_supplicant loads and closes the driver
5939 * interface. */
5940 priv->ieee->wpa_enabled = value;
5941 return 0;
James Ketrenos2c86c272005-03-23 17:32:29 -06005942}
5943
James Ketrenosee8e3652005-09-14 09:47:29 -05005944static int ipw2100_wpa_set_auth_algs(struct ipw2100_priv *priv, int value)
5945{
James Ketrenos2c86c272005-03-23 17:32:29 -06005946
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005947 struct libipw_device *ieee = priv->ieee;
5948 struct libipw_security sec = {
James Ketrenos2c86c272005-03-23 17:32:29 -06005949 .flags = SEC_AUTH_MODE,
5950 };
5951 int ret = 0;
5952
James Ketrenos82328352005-08-24 22:33:31 -05005953 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenos2c86c272005-03-23 17:32:29 -06005954 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
5955 ieee->open_wep = 0;
James Ketrenos82328352005-08-24 22:33:31 -05005956 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenos2c86c272005-03-23 17:32:29 -06005957 sec.auth_mode = WLAN_AUTH_OPEN;
5958 ieee->open_wep = 1;
Zhu Yicbbdd032006-01-24 13:48:53 +08005959 } else if (value & IW_AUTH_ALG_LEAP) {
5960 sec.auth_mode = WLAN_AUTH_LEAP;
5961 ieee->open_wep = 1;
James Ketrenos82328352005-08-24 22:33:31 -05005962 } else
5963 return -EINVAL;
James Ketrenos2c86c272005-03-23 17:32:29 -06005964
5965 if (ieee->set_security)
5966 ieee->set_security(ieee->dev, &sec);
5967 else
5968 ret = -EOPNOTSUPP;
5969
5970 return ret;
5971}
5972
Adrian Bunk3c398b82006-01-21 01:36:36 +01005973static void ipw2100_wpa_assoc_frame(struct ipw2100_priv *priv,
5974 char *wpa_ie, int wpa_ie_len)
James Ketrenosee8e3652005-09-14 09:47:29 -05005975{
James Ketrenos2c86c272005-03-23 17:32:29 -06005976
5977 struct ipw2100_wpa_assoc_frame frame;
5978
5979 frame.fixed_ie_mask = 0;
5980
5981 /* copy WPA IE */
5982 memcpy(frame.var_ie, wpa_ie, wpa_ie_len);
5983 frame.var_ie_len = wpa_ie_len;
5984
5985 /* make sure WPA is enabled */
5986 ipw2100_wpa_enable(priv, 1);
5987 ipw2100_set_wpa_ie(priv, &frame, 0);
5988}
5989
James Ketrenos2c86c272005-03-23 17:32:29 -06005990static void ipw_ethtool_get_drvinfo(struct net_device *dev,
5991 struct ethtool_drvinfo *info)
5992{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005993 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06005994 char fw_ver[64], ucode_ver[64];
5995
5996 strcpy(info->driver, DRV_NAME);
5997 strcpy(info->version, DRV_VERSION);
5998
5999 ipw2100_get_fwversion(priv, fw_ver, sizeof(fw_ver));
6000 ipw2100_get_ucodeversion(priv, ucode_ver, sizeof(ucode_ver));
6001
6002 snprintf(info->fw_version, sizeof(info->fw_version), "%s:%d:%s",
6003 fw_ver, priv->eeprom_version, ucode_ver);
6004
6005 strcpy(info->bus_info, pci_name(priv->pci_dev));
6006}
6007
6008static u32 ipw2100_ethtool_get_link(struct net_device *dev)
6009{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006010 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenosee8e3652005-09-14 09:47:29 -05006011 return (priv->status & STATUS_ASSOCIATED) ? 1 : 0;
James Ketrenos2c86c272005-03-23 17:32:29 -06006012}
6013
Jeff Garzik7282d492006-09-13 14:30:00 -04006014static const struct ethtool_ops ipw2100_ethtool_ops = {
James Ketrenosee8e3652005-09-14 09:47:29 -05006015 .get_link = ipw2100_ethtool_get_link,
6016 .get_drvinfo = ipw_ethtool_get_drvinfo,
James Ketrenos2c86c272005-03-23 17:32:29 -06006017};
6018
David Howellsc4028952006-11-22 14:57:56 +00006019static void ipw2100_hang_check(struct work_struct *work)
James Ketrenos2c86c272005-03-23 17:32:29 -06006020{
David Howellsc4028952006-11-22 14:57:56 +00006021 struct ipw2100_priv *priv =
6022 container_of(work, struct ipw2100_priv, hang_check.work);
James Ketrenos2c86c272005-03-23 17:32:29 -06006023 unsigned long flags;
6024 u32 rtc = 0xa5a5a5a5;
6025 u32 len = sizeof(rtc);
6026 int restart = 0;
6027
6028 spin_lock_irqsave(&priv->low_lock, flags);
6029
6030 if (priv->fatal_error != 0) {
6031 /* If fatal_error is set then we need to restart */
6032 IPW_DEBUG_INFO("%s: Hardware fatal error detected.\n",
6033 priv->net_dev->name);
6034
6035 restart = 1;
6036 } else if (ipw2100_get_ordinal(priv, IPW_ORD_RTC_TIME, &rtc, &len) ||
6037 (rtc == priv->last_rtc)) {
6038 /* Check if firmware is hung */
6039 IPW_DEBUG_INFO("%s: Firmware RTC stalled.\n",
6040 priv->net_dev->name);
6041
6042 restart = 1;
6043 }
6044
6045 if (restart) {
6046 /* Kill timer */
6047 priv->stop_hang_check = 1;
6048 priv->hangs++;
6049
6050 /* Restart the NIC */
6051 schedule_reset(priv);
6052 }
6053
6054 priv->last_rtc = rtc;
6055
6056 if (!priv->stop_hang_check)
6057 queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2);
6058
6059 spin_unlock_irqrestore(&priv->low_lock, flags);
6060}
6061
David Howellsc4028952006-11-22 14:57:56 +00006062static void ipw2100_rf_kill(struct work_struct *work)
James Ketrenos2c86c272005-03-23 17:32:29 -06006063{
David Howellsc4028952006-11-22 14:57:56 +00006064 struct ipw2100_priv *priv =
6065 container_of(work, struct ipw2100_priv, rf_kill.work);
James Ketrenos2c86c272005-03-23 17:32:29 -06006066 unsigned long flags;
6067
6068 spin_lock_irqsave(&priv->low_lock, flags);
6069
6070 if (rf_kill_active(priv)) {
6071 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
6072 if (!priv->stop_rf_kill)
Stephen Hemmingera62056f2007-06-22 21:46:50 -07006073 queue_delayed_work(priv->workqueue, &priv->rf_kill,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05006074 round_jiffies_relative(HZ));
James Ketrenos2c86c272005-03-23 17:32:29 -06006075 goto exit_unlock;
6076 }
6077
6078 /* RF Kill is now disabled, so bring the device back up */
6079
6080 if (!(priv->status & STATUS_RF_KILL_MASK)) {
6081 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
6082 "device\n");
6083 schedule_reset(priv);
6084 } else
6085 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
6086 "enabled\n");
6087
James Ketrenosee8e3652005-09-14 09:47:29 -05006088 exit_unlock:
James Ketrenos2c86c272005-03-23 17:32:29 -06006089 spin_unlock_irqrestore(&priv->low_lock, flags);
6090}
6091
6092static void ipw2100_irq_tasklet(struct ipw2100_priv *priv);
6093
Stephen Hemminger3e47fce2009-03-20 19:36:40 +00006094static const struct net_device_ops ipw2100_netdev_ops = {
6095 .ndo_open = ipw2100_open,
6096 .ndo_stop = ipw2100_close,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006097 .ndo_start_xmit = libipw_xmit,
6098 .ndo_change_mtu = libipw_change_mtu,
Stephen Hemminger3e47fce2009-03-20 19:36:40 +00006099 .ndo_init = ipw2100_net_init,
6100 .ndo_tx_timeout = ipw2100_tx_timeout,
6101 .ndo_set_mac_address = ipw2100_set_address,
6102 .ndo_validate_addr = eth_validate_addr,
6103};
6104
Pavel Roskin27ae60f2010-03-12 00:01:22 -05006105/* Look into using netdev destructor to shutdown libipw? */
James Ketrenos2c86c272005-03-23 17:32:29 -06006106
James Ketrenosee8e3652005-09-14 09:47:29 -05006107static struct net_device *ipw2100_alloc_device(struct pci_dev *pci_dev,
6108 void __iomem * base_addr,
6109 unsigned long mem_start,
6110 unsigned long mem_len)
James Ketrenos2c86c272005-03-23 17:32:29 -06006111{
6112 struct ipw2100_priv *priv;
6113 struct net_device *dev;
6114
Pavel Roskin27ae60f2010-03-12 00:01:22 -05006115 dev = alloc_libipw(sizeof(struct ipw2100_priv), 0);
James Ketrenos2c86c272005-03-23 17:32:29 -06006116 if (!dev)
6117 return NULL;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006118 priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006119 priv->ieee = netdev_priv(dev);
6120 priv->pci_dev = pci_dev;
6121 priv->net_dev = dev;
6122
6123 priv->ieee->hard_start_xmit = ipw2100_tx;
6124 priv->ieee->set_security = shim__set_security;
6125
James Ketrenos82328352005-08-24 22:33:31 -05006126 priv->ieee->perfect_rssi = -20;
6127 priv->ieee->worst_rssi = -85;
6128
Stephen Hemminger3e47fce2009-03-20 19:36:40 +00006129 dev->netdev_ops = &ipw2100_netdev_ops;
James Ketrenos2c86c272005-03-23 17:32:29 -06006130 dev->ethtool_ops = &ipw2100_ethtool_ops;
James Ketrenos2c86c272005-03-23 17:32:29 -06006131 dev->wireless_handlers = &ipw2100_wx_handler_def;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006132 priv->wireless_data.libipw = priv->ieee;
James Ketrenoseaf8f53b2005-11-12 12:50:12 -06006133 dev->wireless_data = &priv->wireless_data;
James Ketrenosee8e3652005-09-14 09:47:29 -05006134 dev->watchdog_timeo = 3 * HZ;
James Ketrenos2c86c272005-03-23 17:32:29 -06006135 dev->irq = 0;
6136
6137 dev->base_addr = (unsigned long)base_addr;
6138 dev->mem_start = mem_start;
6139 dev->mem_end = dev->mem_start + mem_len - 1;
6140
6141 /* NOTE: We don't use the wireless_handlers hook
6142 * in dev as the system will start throwing WX requests
6143 * to us before we're actually initialized and it just
6144 * ends up causing problems. So, we just handle
6145 * the WX extensions through the ipw2100_ioctl interface */
6146
Jean Delvarec03983a2007-10-19 23:22:55 +02006147 /* memset() puts everything to 0, so we only have explicitly set
James Ketrenos2c86c272005-03-23 17:32:29 -06006148 * those values that need to be something else */
6149
6150 /* If power management is turned on, default to AUTO mode */
6151 priv->power_mode = IPW_POWER_AUTO;
6152
James Ketrenos82328352005-08-24 22:33:31 -05006153#ifdef CONFIG_IPW2100_MONITOR
6154 priv->config |= CFG_CRC_CHECK;
6155#endif
James Ketrenos2c86c272005-03-23 17:32:29 -06006156 priv->ieee->wpa_enabled = 0;
James Ketrenos2c86c272005-03-23 17:32:29 -06006157 priv->ieee->drop_unencrypted = 0;
6158 priv->ieee->privacy_invoked = 0;
6159 priv->ieee->ieee802_1x = 1;
James Ketrenos2c86c272005-03-23 17:32:29 -06006160
6161 /* Set module parameters */
Reinette Chatre21f8a732009-08-18 10:25:05 -07006162 switch (network_mode) {
James Ketrenos2c86c272005-03-23 17:32:29 -06006163 case 1:
6164 priv->ieee->iw_mode = IW_MODE_ADHOC;
6165 break;
6166#ifdef CONFIG_IPW2100_MONITOR
6167 case 2:
6168 priv->ieee->iw_mode = IW_MODE_MONITOR;
6169 break;
6170#endif
6171 default:
6172 case 0:
6173 priv->ieee->iw_mode = IW_MODE_INFRA;
6174 break;
6175 }
6176
6177 if (disable == 1)
6178 priv->status |= STATUS_RF_KILL_SW;
6179
6180 if (channel != 0 &&
James Ketrenosee8e3652005-09-14 09:47:29 -05006181 ((channel >= REG_MIN_CHANNEL) && (channel <= REG_MAX_CHANNEL))) {
James Ketrenos2c86c272005-03-23 17:32:29 -06006182 priv->config |= CFG_STATIC_CHANNEL;
6183 priv->channel = channel;
6184 }
6185
6186 if (associate)
6187 priv->config |= CFG_ASSOCIATE;
6188
6189 priv->beacon_interval = DEFAULT_BEACON_INTERVAL;
6190 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
6191 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
6192 priv->rts_threshold = DEFAULT_RTS_THRESHOLD | RTS_DISABLED;
6193 priv->frag_threshold = DEFAULT_FTS | FRAG_DISABLED;
6194 priv->tx_power = IPW_TX_POWER_DEFAULT;
6195 priv->tx_rates = DEFAULT_TX_RATES;
6196
6197 strcpy(priv->nick, "ipw2100");
6198
6199 spin_lock_init(&priv->low_lock);
Ingo Molnar752e3772006-02-28 07:20:54 +08006200 mutex_init(&priv->action_mutex);
6201 mutex_init(&priv->adapter_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006202
6203 init_waitqueue_head(&priv->wait_command_queue);
6204
6205 netif_carrier_off(dev);
6206
6207 INIT_LIST_HEAD(&priv->msg_free_list);
6208 INIT_LIST_HEAD(&priv->msg_pend_list);
6209 INIT_STAT(&priv->msg_free_stat);
6210 INIT_STAT(&priv->msg_pend_stat);
6211
6212 INIT_LIST_HEAD(&priv->tx_free_list);
6213 INIT_LIST_HEAD(&priv->tx_pend_list);
6214 INIT_STAT(&priv->tx_free_stat);
6215 INIT_STAT(&priv->tx_pend_stat);
6216
6217 INIT_LIST_HEAD(&priv->fw_pend_list);
6218 INIT_STAT(&priv->fw_pend_stat);
6219
James Ketrenos2c86c272005-03-23 17:32:29 -06006220 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos392d0f62005-09-07 18:39:03 -05006221
David Howellsc4028952006-11-22 14:57:56 +00006222 INIT_DELAYED_WORK(&priv->reset_work, ipw2100_reset_adapter);
6223 INIT_DELAYED_WORK(&priv->security_work, ipw2100_security_work);
6224 INIT_DELAYED_WORK(&priv->wx_event_work, ipw2100_wx_event_work);
6225 INIT_DELAYED_WORK(&priv->hang_check, ipw2100_hang_check);
6226 INIT_DELAYED_WORK(&priv->rf_kill, ipw2100_rf_kill);
Dan Williamsd20c6782007-10-10 12:28:07 -04006227 INIT_WORK(&priv->scan_event_now, ipw2100_scan_event_now);
6228 INIT_DELAYED_WORK(&priv->scan_event_later, ipw2100_scan_event_later);
James Ketrenos2c86c272005-03-23 17:32:29 -06006229
6230 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
6231 ipw2100_irq_tasklet, (unsigned long)priv);
6232
6233 /* NOTE: We do not start the deferred work for status checks yet */
6234 priv->stop_rf_kill = 1;
6235 priv->stop_hang_check = 1;
6236
6237 return dev;
6238}
6239
James Ketrenos2c86c272005-03-23 17:32:29 -06006240static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
6241 const struct pci_device_id *ent)
6242{
6243 unsigned long mem_start, mem_len, mem_flags;
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01006244 void __iomem *base_addr = NULL;
James Ketrenos2c86c272005-03-23 17:32:29 -06006245 struct net_device *dev = NULL;
6246 struct ipw2100_priv *priv = NULL;
6247 int err = 0;
6248 int registered = 0;
6249 u32 val;
6250
6251 IPW_DEBUG_INFO("enter\n");
6252
6253 mem_start = pci_resource_start(pci_dev, 0);
6254 mem_len = pci_resource_len(pci_dev, 0);
6255 mem_flags = pci_resource_flags(pci_dev, 0);
6256
6257 if ((mem_flags & IORESOURCE_MEM) != IORESOURCE_MEM) {
6258 IPW_DEBUG_INFO("weird - resource type is not memory\n");
6259 err = -ENODEV;
6260 goto fail;
6261 }
6262
6263 base_addr = ioremap_nocache(mem_start, mem_len);
6264 if (!base_addr) {
6265 printk(KERN_WARNING DRV_NAME
6266 "Error calling ioremap_nocache.\n");
6267 err = -EIO;
6268 goto fail;
6269 }
6270
6271 /* allocate and initialize our net_device */
6272 dev = ipw2100_alloc_device(pci_dev, base_addr, mem_start, mem_len);
6273 if (!dev) {
6274 printk(KERN_WARNING DRV_NAME
6275 "Error calling ipw2100_alloc_device.\n");
6276 err = -ENOMEM;
6277 goto fail;
6278 }
6279
6280 /* set up PCI mappings for device */
6281 err = pci_enable_device(pci_dev);
6282 if (err) {
6283 printk(KERN_WARNING DRV_NAME
6284 "Error calling pci_enable_device.\n");
6285 return err;
6286 }
6287
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006288 priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006289
6290 pci_set_master(pci_dev);
6291 pci_set_drvdata(pci_dev, priv);
6292
Yang Hongyang284901a2009-04-06 19:01:15 -07006293 err = pci_set_dma_mask(pci_dev, DMA_BIT_MASK(32));
James Ketrenos2c86c272005-03-23 17:32:29 -06006294 if (err) {
6295 printk(KERN_WARNING DRV_NAME
6296 "Error calling pci_set_dma_mask.\n");
6297 pci_disable_device(pci_dev);
6298 return err;
6299 }
6300
6301 err = pci_request_regions(pci_dev, DRV_NAME);
6302 if (err) {
6303 printk(KERN_WARNING DRV_NAME
6304 "Error calling pci_request_regions.\n");
6305 pci_disable_device(pci_dev);
6306 return err;
6307 }
6308
James Ketrenosee8e3652005-09-14 09:47:29 -05006309 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos2c86c272005-03-23 17:32:29 -06006310 * PCI Tx retries from interfering with C3 CPU state */
6311 pci_read_config_dword(pci_dev, 0x40, &val);
6312 if ((val & 0x0000ff00) != 0)
6313 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6314
Pavel Machek8724a112005-06-20 14:28:43 -07006315 pci_set_power_state(pci_dev, PCI_D0);
James Ketrenos2c86c272005-03-23 17:32:29 -06006316
6317 if (!ipw2100_hw_is_adapter_in_system(dev)) {
6318 printk(KERN_WARNING DRV_NAME
6319 "Device not found via register read.\n");
6320 err = -ENODEV;
6321 goto fail;
6322 }
6323
6324 SET_NETDEV_DEV(dev, &pci_dev->dev);
6325
6326 /* Force interrupts to be shut off on the device */
6327 priv->status |= STATUS_INT_ENABLED;
6328 ipw2100_disable_interrupts(priv);
6329
6330 /* Allocate and initialize the Tx/Rx queues and lists */
6331 if (ipw2100_queues_allocate(priv)) {
6332 printk(KERN_WARNING DRV_NAME
Zhu Yi90c009a2006-12-05 14:41:32 +08006333 "Error calling ipw2100_queues_allocate.\n");
James Ketrenos2c86c272005-03-23 17:32:29 -06006334 err = -ENOMEM;
6335 goto fail;
6336 }
6337 ipw2100_queues_initialize(priv);
6338
6339 err = request_irq(pci_dev->irq,
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07006340 ipw2100_interrupt, IRQF_SHARED, dev->name, priv);
James Ketrenos2c86c272005-03-23 17:32:29 -06006341 if (err) {
6342 printk(KERN_WARNING DRV_NAME
James Ketrenosee8e3652005-09-14 09:47:29 -05006343 "Error calling request_irq: %d.\n", pci_dev->irq);
James Ketrenos2c86c272005-03-23 17:32:29 -06006344 goto fail;
6345 }
6346 dev->irq = pci_dev->irq;
6347
6348 IPW_DEBUG_INFO("Attempting to register device...\n");
6349
James Ketrenos2c86c272005-03-23 17:32:29 -06006350 printk(KERN_INFO DRV_NAME
6351 ": Detected Intel PRO/Wireless 2100 Network Connection\n");
6352
6353 /* Bring up the interface. Pre 0.46, after we registered the
6354 * network device we would call ipw2100_up. This introduced a race
6355 * condition with newer hotplug configurations (network was coming
6356 * up and making calls before the device was initialized).
6357 *
6358 * If we called ipw2100_up before we registered the device, then the
6359 * device name wasn't registered. So, we instead use the net_dev->init
6360 * member to call a function that then just turns and calls ipw2100_up.
6361 * net_dev->init is called after name allocation but before the
6362 * notifier chain is called */
James Ketrenos2c86c272005-03-23 17:32:29 -06006363 err = register_netdev(dev);
6364 if (err) {
6365 printk(KERN_WARNING DRV_NAME
6366 "Error calling register_netdev.\n");
Zhu Yiefbd8092006-08-21 11:38:52 +08006367 goto fail;
James Ketrenos2c86c272005-03-23 17:32:29 -06006368 }
Zhu Yiefbd8092006-08-21 11:38:52 +08006369
6370 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006371 registered = 1;
6372
6373 IPW_DEBUG_INFO("%s: Bound to %s\n", dev->name, pci_name(pci_dev));
6374
6375 /* perform this after register_netdev so that dev->name is set */
Jeff Garzikde897882006-10-01 07:31:09 -04006376 err = sysfs_create_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6377 if (err)
6378 goto fail_unlock;
James Ketrenos2c86c272005-03-23 17:32:29 -06006379
6380 /* If the RF Kill switch is disabled, go ahead and complete the
6381 * startup sequence */
6382 if (!(priv->status & STATUS_RF_KILL_MASK)) {
6383 /* Enable the adapter - sends HOST_COMPLETE */
6384 if (ipw2100_enable_adapter(priv)) {
6385 printk(KERN_WARNING DRV_NAME
6386 ": %s: failed in call to enable adapter.\n",
6387 priv->net_dev->name);
6388 ipw2100_hw_stop_adapter(priv);
6389 err = -EIO;
6390 goto fail_unlock;
6391 }
6392
6393 /* Start a scan . . . */
6394 ipw2100_set_scan_options(priv);
6395 ipw2100_start_scan(priv);
6396 }
6397
6398 IPW_DEBUG_INFO("exit\n");
6399
6400 priv->status |= STATUS_INITIALIZED;
6401
Ingo Molnar752e3772006-02-28 07:20:54 +08006402 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006403
6404 return 0;
6405
James Ketrenosee8e3652005-09-14 09:47:29 -05006406 fail_unlock:
Ingo Molnar752e3772006-02-28 07:20:54 +08006407 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006408
James Ketrenosee8e3652005-09-14 09:47:29 -05006409 fail:
James Ketrenos2c86c272005-03-23 17:32:29 -06006410 if (dev) {
John W. Linville143d40f2009-11-06 12:58:20 -05006411 if (registered)
James Ketrenos2c86c272005-03-23 17:32:29 -06006412 unregister_netdev(dev);
6413
6414 ipw2100_hw_stop_adapter(priv);
6415
6416 ipw2100_disable_interrupts(priv);
6417
6418 if (dev->irq)
6419 free_irq(dev->irq, priv);
6420
6421 ipw2100_kill_workqueue(priv);
6422
6423 /* These are safe to call even if they weren't allocated */
6424 ipw2100_queues_free(priv);
James Ketrenosee8e3652005-09-14 09:47:29 -05006425 sysfs_remove_group(&pci_dev->dev.kobj,
6426 &ipw2100_attribute_group);
James Ketrenos2c86c272005-03-23 17:32:29 -06006427
Pavel Roskin27ae60f2010-03-12 00:01:22 -05006428 free_libipw(dev, 0);
James Ketrenos2c86c272005-03-23 17:32:29 -06006429 pci_set_drvdata(pci_dev, NULL);
6430 }
6431
6432 if (base_addr)
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01006433 iounmap(base_addr);
James Ketrenos2c86c272005-03-23 17:32:29 -06006434
6435 pci_release_regions(pci_dev);
6436 pci_disable_device(pci_dev);
6437
6438 return err;
6439}
6440
6441static void __devexit ipw2100_pci_remove_one(struct pci_dev *pci_dev)
6442{
6443 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6444 struct net_device *dev;
6445
6446 if (priv) {
Ingo Molnar752e3772006-02-28 07:20:54 +08006447 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006448
6449 priv->status &= ~STATUS_INITIALIZED;
6450
6451 dev = priv->net_dev;
James Ketrenosee8e3652005-09-14 09:47:29 -05006452 sysfs_remove_group(&pci_dev->dev.kobj,
6453 &ipw2100_attribute_group);
James Ketrenos2c86c272005-03-23 17:32:29 -06006454
6455#ifdef CONFIG_PM
6456 if (ipw2100_firmware.version)
6457 ipw2100_release_firmware(priv, &ipw2100_firmware);
6458#endif
6459 /* Take down the hardware */
6460 ipw2100_down(priv);
6461
Ingo Molnar752e3772006-02-28 07:20:54 +08006462 /* Release the mutex so that the network subsystem can
James Ketrenos2c86c272005-03-23 17:32:29 -06006463 * complete any needed calls into the driver... */
Ingo Molnar752e3772006-02-28 07:20:54 +08006464 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006465
6466 /* Unregister the device first - this results in close()
6467 * being called if the device is open. If we free storage
6468 * first, then close() will crash. */
6469 unregister_netdev(dev);
6470
6471 /* ipw2100_down will ensure that there is no more pending work
6472 * in the workqueue's, so we can safely remove them now. */
6473 ipw2100_kill_workqueue(priv);
6474
6475 ipw2100_queues_free(priv);
6476
6477 /* Free potential debugging firmware snapshot */
6478 ipw2100_snapshot_free(priv);
6479
6480 if (dev->irq)
6481 free_irq(dev->irq, priv);
6482
6483 if (dev->base_addr)
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01006484 iounmap((void __iomem *)dev->base_addr);
James Ketrenos2c86c272005-03-23 17:32:29 -06006485
Pavel Roskin27ae60f2010-03-12 00:01:22 -05006486 /* wiphy_unregister needs to be here, before free_libipw */
Matthew Garrettc26409a2009-11-11 14:36:30 -05006487 wiphy_unregister(priv->ieee->wdev.wiphy);
6488 kfree(priv->ieee->bg_band.channels);
Pavel Roskin27ae60f2010-03-12 00:01:22 -05006489 free_libipw(dev, 0);
James Ketrenos2c86c272005-03-23 17:32:29 -06006490 }
6491
6492 pci_release_regions(pci_dev);
6493 pci_disable_device(pci_dev);
6494
6495 IPW_DEBUG_INFO("exit\n");
6496}
6497
James Ketrenos2c86c272005-03-23 17:32:29 -06006498#ifdef CONFIG_PM
James Ketrenos2c86c272005-03-23 17:32:29 -06006499static int ipw2100_suspend(struct pci_dev *pci_dev, pm_message_t state)
James Ketrenos2c86c272005-03-23 17:32:29 -06006500{
6501 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6502 struct net_device *dev = priv->net_dev;
6503
James Ketrenosee8e3652005-09-14 09:47:29 -05006504 IPW_DEBUG_INFO("%s: Going into suspend...\n", dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06006505
Ingo Molnar752e3772006-02-28 07:20:54 +08006506 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006507 if (priv->status & STATUS_INITIALIZED) {
6508 /* Take down the device; powers it off, etc. */
6509 ipw2100_down(priv);
6510 }
6511
6512 /* Remove the PRESENT state of the device */
6513 netif_device_detach(dev);
6514
James Ketrenos2c86c272005-03-23 17:32:29 -06006515 pci_save_state(pci_dev);
James Ketrenosee8e3652005-09-14 09:47:29 -05006516 pci_disable_device(pci_dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006517 pci_set_power_state(pci_dev, PCI_D3hot);
James Ketrenos2c86c272005-03-23 17:32:29 -06006518
Dan Williamsc3d72b92009-02-11 13:26:06 -05006519 priv->suspend_at = get_seconds();
6520
Ingo Molnar752e3772006-02-28 07:20:54 +08006521 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006522
6523 return 0;
6524}
6525
6526static int ipw2100_resume(struct pci_dev *pci_dev)
6527{
6528 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6529 struct net_device *dev = priv->net_dev;
John W. Linville02e0e5e2006-11-07 20:53:48 -05006530 int err;
James Ketrenos2c86c272005-03-23 17:32:29 -06006531 u32 val;
6532
6533 if (IPW2100_PM_DISABLED)
6534 return 0;
6535
Ingo Molnar752e3772006-02-28 07:20:54 +08006536 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006537
James Ketrenosee8e3652005-09-14 09:47:29 -05006538 IPW_DEBUG_INFO("%s: Coming out of suspend...\n", dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06006539
James Ketrenos2c86c272005-03-23 17:32:29 -06006540 pci_set_power_state(pci_dev, PCI_D0);
John W. Linville02e0e5e2006-11-07 20:53:48 -05006541 err = pci_enable_device(pci_dev);
6542 if (err) {
6543 printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
6544 dev->name);
Julia Lawall80c42af2008-07-21 09:58:11 +02006545 mutex_unlock(&priv->action_mutex);
John W. Linville02e0e5e2006-11-07 20:53:48 -05006546 return err;
6547 }
James Ketrenos2c86c272005-03-23 17:32:29 -06006548 pci_restore_state(pci_dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006549
6550 /*
6551 * Suspend/Resume resets the PCI configuration space, so we have to
6552 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
6553 * from interfering with C3 CPU state. pci_restore_state won't help
6554 * here since it only restores the first 64 bytes pci config header.
6555 */
6556 pci_read_config_dword(pci_dev, 0x40, &val);
6557 if ((val & 0x0000ff00) != 0)
6558 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6559
6560 /* Set the device back into the PRESENT state; this will also wake
6561 * the queue of needed */
6562 netif_device_attach(dev);
6563
Dan Williamsc3d72b92009-02-11 13:26:06 -05006564 priv->suspend_time = get_seconds() - priv->suspend_at;
6565
James Ketrenosee8e3652005-09-14 09:47:29 -05006566 /* Bring the device back up */
6567 if (!(priv->status & STATUS_RF_KILL_SW))
6568 ipw2100_up(priv, 0);
James Ketrenos2c86c272005-03-23 17:32:29 -06006569
Ingo Molnar752e3772006-02-28 07:20:54 +08006570 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006571
6572 return 0;
6573}
6574#endif
6575
Zhu Yi52ce3e9a72009-12-02 14:24:37 +08006576static void ipw2100_shutdown(struct pci_dev *pci_dev)
6577{
6578 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6579
6580 /* Take down the device; powers it off, etc. */
6581 ipw2100_down(priv);
6582
6583 pci_disable_device(pci_dev);
6584}
6585
James Ketrenos2c86c272005-03-23 17:32:29 -06006586#define IPW2100_DEV_ID(x) { PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, x }
6587
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006588static DEFINE_PCI_DEVICE_TABLE(ipw2100_pci_id_table) = {
James Ketrenosee8e3652005-09-14 09:47:29 -05006589 IPW2100_DEV_ID(0x2520), /* IN 2100A mPCI 3A */
6590 IPW2100_DEV_ID(0x2521), /* IN 2100A mPCI 3B */
6591 IPW2100_DEV_ID(0x2524), /* IN 2100A mPCI 3B */
6592 IPW2100_DEV_ID(0x2525), /* IN 2100A mPCI 3B */
6593 IPW2100_DEV_ID(0x2526), /* IN 2100A mPCI Gen A3 */
6594 IPW2100_DEV_ID(0x2522), /* IN 2100 mPCI 3B */
6595 IPW2100_DEV_ID(0x2523), /* IN 2100 mPCI 3A */
6596 IPW2100_DEV_ID(0x2527), /* IN 2100 mPCI 3B */
6597 IPW2100_DEV_ID(0x2528), /* IN 2100 mPCI 3B */
6598 IPW2100_DEV_ID(0x2529), /* IN 2100 mPCI 3B */
6599 IPW2100_DEV_ID(0x252B), /* IN 2100 mPCI 3A */
6600 IPW2100_DEV_ID(0x252C), /* IN 2100 mPCI 3A */
6601 IPW2100_DEV_ID(0x252D), /* IN 2100 mPCI 3A */
James Ketrenos2c86c272005-03-23 17:32:29 -06006602
James Ketrenosee8e3652005-09-14 09:47:29 -05006603 IPW2100_DEV_ID(0x2550), /* IB 2100A mPCI 3B */
6604 IPW2100_DEV_ID(0x2551), /* IB 2100 mPCI 3B */
6605 IPW2100_DEV_ID(0x2553), /* IB 2100 mPCI 3B */
6606 IPW2100_DEV_ID(0x2554), /* IB 2100 mPCI 3B */
6607 IPW2100_DEV_ID(0x2555), /* IB 2100 mPCI 3B */
James Ketrenos2c86c272005-03-23 17:32:29 -06006608
James Ketrenosee8e3652005-09-14 09:47:29 -05006609 IPW2100_DEV_ID(0x2560), /* DE 2100A mPCI 3A */
6610 IPW2100_DEV_ID(0x2562), /* DE 2100A mPCI 3A */
6611 IPW2100_DEV_ID(0x2563), /* DE 2100A mPCI 3A */
6612 IPW2100_DEV_ID(0x2561), /* DE 2100 mPCI 3A */
6613 IPW2100_DEV_ID(0x2565), /* DE 2100 mPCI 3A */
6614 IPW2100_DEV_ID(0x2566), /* DE 2100 mPCI 3A */
6615 IPW2100_DEV_ID(0x2567), /* DE 2100 mPCI 3A */
James Ketrenos2c86c272005-03-23 17:32:29 -06006616
James Ketrenosee8e3652005-09-14 09:47:29 -05006617 IPW2100_DEV_ID(0x2570), /* GA 2100 mPCI 3B */
James Ketrenos2c86c272005-03-23 17:32:29 -06006618
James Ketrenosee8e3652005-09-14 09:47:29 -05006619 IPW2100_DEV_ID(0x2580), /* TO 2100A mPCI 3B */
6620 IPW2100_DEV_ID(0x2582), /* TO 2100A mPCI 3B */
6621 IPW2100_DEV_ID(0x2583), /* TO 2100A mPCI 3B */
6622 IPW2100_DEV_ID(0x2581), /* TO 2100 mPCI 3B */
6623 IPW2100_DEV_ID(0x2585), /* TO 2100 mPCI 3B */
6624 IPW2100_DEV_ID(0x2586), /* TO 2100 mPCI 3B */
6625 IPW2100_DEV_ID(0x2587), /* TO 2100 mPCI 3B */
James Ketrenos2c86c272005-03-23 17:32:29 -06006626
James Ketrenosee8e3652005-09-14 09:47:29 -05006627 IPW2100_DEV_ID(0x2590), /* SO 2100A mPCI 3B */
6628 IPW2100_DEV_ID(0x2592), /* SO 2100A mPCI 3B */
6629 IPW2100_DEV_ID(0x2591), /* SO 2100 mPCI 3B */
6630 IPW2100_DEV_ID(0x2593), /* SO 2100 mPCI 3B */
6631 IPW2100_DEV_ID(0x2596), /* SO 2100 mPCI 3B */
6632 IPW2100_DEV_ID(0x2598), /* SO 2100 mPCI 3B */
James Ketrenos2c86c272005-03-23 17:32:29 -06006633
James Ketrenosee8e3652005-09-14 09:47:29 -05006634 IPW2100_DEV_ID(0x25A0), /* HP 2100 mPCI 3B */
James Ketrenos2c86c272005-03-23 17:32:29 -06006635 {0,},
6636};
6637
6638MODULE_DEVICE_TABLE(pci, ipw2100_pci_id_table);
6639
6640static struct pci_driver ipw2100_pci_driver = {
6641 .name = DRV_NAME,
6642 .id_table = ipw2100_pci_id_table,
6643 .probe = ipw2100_pci_init_one,
6644 .remove = __devexit_p(ipw2100_pci_remove_one),
6645#ifdef CONFIG_PM
6646 .suspend = ipw2100_suspend,
6647 .resume = ipw2100_resume,
6648#endif
Zhu Yi52ce3e9a72009-12-02 14:24:37 +08006649 .shutdown = ipw2100_shutdown,
James Ketrenos2c86c272005-03-23 17:32:29 -06006650};
6651
James Ketrenos2c86c272005-03-23 17:32:29 -06006652/**
6653 * Initialize the ipw2100 driver/module
6654 *
6655 * @returns 0 if ok, < 0 errno node con error.
6656 *
6657 * Note: we cannot init the /proc stuff until the PCI driver is there,
6658 * or we risk an unlikely race condition on someone accessing
6659 * uninitialized data in the PCI dev struct through /proc.
6660 */
6661static int __init ipw2100_init(void)
6662{
6663 int ret;
6664
6665 printk(KERN_INFO DRV_NAME ": %s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
6666 printk(KERN_INFO DRV_NAME ": %s\n", DRV_COPYRIGHT);
6667
Jeff Garzik29917622006-08-19 17:48:59 -04006668 ret = pci_register_driver(&ipw2100_pci_driver);
Jeff Garzikde897882006-10-01 07:31:09 -04006669 if (ret)
6670 goto out;
James Ketrenos2c86c272005-03-23 17:32:29 -06006671
Mark Grossed771342010-05-06 01:59:26 +02006672 ipw2100_pm_qos_req = pm_qos_add_request(PM_QOS_CPU_DMA_LATENCY,
Mark Grossf011e2e2008-02-04 22:30:09 -08006673 PM_QOS_DEFAULT_VALUE);
Brice Goglin0f52bf92005-12-01 01:41:46 -08006674#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06006675 ipw2100_debug_level = debug;
Jeff Garzikde897882006-10-01 07:31:09 -04006676 ret = driver_create_file(&ipw2100_pci_driver.driver,
6677 &driver_attr_debug_level);
James Ketrenos2c86c272005-03-23 17:32:29 -06006678#endif
6679
Jeff Garzikde897882006-10-01 07:31:09 -04006680out:
James Ketrenos2c86c272005-03-23 17:32:29 -06006681 return ret;
6682}
6683
James Ketrenos2c86c272005-03-23 17:32:29 -06006684/**
6685 * Cleanup ipw2100 driver registration
6686 */
6687static void __exit ipw2100_exit(void)
6688{
6689 /* FIXME: IPG: check that we have no instances of the devices open */
Brice Goglin0f52bf92005-12-01 01:41:46 -08006690#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06006691 driver_remove_file(&ipw2100_pci_driver.driver,
6692 &driver_attr_debug_level);
6693#endif
6694 pci_unregister_driver(&ipw2100_pci_driver);
Mark Grossed771342010-05-06 01:59:26 +02006695 pm_qos_remove_request(ipw2100_pm_qos_req);
James Ketrenos2c86c272005-03-23 17:32:29 -06006696}
6697
6698module_init(ipw2100_init);
6699module_exit(ipw2100_exit);
6700
James Ketrenos2c86c272005-03-23 17:32:29 -06006701static int ipw2100_wx_get_name(struct net_device *dev,
6702 struct iw_request_info *info,
6703 union iwreq_data *wrqu, char *extra)
6704{
6705 /*
6706 * This can be called at any time. No action lock required
6707 */
6708
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006709 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006710 if (!(priv->status & STATUS_ASSOCIATED))
6711 strcpy(wrqu->name, "unassociated");
6712 else
6713 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
6714
6715 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
6716 return 0;
6717}
6718
James Ketrenos2c86c272005-03-23 17:32:29 -06006719static int ipw2100_wx_set_freq(struct net_device *dev,
6720 struct iw_request_info *info,
6721 union iwreq_data *wrqu, char *extra)
6722{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006723 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006724 struct iw_freq *fwrq = &wrqu->freq;
6725 int err = 0;
6726
6727 if (priv->ieee->iw_mode == IW_MODE_INFRA)
6728 return -EOPNOTSUPP;
6729
Ingo Molnar752e3772006-02-28 07:20:54 +08006730 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006731 if (!(priv->status & STATUS_INITIALIZED)) {
6732 err = -EIO;
6733 goto done;
6734 }
6735
6736 /* if setting by freq convert to channel */
6737 if (fwrq->e == 1) {
James Ketrenosee8e3652005-09-14 09:47:29 -05006738 if ((fwrq->m >= (int)2.412e8 && fwrq->m <= (int)2.487e8)) {
James Ketrenos2c86c272005-03-23 17:32:29 -06006739 int f = fwrq->m / 100000;
6740 int c = 0;
6741
6742 while ((c < REG_MAX_CHANNEL) &&
6743 (f != ipw2100_frequencies[c]))
6744 c++;
6745
6746 /* hack to fall through */
6747 fwrq->e = 0;
6748 fwrq->m = c + 1;
6749 }
6750 }
6751
James Ketrenos82328352005-08-24 22:33:31 -05006752 if (fwrq->e > 0 || fwrq->m > 1000) {
6753 err = -EOPNOTSUPP;
6754 goto done;
6755 } else { /* Set the channel */
Frans Pop9fd1ea42010-03-24 19:46:31 +01006756 IPW_DEBUG_WX("SET Freq/Channel -> %d\n", fwrq->m);
James Ketrenos2c86c272005-03-23 17:32:29 -06006757 err = ipw2100_set_channel(priv, fwrq->m, 0);
6758 }
6759
James Ketrenosee8e3652005-09-14 09:47:29 -05006760 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08006761 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006762 return err;
6763}
6764
James Ketrenos2c86c272005-03-23 17:32:29 -06006765static int ipw2100_wx_get_freq(struct net_device *dev,
6766 struct iw_request_info *info,
6767 union iwreq_data *wrqu, char *extra)
6768{
6769 /*
6770 * This can be called at any time. No action lock required
6771 */
6772
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006773 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006774
6775 wrqu->freq.e = 0;
6776
6777 /* If we are associated, trying to associate, or have a statically
6778 * configured CHANNEL then return that; otherwise return ANY */
6779 if (priv->config & CFG_STATIC_CHANNEL ||
6780 priv->status & STATUS_ASSOCIATED)
6781 wrqu->freq.m = priv->channel;
6782 else
6783 wrqu->freq.m = 0;
6784
Frans Pop9fd1ea42010-03-24 19:46:31 +01006785 IPW_DEBUG_WX("GET Freq/Channel -> %d\n", priv->channel);
James Ketrenos2c86c272005-03-23 17:32:29 -06006786 return 0;
6787
6788}
6789
6790static int ipw2100_wx_set_mode(struct net_device *dev,
6791 struct iw_request_info *info,
6792 union iwreq_data *wrqu, char *extra)
6793{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006794 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006795 int err = 0;
6796
Frans Pop9fd1ea42010-03-24 19:46:31 +01006797 IPW_DEBUG_WX("SET Mode -> %d\n", wrqu->mode);
James Ketrenos2c86c272005-03-23 17:32:29 -06006798
6799 if (wrqu->mode == priv->ieee->iw_mode)
6800 return 0;
6801
Ingo Molnar752e3772006-02-28 07:20:54 +08006802 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006803 if (!(priv->status & STATUS_INITIALIZED)) {
6804 err = -EIO;
6805 goto done;
6806 }
6807
6808 switch (wrqu->mode) {
6809#ifdef CONFIG_IPW2100_MONITOR
6810 case IW_MODE_MONITOR:
6811 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
6812 break;
James Ketrenosee8e3652005-09-14 09:47:29 -05006813#endif /* CONFIG_IPW2100_MONITOR */
James Ketrenos2c86c272005-03-23 17:32:29 -06006814 case IW_MODE_ADHOC:
6815 err = ipw2100_switch_mode(priv, IW_MODE_ADHOC);
6816 break;
6817 case IW_MODE_INFRA:
6818 case IW_MODE_AUTO:
6819 default:
6820 err = ipw2100_switch_mode(priv, IW_MODE_INFRA);
6821 break;
6822 }
6823
James Ketrenosee8e3652005-09-14 09:47:29 -05006824 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08006825 mutex_unlock(&priv->action_mutex);
James Ketrenosee8e3652005-09-14 09:47:29 -05006826 return err;
James Ketrenos2c86c272005-03-23 17:32:29 -06006827}
6828
6829static int ipw2100_wx_get_mode(struct net_device *dev,
6830 struct iw_request_info *info,
6831 union iwreq_data *wrqu, char *extra)
6832{
6833 /*
6834 * This can be called at any time. No action lock required
6835 */
6836
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006837 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006838
6839 wrqu->mode = priv->ieee->iw_mode;
6840 IPW_DEBUG_WX("GET Mode -> %d\n", wrqu->mode);
6841
6842 return 0;
6843}
6844
James Ketrenos2c86c272005-03-23 17:32:29 -06006845#define POWER_MODES 5
6846
6847/* Values are in microsecond */
Jiri Bencc4aee8c2005-08-25 20:04:43 -04006848static const s32 timeout_duration[POWER_MODES] = {
James Ketrenos2c86c272005-03-23 17:32:29 -06006849 350000,
6850 250000,
6851 75000,
6852 37000,
6853 25000,
6854};
6855
Jiri Bencc4aee8c2005-08-25 20:04:43 -04006856static const s32 period_duration[POWER_MODES] = {
James Ketrenos2c86c272005-03-23 17:32:29 -06006857 400000,
6858 700000,
6859 1000000,
6860 1000000,
6861 1000000
6862};
6863
6864static int ipw2100_wx_get_range(struct net_device *dev,
6865 struct iw_request_info *info,
6866 union iwreq_data *wrqu, char *extra)
6867{
6868 /*
6869 * This can be called at any time. No action lock required
6870 */
6871
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006872 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006873 struct iw_range *range = (struct iw_range *)extra;
6874 u16 val;
6875 int i, level;
6876
6877 wrqu->data.length = sizeof(*range);
6878 memset(range, 0, sizeof(*range));
6879
6880 /* Let's try to keep this struct in the same order as in
6881 * linux/include/wireless.h
6882 */
6883
6884 /* TODO: See what values we can set, and remove the ones we can't
6885 * set, or fill them with some default data.
6886 */
6887
6888 /* ~5 Mb/s real (802.11b) */
6889 range->throughput = 5 * 1000 * 1000;
6890
James Ketrenosee8e3652005-09-14 09:47:29 -05006891// range->sensitivity; /* signal level threshold range */
James Ketrenos2c86c272005-03-23 17:32:29 -06006892
6893 range->max_qual.qual = 100;
6894 /* TODO: Find real max RSSI and stick here */
6895 range->max_qual.level = 0;
6896 range->max_qual.noise = 0;
James Ketrenosee8e3652005-09-14 09:47:29 -05006897 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos2c86c272005-03-23 17:32:29 -06006898
James Ketrenosee8e3652005-09-14 09:47:29 -05006899 range->avg_qual.qual = 70; /* > 8% missed beacons is 'bad' */
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006900 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
James Ketrenos2c86c272005-03-23 17:32:29 -06006901 range->avg_qual.level = 20 + IPW2100_RSSI_TO_DBM;
6902 range->avg_qual.noise = 0;
James Ketrenosee8e3652005-09-14 09:47:29 -05006903 range->avg_qual.updated = 7; /* Updated all three */
James Ketrenos2c86c272005-03-23 17:32:29 -06006904
6905 range->num_bitrates = RATE_COUNT;
6906
6907 for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++) {
6908 range->bitrate[i] = ipw2100_rates_11b[i];
6909 }
6910
6911 range->min_rts = MIN_RTS_THRESHOLD;
6912 range->max_rts = MAX_RTS_THRESHOLD;
6913 range->min_frag = MIN_FRAG_THRESHOLD;
6914 range->max_frag = MAX_FRAG_THRESHOLD;
6915
6916 range->min_pmp = period_duration[0]; /* Minimal PM period */
James Ketrenosee8e3652005-09-14 09:47:29 -05006917 range->max_pmp = period_duration[POWER_MODES - 1]; /* Maximal PM period */
6918 range->min_pmt = timeout_duration[POWER_MODES - 1]; /* Minimal PM timeout */
6919 range->max_pmt = timeout_duration[0]; /* Maximal PM timeout */
James Ketrenos2c86c272005-03-23 17:32:29 -06006920
James Ketrenosee8e3652005-09-14 09:47:29 -05006921 /* How to decode max/min PM period */
James Ketrenos2c86c272005-03-23 17:32:29 -06006922 range->pmp_flags = IW_POWER_PERIOD;
James Ketrenosee8e3652005-09-14 09:47:29 -05006923 /* How to decode max/min PM period */
James Ketrenos2c86c272005-03-23 17:32:29 -06006924 range->pmt_flags = IW_POWER_TIMEOUT;
6925 /* What PM options are supported */
6926 range->pm_capa = IW_POWER_TIMEOUT | IW_POWER_PERIOD;
6927
6928 range->encoding_size[0] = 5;
James Ketrenosee8e3652005-09-14 09:47:29 -05006929 range->encoding_size[1] = 13; /* Different token sizes */
6930 range->num_encoding_sizes = 2; /* Number of entry in the list */
6931 range->max_encoding_tokens = WEP_KEYS; /* Max number of tokens */
6932// range->encoding_login_index; /* token index for login token */
James Ketrenos2c86c272005-03-23 17:32:29 -06006933
6934 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6935 range->txpower_capa = IW_TXPOW_DBM;
6936 range->num_txpower = IW_MAX_TXPOWER;
James Ketrenosee8e3652005-09-14 09:47:29 -05006937 for (i = 0, level = (IPW_TX_POWER_MAX_DBM * 16);
6938 i < IW_MAX_TXPOWER;
6939 i++, level -=
6940 ((IPW_TX_POWER_MAX_DBM -
6941 IPW_TX_POWER_MIN_DBM) * 16) / (IW_MAX_TXPOWER - 1))
James Ketrenos2c86c272005-03-23 17:32:29 -06006942 range->txpower[i] = level / 16;
6943 } else {
6944 range->txpower_capa = 0;
6945 range->num_txpower = 0;
6946 }
6947
James Ketrenos2c86c272005-03-23 17:32:29 -06006948 /* Set the Wireless Extension versions */
6949 range->we_version_compiled = WIRELESS_EXT;
Dan Williams166c3432006-01-09 11:04:31 -05006950 range->we_version_source = 18;
James Ketrenos2c86c272005-03-23 17:32:29 -06006951
James Ketrenosee8e3652005-09-14 09:47:29 -05006952// range->retry_capa; /* What retry options are supported */
6953// range->retry_flags; /* How to decode max/min retry limit */
6954// range->r_time_flags; /* How to decode max/min retry life */
6955// range->min_retry; /* Minimal number of retries */
6956// range->max_retry; /* Maximal number of retries */
6957// range->min_r_time; /* Minimal retry lifetime */
6958// range->max_r_time; /* Maximal retry lifetime */
James Ketrenos2c86c272005-03-23 17:32:29 -06006959
James Ketrenosee8e3652005-09-14 09:47:29 -05006960 range->num_channels = FREQ_COUNT;
James Ketrenos2c86c272005-03-23 17:32:29 -06006961
6962 val = 0;
6963 for (i = 0; i < FREQ_COUNT; i++) {
6964 // TODO: Include only legal frequencies for some countries
James Ketrenosee8e3652005-09-14 09:47:29 -05006965// if (local->channel_mask & (1 << i)) {
6966 range->freq[val].i = i + 1;
6967 range->freq[val].m = ipw2100_frequencies[i] * 100000;
6968 range->freq[val].e = 1;
6969 val++;
6970// }
James Ketrenos2c86c272005-03-23 17:32:29 -06006971 if (val == IW_MAX_FREQUENCIES)
James Ketrenosee8e3652005-09-14 09:47:29 -05006972 break;
James Ketrenos2c86c272005-03-23 17:32:29 -06006973 }
6974 range->num_frequency = val;
6975
James Ketrenoseaf8f53b2005-11-12 12:50:12 -06006976 /* Event capability (kernel + driver) */
6977 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
6978 IW_EVENT_CAPA_MASK(SIOCGIWAP));
6979 range->event_capa[1] = IW_EVENT_CAPA_K_1;
6980
Dan Williams166c3432006-01-09 11:04:31 -05006981 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
6982 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
6983
James Ketrenos2c86c272005-03-23 17:32:29 -06006984 IPW_DEBUG_WX("GET Range\n");
6985
6986 return 0;
6987}
6988
6989static int ipw2100_wx_set_wap(struct net_device *dev,
6990 struct iw_request_info *info,
6991 union iwreq_data *wrqu, char *extra)
6992{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006993 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006994 int err = 0;
6995
6996 static const unsigned char any[] = {
6997 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
6998 };
6999 static const unsigned char off[] = {
7000 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
7001 };
7002
7003 // sanity checks
7004 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
7005 return -EINVAL;
7006
Ingo Molnar752e3772006-02-28 07:20:54 +08007007 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007008 if (!(priv->status & STATUS_INITIALIZED)) {
7009 err = -EIO;
7010 goto done;
7011 }
7012
7013 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
7014 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
7015 /* we disable mandatory BSSID association */
7016 IPW_DEBUG_WX("exit - disable mandatory BSSID\n");
7017 priv->config &= ~CFG_STATIC_BSSID;
7018 err = ipw2100_set_mandatory_bssid(priv, NULL, 0);
7019 goto done;
7020 }
7021
7022 priv->config |= CFG_STATIC_BSSID;
7023 memcpy(priv->mandatory_bssid_mac, wrqu->ap_addr.sa_data, ETH_ALEN);
7024
7025 err = ipw2100_set_mandatory_bssid(priv, wrqu->ap_addr.sa_data, 0);
7026
Johannes Berge1749612008-10-27 15:59:26 -07007027 IPW_DEBUG_WX("SET BSSID -> %pM\n", wrqu->ap_addr.sa_data);
James Ketrenos2c86c272005-03-23 17:32:29 -06007028
James Ketrenosee8e3652005-09-14 09:47:29 -05007029 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007030 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007031 return err;
7032}
7033
7034static int ipw2100_wx_get_wap(struct net_device *dev,
7035 struct iw_request_info *info,
7036 union iwreq_data *wrqu, char *extra)
7037{
7038 /*
7039 * This can be called at any time. No action lock required
7040 */
7041
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007042 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007043
7044 /* If we are associated, trying to associate, or have a statically
7045 * configured BSSID then return that; otherwise return ANY */
James Ketrenosee8e3652005-09-14 09:47:29 -05007046 if (priv->config & CFG_STATIC_BSSID || priv->status & STATUS_ASSOCIATED) {
James Ketrenos2c86c272005-03-23 17:32:29 -06007047 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenos82328352005-08-24 22:33:31 -05007048 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos2c86c272005-03-23 17:32:29 -06007049 } else
7050 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
7051
Johannes Berge1749612008-10-27 15:59:26 -07007052 IPW_DEBUG_WX("Getting WAP BSSID: %pM\n", wrqu->ap_addr.sa_data);
James Ketrenos2c86c272005-03-23 17:32:29 -06007053 return 0;
7054}
7055
7056static int ipw2100_wx_set_essid(struct net_device *dev,
7057 struct iw_request_info *info,
7058 union iwreq_data *wrqu, char *extra)
7059{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007060 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenosee8e3652005-09-14 09:47:29 -05007061 char *essid = ""; /* ANY */
James Ketrenos2c86c272005-03-23 17:32:29 -06007062 int length = 0;
7063 int err = 0;
John W. Linville9387b7c2008-09-30 20:59:05 -04007064 DECLARE_SSID_BUF(ssid);
James Ketrenos2c86c272005-03-23 17:32:29 -06007065
Ingo Molnar752e3772006-02-28 07:20:54 +08007066 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007067 if (!(priv->status & STATUS_INITIALIZED)) {
7068 err = -EIO;
7069 goto done;
7070 }
7071
7072 if (wrqu->essid.flags && wrqu->essid.length) {
Jean Tourrilhes5b63bae2006-08-29 18:00:48 -07007073 length = wrqu->essid.length;
James Ketrenos2c86c272005-03-23 17:32:29 -06007074 essid = extra;
7075 }
7076
7077 if (length == 0) {
7078 IPW_DEBUG_WX("Setting ESSID to ANY\n");
7079 priv->config &= ~CFG_STATIC_ESSID;
7080 err = ipw2100_set_essid(priv, NULL, 0, 0);
7081 goto done;
7082 }
7083
7084 length = min(length, IW_ESSID_MAX_SIZE);
7085
7086 priv->config |= CFG_STATIC_ESSID;
7087
7088 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
7089 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
7090 err = 0;
7091 goto done;
7092 }
7093
John W. Linville9387b7c2008-09-30 20:59:05 -04007094 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n",
7095 print_ssid(ssid, essid, length), length);
James Ketrenos2c86c272005-03-23 17:32:29 -06007096
7097 priv->essid_len = length;
7098 memcpy(priv->essid, essid, priv->essid_len);
7099
7100 err = ipw2100_set_essid(priv, essid, length, 0);
7101
James Ketrenosee8e3652005-09-14 09:47:29 -05007102 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007103 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007104 return err;
7105}
7106
7107static int ipw2100_wx_get_essid(struct net_device *dev,
7108 struct iw_request_info *info,
7109 union iwreq_data *wrqu, char *extra)
7110{
7111 /*
7112 * This can be called at any time. No action lock required
7113 */
7114
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007115 struct ipw2100_priv *priv = libipw_priv(dev);
John W. Linville9387b7c2008-09-30 20:59:05 -04007116 DECLARE_SSID_BUF(ssid);
James Ketrenos2c86c272005-03-23 17:32:29 -06007117
7118 /* If we are associated, trying to associate, or have a statically
7119 * configured ESSID then return that; otherwise return ANY */
James Ketrenosee8e3652005-09-14 09:47:29 -05007120 if (priv->config & CFG_STATIC_ESSID || priv->status & STATUS_ASSOCIATED) {
James Ketrenos2c86c272005-03-23 17:32:29 -06007121 IPW_DEBUG_WX("Getting essid: '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04007122 print_ssid(ssid, priv->essid, priv->essid_len));
James Ketrenos2c86c272005-03-23 17:32:29 -06007123 memcpy(extra, priv->essid, priv->essid_len);
7124 wrqu->essid.length = priv->essid_len;
James Ketrenosee8e3652005-09-14 09:47:29 -05007125 wrqu->essid.flags = 1; /* active */
James Ketrenos2c86c272005-03-23 17:32:29 -06007126 } else {
7127 IPW_DEBUG_WX("Getting essid: ANY\n");
7128 wrqu->essid.length = 0;
James Ketrenosee8e3652005-09-14 09:47:29 -05007129 wrqu->essid.flags = 0; /* active */
James Ketrenos2c86c272005-03-23 17:32:29 -06007130 }
7131
7132 return 0;
7133}
7134
7135static int ipw2100_wx_set_nick(struct net_device *dev,
7136 struct iw_request_info *info,
7137 union iwreq_data *wrqu, char *extra)
7138{
7139 /*
7140 * This can be called at any time. No action lock required
7141 */
7142
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007143 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007144
7145 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
7146 return -E2BIG;
7147
James Ketrenosee8e3652005-09-14 09:47:29 -05007148 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos2c86c272005-03-23 17:32:29 -06007149 memset(priv->nick, 0, sizeof(priv->nick));
James Ketrenosee8e3652005-09-14 09:47:29 -05007150 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos2c86c272005-03-23 17:32:29 -06007151
Frans Pop9fd1ea42010-03-24 19:46:31 +01007152 IPW_DEBUG_WX("SET Nickname -> %s\n", priv->nick);
James Ketrenos2c86c272005-03-23 17:32:29 -06007153
7154 return 0;
7155}
7156
7157static int ipw2100_wx_get_nick(struct net_device *dev,
7158 struct iw_request_info *info,
7159 union iwreq_data *wrqu, char *extra)
7160{
7161 /*
7162 * This can be called at any time. No action lock required
7163 */
7164
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007165 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007166
Jean Tourrilhes5b63bae2006-08-29 18:00:48 -07007167 wrqu->data.length = strlen(priv->nick);
James Ketrenos2c86c272005-03-23 17:32:29 -06007168 memcpy(extra, priv->nick, wrqu->data.length);
James Ketrenosee8e3652005-09-14 09:47:29 -05007169 wrqu->data.flags = 1; /* active */
James Ketrenos2c86c272005-03-23 17:32:29 -06007170
Frans Pop9fd1ea42010-03-24 19:46:31 +01007171 IPW_DEBUG_WX("GET Nickname -> %s\n", extra);
James Ketrenos2c86c272005-03-23 17:32:29 -06007172
7173 return 0;
7174}
7175
7176static int ipw2100_wx_set_rate(struct net_device *dev,
7177 struct iw_request_info *info,
7178 union iwreq_data *wrqu, char *extra)
7179{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007180 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007181 u32 target_rate = wrqu->bitrate.value;
7182 u32 rate;
7183 int err = 0;
7184
Ingo Molnar752e3772006-02-28 07:20:54 +08007185 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007186 if (!(priv->status & STATUS_INITIALIZED)) {
7187 err = -EIO;
7188 goto done;
7189 }
7190
7191 rate = 0;
7192
7193 if (target_rate == 1000000 ||
7194 (!wrqu->bitrate.fixed && target_rate > 1000000))
7195 rate |= TX_RATE_1_MBIT;
7196 if (target_rate == 2000000 ||
7197 (!wrqu->bitrate.fixed && target_rate > 2000000))
7198 rate |= TX_RATE_2_MBIT;
7199 if (target_rate == 5500000 ||
7200 (!wrqu->bitrate.fixed && target_rate > 5500000))
7201 rate |= TX_RATE_5_5_MBIT;
7202 if (target_rate == 11000000 ||
7203 (!wrqu->bitrate.fixed && target_rate > 11000000))
7204 rate |= TX_RATE_11_MBIT;
7205 if (rate == 0)
7206 rate = DEFAULT_TX_RATES;
7207
7208 err = ipw2100_set_tx_rates(priv, rate, 0);
7209
Frans Pop9fd1ea42010-03-24 19:46:31 +01007210 IPW_DEBUG_WX("SET Rate -> %04X\n", rate);
James Ketrenosee8e3652005-09-14 09:47:29 -05007211 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007212 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007213 return err;
7214}
7215
James Ketrenos2c86c272005-03-23 17:32:29 -06007216static int ipw2100_wx_get_rate(struct net_device *dev,
7217 struct iw_request_info *info,
7218 union iwreq_data *wrqu, char *extra)
7219{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007220 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007221 int val;
Hannes Ederb9da9e92009-02-14 11:50:26 +00007222 unsigned int len = sizeof(val);
James Ketrenos2c86c272005-03-23 17:32:29 -06007223 int err = 0;
7224
7225 if (!(priv->status & STATUS_ENABLED) ||
7226 priv->status & STATUS_RF_KILL_MASK ||
7227 !(priv->status & STATUS_ASSOCIATED)) {
7228 wrqu->bitrate.value = 0;
7229 return 0;
7230 }
7231
Ingo Molnar752e3772006-02-28 07:20:54 +08007232 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007233 if (!(priv->status & STATUS_INITIALIZED)) {
7234 err = -EIO;
7235 goto done;
7236 }
7237
7238 err = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &val, &len);
7239 if (err) {
7240 IPW_DEBUG_WX("failed querying ordinals.\n");
Julia Lawall80c42af2008-07-21 09:58:11 +02007241 goto done;
James Ketrenos2c86c272005-03-23 17:32:29 -06007242 }
7243
7244 switch (val & TX_RATE_MASK) {
7245 case TX_RATE_1_MBIT:
7246 wrqu->bitrate.value = 1000000;
7247 break;
7248 case TX_RATE_2_MBIT:
7249 wrqu->bitrate.value = 2000000;
7250 break;
7251 case TX_RATE_5_5_MBIT:
7252 wrqu->bitrate.value = 5500000;
7253 break;
7254 case TX_RATE_11_MBIT:
7255 wrqu->bitrate.value = 11000000;
7256 break;
7257 default:
7258 wrqu->bitrate.value = 0;
7259 }
7260
Frans Pop9fd1ea42010-03-24 19:46:31 +01007261 IPW_DEBUG_WX("GET Rate -> %d\n", wrqu->bitrate.value);
James Ketrenos2c86c272005-03-23 17:32:29 -06007262
James Ketrenosee8e3652005-09-14 09:47:29 -05007263 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007264 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007265 return err;
7266}
7267
7268static int ipw2100_wx_set_rts(struct net_device *dev,
7269 struct iw_request_info *info,
7270 union iwreq_data *wrqu, char *extra)
7271{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007272 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007273 int value, err;
7274
7275 /* Auto RTS not yet supported */
7276 if (wrqu->rts.fixed == 0)
7277 return -EINVAL;
7278
Ingo Molnar752e3772006-02-28 07:20:54 +08007279 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007280 if (!(priv->status & STATUS_INITIALIZED)) {
7281 err = -EIO;
7282 goto done;
7283 }
7284
7285 if (wrqu->rts.disabled)
7286 value = priv->rts_threshold | RTS_DISABLED;
7287 else {
James Ketrenosee8e3652005-09-14 09:47:29 -05007288 if (wrqu->rts.value < 1 || wrqu->rts.value > 2304) {
James Ketrenos2c86c272005-03-23 17:32:29 -06007289 err = -EINVAL;
7290 goto done;
7291 }
7292 value = wrqu->rts.value;
7293 }
7294
7295 err = ipw2100_set_rts_threshold(priv, value);
7296
Frans Pop9fd1ea42010-03-24 19:46:31 +01007297 IPW_DEBUG_WX("SET RTS Threshold -> 0x%08X\n", value);
James Ketrenosee8e3652005-09-14 09:47:29 -05007298 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007299 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007300 return err;
7301}
7302
7303static int ipw2100_wx_get_rts(struct net_device *dev,
7304 struct iw_request_info *info,
7305 union iwreq_data *wrqu, char *extra)
7306{
7307 /*
7308 * This can be called at any time. No action lock required
7309 */
7310
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007311 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007312
7313 wrqu->rts.value = priv->rts_threshold & ~RTS_DISABLED;
James Ketrenosee8e3652005-09-14 09:47:29 -05007314 wrqu->rts.fixed = 1; /* no auto select */
James Ketrenos2c86c272005-03-23 17:32:29 -06007315
7316 /* If RTS is set to the default value, then it is disabled */
7317 wrqu->rts.disabled = (priv->rts_threshold & RTS_DISABLED) ? 1 : 0;
7318
Frans Pop9fd1ea42010-03-24 19:46:31 +01007319 IPW_DEBUG_WX("GET RTS Threshold -> 0x%08X\n", wrqu->rts.value);
James Ketrenos2c86c272005-03-23 17:32:29 -06007320
7321 return 0;
7322}
7323
7324static int ipw2100_wx_set_txpow(struct net_device *dev,
7325 struct iw_request_info *info,
7326 union iwreq_data *wrqu, char *extra)
7327{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007328 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007329 int err = 0, value;
Zhu Yib6e4da72006-01-24 13:49:32 +08007330
7331 if (ipw_radio_kill_sw(priv, wrqu->txpower.disabled))
7332 return -EINPROGRESS;
James Ketrenos2c86c272005-03-23 17:32:29 -06007333
7334 if (priv->ieee->iw_mode != IW_MODE_ADHOC)
Zhu Yib6e4da72006-01-24 13:49:32 +08007335 return 0;
7336
7337 if ((wrqu->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
James Ketrenos2c86c272005-03-23 17:32:29 -06007338 return -EINVAL;
7339
Zhu Yib6e4da72006-01-24 13:49:32 +08007340 if (wrqu->txpower.fixed == 0)
James Ketrenos2c86c272005-03-23 17:32:29 -06007341 value = IPW_TX_POWER_DEFAULT;
7342 else {
7343 if (wrqu->txpower.value < IPW_TX_POWER_MIN_DBM ||
7344 wrqu->txpower.value > IPW_TX_POWER_MAX_DBM)
7345 return -EINVAL;
7346
Liu Hongf75459e2005-07-13 12:29:21 -05007347 value = wrqu->txpower.value;
James Ketrenos2c86c272005-03-23 17:32:29 -06007348 }
7349
Ingo Molnar752e3772006-02-28 07:20:54 +08007350 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007351 if (!(priv->status & STATUS_INITIALIZED)) {
7352 err = -EIO;
7353 goto done;
7354 }
7355
7356 err = ipw2100_set_tx_power(priv, value);
7357
Frans Pop9fd1ea42010-03-24 19:46:31 +01007358 IPW_DEBUG_WX("SET TX Power -> %d\n", value);
James Ketrenos2c86c272005-03-23 17:32:29 -06007359
James Ketrenosee8e3652005-09-14 09:47:29 -05007360 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007361 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007362 return err;
7363}
7364
7365static int ipw2100_wx_get_txpow(struct net_device *dev,
7366 struct iw_request_info *info,
7367 union iwreq_data *wrqu, char *extra)
7368{
7369 /*
7370 * This can be called at any time. No action lock required
7371 */
7372
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007373 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007374
Zhu Yib6e4da72006-01-24 13:49:32 +08007375 wrqu->txpower.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
James Ketrenos2c86c272005-03-23 17:32:29 -06007376
7377 if (priv->tx_power == IPW_TX_POWER_DEFAULT) {
Zhu Yib6e4da72006-01-24 13:49:32 +08007378 wrqu->txpower.fixed = 0;
7379 wrqu->txpower.value = IPW_TX_POWER_MAX_DBM;
James Ketrenos2c86c272005-03-23 17:32:29 -06007380 } else {
Zhu Yib6e4da72006-01-24 13:49:32 +08007381 wrqu->txpower.fixed = 1;
7382 wrqu->txpower.value = priv->tx_power;
James Ketrenos2c86c272005-03-23 17:32:29 -06007383 }
7384
Zhu Yib6e4da72006-01-24 13:49:32 +08007385 wrqu->txpower.flags = IW_TXPOW_DBM;
James Ketrenos2c86c272005-03-23 17:32:29 -06007386
Frans Pop9fd1ea42010-03-24 19:46:31 +01007387 IPW_DEBUG_WX("GET TX Power -> %d\n", wrqu->txpower.value);
James Ketrenos2c86c272005-03-23 17:32:29 -06007388
7389 return 0;
7390}
7391
7392static int ipw2100_wx_set_frag(struct net_device *dev,
7393 struct iw_request_info *info,
7394 union iwreq_data *wrqu, char *extra)
7395{
7396 /*
7397 * This can be called at any time. No action lock required
7398 */
7399
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007400 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007401
7402 if (!wrqu->frag.fixed)
7403 return -EINVAL;
7404
7405 if (wrqu->frag.disabled) {
7406 priv->frag_threshold |= FRAG_DISABLED;
7407 priv->ieee->fts = DEFAULT_FTS;
7408 } else {
7409 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
7410 wrqu->frag.value > MAX_FRAG_THRESHOLD)
7411 return -EINVAL;
7412
7413 priv->ieee->fts = wrqu->frag.value & ~0x1;
7414 priv->frag_threshold = priv->ieee->fts;
7415 }
7416
Frans Pop9fd1ea42010-03-24 19:46:31 +01007417 IPW_DEBUG_WX("SET Frag Threshold -> %d\n", priv->ieee->fts);
James Ketrenos2c86c272005-03-23 17:32:29 -06007418
7419 return 0;
7420}
7421
7422static int ipw2100_wx_get_frag(struct net_device *dev,
7423 struct iw_request_info *info,
7424 union iwreq_data *wrqu, char *extra)
7425{
7426 /*
7427 * This can be called at any time. No action lock required
7428 */
7429
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007430 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007431 wrqu->frag.value = priv->frag_threshold & ~FRAG_DISABLED;
7432 wrqu->frag.fixed = 0; /* no auto select */
7433 wrqu->frag.disabled = (priv->frag_threshold & FRAG_DISABLED) ? 1 : 0;
7434
Frans Pop9fd1ea42010-03-24 19:46:31 +01007435 IPW_DEBUG_WX("GET Frag Threshold -> %d\n", wrqu->frag.value);
James Ketrenos2c86c272005-03-23 17:32:29 -06007436
7437 return 0;
7438}
7439
7440static int ipw2100_wx_set_retry(struct net_device *dev,
7441 struct iw_request_info *info,
7442 union iwreq_data *wrqu, char *extra)
7443{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007444 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007445 int err = 0;
7446
James Ketrenosee8e3652005-09-14 09:47:29 -05007447 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
James Ketrenos2c86c272005-03-23 17:32:29 -06007448 return -EINVAL;
7449
7450 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
7451 return 0;
7452
Ingo Molnar752e3772006-02-28 07:20:54 +08007453 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007454 if (!(priv->status & STATUS_INITIALIZED)) {
7455 err = -EIO;
7456 goto done;
7457 }
7458
Jean Tourrilhes5b63bae2006-08-29 18:00:48 -07007459 if (wrqu->retry.flags & IW_RETRY_SHORT) {
James Ketrenos2c86c272005-03-23 17:32:29 -06007460 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
Frans Pop9fd1ea42010-03-24 19:46:31 +01007461 IPW_DEBUG_WX("SET Short Retry Limit -> %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05007462 wrqu->retry.value);
James Ketrenos2c86c272005-03-23 17:32:29 -06007463 goto done;
7464 }
7465
Jean Tourrilhes5b63bae2006-08-29 18:00:48 -07007466 if (wrqu->retry.flags & IW_RETRY_LONG) {
James Ketrenos2c86c272005-03-23 17:32:29 -06007467 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
Frans Pop9fd1ea42010-03-24 19:46:31 +01007468 IPW_DEBUG_WX("SET Long Retry Limit -> %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05007469 wrqu->retry.value);
James Ketrenos2c86c272005-03-23 17:32:29 -06007470 goto done;
7471 }
7472
7473 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7474 if (!err)
7475 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7476
Frans Pop9fd1ea42010-03-24 19:46:31 +01007477 IPW_DEBUG_WX("SET Both Retry Limits -> %d\n", wrqu->retry.value);
James Ketrenos2c86c272005-03-23 17:32:29 -06007478
James Ketrenosee8e3652005-09-14 09:47:29 -05007479 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007480 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007481 return err;
7482}
7483
7484static int ipw2100_wx_get_retry(struct net_device *dev,
7485 struct iw_request_info *info,
7486 union iwreq_data *wrqu, char *extra)
7487{
7488 /*
7489 * This can be called at any time. No action lock required
7490 */
7491
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007492 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007493
James Ketrenosee8e3652005-09-14 09:47:29 -05007494 wrqu->retry.disabled = 0; /* can't be disabled */
James Ketrenos2c86c272005-03-23 17:32:29 -06007495
James Ketrenosee8e3652005-09-14 09:47:29 -05007496 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME)
James Ketrenos2c86c272005-03-23 17:32:29 -06007497 return -EINVAL;
7498
Jean Tourrilhes5b63bae2006-08-29 18:00:48 -07007499 if (wrqu->retry.flags & IW_RETRY_LONG) {
7500 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
James Ketrenos2c86c272005-03-23 17:32:29 -06007501 wrqu->retry.value = priv->long_retry_limit;
7502 } else {
7503 wrqu->retry.flags =
7504 (priv->short_retry_limit !=
7505 priv->long_retry_limit) ?
Jean Tourrilhes5b63bae2006-08-29 18:00:48 -07007506 IW_RETRY_LIMIT | IW_RETRY_SHORT : IW_RETRY_LIMIT;
James Ketrenos2c86c272005-03-23 17:32:29 -06007507
7508 wrqu->retry.value = priv->short_retry_limit;
7509 }
7510
Frans Pop9fd1ea42010-03-24 19:46:31 +01007511 IPW_DEBUG_WX("GET Retry -> %d\n", wrqu->retry.value);
James Ketrenos2c86c272005-03-23 17:32:29 -06007512
7513 return 0;
7514}
7515
7516static int ipw2100_wx_set_scan(struct net_device *dev,
7517 struct iw_request_info *info,
7518 union iwreq_data *wrqu, char *extra)
7519{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007520 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007521 int err = 0;
7522
Ingo Molnar752e3772006-02-28 07:20:54 +08007523 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007524 if (!(priv->status & STATUS_INITIALIZED)) {
7525 err = -EIO;
7526 goto done;
7527 }
7528
7529 IPW_DEBUG_WX("Initiating scan...\n");
Dan Williamsd20c6782007-10-10 12:28:07 -04007530
7531 priv->user_requested_scan = 1;
James Ketrenosee8e3652005-09-14 09:47:29 -05007532 if (ipw2100_set_scan_options(priv) || ipw2100_start_scan(priv)) {
James Ketrenos2c86c272005-03-23 17:32:29 -06007533 IPW_DEBUG_WX("Start scan failed.\n");
7534
7535 /* TODO: Mark a scan as pending so when hardware initialized
7536 * a scan starts */
7537 }
7538
James Ketrenosee8e3652005-09-14 09:47:29 -05007539 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007540 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007541 return err;
7542}
7543
7544static int ipw2100_wx_get_scan(struct net_device *dev,
7545 struct iw_request_info *info,
7546 union iwreq_data *wrqu, char *extra)
7547{
7548 /*
7549 * This can be called at any time. No action lock required
7550 */
7551
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007552 struct ipw2100_priv *priv = libipw_priv(dev);
7553 return libipw_wx_get_scan(priv->ieee, info, wrqu, extra);
James Ketrenos2c86c272005-03-23 17:32:29 -06007554}
7555
James Ketrenos2c86c272005-03-23 17:32:29 -06007556/*
7557 * Implementation based on code in hostap-driver v0.1.3 hostap_ioctl.c
7558 */
7559static int ipw2100_wx_set_encode(struct net_device *dev,
7560 struct iw_request_info *info,
7561 union iwreq_data *wrqu, char *key)
7562{
7563 /*
7564 * No check of STATUS_INITIALIZED required
7565 */
7566
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007567 struct ipw2100_priv *priv = libipw_priv(dev);
7568 return libipw_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenos2c86c272005-03-23 17:32:29 -06007569}
7570
7571static int ipw2100_wx_get_encode(struct net_device *dev,
7572 struct iw_request_info *info,
7573 union iwreq_data *wrqu, char *key)
7574{
7575 /*
7576 * This can be called at any time. No action lock required
7577 */
7578
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007579 struct ipw2100_priv *priv = libipw_priv(dev);
7580 return libipw_wx_get_encode(priv->ieee, info, wrqu, key);
James Ketrenos2c86c272005-03-23 17:32:29 -06007581}
7582
7583static int ipw2100_wx_set_power(struct net_device *dev,
James Ketrenosee8e3652005-09-14 09:47:29 -05007584 struct iw_request_info *info,
7585 union iwreq_data *wrqu, char *extra)
James Ketrenos2c86c272005-03-23 17:32:29 -06007586{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007587 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007588 int err = 0;
7589
Ingo Molnar752e3772006-02-28 07:20:54 +08007590 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007591 if (!(priv->status & STATUS_INITIALIZED)) {
7592 err = -EIO;
7593 goto done;
7594 }
7595
7596 if (wrqu->power.disabled) {
7597 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
7598 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
7599 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
7600 goto done;
7601 }
7602
7603 switch (wrqu->power.flags & IW_POWER_MODE) {
James Ketrenosee8e3652005-09-14 09:47:29 -05007604 case IW_POWER_ON: /* If not specified */
7605 case IW_POWER_MODE: /* If set all mask */
Jean Delvarec03983a2007-10-19 23:22:55 +02007606 case IW_POWER_ALL_R: /* If explicitly state all */
James Ketrenos2c86c272005-03-23 17:32:29 -06007607 break;
James Ketrenosee8e3652005-09-14 09:47:29 -05007608 default: /* Otherwise we don't support it */
James Ketrenos2c86c272005-03-23 17:32:29 -06007609 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
7610 wrqu->power.flags);
7611 err = -EOPNOTSUPP;
7612 goto done;
7613 }
7614
7615 /* If the user hasn't specified a power management mode yet, default
7616 * to BATTERY */
7617 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
7618 err = ipw2100_set_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
7619
James Ketrenosee8e3652005-09-14 09:47:29 -05007620 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
James Ketrenos2c86c272005-03-23 17:32:29 -06007621
James Ketrenosee8e3652005-09-14 09:47:29 -05007622 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007623 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007624 return err;
7625
7626}
7627
7628static int ipw2100_wx_get_power(struct net_device *dev,
James Ketrenosee8e3652005-09-14 09:47:29 -05007629 struct iw_request_info *info,
7630 union iwreq_data *wrqu, char *extra)
James Ketrenos2c86c272005-03-23 17:32:29 -06007631{
7632 /*
7633 * This can be called at any time. No action lock required
7634 */
7635
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007636 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007637
James Ketrenos82328352005-08-24 22:33:31 -05007638 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos2c86c272005-03-23 17:32:29 -06007639 wrqu->power.disabled = 1;
James Ketrenos82328352005-08-24 22:33:31 -05007640 else {
James Ketrenos2c86c272005-03-23 17:32:29 -06007641 wrqu->power.disabled = 0;
7642 wrqu->power.flags = 0;
7643 }
7644
7645 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
7646
7647 return 0;
7648}
7649
James Ketrenos82328352005-08-24 22:33:31 -05007650/*
7651 * WE-18 WPA support
7652 */
7653
7654/* SIOCSIWGENIE */
7655static int ipw2100_wx_set_genie(struct net_device *dev,
7656 struct iw_request_info *info,
7657 union iwreq_data *wrqu, char *extra)
7658{
7659
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007660 struct ipw2100_priv *priv = libipw_priv(dev);
7661 struct libipw_device *ieee = priv->ieee;
James Ketrenos82328352005-08-24 22:33:31 -05007662 u8 *buf;
7663
7664 if (!ieee->wpa_enabled)
7665 return -EOPNOTSUPP;
7666
7667 if (wrqu->data.length > MAX_WPA_IE_LEN ||
7668 (wrqu->data.length && extra == NULL))
7669 return -EINVAL;
7670
7671 if (wrqu->data.length) {
Eric Sesterhennc3a9392e2006-10-23 22:20:15 +02007672 buf = kmemdup(extra, wrqu->data.length, GFP_KERNEL);
James Ketrenos82328352005-08-24 22:33:31 -05007673 if (buf == NULL)
7674 return -ENOMEM;
7675
James Ketrenos82328352005-08-24 22:33:31 -05007676 kfree(ieee->wpa_ie);
7677 ieee->wpa_ie = buf;
7678 ieee->wpa_ie_len = wrqu->data.length;
7679 } else {
7680 kfree(ieee->wpa_ie);
7681 ieee->wpa_ie = NULL;
7682 ieee->wpa_ie_len = 0;
7683 }
7684
7685 ipw2100_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
7686
7687 return 0;
7688}
7689
7690/* SIOCGIWGENIE */
7691static int ipw2100_wx_get_genie(struct net_device *dev,
7692 struct iw_request_info *info,
7693 union iwreq_data *wrqu, char *extra)
7694{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007695 struct ipw2100_priv *priv = libipw_priv(dev);
7696 struct libipw_device *ieee = priv->ieee;
James Ketrenos82328352005-08-24 22:33:31 -05007697
7698 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
7699 wrqu->data.length = 0;
7700 return 0;
7701 }
7702
7703 if (wrqu->data.length < ieee->wpa_ie_len)
7704 return -E2BIG;
7705
7706 wrqu->data.length = ieee->wpa_ie_len;
7707 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
7708
7709 return 0;
7710}
7711
7712/* SIOCSIWAUTH */
7713static int ipw2100_wx_set_auth(struct net_device *dev,
7714 struct iw_request_info *info,
7715 union iwreq_data *wrqu, char *extra)
7716{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007717 struct ipw2100_priv *priv = libipw_priv(dev);
7718 struct libipw_device *ieee = priv->ieee;
James Ketrenos82328352005-08-24 22:33:31 -05007719 struct iw_param *param = &wrqu->param;
John W. Linville274bfb82008-10-29 11:35:05 -04007720 struct lib80211_crypt_data *crypt;
James Ketrenos82328352005-08-24 22:33:31 -05007721 unsigned long flags;
7722 int ret = 0;
7723
7724 switch (param->flags & IW_AUTH_INDEX) {
7725 case IW_AUTH_WPA_VERSION:
7726 case IW_AUTH_CIPHER_PAIRWISE:
7727 case IW_AUTH_CIPHER_GROUP:
7728 case IW_AUTH_KEY_MGMT:
7729 /*
7730 * ipw2200 does not use these parameters
7731 */
7732 break;
7733
7734 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04007735 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00007736 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenos82328352005-08-24 22:33:31 -05007737 break;
James Ketrenos82328352005-08-24 22:33:31 -05007738
7739 flags = crypt->ops->get_flags(crypt->priv);
7740
7741 if (param->value)
7742 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
7743 else
7744 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
7745
7746 crypt->ops->set_flags(flags, crypt->priv);
7747
7748 break;
7749
7750 case IW_AUTH_DROP_UNENCRYPTED:{
7751 /* HACK:
7752 *
7753 * wpa_supplicant calls set_wpa_enabled when the driver
7754 * is loaded and unloaded, regardless of if WPA is being
7755 * used. No other calls are made which can be used to
7756 * determine if encryption will be used or not prior to
7757 * association being expected. If encryption is not being
7758 * used, drop_unencrypted is set to false, else true -- we
7759 * can use this to determine if the CAP_PRIVACY_ON bit should
7760 * be set.
7761 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007762 struct libipw_security sec = {
James Ketrenos82328352005-08-24 22:33:31 -05007763 .flags = SEC_ENABLED,
7764 .enabled = param->value,
7765 };
7766 priv->ieee->drop_unencrypted = param->value;
7767 /* We only change SEC_LEVEL for open mode. Others
7768 * are set by ipw_wpa_set_encryption.
7769 */
7770 if (!param->value) {
7771 sec.flags |= SEC_LEVEL;
7772 sec.level = SEC_LEVEL_0;
7773 } else {
7774 sec.flags |= SEC_LEVEL;
7775 sec.level = SEC_LEVEL_1;
7776 }
7777 if (priv->ieee->set_security)
7778 priv->ieee->set_security(priv->ieee->dev, &sec);
7779 break;
7780 }
7781
7782 case IW_AUTH_80211_AUTH_ALG:
7783 ret = ipw2100_wpa_set_auth_algs(priv, param->value);
7784 break;
7785
7786 case IW_AUTH_WPA_ENABLED:
7787 ret = ipw2100_wpa_enable(priv, param->value);
7788 break;
7789
7790 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
7791 ieee->ieee802_1x = param->value;
7792 break;
7793
7794 //case IW_AUTH_ROAMING_CONTROL:
7795 case IW_AUTH_PRIVACY_INVOKED:
7796 ieee->privacy_invoked = param->value;
7797 break;
7798
7799 default:
7800 return -EOPNOTSUPP;
7801 }
7802 return ret;
7803}
7804
7805/* SIOCGIWAUTH */
7806static int ipw2100_wx_get_auth(struct net_device *dev,
7807 struct iw_request_info *info,
7808 union iwreq_data *wrqu, char *extra)
7809{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007810 struct ipw2100_priv *priv = libipw_priv(dev);
7811 struct libipw_device *ieee = priv->ieee;
John W. Linville274bfb82008-10-29 11:35:05 -04007812 struct lib80211_crypt_data *crypt;
James Ketrenos82328352005-08-24 22:33:31 -05007813 struct iw_param *param = &wrqu->param;
7814 int ret = 0;
7815
7816 switch (param->flags & IW_AUTH_INDEX) {
7817 case IW_AUTH_WPA_VERSION:
7818 case IW_AUTH_CIPHER_PAIRWISE:
7819 case IW_AUTH_CIPHER_GROUP:
7820 case IW_AUTH_KEY_MGMT:
7821 /*
7822 * wpa_supplicant will control these internally
7823 */
7824 ret = -EOPNOTSUPP;
7825 break;
7826
7827 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04007828 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos82328352005-08-24 22:33:31 -05007829 if (!crypt || !crypt->ops->get_flags) {
7830 IPW_DEBUG_WARNING("Can't get TKIP countermeasures: "
7831 "crypt not set!\n");
7832 break;
7833 }
7834
7835 param->value = (crypt->ops->get_flags(crypt->priv) &
7836 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
7837
7838 break;
7839
7840 case IW_AUTH_DROP_UNENCRYPTED:
7841 param->value = ieee->drop_unencrypted;
7842 break;
7843
7844 case IW_AUTH_80211_AUTH_ALG:
25b645b2005-07-12 15:45:30 -05007845 param->value = priv->ieee->sec.auth_mode;
James Ketrenos82328352005-08-24 22:33:31 -05007846 break;
7847
7848 case IW_AUTH_WPA_ENABLED:
7849 param->value = ieee->wpa_enabled;
7850 break;
7851
7852 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
7853 param->value = ieee->ieee802_1x;
7854 break;
7855
7856 case IW_AUTH_ROAMING_CONTROL:
7857 case IW_AUTH_PRIVACY_INVOKED:
7858 param->value = ieee->privacy_invoked;
7859 break;
7860
7861 default:
7862 return -EOPNOTSUPP;
7863 }
7864 return 0;
7865}
7866
7867/* SIOCSIWENCODEEXT */
7868static int ipw2100_wx_set_encodeext(struct net_device *dev,
7869 struct iw_request_info *info,
7870 union iwreq_data *wrqu, char *extra)
7871{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007872 struct ipw2100_priv *priv = libipw_priv(dev);
7873 return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenos82328352005-08-24 22:33:31 -05007874}
7875
7876/* SIOCGIWENCODEEXT */
7877static int ipw2100_wx_get_encodeext(struct net_device *dev,
7878 struct iw_request_info *info,
7879 union iwreq_data *wrqu, char *extra)
7880{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007881 struct ipw2100_priv *priv = libipw_priv(dev);
7882 return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenos82328352005-08-24 22:33:31 -05007883}
7884
7885/* SIOCSIWMLME */
7886static int ipw2100_wx_set_mlme(struct net_device *dev,
7887 struct iw_request_info *info,
7888 union iwreq_data *wrqu, char *extra)
7889{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007890 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos82328352005-08-24 22:33:31 -05007891 struct iw_mlme *mlme = (struct iw_mlme *)extra;
Al Viro1edd3a52007-12-21 00:15:18 -05007892 __le16 reason;
James Ketrenos82328352005-08-24 22:33:31 -05007893
7894 reason = cpu_to_le16(mlme->reason_code);
7895
7896 switch (mlme->cmd) {
7897 case IW_MLME_DEAUTH:
7898 // silently ignore
7899 break;
7900
7901 case IW_MLME_DISASSOC:
7902 ipw2100_disassociate_bssid(priv);
7903 break;
7904
7905 default:
7906 return -EOPNOTSUPP;
7907 }
7908 return 0;
7909}
James Ketrenos2c86c272005-03-23 17:32:29 -06007910
7911/*
7912 *
7913 * IWPRIV handlers
7914 *
7915 */
7916#ifdef CONFIG_IPW2100_MONITOR
7917static int ipw2100_wx_set_promisc(struct net_device *dev,
7918 struct iw_request_info *info,
7919 union iwreq_data *wrqu, char *extra)
7920{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007921 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007922 int *parms = (int *)extra;
7923 int enable = (parms[0] > 0);
7924 int err = 0;
7925
Ingo Molnar752e3772006-02-28 07:20:54 +08007926 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007927 if (!(priv->status & STATUS_INITIALIZED)) {
7928 err = -EIO;
7929 goto done;
7930 }
7931
7932 if (enable) {
7933 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7934 err = ipw2100_set_channel(priv, parms[1], 0);
7935 goto done;
7936 }
7937 priv->channel = parms[1];
7938 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
7939 } else {
7940 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
7941 err = ipw2100_switch_mode(priv, priv->last_mode);
7942 }
James Ketrenosee8e3652005-09-14 09:47:29 -05007943 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007944 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007945 return err;
7946}
7947
7948static int ipw2100_wx_reset(struct net_device *dev,
7949 struct iw_request_info *info,
7950 union iwreq_data *wrqu, char *extra)
7951{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007952 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007953 if (priv->status & STATUS_INITIALIZED)
7954 schedule_reset(priv);
7955 return 0;
7956}
7957
7958#endif
7959
7960static int ipw2100_wx_set_powermode(struct net_device *dev,
7961 struct iw_request_info *info,
7962 union iwreq_data *wrqu, char *extra)
7963{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007964 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007965 int err = 0, mode = *(int *)extra;
7966
Ingo Molnar752e3772006-02-28 07:20:54 +08007967 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007968 if (!(priv->status & STATUS_INITIALIZED)) {
7969 err = -EIO;
7970 goto done;
7971 }
7972
Zhu Yi9f3b2412007-07-12 16:09:24 +08007973 if ((mode < 0) || (mode > POWER_MODES))
James Ketrenos2c86c272005-03-23 17:32:29 -06007974 mode = IPW_POWER_AUTO;
7975
Zhu Yi9f3b2412007-07-12 16:09:24 +08007976 if (IPW_POWER_LEVEL(priv->power_mode) != mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06007977 err = ipw2100_set_power_mode(priv, mode);
James Ketrenosee8e3652005-09-14 09:47:29 -05007978 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007979 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007980 return err;
7981}
7982
7983#define MAX_POWER_STRING 80
7984static int ipw2100_wx_get_powermode(struct net_device *dev,
7985 struct iw_request_info *info,
7986 union iwreq_data *wrqu, char *extra)
7987{
7988 /*
7989 * This can be called at any time. No action lock required
7990 */
7991
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007992 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007993 int level = IPW_POWER_LEVEL(priv->power_mode);
7994 s32 timeout, period;
7995
7996 if (!(priv->power_mode & IPW_POWER_ENABLED)) {
7997 snprintf(extra, MAX_POWER_STRING,
7998 "Power save level: %d (Off)", level);
7999 } else {
8000 switch (level) {
8001 case IPW_POWER_MODE_CAM:
8002 snprintf(extra, MAX_POWER_STRING,
8003 "Power save level: %d (None)", level);
8004 break;
8005 case IPW_POWER_AUTO:
James Ketrenosee8e3652005-09-14 09:47:29 -05008006 snprintf(extra, MAX_POWER_STRING,
Zhu Yi9f3b2412007-07-12 16:09:24 +08008007 "Power save level: %d (Auto)", level);
James Ketrenos2c86c272005-03-23 17:32:29 -06008008 break;
8009 default:
8010 timeout = timeout_duration[level - 1] / 1000;
8011 period = period_duration[level - 1] / 1000;
8012 snprintf(extra, MAX_POWER_STRING,
8013 "Power save level: %d "
8014 "(Timeout %dms, Period %dms)",
8015 level, timeout, period);
8016 }
8017 }
8018
8019 wrqu->data.length = strlen(extra) + 1;
8020
8021 return 0;
8022}
8023
James Ketrenos2c86c272005-03-23 17:32:29 -06008024static int ipw2100_wx_set_preamble(struct net_device *dev,
8025 struct iw_request_info *info,
8026 union iwreq_data *wrqu, char *extra)
8027{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008028 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06008029 int err, mode = *(int *)extra;
8030
Ingo Molnar752e3772006-02-28 07:20:54 +08008031 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06008032 if (!(priv->status & STATUS_INITIALIZED)) {
8033 err = -EIO;
8034 goto done;
8035 }
8036
8037 if (mode == 1)
8038 priv->config |= CFG_LONG_PREAMBLE;
8039 else if (mode == 0)
8040 priv->config &= ~CFG_LONG_PREAMBLE;
8041 else {
8042 err = -EINVAL;
8043 goto done;
8044 }
8045
8046 err = ipw2100_system_config(priv, 0);
8047
James Ketrenosee8e3652005-09-14 09:47:29 -05008048 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08008049 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06008050 return err;
8051}
8052
8053static int ipw2100_wx_get_preamble(struct net_device *dev,
James Ketrenosee8e3652005-09-14 09:47:29 -05008054 struct iw_request_info *info,
8055 union iwreq_data *wrqu, char *extra)
James Ketrenos2c86c272005-03-23 17:32:29 -06008056{
8057 /*
8058 * This can be called at any time. No action lock required
8059 */
8060
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008061 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06008062
8063 if (priv->config & CFG_LONG_PREAMBLE)
8064 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
8065 else
8066 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
8067
8068 return 0;
8069}
8070
James Ketrenos82328352005-08-24 22:33:31 -05008071#ifdef CONFIG_IPW2100_MONITOR
8072static int ipw2100_wx_set_crc_check(struct net_device *dev,
8073 struct iw_request_info *info,
8074 union iwreq_data *wrqu, char *extra)
James Ketrenos2c86c272005-03-23 17:32:29 -06008075{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008076 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos82328352005-08-24 22:33:31 -05008077 int err, mode = *(int *)extra;
8078
Ingo Molnar752e3772006-02-28 07:20:54 +08008079 mutex_lock(&priv->action_mutex);
James Ketrenos82328352005-08-24 22:33:31 -05008080 if (!(priv->status & STATUS_INITIALIZED)) {
8081 err = -EIO;
8082 goto done;
8083 }
8084
8085 if (mode == 1)
8086 priv->config |= CFG_CRC_CHECK;
8087 else if (mode == 0)
8088 priv->config &= ~CFG_CRC_CHECK;
8089 else {
8090 err = -EINVAL;
8091 goto done;
8092 }
8093 err = 0;
8094
8095 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08008096 mutex_unlock(&priv->action_mutex);
James Ketrenos82328352005-08-24 22:33:31 -05008097 return err;
8098}
8099
8100static int ipw2100_wx_get_crc_check(struct net_device *dev,
8101 struct iw_request_info *info,
8102 union iwreq_data *wrqu, char *extra)
8103{
8104 /*
8105 * This can be called at any time. No action lock required
8106 */
8107
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008108 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos82328352005-08-24 22:33:31 -05008109
8110 if (priv->config & CFG_CRC_CHECK)
8111 snprintf(wrqu->name, IFNAMSIZ, "CRC checked (1)");
8112 else
8113 snprintf(wrqu->name, IFNAMSIZ, "CRC ignored (0)");
8114
8115 return 0;
8116}
8117#endif /* CONFIG_IPW2100_MONITOR */
8118
James Ketrenosee8e3652005-09-14 09:47:29 -05008119static iw_handler ipw2100_wx_handlers[] = {
8120 NULL, /* SIOCSIWCOMMIT */
8121 ipw2100_wx_get_name, /* SIOCGIWNAME */
8122 NULL, /* SIOCSIWNWID */
8123 NULL, /* SIOCGIWNWID */
8124 ipw2100_wx_set_freq, /* SIOCSIWFREQ */
8125 ipw2100_wx_get_freq, /* SIOCGIWFREQ */
8126 ipw2100_wx_set_mode, /* SIOCSIWMODE */
8127 ipw2100_wx_get_mode, /* SIOCGIWMODE */
8128 NULL, /* SIOCSIWSENS */
8129 NULL, /* SIOCGIWSENS */
8130 NULL, /* SIOCSIWRANGE */
8131 ipw2100_wx_get_range, /* SIOCGIWRANGE */
8132 NULL, /* SIOCSIWPRIV */
8133 NULL, /* SIOCGIWPRIV */
8134 NULL, /* SIOCSIWSTATS */
8135 NULL, /* SIOCGIWSTATS */
8136 NULL, /* SIOCSIWSPY */
8137 NULL, /* SIOCGIWSPY */
8138 NULL, /* SIOCGIWTHRSPY */
8139 NULL, /* SIOCWIWTHRSPY */
8140 ipw2100_wx_set_wap, /* SIOCSIWAP */
8141 ipw2100_wx_get_wap, /* SIOCGIWAP */
James Ketrenos82328352005-08-24 22:33:31 -05008142 ipw2100_wx_set_mlme, /* SIOCSIWMLME */
James Ketrenosee8e3652005-09-14 09:47:29 -05008143 NULL, /* SIOCGIWAPLIST -- deprecated */
8144 ipw2100_wx_set_scan, /* SIOCSIWSCAN */
8145 ipw2100_wx_get_scan, /* SIOCGIWSCAN */
8146 ipw2100_wx_set_essid, /* SIOCSIWESSID */
8147 ipw2100_wx_get_essid, /* SIOCGIWESSID */
8148 ipw2100_wx_set_nick, /* SIOCSIWNICKN */
8149 ipw2100_wx_get_nick, /* SIOCGIWNICKN */
8150 NULL, /* -- hole -- */
8151 NULL, /* -- hole -- */
8152 ipw2100_wx_set_rate, /* SIOCSIWRATE */
8153 ipw2100_wx_get_rate, /* SIOCGIWRATE */
8154 ipw2100_wx_set_rts, /* SIOCSIWRTS */
8155 ipw2100_wx_get_rts, /* SIOCGIWRTS */
8156 ipw2100_wx_set_frag, /* SIOCSIWFRAG */
8157 ipw2100_wx_get_frag, /* SIOCGIWFRAG */
8158 ipw2100_wx_set_txpow, /* SIOCSIWTXPOW */
8159 ipw2100_wx_get_txpow, /* SIOCGIWTXPOW */
8160 ipw2100_wx_set_retry, /* SIOCSIWRETRY */
8161 ipw2100_wx_get_retry, /* SIOCGIWRETRY */
8162 ipw2100_wx_set_encode, /* SIOCSIWENCODE */
8163 ipw2100_wx_get_encode, /* SIOCGIWENCODE */
8164 ipw2100_wx_set_power, /* SIOCSIWPOWER */
8165 ipw2100_wx_get_power, /* SIOCGIWPOWER */
James Ketrenos82328352005-08-24 22:33:31 -05008166 NULL, /* -- hole -- */
8167 NULL, /* -- hole -- */
8168 ipw2100_wx_set_genie, /* SIOCSIWGENIE */
8169 ipw2100_wx_get_genie, /* SIOCGIWGENIE */
8170 ipw2100_wx_set_auth, /* SIOCSIWAUTH */
8171 ipw2100_wx_get_auth, /* SIOCGIWAUTH */
8172 ipw2100_wx_set_encodeext, /* SIOCSIWENCODEEXT */
8173 ipw2100_wx_get_encodeext, /* SIOCGIWENCODEEXT */
8174 NULL, /* SIOCSIWPMKSA */
James Ketrenos2c86c272005-03-23 17:32:29 -06008175};
8176
8177#define IPW2100_PRIV_SET_MONITOR SIOCIWFIRSTPRIV
8178#define IPW2100_PRIV_RESET SIOCIWFIRSTPRIV+1
8179#define IPW2100_PRIV_SET_POWER SIOCIWFIRSTPRIV+2
8180#define IPW2100_PRIV_GET_POWER SIOCIWFIRSTPRIV+3
8181#define IPW2100_PRIV_SET_LONGPREAMBLE SIOCIWFIRSTPRIV+4
8182#define IPW2100_PRIV_GET_LONGPREAMBLE SIOCIWFIRSTPRIV+5
James Ketrenos82328352005-08-24 22:33:31 -05008183#define IPW2100_PRIV_SET_CRC_CHECK SIOCIWFIRSTPRIV+6
8184#define IPW2100_PRIV_GET_CRC_CHECK SIOCIWFIRSTPRIV+7
James Ketrenos2c86c272005-03-23 17:32:29 -06008185
8186static const struct iw_priv_args ipw2100_private_args[] = {
8187
8188#ifdef CONFIG_IPW2100_MONITOR
8189 {
James Ketrenosee8e3652005-09-14 09:47:29 -05008190 IPW2100_PRIV_SET_MONITOR,
8191 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
James Ketrenos2c86c272005-03-23 17:32:29 -06008192 {
James Ketrenosee8e3652005-09-14 09:47:29 -05008193 IPW2100_PRIV_RESET,
8194 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
8195#endif /* CONFIG_IPW2100_MONITOR */
James Ketrenos2c86c272005-03-23 17:32:29 -06008196
8197 {
James Ketrenosee8e3652005-09-14 09:47:29 -05008198 IPW2100_PRIV_SET_POWER,
8199 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_power"},
James Ketrenos2c86c272005-03-23 17:32:29 -06008200 {
James Ketrenosee8e3652005-09-14 09:47:29 -05008201 IPW2100_PRIV_GET_POWER,
8202 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_POWER_STRING,
8203 "get_power"},
James Ketrenos2c86c272005-03-23 17:32:29 -06008204 {
James Ketrenosee8e3652005-09-14 09:47:29 -05008205 IPW2100_PRIV_SET_LONGPREAMBLE,
8206 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_preamble"},
James Ketrenos2c86c272005-03-23 17:32:29 -06008207 {
James Ketrenosee8e3652005-09-14 09:47:29 -05008208 IPW2100_PRIV_GET_LONGPREAMBLE,
8209 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_preamble"},
James Ketrenos82328352005-08-24 22:33:31 -05008210#ifdef CONFIG_IPW2100_MONITOR
8211 {
8212 IPW2100_PRIV_SET_CRC_CHECK,
8213 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_crc_check"},
8214 {
8215 IPW2100_PRIV_GET_CRC_CHECK,
8216 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_crc_check"},
8217#endif /* CONFIG_IPW2100_MONITOR */
James Ketrenos2c86c272005-03-23 17:32:29 -06008218};
8219
8220static iw_handler ipw2100_private_handler[] = {
8221#ifdef CONFIG_IPW2100_MONITOR
8222 ipw2100_wx_set_promisc,
8223 ipw2100_wx_reset,
James Ketrenosee8e3652005-09-14 09:47:29 -05008224#else /* CONFIG_IPW2100_MONITOR */
James Ketrenos2c86c272005-03-23 17:32:29 -06008225 NULL,
8226 NULL,
James Ketrenosee8e3652005-09-14 09:47:29 -05008227#endif /* CONFIG_IPW2100_MONITOR */
James Ketrenos2c86c272005-03-23 17:32:29 -06008228 ipw2100_wx_set_powermode,
8229 ipw2100_wx_get_powermode,
8230 ipw2100_wx_set_preamble,
8231 ipw2100_wx_get_preamble,
James Ketrenos82328352005-08-24 22:33:31 -05008232#ifdef CONFIG_IPW2100_MONITOR
8233 ipw2100_wx_set_crc_check,
8234 ipw2100_wx_get_crc_check,
8235#else /* CONFIG_IPW2100_MONITOR */
8236 NULL,
8237 NULL,
8238#endif /* CONFIG_IPW2100_MONITOR */
James Ketrenos2c86c272005-03-23 17:32:29 -06008239};
8240
James Ketrenos2c86c272005-03-23 17:32:29 -06008241/*
8242 * Get wireless statistics.
8243 * Called by /proc/net/wireless
8244 * Also called by SIOCGIWSTATS
8245 */
James Ketrenosee8e3652005-09-14 09:47:29 -05008246static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device *dev)
James Ketrenos2c86c272005-03-23 17:32:29 -06008247{
8248 enum {
8249 POOR = 30,
8250 FAIR = 60,
8251 GOOD = 80,
8252 VERY_GOOD = 90,
8253 EXCELLENT = 95,
8254 PERFECT = 100
8255 };
8256 int rssi_qual;
8257 int tx_qual;
8258 int beacon_qual;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008259 int quality;
James Ketrenos2c86c272005-03-23 17:32:29 -06008260
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008261 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06008262 struct iw_statistics *wstats;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008263 u32 rssi, tx_retries, missed_beacons, tx_failures;
James Ketrenos2c86c272005-03-23 17:32:29 -06008264 u32 ord_len = sizeof(u32);
8265
8266 if (!priv)
James Ketrenosee8e3652005-09-14 09:47:29 -05008267 return (struct iw_statistics *)NULL;
James Ketrenos2c86c272005-03-23 17:32:29 -06008268
8269 wstats = &priv->wstats;
8270
8271 /* if hw is disabled, then ipw2100_get_ordinal() can't be called.
8272 * ipw2100_wx_wireless_stats seems to be called before fw is
8273 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
8274 * and associated; if not associcated, the values are all meaningless
8275 * anyway, so set them all to NULL and INVALID */
8276 if (!(priv->status & STATUS_ASSOCIATED)) {
8277 wstats->miss.beacon = 0;
8278 wstats->discard.retries = 0;
8279 wstats->qual.qual = 0;
8280 wstats->qual.level = 0;
8281 wstats->qual.noise = 0;
8282 wstats->qual.updated = 7;
8283 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
James Ketrenosee8e3652005-09-14 09:47:29 -05008284 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos2c86c272005-03-23 17:32:29 -06008285 return wstats;
8286 }
8287
8288 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_MISSED_BCNS,
8289 &missed_beacons, &ord_len))
8290 goto fail_get_ordinal;
8291
James Ketrenosee8e3652005-09-14 09:47:29 -05008292 /* If we don't have a connection the quality and level is 0 */
James Ketrenos2c86c272005-03-23 17:32:29 -06008293 if (!(priv->status & STATUS_ASSOCIATED)) {
8294 wstats->qual.qual = 0;
8295 wstats->qual.level = 0;
8296 } else {
8297 if (ipw2100_get_ordinal(priv, IPW_ORD_RSSI_AVG_CURR,
8298 &rssi, &ord_len))
8299 goto fail_get_ordinal;
8300 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8301 if (rssi < 10)
8302 rssi_qual = rssi * POOR / 10;
8303 else if (rssi < 15)
8304 rssi_qual = (rssi - 10) * (FAIR - POOR) / 5 + POOR;
8305 else if (rssi < 20)
8306 rssi_qual = (rssi - 15) * (GOOD - FAIR) / 5 + FAIR;
8307 else if (rssi < 30)
8308 rssi_qual = (rssi - 20) * (VERY_GOOD - GOOD) /
James Ketrenosee8e3652005-09-14 09:47:29 -05008309 10 + GOOD;
James Ketrenos2c86c272005-03-23 17:32:29 -06008310 else
8311 rssi_qual = (rssi - 30) * (PERFECT - VERY_GOOD) /
James Ketrenosee8e3652005-09-14 09:47:29 -05008312 10 + VERY_GOOD;
James Ketrenos2c86c272005-03-23 17:32:29 -06008313
8314 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_RETRIES,
8315 &tx_retries, &ord_len))
8316 goto fail_get_ordinal;
8317
8318 if (tx_retries > 75)
8319 tx_qual = (90 - tx_retries) * POOR / 15;
8320 else if (tx_retries > 70)
8321 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
8322 else if (tx_retries > 65)
8323 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
8324 else if (tx_retries > 50)
8325 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
James Ketrenosee8e3652005-09-14 09:47:29 -05008326 15 + GOOD;
James Ketrenos2c86c272005-03-23 17:32:29 -06008327 else
8328 tx_qual = (50 - tx_retries) *
James Ketrenosee8e3652005-09-14 09:47:29 -05008329 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
James Ketrenos2c86c272005-03-23 17:32:29 -06008330
8331 if (missed_beacons > 50)
8332 beacon_qual = (60 - missed_beacons) * POOR / 10;
8333 else if (missed_beacons > 40)
8334 beacon_qual = (50 - missed_beacons) * (FAIR - POOR) /
James Ketrenosee8e3652005-09-14 09:47:29 -05008335 10 + POOR;
James Ketrenos2c86c272005-03-23 17:32:29 -06008336 else if (missed_beacons > 32)
8337 beacon_qual = (40 - missed_beacons) * (GOOD - FAIR) /
James Ketrenosee8e3652005-09-14 09:47:29 -05008338 18 + FAIR;
James Ketrenos2c86c272005-03-23 17:32:29 -06008339 else if (missed_beacons > 20)
8340 beacon_qual = (32 - missed_beacons) *
James Ketrenosee8e3652005-09-14 09:47:29 -05008341 (VERY_GOOD - GOOD) / 20 + GOOD;
James Ketrenos2c86c272005-03-23 17:32:29 -06008342 else
8343 beacon_qual = (20 - missed_beacons) *
James Ketrenosee8e3652005-09-14 09:47:29 -05008344 (PERFECT - VERY_GOOD) / 20 + VERY_GOOD;
James Ketrenos2c86c272005-03-23 17:32:29 -06008345
Reinette Chatre21f8a732009-08-18 10:25:05 -07008346 quality = min(tx_qual, rssi_qual);
8347 quality = min(beacon_qual, quality);
James Ketrenos2c86c272005-03-23 17:32:29 -06008348
Brice Goglin0f52bf92005-12-01 01:41:46 -08008349#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06008350 if (beacon_qual == quality)
8351 IPW_DEBUG_WX("Quality clamped by Missed Beacons\n");
8352 else if (tx_qual == quality)
8353 IPW_DEBUG_WX("Quality clamped by Tx Retries\n");
8354 else if (quality != 100)
8355 IPW_DEBUG_WX("Quality clamped by Signal Strength\n");
8356 else
8357 IPW_DEBUG_WX("Quality not clamped.\n");
8358#endif
8359
8360 wstats->qual.qual = quality;
8361 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8362 }
8363
8364 wstats->qual.noise = 0;
8365 wstats->qual.updated = 7;
8366 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
8367
James Ketrenosee8e3652005-09-14 09:47:29 -05008368 /* FIXME: this is percent and not a # */
James Ketrenos2c86c272005-03-23 17:32:29 -06008369 wstats->miss.beacon = missed_beacons;
8370
8371 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURES,
8372 &tx_failures, &ord_len))
8373 goto fail_get_ordinal;
8374 wstats->discard.retries = tx_failures;
8375
8376 return wstats;
8377
James Ketrenosee8e3652005-09-14 09:47:29 -05008378 fail_get_ordinal:
James Ketrenos2c86c272005-03-23 17:32:29 -06008379 IPW_DEBUG_WX("failed querying ordinals.\n");
8380
James Ketrenosee8e3652005-09-14 09:47:29 -05008381 return (struct iw_statistics *)NULL;
James Ketrenos2c86c272005-03-23 17:32:29 -06008382}
8383
James Ketrenoseaf8f53b2005-11-12 12:50:12 -06008384static struct iw_handler_def ipw2100_wx_handler_def = {
8385 .standard = ipw2100_wx_handlers,
Denis Chengff8ac602007-09-02 18:30:18 +08008386 .num_standard = ARRAY_SIZE(ipw2100_wx_handlers),
8387 .num_private = ARRAY_SIZE(ipw2100_private_handler),
8388 .num_private_args = ARRAY_SIZE(ipw2100_private_args),
James Ketrenoseaf8f53b2005-11-12 12:50:12 -06008389 .private = (iw_handler *) ipw2100_private_handler,
8390 .private_args = (struct iw_priv_args *)ipw2100_private_args,
8391 .get_wireless_stats = ipw2100_wx_wireless_stats,
8392};
8393
David Howellsc4028952006-11-22 14:57:56 +00008394static void ipw2100_wx_event_work(struct work_struct *work)
James Ketrenos2c86c272005-03-23 17:32:29 -06008395{
David Howellsc4028952006-11-22 14:57:56 +00008396 struct ipw2100_priv *priv =
8397 container_of(work, struct ipw2100_priv, wx_event_work.work);
James Ketrenos2c86c272005-03-23 17:32:29 -06008398 union iwreq_data wrqu;
Hannes Ederb9da9e92009-02-14 11:50:26 +00008399 unsigned int len = ETH_ALEN;
James Ketrenos2c86c272005-03-23 17:32:29 -06008400
8401 if (priv->status & STATUS_STOPPING)
8402 return;
8403
Ingo Molnar752e3772006-02-28 07:20:54 +08008404 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06008405
8406 IPW_DEBUG_WX("enter\n");
8407
Ingo Molnar752e3772006-02-28 07:20:54 +08008408 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06008409
8410 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
8411
8412 /* Fetch BSSID from the hardware */
8413 if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) ||
8414 priv->status & STATUS_RF_KILL_MASK ||
8415 ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
James Ketrenosee8e3652005-09-14 09:47:29 -05008416 &priv->bssid, &len)) {
James Ketrenos2c86c272005-03-23 17:32:29 -06008417 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
8418 } else {
8419 /* We now have the BSSID, so can finish setting to the full
8420 * associated state */
8421 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos82328352005-08-24 22:33:31 -05008422 memcpy(priv->ieee->bssid, priv->bssid, ETH_ALEN);
James Ketrenos2c86c272005-03-23 17:32:29 -06008423 priv->status &= ~STATUS_ASSOCIATING;
8424 priv->status |= STATUS_ASSOCIATED;
8425 netif_carrier_on(priv->net_dev);
James Ketrenos82328352005-08-24 22:33:31 -05008426 netif_wake_queue(priv->net_dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06008427 }
8428
8429 if (!(priv->status & STATUS_ASSOCIATED)) {
8430 IPW_DEBUG_WX("Configuring ESSID\n");
Ingo Molnar752e3772006-02-28 07:20:54 +08008431 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06008432 /* This is a disassociation event, so kick the firmware to
8433 * look for another AP */
8434 if (priv->config & CFG_STATIC_ESSID)
James Ketrenosee8e3652005-09-14 09:47:29 -05008435 ipw2100_set_essid(priv, priv->essid, priv->essid_len,
8436 0);
James Ketrenos2c86c272005-03-23 17:32:29 -06008437 else
8438 ipw2100_set_essid(priv, NULL, 0, 0);
Ingo Molnar752e3772006-02-28 07:20:54 +08008439 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06008440 }
8441
8442 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
8443}
8444
8445#define IPW2100_FW_MAJOR_VERSION 1
8446#define IPW2100_FW_MINOR_VERSION 3
8447
8448#define IPW2100_FW_MINOR(x) ((x & 0xff) >> 8)
8449#define IPW2100_FW_MAJOR(x) (x & 0xff)
8450
8451#define IPW2100_FW_VERSION ((IPW2100_FW_MINOR_VERSION << 8) | \
8452 IPW2100_FW_MAJOR_VERSION)
8453
8454#define IPW2100_FW_PREFIX "ipw2100-" __stringify(IPW2100_FW_MAJOR_VERSION) \
8455"." __stringify(IPW2100_FW_MINOR_VERSION)
8456
8457#define IPW2100_FW_NAME(x) IPW2100_FW_PREFIX "" x ".fw"
8458
James Ketrenos2c86c272005-03-23 17:32:29 -06008459/*
8460
8461BINARY FIRMWARE HEADER FORMAT
8462
8463offset length desc
84640 2 version
84652 2 mode == 0:BSS,1:IBSS,2:MONITOR
84664 4 fw_len
84678 4 uc_len
8468C fw_len firmware data
846912 + fw_len uc_len microcode data
8470
8471*/
8472
8473struct ipw2100_fw_header {
8474 short version;
8475 short mode;
8476 unsigned int fw_size;
8477 unsigned int uc_size;
Eric Dumazetba2d3582010-06-02 18:10:09 +00008478} __packed;
James Ketrenos2c86c272005-03-23 17:32:29 -06008479
James Ketrenos2c86c272005-03-23 17:32:29 -06008480static int ipw2100_mod_firmware_load(struct ipw2100_fw *fw)
8481{
8482 struct ipw2100_fw_header *h =
James Ketrenosee8e3652005-09-14 09:47:29 -05008483 (struct ipw2100_fw_header *)fw->fw_entry->data;
James Ketrenos2c86c272005-03-23 17:32:29 -06008484
8485 if (IPW2100_FW_MAJOR(h->version) != IPW2100_FW_MAJOR_VERSION) {
Jiri Benc797b4f72005-08-25 20:03:27 -04008486 printk(KERN_WARNING DRV_NAME ": Firmware image not compatible "
James Ketrenos2c86c272005-03-23 17:32:29 -06008487 "(detected version id of %u). "
8488 "See Documentation/networking/README.ipw2100\n",
8489 h->version);
8490 return 1;
8491 }
8492
8493 fw->version = h->version;
8494 fw->fw.data = fw->fw_entry->data + sizeof(struct ipw2100_fw_header);
8495 fw->fw.size = h->fw_size;
8496 fw->uc.data = fw->fw.data + h->fw_size;
8497 fw->uc.size = h->uc_size;
8498
8499 return 0;
8500}
8501
Jiri Bencc4aee8c2005-08-25 20:04:43 -04008502static int ipw2100_get_firmware(struct ipw2100_priv *priv,
8503 struct ipw2100_fw *fw)
James Ketrenos2c86c272005-03-23 17:32:29 -06008504{
8505 char *fw_name;
8506 int rc;
8507
8508 IPW_DEBUG_INFO("%s: Using hotplug firmware load.\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05008509 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06008510
8511 switch (priv->ieee->iw_mode) {
8512 case IW_MODE_ADHOC:
8513 fw_name = IPW2100_FW_NAME("-i");
8514 break;
8515#ifdef CONFIG_IPW2100_MONITOR
8516 case IW_MODE_MONITOR:
8517 fw_name = IPW2100_FW_NAME("-p");
8518 break;
8519#endif
8520 case IW_MODE_INFRA:
8521 default:
8522 fw_name = IPW2100_FW_NAME("");
8523 break;
8524 }
8525
8526 rc = request_firmware(&fw->fw_entry, fw_name, &priv->pci_dev->dev);
8527
8528 if (rc < 0) {
Jiri Benc797b4f72005-08-25 20:03:27 -04008529 printk(KERN_ERR DRV_NAME ": "
James Ketrenos2c86c272005-03-23 17:32:29 -06008530 "%s: Firmware '%s' not available or load failed.\n",
8531 priv->net_dev->name, fw_name);
8532 return rc;
8533 }
Jiri Bencaaa4d302005-06-07 14:58:41 +02008534 IPW_DEBUG_INFO("firmware data %p size %zd\n", fw->fw_entry->data,
James Ketrenosee8e3652005-09-14 09:47:29 -05008535 fw->fw_entry->size);
James Ketrenos2c86c272005-03-23 17:32:29 -06008536
8537 ipw2100_mod_firmware_load(fw);
8538
8539 return 0;
8540}
8541
Ben Hutchingsa278ea32009-11-07 21:58:47 +00008542MODULE_FIRMWARE(IPW2100_FW_NAME("-i"));
8543#ifdef CONFIG_IPW2100_MONITOR
8544MODULE_FIRMWARE(IPW2100_FW_NAME("-p"));
8545#endif
8546MODULE_FIRMWARE(IPW2100_FW_NAME(""));
8547
Jiri Bencc4aee8c2005-08-25 20:04:43 -04008548static void ipw2100_release_firmware(struct ipw2100_priv *priv,
8549 struct ipw2100_fw *fw)
James Ketrenos2c86c272005-03-23 17:32:29 -06008550{
8551 fw->version = 0;
8552 if (fw->fw_entry)
8553 release_firmware(fw->fw_entry);
8554 fw->fw_entry = NULL;
8555}
8556
Jiri Bencc4aee8c2005-08-25 20:04:43 -04008557static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf,
8558 size_t max)
James Ketrenos2c86c272005-03-23 17:32:29 -06008559{
8560 char ver[MAX_FW_VERSION_LEN];
8561 u32 len = MAX_FW_VERSION_LEN;
8562 u32 tmp;
8563 int i;
8564 /* firmware version is an ascii string (max len of 14) */
James Ketrenosee8e3652005-09-14 09:47:29 -05008565 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_FW_VER_NUM, ver, &len))
James Ketrenos2c86c272005-03-23 17:32:29 -06008566 return -EIO;
8567 tmp = max;
8568 if (len >= max)
8569 len = max - 1;
8570 for (i = 0; i < len; i++)
8571 buf[i] = ver[i];
8572 buf[i] = '\0';
8573 return tmp;
8574}
8575
Jiri Bencc4aee8c2005-08-25 20:04:43 -04008576static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf,
8577 size_t max)
James Ketrenos2c86c272005-03-23 17:32:29 -06008578{
8579 u32 ver;
8580 u32 len = sizeof(ver);
8581 /* microcode version is a 32 bit integer */
James Ketrenosee8e3652005-09-14 09:47:29 -05008582 if (ipw2100_get_ordinal(priv, IPW_ORD_UCODE_VERSION, &ver, &len))
James Ketrenos2c86c272005-03-23 17:32:29 -06008583 return -EIO;
8584 return snprintf(buf, max, "%08X", ver);
8585}
8586
8587/*
8588 * On exit, the firmware will have been freed from the fw list
8589 */
James Ketrenosee8e3652005-09-14 09:47:29 -05008590static int ipw2100_fw_download(struct ipw2100_priv *priv, struct ipw2100_fw *fw)
James Ketrenos2c86c272005-03-23 17:32:29 -06008591{
8592 /* firmware is constructed of N contiguous entries, each entry is
8593 * structured as:
8594 *
8595 * offset sie desc
8596 * 0 4 address to write to
8597 * 4 2 length of data run
James Ketrenosee8e3652005-09-14 09:47:29 -05008598 * 6 length data
James Ketrenos2c86c272005-03-23 17:32:29 -06008599 */
8600 unsigned int addr;
8601 unsigned short len;
8602
8603 const unsigned char *firmware_data = fw->fw.data;
8604 unsigned int firmware_data_left = fw->fw.size;
8605
8606 while (firmware_data_left > 0) {
James Ketrenosee8e3652005-09-14 09:47:29 -05008607 addr = *(u32 *) (firmware_data);
8608 firmware_data += 4;
James Ketrenos2c86c272005-03-23 17:32:29 -06008609 firmware_data_left -= 4;
8610
James Ketrenosee8e3652005-09-14 09:47:29 -05008611 len = *(u16 *) (firmware_data);
8612 firmware_data += 2;
James Ketrenos2c86c272005-03-23 17:32:29 -06008613 firmware_data_left -= 2;
8614
8615 if (len > 32) {
Jiri Benc797b4f72005-08-25 20:03:27 -04008616 printk(KERN_ERR DRV_NAME ": "
James Ketrenos2c86c272005-03-23 17:32:29 -06008617 "Invalid firmware run-length of %d bytes\n",
8618 len);
8619 return -EINVAL;
8620 }
8621
8622 write_nic_memory(priv->net_dev, addr, len, firmware_data);
James Ketrenosee8e3652005-09-14 09:47:29 -05008623 firmware_data += len;
James Ketrenos2c86c272005-03-23 17:32:29 -06008624 firmware_data_left -= len;
8625 }
8626
8627 return 0;
8628}
8629
8630struct symbol_alive_response {
8631 u8 cmd_id;
8632 u8 seq_num;
8633 u8 ucode_rev;
8634 u8 eeprom_valid;
8635 u16 valid_flags;
8636 u8 IEEE_addr[6];
8637 u16 flags;
8638 u16 pcb_rev;
8639 u16 clock_settle_time; // 1us LSB
8640 u16 powerup_settle_time; // 1us LSB
8641 u16 hop_settle_time; // 1us LSB
8642 u8 date[3]; // month, day, year
8643 u8 time[2]; // hours, minutes
8644 u8 ucode_valid;
8645};
8646
Jiri Bencc4aee8c2005-08-25 20:04:43 -04008647static int ipw2100_ucode_download(struct ipw2100_priv *priv,
8648 struct ipw2100_fw *fw)
James Ketrenos2c86c272005-03-23 17:32:29 -06008649{
8650 struct net_device *dev = priv->net_dev;
8651 const unsigned char *microcode_data = fw->uc.data;
8652 unsigned int microcode_data_left = fw->uc.size;
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008653 void __iomem *reg = (void __iomem *)dev->base_addr;
James Ketrenos2c86c272005-03-23 17:32:29 -06008654
8655 struct symbol_alive_response response;
8656 int i, j;
8657 u8 data;
8658
8659 /* Symbol control */
8660 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008661 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008662 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008663 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008664
8665 /* HW config */
8666 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008667 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008668 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008669 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008670
8671 /* EN_CS_ACCESS bit to reset control store pointer */
8672 write_nic_byte(dev, 0x210000, 0x40);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008673 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008674 write_nic_byte(dev, 0x210000, 0x0);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008675 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008676 write_nic_byte(dev, 0x210000, 0x40);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008677 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008678
8679 /* copy microcode from buffer into Symbol */
8680
8681 while (microcode_data_left > 0) {
8682 write_nic_byte(dev, 0x210010, *microcode_data++);
8683 write_nic_byte(dev, 0x210010, *microcode_data++);
8684 microcode_data_left -= 2;
8685 }
8686
8687 /* EN_CS_ACCESS bit to reset the control store pointer */
8688 write_nic_byte(dev, 0x210000, 0x0);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008689 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008690
8691 /* Enable System (Reg 0)
8692 * first enable causes garbage in RX FIFO */
8693 write_nic_byte(dev, 0x210000, 0x0);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008694 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008695 write_nic_byte(dev, 0x210000, 0x80);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008696 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008697
8698 /* Reset External Baseband Reg */
8699 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008700 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008701 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008702 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008703
8704 /* HW Config (Reg 5) */
8705 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008706 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008707 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008708 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008709
8710 /* Enable System (Reg 0)
8711 * second enable should be OK */
8712 write_nic_byte(dev, 0x210000, 0x00); // clear enable system
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008713 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008714 write_nic_byte(dev, 0x210000, 0x80); // set enable system
8715
8716 /* check Symbol is enabled - upped this from 5 as it wasn't always
8717 * catching the update */
8718 for (i = 0; i < 10; i++) {
8719 udelay(10);
8720
8721 /* check Dino is enabled bit */
8722 read_nic_byte(dev, 0x210000, &data);
8723 if (data & 0x1)
8724 break;
8725 }
8726
8727 if (i == 10) {
Jiri Benc797b4f72005-08-25 20:03:27 -04008728 printk(KERN_ERR DRV_NAME ": %s: Error initializing Symbol\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06008729 dev->name);
8730 return -EIO;
8731 }
8732
8733 /* Get Symbol alive response */
8734 for (i = 0; i < 30; i++) {
8735 /* Read alive response structure */
8736 for (j = 0;
James Ketrenosee8e3652005-09-14 09:47:29 -05008737 j < (sizeof(struct symbol_alive_response) >> 1); j++)
8738 read_nic_word(dev, 0x210004, ((u16 *) & response) + j);
James Ketrenos2c86c272005-03-23 17:32:29 -06008739
James Ketrenosee8e3652005-09-14 09:47:29 -05008740 if ((response.cmd_id == 1) && (response.ucode_valid == 0x1))
James Ketrenos2c86c272005-03-23 17:32:29 -06008741 break;
8742 udelay(10);
8743 }
8744
8745 if (i == 30) {
James Ketrenosee8e3652005-09-14 09:47:29 -05008746 printk(KERN_ERR DRV_NAME
8747 ": %s: No response from Symbol - hw not alive\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06008748 dev->name);
James Ketrenosee8e3652005-09-14 09:47:29 -05008749 printk_buf(IPW_DL_ERROR, (u8 *) & response, sizeof(response));
James Ketrenos2c86c272005-03-23 17:32:29 -06008750 return -EIO;
8751 }
8752
8753 return 0;
8754}