blob: 6c836c892e4329cd850b2d87832b3b8f3fc9c2f5 [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
177/* Debugging stuff */
Brice Goglin0f52bf92005-12-01 01:41:46 -0800178#ifdef CONFIG_IPW2100_DEBUG
Robert P. J. Dayae800312007-01-31 02:39:40 -0500179#define IPW2100_RX_DEBUG /* Reception debugging */
James Ketrenos2c86c272005-03-23 17:32:29 -0600180#endif
181
182MODULE_DESCRIPTION(DRV_DESCRIPTION);
183MODULE_VERSION(DRV_VERSION);
184MODULE_AUTHOR(DRV_COPYRIGHT);
185MODULE_LICENSE("GPL");
186
187static int debug = 0;
Reinette Chatre21f8a732009-08-18 10:25:05 -0700188static int network_mode = 0;
James Ketrenos2c86c272005-03-23 17:32:29 -0600189static int channel = 0;
Tim Gardner5c7f9b72008-10-14 10:38:03 -0600190static int associate = 0;
James Ketrenos2c86c272005-03-23 17:32:29 -0600191static int disable = 0;
192#ifdef CONFIG_PM
193static struct ipw2100_fw ipw2100_firmware;
194#endif
195
196#include <linux/moduleparam.h>
197module_param(debug, int, 0444);
Reinette Chatre21f8a732009-08-18 10:25:05 -0700198module_param_named(mode, network_mode, int, 0444);
James Ketrenos2c86c272005-03-23 17:32:29 -0600199module_param(channel, int, 0444);
200module_param(associate, int, 0444);
201module_param(disable, int, 0444);
202
203MODULE_PARM_DESC(debug, "debug level");
204MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
205MODULE_PARM_DESC(channel, "channel");
Tim Gardner5c7f9b72008-10-14 10:38:03 -0600206MODULE_PARM_DESC(associate, "auto associate when scanning (default off)");
James Ketrenos2c86c272005-03-23 17:32:29 -0600207MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
208
Jiri Bencc4aee8c2005-08-25 20:04:43 -0400209static u32 ipw2100_debug_level = IPW_DL_NONE;
210
Brice Goglin0f52bf92005-12-01 01:41:46 -0800211#ifdef CONFIG_IPW2100_DEBUG
Jiri Bencc4aee8c2005-08-25 20:04:43 -0400212#define IPW_DEBUG(level, message...) \
213do { \
214 if (ipw2100_debug_level & (level)) { \
215 printk(KERN_DEBUG "ipw2100: %c %s ", \
Harvey Harrisonc94c93d2008-07-28 23:01:34 -0700216 in_interrupt() ? 'I' : 'U', __func__); \
Jiri Bencc4aee8c2005-08-25 20:04:43 -0400217 printk(message); \
218 } \
219} while (0)
220#else
221#define IPW_DEBUG(level, message...) do {} while (0)
Brice Goglin0f52bf92005-12-01 01:41:46 -0800222#endif /* CONFIG_IPW2100_DEBUG */
James Ketrenos2c86c272005-03-23 17:32:29 -0600223
Brice Goglin0f52bf92005-12-01 01:41:46 -0800224#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -0600225static const char *command_types[] = {
226 "undefined",
James Ketrenosee8e3652005-09-14 09:47:29 -0500227 "unused", /* HOST_ATTENTION */
James Ketrenos2c86c272005-03-23 17:32:29 -0600228 "HOST_COMPLETE",
James Ketrenosee8e3652005-09-14 09:47:29 -0500229 "unused", /* SLEEP */
230 "unused", /* HOST_POWER_DOWN */
James Ketrenos2c86c272005-03-23 17:32:29 -0600231 "unused",
232 "SYSTEM_CONFIG",
James Ketrenosee8e3652005-09-14 09:47:29 -0500233 "unused", /* SET_IMR */
James Ketrenos2c86c272005-03-23 17:32:29 -0600234 "SSID",
235 "MANDATORY_BSSID",
236 "AUTHENTICATION_TYPE",
237 "ADAPTER_ADDRESS",
238 "PORT_TYPE",
239 "INTERNATIONAL_MODE",
240 "CHANNEL",
241 "RTS_THRESHOLD",
242 "FRAG_THRESHOLD",
243 "POWER_MODE",
244 "TX_RATES",
245 "BASIC_TX_RATES",
246 "WEP_KEY_INFO",
247 "unused",
248 "unused",
249 "unused",
250 "unused",
251 "WEP_KEY_INDEX",
252 "WEP_FLAGS",
253 "ADD_MULTICAST",
254 "CLEAR_ALL_MULTICAST",
255 "BEACON_INTERVAL",
256 "ATIM_WINDOW",
257 "CLEAR_STATISTICS",
258 "undefined",
259 "undefined",
260 "undefined",
261 "undefined",
262 "TX_POWER_INDEX",
263 "undefined",
264 "undefined",
265 "undefined",
266 "undefined",
267 "undefined",
268 "undefined",
269 "BROADCAST_SCAN",
270 "CARD_DISABLE",
271 "PREFERRED_BSSID",
272 "SET_SCAN_OPTIONS",
273 "SCAN_DWELL_TIME",
274 "SWEEP_TABLE",
275 "AP_OR_STATION_TABLE",
276 "GROUP_ORDINALS",
277 "SHORT_RETRY_LIMIT",
278 "LONG_RETRY_LIMIT",
James Ketrenosee8e3652005-09-14 09:47:29 -0500279 "unused", /* SAVE_CALIBRATION */
280 "unused", /* RESTORE_CALIBRATION */
James Ketrenos2c86c272005-03-23 17:32:29 -0600281 "undefined",
282 "undefined",
283 "undefined",
284 "HOST_PRE_POWER_DOWN",
James Ketrenosee8e3652005-09-14 09:47:29 -0500285 "unused", /* HOST_INTERRUPT_COALESCING */
James Ketrenos2c86c272005-03-23 17:32:29 -0600286 "undefined",
287 "CARD_DISABLE_PHY_OFF",
James Ketrenosee8e3652005-09-14 09:47:29 -0500288 "MSDU_TX_RATES" "undefined",
James Ketrenos2c86c272005-03-23 17:32:29 -0600289 "undefined",
290 "SET_STATION_STAT_BITS",
291 "CLEAR_STATIONS_STAT_BITS",
292 "LEAP_ROGUE_MODE",
293 "SET_SECURITY_INFORMATION",
294 "DISASSOCIATION_BSSID",
295 "SET_WPA_ASS_IE"
296};
297#endif
298
Matthew Garrettc26409a2009-11-11 14:36:30 -0500299#define WEXT_USECHANNELS 1
300
301static const long ipw2100_frequencies[] = {
302 2412, 2417, 2422, 2427,
303 2432, 2437, 2442, 2447,
304 2452, 2457, 2462, 2467,
305 2472, 2484
306};
307
308#define FREQ_COUNT ARRAY_SIZE(ipw2100_frequencies)
309
310static const long ipw2100_rates_11b[] = {
311 1000000,
312 2000000,
313 5500000,
314 11000000
315};
316
317static struct ieee80211_rate ipw2100_bg_rates[] = {
318 { .bitrate = 10 },
319 { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
320 { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
321 { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
322};
323
324#define RATE_COUNT ARRAY_SIZE(ipw2100_rates_11b)
325
James Ketrenos2c86c272005-03-23 17:32:29 -0600326/* Pre-decl until we get the code solid and then we can clean it up */
Jiri Benc19f7f742005-08-25 20:02:10 -0400327static void ipw2100_tx_send_commands(struct ipw2100_priv *priv);
328static void ipw2100_tx_send_data(struct ipw2100_priv *priv);
James Ketrenos2c86c272005-03-23 17:32:29 -0600329static int ipw2100_adapter_setup(struct ipw2100_priv *priv);
330
331static void ipw2100_queues_initialize(struct ipw2100_priv *priv);
332static void ipw2100_queues_free(struct ipw2100_priv *priv);
333static int ipw2100_queues_allocate(struct ipw2100_priv *priv);
334
Jiri Bencc4aee8c2005-08-25 20:04:43 -0400335static int ipw2100_fw_download(struct ipw2100_priv *priv,
336 struct ipw2100_fw *fw);
337static int ipw2100_get_firmware(struct ipw2100_priv *priv,
338 struct ipw2100_fw *fw);
339static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf,
340 size_t max);
341static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf,
342 size_t max);
343static void ipw2100_release_firmware(struct ipw2100_priv *priv,
344 struct ipw2100_fw *fw);
345static int ipw2100_ucode_download(struct ipw2100_priv *priv,
346 struct ipw2100_fw *fw);
David Howellsc4028952006-11-22 14:57:56 +0000347static void ipw2100_wx_event_work(struct work_struct *work);
James Ketrenosee8e3652005-09-14 09:47:29 -0500348static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device *dev);
Jiri Bencc4aee8c2005-08-25 20:04:43 -0400349static struct iw_handler_def ipw2100_wx_handler_def;
350
James Ketrenosee8e3652005-09-14 09:47:29 -0500351static inline void read_register(struct net_device *dev, u32 reg, u32 * val)
James Ketrenos2c86c272005-03-23 17:32:29 -0600352{
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +0100353 *val = readl((void __iomem *)(dev->base_addr + reg));
James Ketrenos2c86c272005-03-23 17:32:29 -0600354 IPW_DEBUG_IO("r: 0x%08X => 0x%08X\n", reg, *val);
355}
356
357static inline void write_register(struct net_device *dev, u32 reg, u32 val)
358{
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +0100359 writel(val, (void __iomem *)(dev->base_addr + reg));
James Ketrenos2c86c272005-03-23 17:32:29 -0600360 IPW_DEBUG_IO("w: 0x%08X <= 0x%08X\n", reg, val);
361}
362
James Ketrenosee8e3652005-09-14 09:47:29 -0500363static inline void read_register_word(struct net_device *dev, u32 reg,
364 u16 * val)
James Ketrenos2c86c272005-03-23 17:32:29 -0600365{
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +0100366 *val = readw((void __iomem *)(dev->base_addr + reg));
James Ketrenos2c86c272005-03-23 17:32:29 -0600367 IPW_DEBUG_IO("r: 0x%08X => %04X\n", reg, *val);
368}
369
James Ketrenosee8e3652005-09-14 09:47:29 -0500370static inline void read_register_byte(struct net_device *dev, u32 reg, u8 * val)
James Ketrenos2c86c272005-03-23 17:32:29 -0600371{
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +0100372 *val = readb((void __iomem *)(dev->base_addr + reg));
James Ketrenos2c86c272005-03-23 17:32:29 -0600373 IPW_DEBUG_IO("r: 0x%08X => %02X\n", reg, *val);
374}
375
376static inline void write_register_word(struct net_device *dev, u32 reg, u16 val)
377{
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +0100378 writew(val, (void __iomem *)(dev->base_addr + reg));
James Ketrenos2c86c272005-03-23 17:32:29 -0600379 IPW_DEBUG_IO("w: 0x%08X <= %04X\n", reg, val);
380}
381
James Ketrenos2c86c272005-03-23 17:32:29 -0600382static inline void write_register_byte(struct net_device *dev, u32 reg, u8 val)
383{
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +0100384 writeb(val, (void __iomem *)(dev->base_addr + reg));
James Ketrenos2c86c272005-03-23 17:32:29 -0600385 IPW_DEBUG_IO("w: 0x%08X =< %02X\n", reg, val);
386}
387
James Ketrenosee8e3652005-09-14 09:47:29 -0500388static inline void read_nic_dword(struct net_device *dev, u32 addr, u32 * val)
James Ketrenos2c86c272005-03-23 17:32:29 -0600389{
390 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
391 addr & IPW_REG_INDIRECT_ADDR_MASK);
392 read_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
393}
394
395static inline void write_nic_dword(struct net_device *dev, u32 addr, u32 val)
396{
397 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
398 addr & IPW_REG_INDIRECT_ADDR_MASK);
399 write_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
400}
401
James Ketrenosee8e3652005-09-14 09:47:29 -0500402static inline void read_nic_word(struct net_device *dev, u32 addr, u16 * val)
James Ketrenos2c86c272005-03-23 17:32:29 -0600403{
404 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
405 addr & IPW_REG_INDIRECT_ADDR_MASK);
406 read_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
407}
408
409static inline void write_nic_word(struct net_device *dev, u32 addr, u16 val)
410{
411 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
412 addr & IPW_REG_INDIRECT_ADDR_MASK);
413 write_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
414}
415
James Ketrenosee8e3652005-09-14 09:47:29 -0500416static inline void read_nic_byte(struct net_device *dev, u32 addr, u8 * val)
James Ketrenos2c86c272005-03-23 17:32:29 -0600417{
418 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
419 addr & IPW_REG_INDIRECT_ADDR_MASK);
420 read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
421}
422
423static inline void write_nic_byte(struct net_device *dev, u32 addr, u8 val)
424{
425 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
426 addr & IPW_REG_INDIRECT_ADDR_MASK);
427 write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
428}
429
430static inline void write_nic_auto_inc_address(struct net_device *dev, u32 addr)
431{
432 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS,
433 addr & IPW_REG_INDIRECT_ADDR_MASK);
434}
435
436static inline void write_nic_dword_auto_inc(struct net_device *dev, u32 val)
437{
438 write_register(dev, IPW_REG_AUTOINCREMENT_DATA, val);
439}
440
Arjan van de Ven858119e2006-01-14 13:20:43 -0800441static void write_nic_memory(struct net_device *dev, u32 addr, u32 len,
James Ketrenosee8e3652005-09-14 09:47:29 -0500442 const u8 * buf)
James Ketrenos2c86c272005-03-23 17:32:29 -0600443{
444 u32 aligned_addr;
445 u32 aligned_len;
446 u32 dif_len;
447 u32 i;
448
449 /* read first nibble byte by byte */
450 aligned_addr = addr & (~0x3);
451 dif_len = addr - aligned_addr;
452 if (dif_len) {
453 /* Start reading at aligned_addr + dif_len */
454 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
455 aligned_addr);
456 for (i = dif_len; i < 4; i++, buf++)
James Ketrenosee8e3652005-09-14 09:47:29 -0500457 write_register_byte(dev,
458 IPW_REG_INDIRECT_ACCESS_DATA + i,
459 *buf);
James Ketrenos2c86c272005-03-23 17:32:29 -0600460
461 len -= dif_len;
462 aligned_addr += 4;
463 }
464
465 /* read DWs through autoincrement registers */
James Ketrenosee8e3652005-09-14 09:47:29 -0500466 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS, aligned_addr);
James Ketrenos2c86c272005-03-23 17:32:29 -0600467 aligned_len = len & (~0x3);
468 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
James Ketrenosee8e3652005-09-14 09:47:29 -0500469 write_register(dev, IPW_REG_AUTOINCREMENT_DATA, *(u32 *) buf);
James Ketrenos2c86c272005-03-23 17:32:29 -0600470
471 /* copy the last nibble */
472 dif_len = len - aligned_len;
473 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr);
474 for (i = 0; i < dif_len; i++, buf++)
James Ketrenosee8e3652005-09-14 09:47:29 -0500475 write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA + i,
476 *buf);
James Ketrenos2c86c272005-03-23 17:32:29 -0600477}
478
Arjan van de Ven858119e2006-01-14 13:20:43 -0800479static void read_nic_memory(struct net_device *dev, u32 addr, u32 len,
James Ketrenosee8e3652005-09-14 09:47:29 -0500480 u8 * buf)
James Ketrenos2c86c272005-03-23 17:32:29 -0600481{
482 u32 aligned_addr;
483 u32 aligned_len;
484 u32 dif_len;
485 u32 i;
486
487 /* read first nibble byte by byte */
488 aligned_addr = addr & (~0x3);
489 dif_len = addr - aligned_addr;
490 if (dif_len) {
491 /* Start reading at aligned_addr + dif_len */
492 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
493 aligned_addr);
494 for (i = dif_len; i < 4; i++, buf++)
James Ketrenosee8e3652005-09-14 09:47:29 -0500495 read_register_byte(dev,
496 IPW_REG_INDIRECT_ACCESS_DATA + i,
497 buf);
James Ketrenos2c86c272005-03-23 17:32:29 -0600498
499 len -= dif_len;
500 aligned_addr += 4;
501 }
502
503 /* read DWs through autoincrement registers */
James Ketrenosee8e3652005-09-14 09:47:29 -0500504 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS, aligned_addr);
James Ketrenos2c86c272005-03-23 17:32:29 -0600505 aligned_len = len & (~0x3);
506 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
James Ketrenosee8e3652005-09-14 09:47:29 -0500507 read_register(dev, IPW_REG_AUTOINCREMENT_DATA, (u32 *) buf);
James Ketrenos2c86c272005-03-23 17:32:29 -0600508
509 /* copy the last nibble */
510 dif_len = len - aligned_len;
James Ketrenosee8e3652005-09-14 09:47:29 -0500511 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr);
James Ketrenos2c86c272005-03-23 17:32:29 -0600512 for (i = 0; i < dif_len; i++, buf++)
James Ketrenosee8e3652005-09-14 09:47:29 -0500513 read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA + i, buf);
James Ketrenos2c86c272005-03-23 17:32:29 -0600514}
515
516static inline int ipw2100_hw_is_adapter_in_system(struct net_device *dev)
517{
518 return (dev->base_addr &&
James Ketrenosee8e3652005-09-14 09:47:29 -0500519 (readl
520 ((void __iomem *)(dev->base_addr +
521 IPW_REG_DOA_DEBUG_AREA_START))
James Ketrenos2c86c272005-03-23 17:32:29 -0600522 == IPW_DATA_DOA_DEBUG_VALUE));
523}
524
Jiri Bencc4aee8c2005-08-25 20:04:43 -0400525static int ipw2100_get_ordinal(struct ipw2100_priv *priv, u32 ord,
James Ketrenosee8e3652005-09-14 09:47:29 -0500526 void *val, u32 * len)
James Ketrenos2c86c272005-03-23 17:32:29 -0600527{
528 struct ipw2100_ordinals *ordinals = &priv->ordinals;
529 u32 addr;
530 u32 field_info;
531 u16 field_len;
532 u16 field_count;
533 u32 total_length;
534
535 if (ordinals->table1_addr == 0) {
Jiri Benc797b4f72005-08-25 20:03:27 -0400536 printk(KERN_WARNING DRV_NAME ": attempt to use fw ordinals "
James Ketrenos2c86c272005-03-23 17:32:29 -0600537 "before they have been loaded.\n");
538 return -EINVAL;
539 }
540
541 if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
542 if (*len < IPW_ORD_TAB_1_ENTRY_SIZE) {
543 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
544
Jiri Benc797b4f72005-08-25 20:03:27 -0400545 printk(KERN_WARNING DRV_NAME
Jiri Bencaaa4d302005-06-07 14:58:41 +0200546 ": ordinal buffer length too small, need %zd\n",
James Ketrenos2c86c272005-03-23 17:32:29 -0600547 IPW_ORD_TAB_1_ENTRY_SIZE);
548
549 return -EINVAL;
550 }
551
James Ketrenosee8e3652005-09-14 09:47:29 -0500552 read_nic_dword(priv->net_dev,
553 ordinals->table1_addr + (ord << 2), &addr);
James Ketrenos2c86c272005-03-23 17:32:29 -0600554 read_nic_dword(priv->net_dev, addr, val);
555
556 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
557
558 return 0;
559 }
560
561 if (IS_ORDINAL_TABLE_TWO(ordinals, ord)) {
562
563 ord -= IPW_START_ORD_TAB_2;
564
565 /* get the address of statistic */
James Ketrenosee8e3652005-09-14 09:47:29 -0500566 read_nic_dword(priv->net_dev,
567 ordinals->table2_addr + (ord << 3), &addr);
James Ketrenos2c86c272005-03-23 17:32:29 -0600568
569 /* get the second DW of statistics ;
570 * two 16-bit words - first is length, second is count */
571 read_nic_dword(priv->net_dev,
572 ordinals->table2_addr + (ord << 3) + sizeof(u32),
573 &field_info);
574
575 /* get each entry length */
James Ketrenosee8e3652005-09-14 09:47:29 -0500576 field_len = *((u16 *) & field_info);
James Ketrenos2c86c272005-03-23 17:32:29 -0600577
578 /* get number of entries */
James Ketrenosee8e3652005-09-14 09:47:29 -0500579 field_count = *(((u16 *) & field_info) + 1);
James Ketrenos2c86c272005-03-23 17:32:29 -0600580
581 /* abort if no enought memory */
582 total_length = field_len * field_count;
583 if (total_length > *len) {
584 *len = total_length;
585 return -EINVAL;
586 }
587
588 *len = total_length;
589 if (!total_length)
590 return 0;
591
592 /* read the ordinal data from the SRAM */
593 read_nic_memory(priv->net_dev, addr, total_length, val);
594
595 return 0;
596 }
597
Jiri Benc797b4f72005-08-25 20:03:27 -0400598 printk(KERN_WARNING DRV_NAME ": ordinal %d neither in table 1 nor "
James Ketrenos2c86c272005-03-23 17:32:29 -0600599 "in table 2\n", ord);
600
601 return -EINVAL;
602}
603
James Ketrenosee8e3652005-09-14 09:47:29 -0500604static int ipw2100_set_ordinal(struct ipw2100_priv *priv, u32 ord, u32 * val,
605 u32 * len)
James Ketrenos2c86c272005-03-23 17:32:29 -0600606{
607 struct ipw2100_ordinals *ordinals = &priv->ordinals;
608 u32 addr;
609
610 if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
611 if (*len != IPW_ORD_TAB_1_ENTRY_SIZE) {
612 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
613 IPW_DEBUG_INFO("wrong size\n");
614 return -EINVAL;
615 }
616
James Ketrenosee8e3652005-09-14 09:47:29 -0500617 read_nic_dword(priv->net_dev,
618 ordinals->table1_addr + (ord << 2), &addr);
James Ketrenos2c86c272005-03-23 17:32:29 -0600619
620 write_nic_dword(priv->net_dev, addr, *val);
621
622 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
623
624 return 0;
625 }
626
627 IPW_DEBUG_INFO("wrong table\n");
628 if (IS_ORDINAL_TABLE_TWO(ordinals, ord))
629 return -EINVAL;
630
631 return -EINVAL;
632}
633
634static char *snprint_line(char *buf, size_t count,
James Ketrenosee8e3652005-09-14 09:47:29 -0500635 const u8 * data, u32 len, u32 ofs)
James Ketrenos2c86c272005-03-23 17:32:29 -0600636{
637 int out, i, j, l;
638 char c;
639
640 out = snprintf(buf, count, "%08X", ofs);
641
642 for (l = 0, i = 0; i < 2; i++) {
643 out += snprintf(buf + out, count - out, " ");
644 for (j = 0; j < 8 && l < len; j++, l++)
645 out += snprintf(buf + out, count - out, "%02X ",
646 data[(i * 8 + j)]);
647 for (; j < 8; j++)
648 out += snprintf(buf + out, count - out, " ");
649 }
650
651 out += snprintf(buf + out, count - out, " ");
652 for (l = 0, i = 0; i < 2; i++) {
653 out += snprintf(buf + out, count - out, " ");
654 for (j = 0; j < 8 && l < len; j++, l++) {
655 c = data[(i * 8 + j)];
656 if (!isascii(c) || !isprint(c))
657 c = '.';
658
659 out += snprintf(buf + out, count - out, "%c", c);
660 }
661
662 for (; j < 8; j++)
663 out += snprintf(buf + out, count - out, " ");
664 }
665
666 return buf;
667}
668
James Ketrenosee8e3652005-09-14 09:47:29 -0500669static void printk_buf(int level, const u8 * data, u32 len)
James Ketrenos2c86c272005-03-23 17:32:29 -0600670{
671 char line[81];
672 u32 ofs = 0;
673 if (!(ipw2100_debug_level & level))
674 return;
675
676 while (len) {
677 printk(KERN_DEBUG "%s\n",
678 snprint_line(line, sizeof(line), &data[ofs],
679 min(len, 16U), ofs));
680 ofs += 16;
681 len -= min(len, 16U);
682 }
683}
684
James Ketrenos2c86c272005-03-23 17:32:29 -0600685#define MAX_RESET_BACKOFF 10
686
Arjan van de Ven858119e2006-01-14 13:20:43 -0800687static void schedule_reset(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -0600688{
689 unsigned long now = get_seconds();
690
691 /* If we haven't received a reset request within the backoff period,
692 * then we can reset the backoff interval so this reset occurs
693 * immediately */
694 if (priv->reset_backoff &&
695 (now - priv->last_reset > priv->reset_backoff))
696 priv->reset_backoff = 0;
697
698 priv->last_reset = get_seconds();
699
700 if (!(priv->status & STATUS_RESET_PENDING)) {
701 IPW_DEBUG_INFO("%s: Scheduling firmware restart (%ds).\n",
702 priv->net_dev->name, priv->reset_backoff);
703 netif_carrier_off(priv->net_dev);
704 netif_stop_queue(priv->net_dev);
705 priv->status |= STATUS_RESET_PENDING;
706 if (priv->reset_backoff)
707 queue_delayed_work(priv->workqueue, &priv->reset_work,
708 priv->reset_backoff * HZ);
709 else
David Howellsc4028952006-11-22 14:57:56 +0000710 queue_delayed_work(priv->workqueue, &priv->reset_work,
711 0);
James Ketrenos2c86c272005-03-23 17:32:29 -0600712
713 if (priv->reset_backoff < MAX_RESET_BACKOFF)
714 priv->reset_backoff++;
715
716 wake_up_interruptible(&priv->wait_command_queue);
717 } else
718 IPW_DEBUG_INFO("%s: Firmware restart already in progress.\n",
719 priv->net_dev->name);
720
721}
722
723#define HOST_COMPLETE_TIMEOUT (2 * HZ)
724static int ipw2100_hw_send_command(struct ipw2100_priv *priv,
James Ketrenosee8e3652005-09-14 09:47:29 -0500725 struct host_command *cmd)
James Ketrenos2c86c272005-03-23 17:32:29 -0600726{
727 struct list_head *element;
728 struct ipw2100_tx_packet *packet;
729 unsigned long flags;
730 int err = 0;
731
732 IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n",
733 command_types[cmd->host_command], cmd->host_command,
734 cmd->host_command_length);
James Ketrenosee8e3652005-09-14 09:47:29 -0500735 printk_buf(IPW_DL_HC, (u8 *) cmd->host_command_parameters,
James Ketrenos2c86c272005-03-23 17:32:29 -0600736 cmd->host_command_length);
737
738 spin_lock_irqsave(&priv->low_lock, flags);
739
740 if (priv->fatal_error) {
James Ketrenosee8e3652005-09-14 09:47:29 -0500741 IPW_DEBUG_INFO
742 ("Attempt to send command while hardware in fatal error condition.\n");
James Ketrenos2c86c272005-03-23 17:32:29 -0600743 err = -EIO;
744 goto fail_unlock;
745 }
746
747 if (!(priv->status & STATUS_RUNNING)) {
James Ketrenosee8e3652005-09-14 09:47:29 -0500748 IPW_DEBUG_INFO
749 ("Attempt to send command while hardware is not running.\n");
James Ketrenos2c86c272005-03-23 17:32:29 -0600750 err = -EIO;
751 goto fail_unlock;
752 }
753
754 if (priv->status & STATUS_CMD_ACTIVE) {
James Ketrenosee8e3652005-09-14 09:47:29 -0500755 IPW_DEBUG_INFO
756 ("Attempt to send command while another command is pending.\n");
James Ketrenos2c86c272005-03-23 17:32:29 -0600757 err = -EBUSY;
758 goto fail_unlock;
759 }
760
761 if (list_empty(&priv->msg_free_list)) {
762 IPW_DEBUG_INFO("no available msg buffers\n");
763 goto fail_unlock;
764 }
765
766 priv->status |= STATUS_CMD_ACTIVE;
767 priv->messages_sent++;
768
769 element = priv->msg_free_list.next;
770
771 packet = list_entry(element, struct ipw2100_tx_packet, list);
772 packet->jiffy_start = jiffies;
773
774 /* initialize the firmware command packet */
775 packet->info.c_struct.cmd->host_command_reg = cmd->host_command;
776 packet->info.c_struct.cmd->host_command_reg1 = cmd->host_command1;
James Ketrenosee8e3652005-09-14 09:47:29 -0500777 packet->info.c_struct.cmd->host_command_len_reg =
778 cmd->host_command_length;
James Ketrenos2c86c272005-03-23 17:32:29 -0600779 packet->info.c_struct.cmd->sequence = cmd->host_command_sequence;
780
781 memcpy(packet->info.c_struct.cmd->host_command_params_reg,
782 cmd->host_command_parameters,
783 sizeof(packet->info.c_struct.cmd->host_command_params_reg));
784
785 list_del(element);
786 DEC_STAT(&priv->msg_free_stat);
787
788 list_add_tail(element, &priv->msg_pend_list);
789 INC_STAT(&priv->msg_pend_stat);
790
Jiri Benc19f7f742005-08-25 20:02:10 -0400791 ipw2100_tx_send_commands(priv);
792 ipw2100_tx_send_data(priv);
James Ketrenos2c86c272005-03-23 17:32:29 -0600793
794 spin_unlock_irqrestore(&priv->low_lock, flags);
795
796 /*
797 * We must wait for this command to complete before another
798 * command can be sent... but if we wait more than 3 seconds
799 * then there is a problem.
800 */
801
James Ketrenosee8e3652005-09-14 09:47:29 -0500802 err =
803 wait_event_interruptible_timeout(priv->wait_command_queue,
804 !(priv->
805 status & STATUS_CMD_ACTIVE),
806 HOST_COMPLETE_TIMEOUT);
James Ketrenos2c86c272005-03-23 17:32:29 -0600807
808 if (err == 0) {
809 IPW_DEBUG_INFO("Command completion failed out after %dms.\n",
James Ketrenos82328352005-08-24 22:33:31 -0500810 1000 * (HOST_COMPLETE_TIMEOUT / HZ));
James Ketrenos2c86c272005-03-23 17:32:29 -0600811 priv->fatal_error = IPW2100_ERR_MSG_TIMEOUT;
812 priv->status &= ~STATUS_CMD_ACTIVE;
813 schedule_reset(priv);
814 return -EIO;
815 }
816
817 if (priv->fatal_error) {
Jiri Benc797b4f72005-08-25 20:03:27 -0400818 printk(KERN_WARNING DRV_NAME ": %s: firmware fatal error\n",
James Ketrenos2c86c272005-03-23 17:32:29 -0600819 priv->net_dev->name);
820 return -EIO;
821 }
822
823 /* !!!!! HACK TEST !!!!!
824 * When lots of debug trace statements are enabled, the driver
825 * doesn't seem to have as many firmware restart cycles...
826 *
827 * As a test, we're sticking in a 1/100s delay here */
Nishanth Aravamudan3173c892005-09-11 02:09:55 -0700828 schedule_timeout_uninterruptible(msecs_to_jiffies(10));
James Ketrenos2c86c272005-03-23 17:32:29 -0600829
830 return 0;
831
James Ketrenosee8e3652005-09-14 09:47:29 -0500832 fail_unlock:
James Ketrenos2c86c272005-03-23 17:32:29 -0600833 spin_unlock_irqrestore(&priv->low_lock, flags);
834
835 return err;
836}
837
James Ketrenos2c86c272005-03-23 17:32:29 -0600838/*
839 * Verify the values and data access of the hardware
840 * No locks needed or used. No functions called.
841 */
842static int ipw2100_verify(struct ipw2100_priv *priv)
843{
844 u32 data1, data2;
845 u32 address;
846
847 u32 val1 = 0x76543210;
848 u32 val2 = 0xFEDCBA98;
849
850 /* Domain 0 check - all values should be DOA_DEBUG */
851 for (address = IPW_REG_DOA_DEBUG_AREA_START;
James Ketrenosee8e3652005-09-14 09:47:29 -0500852 address < IPW_REG_DOA_DEBUG_AREA_END; address += sizeof(u32)) {
James Ketrenos2c86c272005-03-23 17:32:29 -0600853 read_register(priv->net_dev, address, &data1);
854 if (data1 != IPW_DATA_DOA_DEBUG_VALUE)
855 return -EIO;
856 }
857
858 /* Domain 1 check - use arbitrary read/write compare */
859 for (address = 0; address < 5; address++) {
860 /* The memory area is not used now */
861 write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
862 val1);
863 write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
864 val2);
865 read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
866 &data1);
867 read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
868 &data2);
869 if (val1 == data1 && val2 == data2)
870 return 0;
871 }
872
873 return -EIO;
874}
875
876/*
877 *
878 * Loop until the CARD_DISABLED bit is the same value as the
879 * supplied parameter
880 *
881 * TODO: See if it would be more efficient to do a wait/wake
882 * cycle and have the completion event trigger the wakeup
883 *
884 */
885#define IPW_CARD_DISABLE_COMPLETE_WAIT 100 // 100 milli
886static int ipw2100_wait_for_card_state(struct ipw2100_priv *priv, int state)
887{
888 int i;
889 u32 card_state;
890 u32 len = sizeof(card_state);
891 int err;
892
893 for (i = 0; i <= IPW_CARD_DISABLE_COMPLETE_WAIT * 1000; i += 50) {
894 err = ipw2100_get_ordinal(priv, IPW_ORD_CARD_DISABLED,
895 &card_state, &len);
896 if (err) {
897 IPW_DEBUG_INFO("Query of CARD_DISABLED ordinal "
898 "failed.\n");
899 return 0;
900 }
901
902 /* We'll break out if either the HW state says it is
903 * in the state we want, or if HOST_COMPLETE command
904 * finishes */
905 if ((card_state == state) ||
906 ((priv->status & STATUS_ENABLED) ?
907 IPW_HW_STATE_ENABLED : IPW_HW_STATE_DISABLED) == state) {
908 if (state == IPW_HW_STATE_ENABLED)
909 priv->status |= STATUS_ENABLED;
910 else
911 priv->status &= ~STATUS_ENABLED;
912
913 return 0;
914 }
915
916 udelay(50);
917 }
918
919 IPW_DEBUG_INFO("ipw2100_wait_for_card_state to %s state timed out\n",
920 state ? "DISABLED" : "ENABLED");
921 return -EIO;
922}
923
James Ketrenos2c86c272005-03-23 17:32:29 -0600924/*********************************************************************
925 Procedure : sw_reset_and_clock
926 Purpose : Asserts s/w reset, asserts clock initialization
927 and waits for clock stabilization
928 ********************************************************************/
929static int sw_reset_and_clock(struct ipw2100_priv *priv)
930{
931 int i;
932 u32 r;
933
934 // assert s/w reset
935 write_register(priv->net_dev, IPW_REG_RESET_REG,
936 IPW_AUX_HOST_RESET_REG_SW_RESET);
937
938 // wait for clock stabilization
939 for (i = 0; i < 1000; i++) {
940 udelay(IPW_WAIT_RESET_ARC_COMPLETE_DELAY);
941
942 // check clock ready bit
943 read_register(priv->net_dev, IPW_REG_RESET_REG, &r);
944 if (r & IPW_AUX_HOST_RESET_REG_PRINCETON_RESET)
945 break;
946 }
947
948 if (i == 1000)
949 return -EIO; // TODO: better error value
950
951 /* set "initialization complete" bit to move adapter to
952 * D0 state */
953 write_register(priv->net_dev, IPW_REG_GP_CNTRL,
954 IPW_AUX_HOST_GP_CNTRL_BIT_INIT_DONE);
955
956 /* wait for clock stabilization */
957 for (i = 0; i < 10000; i++) {
958 udelay(IPW_WAIT_CLOCK_STABILIZATION_DELAY * 4);
959
960 /* check clock ready bit */
961 read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
962 if (r & IPW_AUX_HOST_GP_CNTRL_BIT_CLOCK_READY)
963 break;
964 }
965
966 if (i == 10000)
967 return -EIO; /* TODO: better error value */
968
James Ketrenos2c86c272005-03-23 17:32:29 -0600969 /* set D0 standby bit */
970 read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
971 write_register(priv->net_dev, IPW_REG_GP_CNTRL,
972 r | IPW_AUX_HOST_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos2c86c272005-03-23 17:32:29 -0600973
974 return 0;
975}
976
977/*********************************************************************
Pavel Machek8724a112005-06-20 14:28:43 -0700978 Procedure : ipw2100_download_firmware
James Ketrenos2c86c272005-03-23 17:32:29 -0600979 Purpose : Initiaze adapter after power on.
980 The sequence is:
981 1. assert s/w reset first!
982 2. awake clocks & wait for clock stabilization
983 3. hold ARC (don't ask me why...)
984 4. load Dino ucode and reset/clock init again
985 5. zero-out shared mem
986 6. download f/w
987 *******************************************************************/
988static int ipw2100_download_firmware(struct ipw2100_priv *priv)
989{
990 u32 address;
991 int err;
992
993#ifndef CONFIG_PM
994 /* Fetch the firmware and microcode */
995 struct ipw2100_fw ipw2100_firmware;
996#endif
997
998 if (priv->fatal_error) {
999 IPW_DEBUG_ERROR("%s: ipw2100_download_firmware called after "
James Ketrenosee8e3652005-09-14 09:47:29 -05001000 "fatal error %d. Interface must be brought down.\n",
1001 priv->net_dev->name, priv->fatal_error);
James Ketrenos2c86c272005-03-23 17:32:29 -06001002 return -EINVAL;
1003 }
James Ketrenos2c86c272005-03-23 17:32:29 -06001004#ifdef CONFIG_PM
1005 if (!ipw2100_firmware.version) {
1006 err = ipw2100_get_firmware(priv, &ipw2100_firmware);
1007 if (err) {
1008 IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001009 priv->net_dev->name, err);
James Ketrenos2c86c272005-03-23 17:32:29 -06001010 priv->fatal_error = IPW2100_ERR_FW_LOAD;
1011 goto fail;
1012 }
1013 }
1014#else
1015 err = ipw2100_get_firmware(priv, &ipw2100_firmware);
1016 if (err) {
1017 IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001018 priv->net_dev->name, err);
James Ketrenos2c86c272005-03-23 17:32:29 -06001019 priv->fatal_error = IPW2100_ERR_FW_LOAD;
1020 goto fail;
1021 }
1022#endif
1023 priv->firmware_version = ipw2100_firmware.version;
1024
1025 /* s/w reset and clock stabilization */
1026 err = sw_reset_and_clock(priv);
1027 if (err) {
1028 IPW_DEBUG_ERROR("%s: sw_reset_and_clock failed: %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001029 priv->net_dev->name, err);
James Ketrenos2c86c272005-03-23 17:32:29 -06001030 goto fail;
1031 }
1032
1033 err = ipw2100_verify(priv);
1034 if (err) {
1035 IPW_DEBUG_ERROR("%s: ipw2100_verify failed: %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001036 priv->net_dev->name, err);
James Ketrenos2c86c272005-03-23 17:32:29 -06001037 goto fail;
1038 }
1039
1040 /* Hold ARC */
1041 write_nic_dword(priv->net_dev,
James Ketrenosee8e3652005-09-14 09:47:29 -05001042 IPW_INTERNAL_REGISTER_HALT_AND_RESET, 0x80000000);
James Ketrenos2c86c272005-03-23 17:32:29 -06001043
1044 /* allow ARC to run */
1045 write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
1046
1047 /* load microcode */
1048 err = ipw2100_ucode_download(priv, &ipw2100_firmware);
1049 if (err) {
Jiri Benc797b4f72005-08-25 20:03:27 -04001050 printk(KERN_ERR DRV_NAME ": %s: Error loading microcode: %d\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06001051 priv->net_dev->name, err);
1052 goto fail;
1053 }
1054
1055 /* release ARC */
1056 write_nic_dword(priv->net_dev,
James Ketrenosee8e3652005-09-14 09:47:29 -05001057 IPW_INTERNAL_REGISTER_HALT_AND_RESET, 0x00000000);
James Ketrenos2c86c272005-03-23 17:32:29 -06001058
1059 /* s/w reset and clock stabilization (again!!!) */
1060 err = sw_reset_and_clock(priv);
1061 if (err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001062 printk(KERN_ERR DRV_NAME
1063 ": %s: sw_reset_and_clock failed: %d\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06001064 priv->net_dev->name, err);
1065 goto fail;
1066 }
1067
1068 /* load f/w */
1069 err = ipw2100_fw_download(priv, &ipw2100_firmware);
1070 if (err) {
1071 IPW_DEBUG_ERROR("%s: Error loading firmware: %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001072 priv->net_dev->name, err);
James Ketrenos2c86c272005-03-23 17:32:29 -06001073 goto fail;
1074 }
James Ketrenos2c86c272005-03-23 17:32:29 -06001075#ifndef CONFIG_PM
1076 /*
1077 * When the .resume method of the driver is called, the other
1078 * part of the system, i.e. the ide driver could still stay in
1079 * the suspend stage. This prevents us from loading the firmware
1080 * from the disk. --YZ
1081 */
1082
1083 /* free any storage allocated for firmware image */
1084 ipw2100_release_firmware(priv, &ipw2100_firmware);
1085#endif
1086
1087 /* zero out Domain 1 area indirectly (Si requirement) */
1088 for (address = IPW_HOST_FW_SHARED_AREA0;
1089 address < IPW_HOST_FW_SHARED_AREA0_END; address += 4)
1090 write_nic_dword(priv->net_dev, address, 0);
1091 for (address = IPW_HOST_FW_SHARED_AREA1;
1092 address < IPW_HOST_FW_SHARED_AREA1_END; address += 4)
1093 write_nic_dword(priv->net_dev, address, 0);
1094 for (address = IPW_HOST_FW_SHARED_AREA2;
1095 address < IPW_HOST_FW_SHARED_AREA2_END; address += 4)
1096 write_nic_dword(priv->net_dev, address, 0);
1097 for (address = IPW_HOST_FW_SHARED_AREA3;
1098 address < IPW_HOST_FW_SHARED_AREA3_END; address += 4)
1099 write_nic_dword(priv->net_dev, address, 0);
1100 for (address = IPW_HOST_FW_INTERRUPT_AREA;
1101 address < IPW_HOST_FW_INTERRUPT_AREA_END; address += 4)
1102 write_nic_dword(priv->net_dev, address, 0);
1103
1104 return 0;
1105
James Ketrenosee8e3652005-09-14 09:47:29 -05001106 fail:
James Ketrenos2c86c272005-03-23 17:32:29 -06001107 ipw2100_release_firmware(priv, &ipw2100_firmware);
1108 return err;
1109}
1110
1111static inline void ipw2100_enable_interrupts(struct ipw2100_priv *priv)
1112{
1113 if (priv->status & STATUS_INT_ENABLED)
1114 return;
1115 priv->status |= STATUS_INT_ENABLED;
1116 write_register(priv->net_dev, IPW_REG_INTA_MASK, IPW_INTERRUPT_MASK);
1117}
1118
1119static inline void ipw2100_disable_interrupts(struct ipw2100_priv *priv)
1120{
1121 if (!(priv->status & STATUS_INT_ENABLED))
1122 return;
1123 priv->status &= ~STATUS_INT_ENABLED;
1124 write_register(priv->net_dev, IPW_REG_INTA_MASK, 0x0);
1125}
1126
James Ketrenos2c86c272005-03-23 17:32:29 -06001127static void ipw2100_initialize_ordinals(struct ipw2100_priv *priv)
1128{
1129 struct ipw2100_ordinals *ord = &priv->ordinals;
1130
1131 IPW_DEBUG_INFO("enter\n");
1132
1133 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_1,
1134 &ord->table1_addr);
1135
1136 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_2,
1137 &ord->table2_addr);
1138
1139 read_nic_dword(priv->net_dev, ord->table1_addr, &ord->table1_size);
1140 read_nic_dword(priv->net_dev, ord->table2_addr, &ord->table2_size);
1141
1142 ord->table2_size &= 0x0000FFFF;
1143
1144 IPW_DEBUG_INFO("table 1 size: %d\n", ord->table1_size);
1145 IPW_DEBUG_INFO("table 2 size: %d\n", ord->table2_size);
1146 IPW_DEBUG_INFO("exit\n");
1147}
1148
1149static inline void ipw2100_hw_set_gpio(struct ipw2100_priv *priv)
1150{
1151 u32 reg = 0;
1152 /*
1153 * Set GPIO 3 writable by FW; GPIO 1 writable
1154 * by driver and enable clock
1155 */
1156 reg = (IPW_BIT_GPIO_GPIO3_MASK | IPW_BIT_GPIO_GPIO1_ENABLE |
1157 IPW_BIT_GPIO_LED_OFF);
1158 write_register(priv->net_dev, IPW_REG_GPIO, reg);
1159}
1160
Arjan van de Ven858119e2006-01-14 13:20:43 -08001161static int rf_kill_active(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06001162{
1163#define MAX_RF_KILL_CHECKS 5
1164#define RF_KILL_CHECK_DELAY 40
James Ketrenos2c86c272005-03-23 17:32:29 -06001165
1166 unsigned short value = 0;
1167 u32 reg = 0;
1168 int i;
1169
1170 if (!(priv->hw_features & HW_FEATURE_RFKILL)) {
Matthew Garrettc26409a2009-11-11 14:36:30 -05001171 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, false);
James Ketrenos2c86c272005-03-23 17:32:29 -06001172 priv->status &= ~STATUS_RF_KILL_HW;
1173 return 0;
1174 }
1175
1176 for (i = 0; i < MAX_RF_KILL_CHECKS; i++) {
1177 udelay(RF_KILL_CHECK_DELAY);
1178 read_register(priv->net_dev, IPW_REG_GPIO, &reg);
1179 value = (value << 1) | ((reg & IPW_BIT_GPIO_RF_KILL) ? 0 : 1);
1180 }
1181
Matthew Garrettc26409a2009-11-11 14:36:30 -05001182 if (value == 0) {
1183 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
James Ketrenos2c86c272005-03-23 17:32:29 -06001184 priv->status |= STATUS_RF_KILL_HW;
Matthew Garrettc26409a2009-11-11 14:36:30 -05001185 } else {
1186 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, false);
James Ketrenos2c86c272005-03-23 17:32:29 -06001187 priv->status &= ~STATUS_RF_KILL_HW;
Matthew Garrettc26409a2009-11-11 14:36:30 -05001188 }
James Ketrenos2c86c272005-03-23 17:32:29 -06001189
1190 return (value == 0);
1191}
1192
1193static int ipw2100_get_hw_features(struct ipw2100_priv *priv)
1194{
1195 u32 addr, len;
1196 u32 val;
1197
1198 /*
1199 * EEPROM_SRAM_DB_START_ADDRESS using ordinal in ordinal table 1
1200 */
1201 len = sizeof(addr);
James Ketrenosee8e3652005-09-14 09:47:29 -05001202 if (ipw2100_get_ordinal
1203 (priv, IPW_ORD_EEPROM_SRAM_DB_BLOCK_START_ADDRESS, &addr, &len)) {
James Ketrenos2c86c272005-03-23 17:32:29 -06001204 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001205 __LINE__);
James Ketrenos2c86c272005-03-23 17:32:29 -06001206 return -EIO;
1207 }
1208
1209 IPW_DEBUG_INFO("EEPROM address: %08X\n", addr);
1210
1211 /*
1212 * EEPROM version is the byte at offset 0xfd in firmware
1213 * We read 4 bytes, then shift out the byte we actually want */
1214 read_nic_dword(priv->net_dev, addr + 0xFC, &val);
1215 priv->eeprom_version = (val >> 24) & 0xFF;
1216 IPW_DEBUG_INFO("EEPROM version: %d\n", priv->eeprom_version);
1217
James Ketrenosee8e3652005-09-14 09:47:29 -05001218 /*
James Ketrenos2c86c272005-03-23 17:32:29 -06001219 * HW RF Kill enable is bit 0 in byte at offset 0x21 in firmware
1220 *
1221 * notice that the EEPROM bit is reverse polarity, i.e.
1222 * bit = 0 signifies HW RF kill switch is supported
1223 * bit = 1 signifies HW RF kill switch is NOT supported
1224 */
1225 read_nic_dword(priv->net_dev, addr + 0x20, &val);
1226 if (!((val >> 24) & 0x01))
1227 priv->hw_features |= HW_FEATURE_RFKILL;
1228
1229 IPW_DEBUG_INFO("HW RF Kill: %ssupported.\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001230 (priv->hw_features & HW_FEATURE_RFKILL) ? "" : "not ");
James Ketrenos2c86c272005-03-23 17:32:29 -06001231
1232 return 0;
1233}
1234
1235/*
1236 * Start firmware execution after power on and intialization
1237 * The sequence is:
1238 * 1. Release ARC
1239 * 2. Wait for f/w initialization completes;
1240 */
1241static int ipw2100_start_adapter(struct ipw2100_priv *priv)
1242{
James Ketrenos2c86c272005-03-23 17:32:29 -06001243 int i;
1244 u32 inta, inta_mask, gpio;
1245
1246 IPW_DEBUG_INFO("enter\n");
1247
1248 if (priv->status & STATUS_RUNNING)
1249 return 0;
1250
1251 /*
1252 * Initialize the hw - drive adapter to DO state by setting
1253 * init_done bit. Wait for clk_ready bit and Download
1254 * fw & dino ucode
1255 */
1256 if (ipw2100_download_firmware(priv)) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001257 printk(KERN_ERR DRV_NAME
1258 ": %s: Failed to power on the adapter.\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06001259 priv->net_dev->name);
1260 return -EIO;
1261 }
1262
1263 /* Clear the Tx, Rx and Msg queues and the r/w indexes
1264 * in the firmware RBD and TBD ring queue */
1265 ipw2100_queues_initialize(priv);
1266
1267 ipw2100_hw_set_gpio(priv);
1268
1269 /* TODO -- Look at disabling interrupts here to make sure none
1270 * get fired during FW initialization */
1271
1272 /* Release ARC - clear reset bit */
1273 write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
1274
1275 /* wait for f/w intialization complete */
1276 IPW_DEBUG_FW("Waiting for f/w initialization to complete...\n");
1277 i = 5000;
1278 do {
Nishanth Aravamudan3173c892005-09-11 02:09:55 -07001279 schedule_timeout_uninterruptible(msecs_to_jiffies(40));
James Ketrenos2c86c272005-03-23 17:32:29 -06001280 /* Todo... wait for sync command ... */
1281
1282 read_register(priv->net_dev, IPW_REG_INTA, &inta);
1283
1284 /* check "init done" bit */
1285 if (inta & IPW2100_INTA_FW_INIT_DONE) {
1286 /* reset "init done" bit */
1287 write_register(priv->net_dev, IPW_REG_INTA,
1288 IPW2100_INTA_FW_INIT_DONE);
1289 break;
1290 }
1291
1292 /* check error conditions : we check these after the firmware
1293 * check so that if there is an error, the interrupt handler
1294 * will see it and the adapter will be reset */
1295 if (inta &
1296 (IPW2100_INTA_FATAL_ERROR | IPW2100_INTA_PARITY_ERROR)) {
1297 /* clear error conditions */
1298 write_register(priv->net_dev, IPW_REG_INTA,
1299 IPW2100_INTA_FATAL_ERROR |
1300 IPW2100_INTA_PARITY_ERROR);
1301 }
Roel Kluina2a1c3e2007-11-05 23:55:02 +01001302 } while (--i);
James Ketrenos2c86c272005-03-23 17:32:29 -06001303
1304 /* Clear out any pending INTAs since we aren't supposed to have
1305 * interrupts enabled at this point... */
1306 read_register(priv->net_dev, IPW_REG_INTA, &inta);
1307 read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
1308 inta &= IPW_INTERRUPT_MASK;
1309 /* Clear out any pending interrupts */
1310 if (inta & inta_mask)
1311 write_register(priv->net_dev, IPW_REG_INTA, inta);
1312
1313 IPW_DEBUG_FW("f/w initialization complete: %s\n",
1314 i ? "SUCCESS" : "FAILED");
1315
1316 if (!i) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001317 printk(KERN_WARNING DRV_NAME
1318 ": %s: Firmware did not initialize.\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06001319 priv->net_dev->name);
1320 return -EIO;
1321 }
1322
1323 /* allow firmware to write to GPIO1 & GPIO3 */
1324 read_register(priv->net_dev, IPW_REG_GPIO, &gpio);
1325
1326 gpio |= (IPW_BIT_GPIO_GPIO1_MASK | IPW_BIT_GPIO_GPIO3_MASK);
1327
1328 write_register(priv->net_dev, IPW_REG_GPIO, gpio);
1329
1330 /* Ready to receive commands */
1331 priv->status |= STATUS_RUNNING;
1332
1333 /* The adapter has been reset; we are not associated */
1334 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
1335
1336 IPW_DEBUG_INFO("exit\n");
1337
1338 return 0;
1339}
1340
1341static inline void ipw2100_reset_fatalerror(struct ipw2100_priv *priv)
1342{
1343 if (!priv->fatal_error)
1344 return;
1345
1346 priv->fatal_errors[priv->fatal_index++] = priv->fatal_error;
1347 priv->fatal_index %= IPW2100_ERROR_QUEUE;
1348 priv->fatal_error = 0;
1349}
1350
James Ketrenos2c86c272005-03-23 17:32:29 -06001351/* NOTE: Our interrupt is disabled when this method is called */
1352static int ipw2100_power_cycle_adapter(struct ipw2100_priv *priv)
1353{
1354 u32 reg;
1355 int i;
1356
1357 IPW_DEBUG_INFO("Power cycling the hardware.\n");
1358
1359 ipw2100_hw_set_gpio(priv);
1360
1361 /* Step 1. Stop Master Assert */
1362 write_register(priv->net_dev, IPW_REG_RESET_REG,
1363 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
1364
1365 /* Step 2. Wait for stop Master Assert
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02001366 * (not more than 50us, otherwise ret error */
James Ketrenos2c86c272005-03-23 17:32:29 -06001367 i = 5;
1368 do {
1369 udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
1370 read_register(priv->net_dev, IPW_REG_RESET_REG, &reg);
1371
1372 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
1373 break;
Roel Kluina2a1c3e2007-11-05 23:55:02 +01001374 } while (--i);
James Ketrenos2c86c272005-03-23 17:32:29 -06001375
1376 priv->status &= ~STATUS_RESET_PENDING;
1377
1378 if (!i) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001379 IPW_DEBUG_INFO
1380 ("exit - waited too long for master assert stop\n");
James Ketrenos2c86c272005-03-23 17:32:29 -06001381 return -EIO;
1382 }
1383
1384 write_register(priv->net_dev, IPW_REG_RESET_REG,
1385 IPW_AUX_HOST_RESET_REG_SW_RESET);
1386
James Ketrenos2c86c272005-03-23 17:32:29 -06001387 /* Reset any fatal_error conditions */
1388 ipw2100_reset_fatalerror(priv);
1389
1390 /* At this point, the adapter is now stopped and disabled */
1391 priv->status &= ~(STATUS_RUNNING | STATUS_ASSOCIATING |
1392 STATUS_ASSOCIATED | STATUS_ENABLED);
1393
1394 return 0;
1395}
1396
1397/*
1398 * Send the CARD_DISABLE_PHY_OFF comamnd to the card to disable it
1399 *
1400 * After disabling, if the card was associated, a STATUS_ASSN_LOST will be sent.
1401 *
1402 * STATUS_CARD_DISABLE_NOTIFICATION will be sent regardless of
1403 * if STATUS_ASSN_LOST is sent.
1404 */
1405static int ipw2100_hw_phy_off(struct ipw2100_priv *priv)
1406{
1407
1408#define HW_PHY_OFF_LOOP_DELAY (HZ / 5000)
1409
1410 struct host_command cmd = {
1411 .host_command = CARD_DISABLE_PHY_OFF,
1412 .host_command_sequence = 0,
1413 .host_command_length = 0,
1414 };
1415 int err, i;
1416 u32 val1, val2;
1417
1418 IPW_DEBUG_HC("CARD_DISABLE_PHY_OFF\n");
1419
1420 /* Turn off the radio */
1421 err = ipw2100_hw_send_command(priv, &cmd);
1422 if (err)
1423 return err;
1424
1425 for (i = 0; i < 2500; i++) {
1426 read_nic_dword(priv->net_dev, IPW2100_CONTROL_REG, &val1);
1427 read_nic_dword(priv->net_dev, IPW2100_COMMAND, &val2);
1428
1429 if ((val1 & IPW2100_CONTROL_PHY_OFF) &&
1430 (val2 & IPW2100_COMMAND_PHY_OFF))
1431 return 0;
1432
Nishanth Aravamudan3173c892005-09-11 02:09:55 -07001433 schedule_timeout_uninterruptible(HW_PHY_OFF_LOOP_DELAY);
James Ketrenos2c86c272005-03-23 17:32:29 -06001434 }
1435
1436 return -EIO;
1437}
1438
James Ketrenos2c86c272005-03-23 17:32:29 -06001439static int ipw2100_enable_adapter(struct ipw2100_priv *priv)
1440{
1441 struct host_command cmd = {
1442 .host_command = HOST_COMPLETE,
1443 .host_command_sequence = 0,
1444 .host_command_length = 0
1445 };
1446 int err = 0;
1447
1448 IPW_DEBUG_HC("HOST_COMPLETE\n");
1449
1450 if (priv->status & STATUS_ENABLED)
1451 return 0;
1452
Ingo Molnar752e3772006-02-28 07:20:54 +08001453 mutex_lock(&priv->adapter_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06001454
1455 if (rf_kill_active(priv)) {
1456 IPW_DEBUG_HC("Command aborted due to RF kill active.\n");
1457 goto fail_up;
1458 }
1459
1460 err = ipw2100_hw_send_command(priv, &cmd);
1461 if (err) {
1462 IPW_DEBUG_INFO("Failed to send HOST_COMPLETE command\n");
1463 goto fail_up;
1464 }
1465
1466 err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_ENABLED);
1467 if (err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001468 IPW_DEBUG_INFO("%s: card not responding to init command.\n",
1469 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001470 goto fail_up;
1471 }
1472
1473 if (priv->stop_hang_check) {
1474 priv->stop_hang_check = 0;
1475 queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2);
1476 }
1477
James Ketrenosee8e3652005-09-14 09:47:29 -05001478 fail_up:
Ingo Molnar752e3772006-02-28 07:20:54 +08001479 mutex_unlock(&priv->adapter_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06001480 return err;
1481}
1482
1483static int ipw2100_hw_stop_adapter(struct ipw2100_priv *priv)
1484{
Nishanth Aravamudan3173c892005-09-11 02:09:55 -07001485#define HW_POWER_DOWN_DELAY (msecs_to_jiffies(100))
James Ketrenos2c86c272005-03-23 17:32:29 -06001486
1487 struct host_command cmd = {
1488 .host_command = HOST_PRE_POWER_DOWN,
1489 .host_command_sequence = 0,
1490 .host_command_length = 0,
1491 };
1492 int err, i;
1493 u32 reg;
1494
1495 if (!(priv->status & STATUS_RUNNING))
1496 return 0;
1497
1498 priv->status |= STATUS_STOPPING;
1499
1500 /* We can only shut down the card if the firmware is operational. So,
1501 * if we haven't reset since a fatal_error, then we can not send the
1502 * shutdown commands. */
1503 if (!priv->fatal_error) {
1504 /* First, make sure the adapter is enabled so that the PHY_OFF
1505 * command can shut it down */
1506 ipw2100_enable_adapter(priv);
1507
1508 err = ipw2100_hw_phy_off(priv);
1509 if (err)
James Ketrenosee8e3652005-09-14 09:47:29 -05001510 printk(KERN_WARNING DRV_NAME
1511 ": Error disabling radio %d\n", err);
James Ketrenos2c86c272005-03-23 17:32:29 -06001512
1513 /*
1514 * If in D0-standby mode going directly to D3 may cause a
1515 * PCI bus violation. Therefore we must change out of the D0
1516 * state.
1517 *
1518 * Sending the PREPARE_FOR_POWER_DOWN will restrict the
1519 * hardware from going into standby mode and will transition
Andreas Mohrd6e05ed2006-06-26 18:35:02 +02001520 * out of D0-standby if it is already in that state.
James Ketrenos2c86c272005-03-23 17:32:29 -06001521 *
1522 * STATUS_PREPARE_POWER_DOWN_COMPLETE will be sent by the
1523 * driver upon completion. Once received, the driver can
1524 * proceed to the D3 state.
1525 *
1526 * Prepare for power down command to fw. This command would
1527 * take HW out of D0-standby and prepare it for D3 state.
1528 *
1529 * Currently FW does not support event notification for this
1530 * event. Therefore, skip waiting for it. Just wait a fixed
1531 * 100ms
1532 */
1533 IPW_DEBUG_HC("HOST_PRE_POWER_DOWN\n");
1534
1535 err = ipw2100_hw_send_command(priv, &cmd);
1536 if (err)
Jiri Benc797b4f72005-08-25 20:03:27 -04001537 printk(KERN_WARNING DRV_NAME ": "
James Ketrenos2c86c272005-03-23 17:32:29 -06001538 "%s: Power down command failed: Error %d\n",
1539 priv->net_dev->name, err);
Nishanth Aravamudan3173c892005-09-11 02:09:55 -07001540 else
1541 schedule_timeout_uninterruptible(HW_POWER_DOWN_DELAY);
James Ketrenos2c86c272005-03-23 17:32:29 -06001542 }
1543
1544 priv->status &= ~STATUS_ENABLED;
1545
1546 /*
1547 * Set GPIO 3 writable by FW; GPIO 1 writable
1548 * by driver and enable clock
1549 */
1550 ipw2100_hw_set_gpio(priv);
1551
1552 /*
1553 * Power down adapter. Sequence:
1554 * 1. Stop master assert (RESET_REG[9]=1)
1555 * 2. Wait for stop master (RESET_REG[8]==1)
1556 * 3. S/w reset assert (RESET_REG[7] = 1)
1557 */
1558
1559 /* Stop master assert */
1560 write_register(priv->net_dev, IPW_REG_RESET_REG,
1561 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
1562
1563 /* wait stop master not more than 50 usec.
1564 * Otherwise return error. */
1565 for (i = 5; i > 0; i--) {
1566 udelay(10);
1567
1568 /* Check master stop bit */
1569 read_register(priv->net_dev, IPW_REG_RESET_REG, &reg);
1570
1571 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
1572 break;
1573 }
1574
1575 if (i == 0)
Jiri Benc797b4f72005-08-25 20:03:27 -04001576 printk(KERN_WARNING DRV_NAME
James Ketrenos2c86c272005-03-23 17:32:29 -06001577 ": %s: Could now power down adapter.\n",
1578 priv->net_dev->name);
1579
1580 /* assert s/w reset */
1581 write_register(priv->net_dev, IPW_REG_RESET_REG,
1582 IPW_AUX_HOST_RESET_REG_SW_RESET);
1583
1584 priv->status &= ~(STATUS_RUNNING | STATUS_STOPPING);
1585
1586 return 0;
1587}
1588
James Ketrenos2c86c272005-03-23 17:32:29 -06001589static int ipw2100_disable_adapter(struct ipw2100_priv *priv)
1590{
1591 struct host_command cmd = {
1592 .host_command = CARD_DISABLE,
1593 .host_command_sequence = 0,
1594 .host_command_length = 0
1595 };
1596 int err = 0;
1597
1598 IPW_DEBUG_HC("CARD_DISABLE\n");
1599
1600 if (!(priv->status & STATUS_ENABLED))
1601 return 0;
1602
1603 /* Make sure we clear the associated state */
1604 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1605
1606 if (!priv->stop_hang_check) {
1607 priv->stop_hang_check = 1;
1608 cancel_delayed_work(&priv->hang_check);
1609 }
1610
Ingo Molnar752e3772006-02-28 07:20:54 +08001611 mutex_lock(&priv->adapter_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06001612
1613 err = ipw2100_hw_send_command(priv, &cmd);
1614 if (err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001615 printk(KERN_WARNING DRV_NAME
1616 ": exit - failed to send CARD_DISABLE command\n");
James Ketrenos2c86c272005-03-23 17:32:29 -06001617 goto fail_up;
1618 }
1619
1620 err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_DISABLED);
1621 if (err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001622 printk(KERN_WARNING DRV_NAME
1623 ": exit - card failed to change to DISABLED\n");
James Ketrenos2c86c272005-03-23 17:32:29 -06001624 goto fail_up;
1625 }
1626
1627 IPW_DEBUG_INFO("TODO: implement scan state machine\n");
1628
James Ketrenosee8e3652005-09-14 09:47:29 -05001629 fail_up:
Ingo Molnar752e3772006-02-28 07:20:54 +08001630 mutex_unlock(&priv->adapter_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06001631 return err;
1632}
1633
Jiri Bencc4aee8c2005-08-25 20:04:43 -04001634static int ipw2100_set_scan_options(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06001635{
1636 struct host_command cmd = {
1637 .host_command = SET_SCAN_OPTIONS,
1638 .host_command_sequence = 0,
1639 .host_command_length = 8
1640 };
1641 int err;
1642
1643 IPW_DEBUG_INFO("enter\n");
1644
1645 IPW_DEBUG_SCAN("setting scan options\n");
1646
1647 cmd.host_command_parameters[0] = 0;
1648
1649 if (!(priv->config & CFG_ASSOCIATE))
1650 cmd.host_command_parameters[0] |= IPW_SCAN_NOASSOCIATE;
25b645b2005-07-12 15:45:30 -05001651 if ((priv->ieee->sec.flags & SEC_ENABLED) && priv->ieee->sec.enabled)
James Ketrenos2c86c272005-03-23 17:32:29 -06001652 cmd.host_command_parameters[0] |= IPW_SCAN_MIXED_CELL;
1653 if (priv->config & CFG_PASSIVE_SCAN)
1654 cmd.host_command_parameters[0] |= IPW_SCAN_PASSIVE;
1655
1656 cmd.host_command_parameters[1] = priv->channel_mask;
1657
1658 err = ipw2100_hw_send_command(priv, &cmd);
1659
1660 IPW_DEBUG_HC("SET_SCAN_OPTIONS 0x%04X\n",
1661 cmd.host_command_parameters[0]);
1662
1663 return err;
1664}
1665
Jiri Bencc4aee8c2005-08-25 20:04:43 -04001666static int ipw2100_start_scan(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06001667{
1668 struct host_command cmd = {
1669 .host_command = BROADCAST_SCAN,
1670 .host_command_sequence = 0,
1671 .host_command_length = 4
1672 };
1673 int err;
1674
1675 IPW_DEBUG_HC("START_SCAN\n");
1676
1677 cmd.host_command_parameters[0] = 0;
1678
1679 /* No scanning if in monitor mode */
1680 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
1681 return 1;
1682
1683 if (priv->status & STATUS_SCANNING) {
1684 IPW_DEBUG_SCAN("Scan requested while already in scan...\n");
1685 return 0;
1686 }
1687
1688 IPW_DEBUG_INFO("enter\n");
1689
1690 /* Not clearing here; doing so makes iwlist always return nothing...
1691 *
1692 * We should modify the table logic to use aging tables vs. clearing
1693 * the table on each scan start.
1694 */
1695 IPW_DEBUG_SCAN("starting scan\n");
1696
1697 priv->status |= STATUS_SCANNING;
1698 err = ipw2100_hw_send_command(priv, &cmd);
1699 if (err)
1700 priv->status &= ~STATUS_SCANNING;
1701
1702 IPW_DEBUG_INFO("exit\n");
1703
1704 return err;
1705}
1706
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001707static const struct libipw_geo ipw_geos[] = {
Zhu Yibe6b3b12006-01-24 13:49:08 +08001708 { /* Restricted */
1709 "---",
1710 .bg_channels = 14,
1711 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
1712 {2427, 4}, {2432, 5}, {2437, 6},
1713 {2442, 7}, {2447, 8}, {2452, 9},
1714 {2457, 10}, {2462, 11}, {2467, 12},
1715 {2472, 13}, {2484, 14}},
1716 },
1717};
1718
James Ketrenos2c86c272005-03-23 17:32:29 -06001719static int ipw2100_up(struct ipw2100_priv *priv, int deferred)
1720{
1721 unsigned long flags;
1722 int rc = 0;
1723 u32 lock;
1724 u32 ord_len = sizeof(lock);
1725
Dan Williamsc3d72b92009-02-11 13:26:06 -05001726 /* Age scan list entries found before suspend */
1727 if (priv->suspend_time) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001728 libipw_networks_age(priv->ieee, priv->suspend_time);
Dan Williamsc3d72b92009-02-11 13:26:06 -05001729 priv->suspend_time = 0;
1730 }
1731
1732 /* Quiet if manually disabled. */
James Ketrenos2c86c272005-03-23 17:32:29 -06001733 if (priv->status & STATUS_RF_KILL_SW) {
1734 IPW_DEBUG_INFO("%s: Radio is disabled by Manual Disable "
1735 "switch\n", priv->net_dev->name);
1736 return 0;
1737 }
1738
Arjan van de Ven5c875792006-09-30 23:27:17 -07001739 /* the ipw2100 hardware really doesn't want power management delays
1740 * longer than 175usec
1741 */
Mark Grossf011e2e2008-02-04 22:30:09 -08001742 pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100", 175);
Arjan van de Ven5c875792006-09-30 23:27:17 -07001743
James Ketrenos2c86c272005-03-23 17:32:29 -06001744 /* If the interrupt is enabled, turn it off... */
1745 spin_lock_irqsave(&priv->low_lock, flags);
1746 ipw2100_disable_interrupts(priv);
1747
1748 /* Reset any fatal_error conditions */
1749 ipw2100_reset_fatalerror(priv);
1750 spin_unlock_irqrestore(&priv->low_lock, flags);
1751
1752 if (priv->status & STATUS_POWERED ||
1753 (priv->status & STATUS_RESET_PENDING)) {
1754 /* Power cycle the card ... */
1755 if (ipw2100_power_cycle_adapter(priv)) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001756 printk(KERN_WARNING DRV_NAME
1757 ": %s: Could not cycle adapter.\n",
1758 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001759 rc = 1;
1760 goto exit;
1761 }
1762 } else
1763 priv->status |= STATUS_POWERED;
1764
Pavel Machek8724a112005-06-20 14:28:43 -07001765 /* Load the firmware, start the clocks, etc. */
James Ketrenos2c86c272005-03-23 17:32:29 -06001766 if (ipw2100_start_adapter(priv)) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001767 printk(KERN_ERR DRV_NAME
1768 ": %s: Failed to start the firmware.\n",
1769 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001770 rc = 1;
1771 goto exit;
1772 }
1773
1774 ipw2100_initialize_ordinals(priv);
1775
1776 /* Determine capabilities of this particular HW configuration */
1777 if (ipw2100_get_hw_features(priv)) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001778 printk(KERN_ERR DRV_NAME
1779 ": %s: Failed to determine HW features.\n",
1780 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001781 rc = 1;
1782 goto exit;
1783 }
1784
Zhu Yibe6b3b12006-01-24 13:49:08 +08001785 /* Initialize the geo */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001786 if (libipw_set_geo(priv->ieee, &ipw_geos[0])) {
Zhu Yibe6b3b12006-01-24 13:49:08 +08001787 printk(KERN_WARNING DRV_NAME "Could not set geo\n");
1788 return 0;
1789 }
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001790 priv->ieee->freq_band = LIBIPW_24GHZ_BAND;
Zhu Yibe6b3b12006-01-24 13:49:08 +08001791
James Ketrenos2c86c272005-03-23 17:32:29 -06001792 lock = LOCK_NONE;
1793 if (ipw2100_set_ordinal(priv, IPW_ORD_PERS_DB_LOCK, &lock, &ord_len)) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001794 printk(KERN_ERR DRV_NAME
1795 ": %s: Failed to clear ordinal lock.\n",
1796 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001797 rc = 1;
1798 goto exit;
1799 }
1800
1801 priv->status &= ~STATUS_SCANNING;
1802
1803 if (rf_kill_active(priv)) {
1804 printk(KERN_INFO "%s: Radio is disabled by RF switch.\n",
1805 priv->net_dev->name);
1806
1807 if (priv->stop_rf_kill) {
1808 priv->stop_rf_kill = 0;
Stephen Hemmingera62056f2007-06-22 21:46:50 -07001809 queue_delayed_work(priv->workqueue, &priv->rf_kill,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05001810 round_jiffies_relative(HZ));
James Ketrenos2c86c272005-03-23 17:32:29 -06001811 }
1812
1813 deferred = 1;
1814 }
1815
1816 /* Turn on the interrupt so that commands can be processed */
1817 ipw2100_enable_interrupts(priv);
1818
1819 /* Send all of the commands that must be sent prior to
1820 * HOST_COMPLETE */
1821 if (ipw2100_adapter_setup(priv)) {
Jiri Benc797b4f72005-08-25 20:03:27 -04001822 printk(KERN_ERR DRV_NAME ": %s: Failed to start the card.\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001823 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001824 rc = 1;
1825 goto exit;
1826 }
1827
1828 if (!deferred) {
1829 /* Enable the adapter - sends HOST_COMPLETE */
1830 if (ipw2100_enable_adapter(priv)) {
Jiri Benc797b4f72005-08-25 20:03:27 -04001831 printk(KERN_ERR DRV_NAME ": "
James Ketrenosee8e3652005-09-14 09:47:29 -05001832 "%s: failed in call to enable adapter.\n",
1833 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001834 ipw2100_hw_stop_adapter(priv);
1835 rc = 1;
1836 goto exit;
1837 }
1838
James Ketrenos2c86c272005-03-23 17:32:29 -06001839 /* Start a scan . . . */
1840 ipw2100_set_scan_options(priv);
1841 ipw2100_start_scan(priv);
1842 }
1843
James Ketrenosee8e3652005-09-14 09:47:29 -05001844 exit:
James Ketrenos2c86c272005-03-23 17:32:29 -06001845 return rc;
1846}
1847
James Ketrenos2c86c272005-03-23 17:32:29 -06001848static void ipw2100_down(struct ipw2100_priv *priv)
1849{
1850 unsigned long flags;
1851 union iwreq_data wrqu = {
1852 .ap_addr = {
James Ketrenosee8e3652005-09-14 09:47:29 -05001853 .sa_family = ARPHRD_ETHER}
James Ketrenos2c86c272005-03-23 17:32:29 -06001854 };
1855 int associated = priv->status & STATUS_ASSOCIATED;
1856
1857 /* Kill the RF switch timer */
1858 if (!priv->stop_rf_kill) {
1859 priv->stop_rf_kill = 1;
1860 cancel_delayed_work(&priv->rf_kill);
1861 }
1862
Nick Andrew44072452009-01-03 18:52:40 +11001863 /* Kill the firmware hang check timer */
James Ketrenos2c86c272005-03-23 17:32:29 -06001864 if (!priv->stop_hang_check) {
1865 priv->stop_hang_check = 1;
1866 cancel_delayed_work(&priv->hang_check);
1867 }
1868
1869 /* Kill any pending resets */
1870 if (priv->status & STATUS_RESET_PENDING)
1871 cancel_delayed_work(&priv->reset_work);
1872
1873 /* Make sure the interrupt is on so that FW commands will be
1874 * processed correctly */
1875 spin_lock_irqsave(&priv->low_lock, flags);
1876 ipw2100_enable_interrupts(priv);
1877 spin_unlock_irqrestore(&priv->low_lock, flags);
1878
1879 if (ipw2100_hw_stop_adapter(priv))
Jiri Benc797b4f72005-08-25 20:03:27 -04001880 printk(KERN_ERR DRV_NAME ": %s: Error stopping adapter.\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06001881 priv->net_dev->name);
1882
1883 /* Do not disable the interrupt until _after_ we disable
1884 * the adaptor. Otherwise the CARD_DISABLE command will never
1885 * be ack'd by the firmware */
1886 spin_lock_irqsave(&priv->low_lock, flags);
1887 ipw2100_disable_interrupts(priv);
1888 spin_unlock_irqrestore(&priv->low_lock, flags);
1889
Mark Grossf011e2e2008-02-04 22:30:09 -08001890 pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100",
1891 PM_QOS_DEFAULT_VALUE);
Arjan van de Ven5c875792006-09-30 23:27:17 -07001892
James Ketrenos2c86c272005-03-23 17:32:29 -06001893 /* We have to signal any supplicant if we are disassociating */
1894 if (associated)
1895 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1896
1897 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1898 netif_carrier_off(priv->net_dev);
1899 netif_stop_queue(priv->net_dev);
1900}
1901
Matthew Garrettc26409a2009-11-11 14:36:30 -05001902/* Called by register_netdev() */
1903static int ipw2100_net_init(struct net_device *dev)
1904{
1905 struct ipw2100_priv *priv = libipw_priv(dev);
1906 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
1907 struct wireless_dev *wdev = &priv->ieee->wdev;
1908 int ret;
1909 int i;
1910
1911 ret = ipw2100_up(priv, 1);
1912 if (ret)
1913 return ret;
1914
1915 memcpy(wdev->wiphy->perm_addr, priv->mac_addr, ETH_ALEN);
1916
1917 /* fill-out priv->ieee->bg_band */
1918 if (geo->bg_channels) {
1919 struct ieee80211_supported_band *bg_band = &priv->ieee->bg_band;
1920
1921 bg_band->band = IEEE80211_BAND_2GHZ;
1922 bg_band->n_channels = geo->bg_channels;
1923 bg_band->channels =
1924 kzalloc(geo->bg_channels *
1925 sizeof(struct ieee80211_channel), GFP_KERNEL);
1926 /* translate geo->bg to bg_band.channels */
1927 for (i = 0; i < geo->bg_channels; i++) {
1928 bg_band->channels[i].band = IEEE80211_BAND_2GHZ;
1929 bg_band->channels[i].center_freq = geo->bg[i].freq;
1930 bg_band->channels[i].hw_value = geo->bg[i].channel;
1931 bg_band->channels[i].max_power = geo->bg[i].max_power;
1932 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY)
1933 bg_band->channels[i].flags |=
1934 IEEE80211_CHAN_PASSIVE_SCAN;
1935 if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS)
1936 bg_band->channels[i].flags |=
1937 IEEE80211_CHAN_NO_IBSS;
1938 if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)
1939 bg_band->channels[i].flags |=
1940 IEEE80211_CHAN_RADAR;
1941 /* No equivalent for LIBIPW_CH_80211H_RULES,
1942 LIBIPW_CH_UNIFORM_SPREADING, or
1943 LIBIPW_CH_B_ONLY... */
1944 }
1945 /* point at bitrate info */
1946 bg_band->bitrates = ipw2100_bg_rates;
1947 bg_band->n_bitrates = RATE_COUNT;
1948
1949 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = bg_band;
1950 }
1951
1952 set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev);
1953 if (wiphy_register(wdev->wiphy)) {
1954 ipw2100_down(priv);
1955 return -EIO;
1956 }
1957 return 0;
1958}
1959
David Howellsc4028952006-11-22 14:57:56 +00001960static void ipw2100_reset_adapter(struct work_struct *work)
James Ketrenos2c86c272005-03-23 17:32:29 -06001961{
David Howellsc4028952006-11-22 14:57:56 +00001962 struct ipw2100_priv *priv =
1963 container_of(work, struct ipw2100_priv, reset_work.work);
James Ketrenos2c86c272005-03-23 17:32:29 -06001964 unsigned long flags;
1965 union iwreq_data wrqu = {
1966 .ap_addr = {
James Ketrenosee8e3652005-09-14 09:47:29 -05001967 .sa_family = ARPHRD_ETHER}
James Ketrenos2c86c272005-03-23 17:32:29 -06001968 };
1969 int associated = priv->status & STATUS_ASSOCIATED;
1970
1971 spin_lock_irqsave(&priv->low_lock, flags);
Zhu Yia1e695a2005-07-04 14:06:00 +08001972 IPW_DEBUG_INFO(": %s: Restarting adapter.\n", priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001973 priv->resets++;
1974 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1975 priv->status |= STATUS_SECURITY_UPDATED;
1976
1977 /* Force a power cycle even if interface hasn't been opened
1978 * yet */
1979 cancel_delayed_work(&priv->reset_work);
1980 priv->status |= STATUS_RESET_PENDING;
1981 spin_unlock_irqrestore(&priv->low_lock, flags);
1982
Ingo Molnar752e3772006-02-28 07:20:54 +08001983 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06001984 /* stop timed checks so that they don't interfere with reset */
1985 priv->stop_hang_check = 1;
1986 cancel_delayed_work(&priv->hang_check);
1987
1988 /* We have to signal any supplicant if we are disassociating */
1989 if (associated)
1990 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1991
1992 ipw2100_up(priv, 0);
Ingo Molnar752e3772006-02-28 07:20:54 +08001993 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06001994
1995}
1996
James Ketrenos2c86c272005-03-23 17:32:29 -06001997static void isr_indicate_associated(struct ipw2100_priv *priv, u32 status)
1998{
1999
2000#define MAC_ASSOCIATION_READ_DELAY (HZ)
Hannes Ederb9da9e92009-02-14 11:50:26 +00002001 int ret;
2002 unsigned int len, essid_len;
James Ketrenos2c86c272005-03-23 17:32:29 -06002003 char essid[IW_ESSID_MAX_SIZE];
2004 u32 txrate;
2005 u32 chan;
2006 char *txratename;
James Ketrenosee8e3652005-09-14 09:47:29 -05002007 u8 bssid[ETH_ALEN];
John W. Linville9387b7c2008-09-30 20:59:05 -04002008 DECLARE_SSID_BUF(ssid);
James Ketrenos2c86c272005-03-23 17:32:29 -06002009
2010 /*
2011 * TBD: BSSID is usually 00:00:00:00:00:00 here and not
2012 * an actual MAC of the AP. Seems like FW sets this
2013 * address too late. Read it later and expose through
2014 * /proc or schedule a later task to query and update
2015 */
2016
2017 essid_len = IW_ESSID_MAX_SIZE;
2018 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID,
2019 essid, &essid_len);
2020 if (ret) {
2021 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05002022 __LINE__);
James Ketrenos2c86c272005-03-23 17:32:29 -06002023 return;
2024 }
2025
2026 len = sizeof(u32);
James Ketrenosee8e3652005-09-14 09:47:29 -05002027 ret = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &txrate, &len);
James Ketrenos2c86c272005-03-23 17:32:29 -06002028 if (ret) {
2029 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05002030 __LINE__);
James Ketrenos2c86c272005-03-23 17:32:29 -06002031 return;
2032 }
2033
2034 len = sizeof(u32);
2035 ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &len);
2036 if (ret) {
2037 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05002038 __LINE__);
James Ketrenos2c86c272005-03-23 17:32:29 -06002039 return;
2040 }
2041 len = ETH_ALEN;
James Ketrenosee8e3652005-09-14 09:47:29 -05002042 ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID, &bssid, &len);
James Ketrenos2c86c272005-03-23 17:32:29 -06002043 if (ret) {
2044 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05002045 __LINE__);
James Ketrenos2c86c272005-03-23 17:32:29 -06002046 return;
2047 }
2048 memcpy(priv->ieee->bssid, bssid, ETH_ALEN);
2049
James Ketrenos2c86c272005-03-23 17:32:29 -06002050 switch (txrate) {
2051 case TX_RATE_1_MBIT:
2052 txratename = "1Mbps";
2053 break;
2054 case TX_RATE_2_MBIT:
2055 txratename = "2Mbsp";
2056 break;
2057 case TX_RATE_5_5_MBIT:
2058 txratename = "5.5Mbps";
2059 break;
2060 case TX_RATE_11_MBIT:
2061 txratename = "11Mbps";
2062 break;
2063 default:
2064 IPW_DEBUG_INFO("Unknown rate: %d\n", txrate);
2065 txratename = "unknown rate";
2066 break;
2067 }
2068
Johannes Berge1749612008-10-27 15:59:26 -07002069 IPW_DEBUG_INFO("%s: Associated with '%s' at %s, channel %d (BSSID=%pM)\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04002070 priv->net_dev->name, print_ssid(ssid, essid, essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07002071 txratename, chan, bssid);
James Ketrenos2c86c272005-03-23 17:32:29 -06002072
2073 /* now we copy read ssid into dev */
2074 if (!(priv->config & CFG_STATIC_ESSID)) {
James Ketrenosee8e3652005-09-14 09:47:29 -05002075 priv->essid_len = min((u8) essid_len, (u8) IW_ESSID_MAX_SIZE);
James Ketrenos2c86c272005-03-23 17:32:29 -06002076 memcpy(priv->essid, essid, priv->essid_len);
2077 }
2078 priv->channel = chan;
2079 memcpy(priv->bssid, bssid, ETH_ALEN);
2080
2081 priv->status |= STATUS_ASSOCIATING;
2082 priv->connect_start = get_seconds();
2083
2084 queue_delayed_work(priv->workqueue, &priv->wx_event_work, HZ / 10);
2085}
2086
Jiri Bencc4aee8c2005-08-25 20:04:43 -04002087static int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid,
2088 int length, int batch_mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06002089{
2090 int ssid_len = min(length, IW_ESSID_MAX_SIZE);
2091 struct host_command cmd = {
2092 .host_command = SSID,
2093 .host_command_sequence = 0,
2094 .host_command_length = ssid_len
2095 };
2096 int err;
John W. Linville9387b7c2008-09-30 20:59:05 -04002097 DECLARE_SSID_BUF(ssid);
James Ketrenos2c86c272005-03-23 17:32:29 -06002098
John W. Linville9387b7c2008-09-30 20:59:05 -04002099 IPW_DEBUG_HC("SSID: '%s'\n", print_ssid(ssid, essid, ssid_len));
James Ketrenos2c86c272005-03-23 17:32:29 -06002100
2101 if (ssid_len)
James Ketrenos82328352005-08-24 22:33:31 -05002102 memcpy(cmd.host_command_parameters, essid, ssid_len);
James Ketrenos2c86c272005-03-23 17:32:29 -06002103
2104 if (!batch_mode) {
2105 err = ipw2100_disable_adapter(priv);
2106 if (err)
2107 return err;
2108 }
2109
2110 /* Bug in FW currently doesn't honor bit 0 in SET_SCAN_OPTIONS to
2111 * disable auto association -- so we cheat by setting a bogus SSID */
2112 if (!ssid_len && !(priv->config & CFG_ASSOCIATE)) {
2113 int i;
James Ketrenosee8e3652005-09-14 09:47:29 -05002114 u8 *bogus = (u8 *) cmd.host_command_parameters;
James Ketrenos2c86c272005-03-23 17:32:29 -06002115 for (i = 0; i < IW_ESSID_MAX_SIZE; i++)
2116 bogus[i] = 0x18 + i;
2117 cmd.host_command_length = IW_ESSID_MAX_SIZE;
2118 }
2119
2120 /* NOTE: We always send the SSID command even if the provided ESSID is
2121 * the same as what we currently think is set. */
2122
2123 err = ipw2100_hw_send_command(priv, &cmd);
2124 if (!err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05002125 memset(priv->essid + ssid_len, 0, IW_ESSID_MAX_SIZE - ssid_len);
James Ketrenos2c86c272005-03-23 17:32:29 -06002126 memcpy(priv->essid, essid, ssid_len);
2127 priv->essid_len = ssid_len;
2128 }
2129
2130 if (!batch_mode) {
2131 if (ipw2100_enable_adapter(priv))
2132 err = -EIO;
2133 }
2134
2135 return err;
2136}
2137
2138static void isr_indicate_association_lost(struct ipw2100_priv *priv, u32 status)
2139{
John W. Linville9387b7c2008-09-30 20:59:05 -04002140 DECLARE_SSID_BUF(ssid);
2141
James Ketrenos2c86c272005-03-23 17:32:29 -06002142 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07002143 "disassociated: '%s' %pM \n",
John W. Linville9387b7c2008-09-30 20:59:05 -04002144 print_ssid(ssid, priv->essid, priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07002145 priv->bssid);
James Ketrenos2c86c272005-03-23 17:32:29 -06002146
2147 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
2148
2149 if (priv->status & STATUS_STOPPING) {
2150 IPW_DEBUG_INFO("Card is stopping itself, discard ASSN_LOST.\n");
2151 return;
2152 }
2153
2154 memset(priv->bssid, 0, ETH_ALEN);
2155 memset(priv->ieee->bssid, 0, ETH_ALEN);
2156
2157 netif_carrier_off(priv->net_dev);
2158 netif_stop_queue(priv->net_dev);
2159
2160 if (!(priv->status & STATUS_RUNNING))
2161 return;
2162
2163 if (priv->status & STATUS_SECURITY_UPDATED)
David Howellsc4028952006-11-22 14:57:56 +00002164 queue_delayed_work(priv->workqueue, &priv->security_work, 0);
James Ketrenos2c86c272005-03-23 17:32:29 -06002165
David Howellsc4028952006-11-22 14:57:56 +00002166 queue_delayed_work(priv->workqueue, &priv->wx_event_work, 0);
James Ketrenos2c86c272005-03-23 17:32:29 -06002167}
2168
2169static void isr_indicate_rf_kill(struct ipw2100_priv *priv, u32 status)
2170{
2171 IPW_DEBUG_INFO("%s: RF Kill state changed to radio OFF.\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05002172 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06002173
2174 /* RF_KILL is now enabled (else we wouldn't be here) */
Matthew Garrettc26409a2009-11-11 14:36:30 -05002175 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
James Ketrenos2c86c272005-03-23 17:32:29 -06002176 priv->status |= STATUS_RF_KILL_HW;
2177
James Ketrenos2c86c272005-03-23 17:32:29 -06002178 /* Make sure the RF Kill check timer is running */
2179 priv->stop_rf_kill = 0;
2180 cancel_delayed_work(&priv->rf_kill);
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05002181 queue_delayed_work(priv->workqueue, &priv->rf_kill,
2182 round_jiffies_relative(HZ));
James Ketrenos2c86c272005-03-23 17:32:29 -06002183}
2184
Dan Williamsd20c6782007-10-10 12:28:07 -04002185static void send_scan_event(void *data)
2186{
2187 struct ipw2100_priv *priv = data;
2188 union iwreq_data wrqu;
2189
2190 wrqu.data.length = 0;
2191 wrqu.data.flags = 0;
2192 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
2193}
2194
2195static void ipw2100_scan_event_later(struct work_struct *work)
2196{
2197 send_scan_event(container_of(work, struct ipw2100_priv,
2198 scan_event_later.work));
2199}
2200
2201static void ipw2100_scan_event_now(struct work_struct *work)
2202{
2203 send_scan_event(container_of(work, struct ipw2100_priv,
2204 scan_event_now));
2205}
2206
James Ketrenos2c86c272005-03-23 17:32:29 -06002207static void isr_scan_complete(struct ipw2100_priv *priv, u32 status)
2208{
2209 IPW_DEBUG_SCAN("scan complete\n");
2210 /* Age the scan results... */
2211 priv->ieee->scans++;
2212 priv->status &= ~STATUS_SCANNING;
Dan Williamsd20c6782007-10-10 12:28:07 -04002213
2214 /* Only userspace-requested scan completion events go out immediately */
2215 if (!priv->user_requested_scan) {
2216 if (!delayed_work_pending(&priv->scan_event_later))
2217 queue_delayed_work(priv->workqueue,
2218 &priv->scan_event_later,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05002219 round_jiffies_relative(msecs_to_jiffies(4000)));
Dan Williamsd20c6782007-10-10 12:28:07 -04002220 } else {
2221 priv->user_requested_scan = 0;
2222 cancel_delayed_work(&priv->scan_event_later);
2223 queue_work(priv->workqueue, &priv->scan_event_now);
2224 }
James Ketrenos2c86c272005-03-23 17:32:29 -06002225}
2226
Brice Goglin0f52bf92005-12-01 01:41:46 -08002227#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06002228#define IPW2100_HANDLER(v, f) { v, f, # v }
2229struct ipw2100_status_indicator {
2230 int status;
James Ketrenosee8e3652005-09-14 09:47:29 -05002231 void (*cb) (struct ipw2100_priv * priv, u32 status);
James Ketrenos2c86c272005-03-23 17:32:29 -06002232 char *name;
2233};
2234#else
2235#define IPW2100_HANDLER(v, f) { v, f }
2236struct ipw2100_status_indicator {
2237 int status;
James Ketrenosee8e3652005-09-14 09:47:29 -05002238 void (*cb) (struct ipw2100_priv * priv, u32 status);
James Ketrenos2c86c272005-03-23 17:32:29 -06002239};
Brice Goglin0f52bf92005-12-01 01:41:46 -08002240#endif /* CONFIG_IPW2100_DEBUG */
James Ketrenos2c86c272005-03-23 17:32:29 -06002241
2242static void isr_indicate_scanning(struct ipw2100_priv *priv, u32 status)
2243{
2244 IPW_DEBUG_SCAN("Scanning...\n");
2245 priv->status |= STATUS_SCANNING;
2246}
2247
Jiri Bencc4aee8c2005-08-25 20:04:43 -04002248static const struct ipw2100_status_indicator status_handlers[] = {
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01002249 IPW2100_HANDLER(IPW_STATE_INITIALIZED, NULL),
2250 IPW2100_HANDLER(IPW_STATE_COUNTRY_FOUND, NULL),
James Ketrenos2c86c272005-03-23 17:32:29 -06002251 IPW2100_HANDLER(IPW_STATE_ASSOCIATED, isr_indicate_associated),
2252 IPW2100_HANDLER(IPW_STATE_ASSN_LOST, isr_indicate_association_lost),
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01002253 IPW2100_HANDLER(IPW_STATE_ASSN_CHANGED, NULL),
James Ketrenos2c86c272005-03-23 17:32:29 -06002254 IPW2100_HANDLER(IPW_STATE_SCAN_COMPLETE, isr_scan_complete),
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01002255 IPW2100_HANDLER(IPW_STATE_ENTERED_PSP, NULL),
2256 IPW2100_HANDLER(IPW_STATE_LEFT_PSP, NULL),
James Ketrenos2c86c272005-03-23 17:32:29 -06002257 IPW2100_HANDLER(IPW_STATE_RF_KILL, isr_indicate_rf_kill),
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01002258 IPW2100_HANDLER(IPW_STATE_DISABLED, NULL),
2259 IPW2100_HANDLER(IPW_STATE_POWER_DOWN, NULL),
James Ketrenos2c86c272005-03-23 17:32:29 -06002260 IPW2100_HANDLER(IPW_STATE_SCANNING, isr_indicate_scanning),
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01002261 IPW2100_HANDLER(-1, NULL)
James Ketrenos2c86c272005-03-23 17:32:29 -06002262};
2263
James Ketrenos2c86c272005-03-23 17:32:29 -06002264static void isr_status_change(struct ipw2100_priv *priv, int status)
2265{
2266 int i;
2267
2268 if (status == IPW_STATE_SCANNING &&
2269 priv->status & STATUS_ASSOCIATED &&
2270 !(priv->status & STATUS_SCANNING)) {
2271 IPW_DEBUG_INFO("Scan detected while associated, with "
2272 "no scan request. Restarting firmware.\n");
2273
2274 /* Wake up any sleeping jobs */
2275 schedule_reset(priv);
2276 }
2277
2278 for (i = 0; status_handlers[i].status != -1; i++) {
2279 if (status == status_handlers[i].status) {
2280 IPW_DEBUG_NOTIF("Status change: %s\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05002281 status_handlers[i].name);
James Ketrenos2c86c272005-03-23 17:32:29 -06002282 if (status_handlers[i].cb)
2283 status_handlers[i].cb(priv, status);
2284 priv->wstats.status = status;
2285 return;
2286 }
2287 }
2288
2289 IPW_DEBUG_NOTIF("unknown status received: %04x\n", status);
2290}
2291
James Ketrenosee8e3652005-09-14 09:47:29 -05002292static void isr_rx_complete_command(struct ipw2100_priv *priv,
2293 struct ipw2100_cmd_header *cmd)
James Ketrenos2c86c272005-03-23 17:32:29 -06002294{
Brice Goglin0f52bf92005-12-01 01:41:46 -08002295#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06002296 if (cmd->host_command_reg < ARRAY_SIZE(command_types)) {
2297 IPW_DEBUG_HC("Command completed '%s (%d)'\n",
2298 command_types[cmd->host_command_reg],
2299 cmd->host_command_reg);
2300 }
2301#endif
2302 if (cmd->host_command_reg == HOST_COMPLETE)
2303 priv->status |= STATUS_ENABLED;
2304
2305 if (cmd->host_command_reg == CARD_DISABLE)
2306 priv->status &= ~STATUS_ENABLED;
2307
2308 priv->status &= ~STATUS_CMD_ACTIVE;
2309
2310 wake_up_interruptible(&priv->wait_command_queue);
2311}
2312
Brice Goglin0f52bf92005-12-01 01:41:46 -08002313#ifdef CONFIG_IPW2100_DEBUG
Jiri Bencc4aee8c2005-08-25 20:04:43 -04002314static const char *frame_types[] = {
James Ketrenos2c86c272005-03-23 17:32:29 -06002315 "COMMAND_STATUS_VAL",
2316 "STATUS_CHANGE_VAL",
2317 "P80211_DATA_VAL",
2318 "P8023_DATA_VAL",
2319 "HOST_NOTIFICATION_VAL"
2320};
2321#endif
2322
Arjan van de Ven858119e2006-01-14 13:20:43 -08002323static int ipw2100_alloc_skb(struct ipw2100_priv *priv,
James Ketrenosee8e3652005-09-14 09:47:29 -05002324 struct ipw2100_rx_packet *packet)
James Ketrenos2c86c272005-03-23 17:32:29 -06002325{
2326 packet->skb = dev_alloc_skb(sizeof(struct ipw2100_rx));
2327 if (!packet->skb)
2328 return -ENOMEM;
2329
2330 packet->rxp = (struct ipw2100_rx *)packet->skb->data;
2331 packet->dma_addr = pci_map_single(priv->pci_dev, packet->skb->data,
2332 sizeof(struct ipw2100_rx),
2333 PCI_DMA_FROMDEVICE);
2334 /* NOTE: pci_map_single does not return an error code, and 0 is a valid
2335 * dma_addr */
2336
2337 return 0;
2338}
2339
James Ketrenos2c86c272005-03-23 17:32:29 -06002340#define SEARCH_ERROR 0xffffffff
2341#define SEARCH_FAIL 0xfffffffe
2342#define SEARCH_SUCCESS 0xfffffff0
2343#define SEARCH_DISCARD 0
2344#define SEARCH_SNAPSHOT 1
2345
2346#define SNAPSHOT_ADDR(ofs) (priv->snapshot[((ofs) >> 12) & 0xff] + ((ofs) & 0xfff))
Zhu Yi3c5eca52006-01-24 13:49:26 +08002347static void ipw2100_snapshot_free(struct ipw2100_priv *priv)
2348{
2349 int i;
2350 if (!priv->snapshot[0])
2351 return;
2352 for (i = 0; i < 0x30; i++)
2353 kfree(priv->snapshot[i]);
2354 priv->snapshot[0] = NULL;
2355}
2356
Robert P. J. Dayae800312007-01-31 02:39:40 -05002357#ifdef IPW2100_DEBUG_C3
Arjan van de Ven858119e2006-01-14 13:20:43 -08002358static int ipw2100_snapshot_alloc(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06002359{
2360 int i;
2361 if (priv->snapshot[0])
2362 return 1;
2363 for (i = 0; i < 0x30; i++) {
Robert P. J. Day5cbded52006-12-13 00:35:56 -08002364 priv->snapshot[i] = kmalloc(0x1000, GFP_ATOMIC);
James Ketrenos2c86c272005-03-23 17:32:29 -06002365 if (!priv->snapshot[i]) {
2366 IPW_DEBUG_INFO("%s: Error allocating snapshot "
James Ketrenosee8e3652005-09-14 09:47:29 -05002367 "buffer %d\n", priv->net_dev->name, i);
James Ketrenos2c86c272005-03-23 17:32:29 -06002368 while (i > 0)
2369 kfree(priv->snapshot[--i]);
2370 priv->snapshot[0] = NULL;
2371 return 0;
2372 }
2373 }
2374
2375 return 1;
2376}
2377
Arjan van de Ven858119e2006-01-14 13:20:43 -08002378static u32 ipw2100_match_buf(struct ipw2100_priv *priv, u8 * in_buf,
James Ketrenos2c86c272005-03-23 17:32:29 -06002379 size_t len, int mode)
2380{
2381 u32 i, j;
2382 u32 tmp;
2383 u8 *s, *d;
2384 u32 ret;
2385
2386 s = in_buf;
2387 if (mode == SEARCH_SNAPSHOT) {
2388 if (!ipw2100_snapshot_alloc(priv))
2389 mode = SEARCH_DISCARD;
2390 }
2391
2392 for (ret = SEARCH_FAIL, i = 0; i < 0x30000; i += 4) {
2393 read_nic_dword(priv->net_dev, i, &tmp);
2394 if (mode == SEARCH_SNAPSHOT)
James Ketrenosee8e3652005-09-14 09:47:29 -05002395 *(u32 *) SNAPSHOT_ADDR(i) = tmp;
James Ketrenos2c86c272005-03-23 17:32:29 -06002396 if (ret == SEARCH_FAIL) {
James Ketrenosee8e3652005-09-14 09:47:29 -05002397 d = (u8 *) & tmp;
James Ketrenos2c86c272005-03-23 17:32:29 -06002398 for (j = 0; j < 4; j++) {
2399 if (*s != *d) {
2400 s = in_buf;
2401 continue;
2402 }
2403
2404 s++;
2405 d++;
2406
2407 if ((s - in_buf) == len)
2408 ret = (i + j) - len + 1;
2409 }
2410 } else if (mode == SEARCH_DISCARD)
2411 return ret;
2412 }
2413
2414 return ret;
2415}
Zhu Yi3c5eca52006-01-24 13:49:26 +08002416#endif
James Ketrenos2c86c272005-03-23 17:32:29 -06002417
2418/*
2419 *
2420 * 0) Disconnect the SKB from the firmware (just unmap)
2421 * 1) Pack the ETH header into the SKB
2422 * 2) Pass the SKB to the network stack
2423 *
2424 * When packet is provided by the firmware, it contains the following:
2425 *
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002426 * . libipw_hdr
2427 * . libipw_snap_hdr
James Ketrenos2c86c272005-03-23 17:32:29 -06002428 *
2429 * The size of the constructed ethernet
2430 *
2431 */
Robert P. J. Dayae800312007-01-31 02:39:40 -05002432#ifdef IPW2100_RX_DEBUG
Jiri Bencc4aee8c2005-08-25 20:04:43 -04002433static u8 packet_data[IPW_RX_NIC_BUFFER_LENGTH];
James Ketrenos2c86c272005-03-23 17:32:29 -06002434#endif
2435
Arjan van de Ven858119e2006-01-14 13:20:43 -08002436static void ipw2100_corruption_detected(struct ipw2100_priv *priv, int i)
James Ketrenos2c86c272005-03-23 17:32:29 -06002437{
Robert P. J. Dayae800312007-01-31 02:39:40 -05002438#ifdef IPW2100_DEBUG_C3
James Ketrenos2c86c272005-03-23 17:32:29 -06002439 struct ipw2100_status *status = &priv->status_queue.drv[i];
2440 u32 match, reg;
2441 int j;
2442#endif
James Ketrenos2c86c272005-03-23 17:32:29 -06002443
Zhu Yia1e695a2005-07-04 14:06:00 +08002444 IPW_DEBUG_INFO(": PCI latency error detected at 0x%04zX.\n",
2445 i * sizeof(struct ipw2100_status));
James Ketrenos2c86c272005-03-23 17:32:29 -06002446
Robert P. J. Dayae800312007-01-31 02:39:40 -05002447#ifdef IPW2100_DEBUG_C3
Nick Andrew877d0312009-01-26 11:06:57 +01002448 /* Halt the firmware so we can get a good image */
James Ketrenos2c86c272005-03-23 17:32:29 -06002449 write_register(priv->net_dev, IPW_REG_RESET_REG,
2450 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
2451 j = 5;
2452 do {
2453 udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
2454 read_register(priv->net_dev, IPW_REG_RESET_REG, &reg);
2455
2456 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
2457 break;
James Ketrenosee8e3652005-09-14 09:47:29 -05002458 } while (j--);
James Ketrenos2c86c272005-03-23 17:32:29 -06002459
James Ketrenosee8e3652005-09-14 09:47:29 -05002460 match = ipw2100_match_buf(priv, (u8 *) status,
James Ketrenos2c86c272005-03-23 17:32:29 -06002461 sizeof(struct ipw2100_status),
2462 SEARCH_SNAPSHOT);
2463 if (match < SEARCH_SUCCESS)
2464 IPW_DEBUG_INFO("%s: DMA status match in Firmware at "
2465 "offset 0x%06X, length %d:\n",
2466 priv->net_dev->name, match,
2467 sizeof(struct ipw2100_status));
2468 else
2469 IPW_DEBUG_INFO("%s: No DMA status match in "
2470 "Firmware.\n", priv->net_dev->name);
2471
James Ketrenosee8e3652005-09-14 09:47:29 -05002472 printk_buf((u8 *) priv->status_queue.drv,
James Ketrenos2c86c272005-03-23 17:32:29 -06002473 sizeof(struct ipw2100_status) * RX_QUEUE_LENGTH);
2474#endif
2475
2476 priv->fatal_error = IPW2100_ERR_C3_CORRUPTION;
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002477 priv->net_dev->stats.rx_errors++;
James Ketrenos2c86c272005-03-23 17:32:29 -06002478 schedule_reset(priv);
2479}
2480
Arjan van de Ven858119e2006-01-14 13:20:43 -08002481static void isr_rx(struct ipw2100_priv *priv, int i,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002482 struct libipw_rx_stats *stats)
James Ketrenos2c86c272005-03-23 17:32:29 -06002483{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002484 struct net_device *dev = priv->net_dev;
James Ketrenos2c86c272005-03-23 17:32:29 -06002485 struct ipw2100_status *status = &priv->status_queue.drv[i];
2486 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
2487
2488 IPW_DEBUG_RX("Handler...\n");
2489
2490 if (unlikely(status->frame_size > skb_tailroom(packet->skb))) {
2491 IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!"
2492 " Dropping.\n",
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002493 dev->name,
James Ketrenos2c86c272005-03-23 17:32:29 -06002494 status->frame_size, skb_tailroom(packet->skb));
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002495 dev->stats.rx_errors++;
James Ketrenos2c86c272005-03-23 17:32:29 -06002496 return;
2497 }
2498
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002499 if (unlikely(!netif_running(dev))) {
2500 dev->stats.rx_errors++;
James Ketrenos2c86c272005-03-23 17:32:29 -06002501 priv->wstats.discard.misc++;
2502 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
2503 return;
2504 }
James Ketrenos2c86c272005-03-23 17:32:29 -06002505
2506 if (unlikely(priv->ieee->iw_mode != IW_MODE_MONITOR &&
James Ketrenosee8e3652005-09-14 09:47:29 -05002507 !(priv->status & STATUS_ASSOCIATED))) {
James Ketrenos2c86c272005-03-23 17:32:29 -06002508 IPW_DEBUG_DROP("Dropping packet while not associated.\n");
2509 priv->wstats.discard.misc++;
2510 return;
2511 }
2512
James Ketrenos2c86c272005-03-23 17:32:29 -06002513 pci_unmap_single(priv->pci_dev,
2514 packet->dma_addr,
James Ketrenosee8e3652005-09-14 09:47:29 -05002515 sizeof(struct ipw2100_rx), PCI_DMA_FROMDEVICE);
James Ketrenos2c86c272005-03-23 17:32:29 -06002516
2517 skb_put(packet->skb, status->frame_size);
2518
Robert P. J. Dayae800312007-01-31 02:39:40 -05002519#ifdef IPW2100_RX_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06002520 /* Make a copy of the frame so we can dump it to the logs if
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002521 * libipw_rx fails */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002522 skb_copy_from_linear_data(packet->skb, packet_data,
2523 min_t(u32, status->frame_size,
2524 IPW_RX_NIC_BUFFER_LENGTH));
James Ketrenos2c86c272005-03-23 17:32:29 -06002525#endif
2526
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002527 if (!libipw_rx(priv->ieee, packet->skb, stats)) {
Robert P. J. Dayae800312007-01-31 02:39:40 -05002528#ifdef IPW2100_RX_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06002529 IPW_DEBUG_DROP("%s: Non consumed packet:\n",
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002530 dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06002531 printk_buf(IPW_DL_DROP, packet_data, status->frame_size);
2532#endif
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002533 dev->stats.rx_errors++;
James Ketrenos2c86c272005-03-23 17:32:29 -06002534
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002535 /* libipw_rx failed, so it didn't free the SKB */
James Ketrenos2c86c272005-03-23 17:32:29 -06002536 dev_kfree_skb_any(packet->skb);
2537 packet->skb = NULL;
2538 }
2539
2540 /* We need to allocate a new SKB and attach it to the RDB. */
2541 if (unlikely(ipw2100_alloc_skb(priv, packet))) {
Jiri Benc797b4f72005-08-25 20:03:27 -04002542 printk(KERN_WARNING DRV_NAME ": "
James Ketrenosee8e3652005-09-14 09:47:29 -05002543 "%s: Unable to allocate SKB onto RBD ring - disabling "
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002544 "adapter.\n", dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06002545 /* TODO: schedule adapter shutdown */
2546 IPW_DEBUG_INFO("TODO: Shutdown adapter...\n");
2547 }
2548
2549 /* Update the RDB entry */
2550 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
2551}
2552
Stefan Rompf15745a72006-02-21 18:36:17 +08002553#ifdef CONFIG_IPW2100_MONITOR
2554
2555static void isr_rx_monitor(struct ipw2100_priv *priv, int i,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002556 struct libipw_rx_stats *stats)
Stefan Rompf15745a72006-02-21 18:36:17 +08002557{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002558 struct net_device *dev = priv->net_dev;
Stefan Rompf15745a72006-02-21 18:36:17 +08002559 struct ipw2100_status *status = &priv->status_queue.drv[i];
2560 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
2561
Stefan Rompf15745a72006-02-21 18:36:17 +08002562 /* Magic struct that slots into the radiotap header -- no reason
2563 * to build this manually element by element, we can write it much
2564 * more efficiently than we can parse it. ORDER MATTERS HERE */
2565 struct ipw_rt_hdr {
2566 struct ieee80211_radiotap_header rt_hdr;
2567 s8 rt_dbmsignal; /* signal in dbM, kluged to signed */
2568 } *ipw_rt;
2569
Zhu Yicae16292006-02-21 18:41:14 +08002570 IPW_DEBUG_RX("Handler...\n");
2571
2572 if (unlikely(status->frame_size > skb_tailroom(packet->skb) -
2573 sizeof(struct ipw_rt_hdr))) {
Stefan Rompf15745a72006-02-21 18:36:17 +08002574 IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!"
2575 " Dropping.\n",
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002576 dev->name,
Zhu Yicae16292006-02-21 18:41:14 +08002577 status->frame_size,
2578 skb_tailroom(packet->skb));
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002579 dev->stats.rx_errors++;
Stefan Rompf15745a72006-02-21 18:36:17 +08002580 return;
2581 }
2582
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002583 if (unlikely(!netif_running(dev))) {
2584 dev->stats.rx_errors++;
Stefan Rompf15745a72006-02-21 18:36:17 +08002585 priv->wstats.discard.misc++;
2586 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
2587 return;
2588 }
2589
2590 if (unlikely(priv->config & CFG_CRC_CHECK &&
2591 status->flags & IPW_STATUS_FLAG_CRC_ERROR)) {
2592 IPW_DEBUG_RX("CRC error in packet. Dropping.\n");
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002593 dev->stats.rx_errors++;
Stefan Rompf15745a72006-02-21 18:36:17 +08002594 return;
2595 }
2596
Zhu Yicae16292006-02-21 18:41:14 +08002597 pci_unmap_single(priv->pci_dev, packet->dma_addr,
Stefan Rompf15745a72006-02-21 18:36:17 +08002598 sizeof(struct ipw2100_rx), PCI_DMA_FROMDEVICE);
2599 memmove(packet->skb->data + sizeof(struct ipw_rt_hdr),
2600 packet->skb->data, status->frame_size);
2601
2602 ipw_rt = (struct ipw_rt_hdr *) packet->skb->data;
2603
2604 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
2605 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
Al Viro1edd3a52007-12-21 00:15:18 -05002606 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total hdr+data */
Stefan Rompf15745a72006-02-21 18:36:17 +08002607
Al Viro1edd3a52007-12-21 00:15:18 -05002608 ipw_rt->rt_hdr.it_present = cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
Stefan Rompf15745a72006-02-21 18:36:17 +08002609
2610 ipw_rt->rt_dbmsignal = status->rssi + IPW2100_RSSI_TO_DBM;
2611
2612 skb_put(packet->skb, status->frame_size + sizeof(struct ipw_rt_hdr));
2613
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002614 if (!libipw_rx(priv->ieee, packet->skb, stats)) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002615 dev->stats.rx_errors++;
Stefan Rompf15745a72006-02-21 18:36:17 +08002616
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002617 /* libipw_rx failed, so it didn't free the SKB */
Stefan Rompf15745a72006-02-21 18:36:17 +08002618 dev_kfree_skb_any(packet->skb);
2619 packet->skb = NULL;
2620 }
2621
2622 /* We need to allocate a new SKB and attach it to the RDB. */
2623 if (unlikely(ipw2100_alloc_skb(priv, packet))) {
2624 IPW_DEBUG_WARNING(
2625 "%s: Unable to allocate SKB onto RBD ring - disabling "
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002626 "adapter.\n", dev->name);
Stefan Rompf15745a72006-02-21 18:36:17 +08002627 /* TODO: schedule adapter shutdown */
2628 IPW_DEBUG_INFO("TODO: Shutdown adapter...\n");
2629 }
2630
2631 /* Update the RDB entry */
2632 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
2633}
2634
2635#endif
2636
Arjan van de Ven858119e2006-01-14 13:20:43 -08002637static int ipw2100_corruption_check(struct ipw2100_priv *priv, int i)
James Ketrenos2c86c272005-03-23 17:32:29 -06002638{
2639 struct ipw2100_status *status = &priv->status_queue.drv[i];
2640 struct ipw2100_rx *u = priv->rx_buffers[i].rxp;
2641 u16 frame_type = status->status_fields & STATUS_TYPE_MASK;
2642
2643 switch (frame_type) {
2644 case COMMAND_STATUS_VAL:
2645 return (status->frame_size != sizeof(u->rx_data.command));
2646 case STATUS_CHANGE_VAL:
2647 return (status->frame_size != sizeof(u->rx_data.status));
2648 case HOST_NOTIFICATION_VAL:
2649 return (status->frame_size < sizeof(u->rx_data.notification));
2650 case P80211_DATA_VAL:
2651 case P8023_DATA_VAL:
2652#ifdef CONFIG_IPW2100_MONITOR
2653 return 0;
2654#else
Al Viro1edd3a52007-12-21 00:15:18 -05002655 switch (WLAN_FC_GET_TYPE(le16_to_cpu(u->rx_data.header.frame_ctl))) {
James Ketrenos2c86c272005-03-23 17:32:29 -06002656 case IEEE80211_FTYPE_MGMT:
2657 case IEEE80211_FTYPE_CTL:
2658 return 0;
2659 case IEEE80211_FTYPE_DATA:
2660 return (status->frame_size >
2661 IPW_MAX_802_11_PAYLOAD_LENGTH);
2662 }
2663#endif
2664 }
2665
2666 return 1;
2667}
2668
2669/*
2670 * ipw2100 interrupts are disabled at this point, and the ISR
2671 * is the only code that calls this method. So, we do not need
2672 * to play with any locks.
2673 *
2674 * RX Queue works as follows:
2675 *
2676 * Read index - firmware places packet in entry identified by the
2677 * Read index and advances Read index. In this manner,
2678 * Read index will always point to the next packet to
2679 * be filled--but not yet valid.
2680 *
2681 * Write index - driver fills this entry with an unused RBD entry.
2682 * This entry has not filled by the firmware yet.
2683 *
2684 * In between the W and R indexes are the RBDs that have been received
2685 * but not yet processed.
2686 *
2687 * The process of handling packets will start at WRITE + 1 and advance
2688 * until it reaches the READ index.
2689 *
2690 * The WRITE index is cached in the variable 'priv->rx_queue.next'.
2691 *
2692 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002693static void __ipw2100_rx_process(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06002694{
2695 struct ipw2100_bd_queue *rxq = &priv->rx_queue;
2696 struct ipw2100_status_queue *sq = &priv->status_queue;
2697 struct ipw2100_rx_packet *packet;
2698 u16 frame_type;
2699 u32 r, w, i, s;
2700 struct ipw2100_rx *u;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002701 struct libipw_rx_stats stats = {
James Ketrenos2c86c272005-03-23 17:32:29 -06002702 .mac_time = jiffies,
2703 };
2704
2705 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_READ_INDEX, &r);
2706 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, &w);
2707
2708 if (r >= rxq->entries) {
2709 IPW_DEBUG_RX("exit - bad read index\n");
2710 return;
2711 }
2712
2713 i = (rxq->next + 1) % rxq->entries;
2714 s = i;
2715 while (i != r) {
2716 /* IPW_DEBUG_RX("r = %d : w = %d : processing = %d\n",
2717 r, rxq->next, i); */
2718
2719 packet = &priv->rx_buffers[i];
2720
2721 /* Sync the DMA for the STATUS buffer so CPU is sure to get
2722 * the correct values */
James Ketrenosee8e3652005-09-14 09:47:29 -05002723 pci_dma_sync_single_for_cpu(priv->pci_dev,
2724 sq->nic +
2725 sizeof(struct ipw2100_status) * i,
2726 sizeof(struct ipw2100_status),
2727 PCI_DMA_FROMDEVICE);
James Ketrenos2c86c272005-03-23 17:32:29 -06002728
2729 /* Sync the DMA for the RX buffer so CPU is sure to get
2730 * the correct values */
2731 pci_dma_sync_single_for_cpu(priv->pci_dev, packet->dma_addr,
2732 sizeof(struct ipw2100_rx),
2733 PCI_DMA_FROMDEVICE);
2734
2735 if (unlikely(ipw2100_corruption_check(priv, i))) {
2736 ipw2100_corruption_detected(priv, i);
2737 goto increment;
2738 }
2739
2740 u = packet->rxp;
James Ketrenosee8e3652005-09-14 09:47:29 -05002741 frame_type = sq->drv[i].status_fields & STATUS_TYPE_MASK;
James Ketrenos2c86c272005-03-23 17:32:29 -06002742 stats.rssi = sq->drv[i].rssi + IPW2100_RSSI_TO_DBM;
2743 stats.len = sq->drv[i].frame_size;
2744
2745 stats.mask = 0;
2746 if (stats.rssi != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002747 stats.mask |= LIBIPW_STATMASK_RSSI;
2748 stats.freq = LIBIPW_24GHZ_BAND;
James Ketrenos2c86c272005-03-23 17:32:29 -06002749
James Ketrenosee8e3652005-09-14 09:47:29 -05002750 IPW_DEBUG_RX("%s: '%s' frame type received (%d).\n",
2751 priv->net_dev->name, frame_types[frame_type],
2752 stats.len);
James Ketrenos2c86c272005-03-23 17:32:29 -06002753
2754 switch (frame_type) {
2755 case COMMAND_STATUS_VAL:
2756 /* Reset Rx watchdog */
James Ketrenosee8e3652005-09-14 09:47:29 -05002757 isr_rx_complete_command(priv, &u->rx_data.command);
James Ketrenos2c86c272005-03-23 17:32:29 -06002758 break;
2759
2760 case STATUS_CHANGE_VAL:
2761 isr_status_change(priv, u->rx_data.status);
2762 break;
2763
2764 case P80211_DATA_VAL:
2765 case P8023_DATA_VAL:
2766#ifdef CONFIG_IPW2100_MONITOR
2767 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Stefan Rompf15745a72006-02-21 18:36:17 +08002768 isr_rx_monitor(priv, i, &stats);
James Ketrenos2c86c272005-03-23 17:32:29 -06002769 break;
2770 }
2771#endif
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002772 if (stats.len < sizeof(struct libipw_hdr_3addr))
James Ketrenos2c86c272005-03-23 17:32:29 -06002773 break;
Al Viro1edd3a52007-12-21 00:15:18 -05002774 switch (WLAN_FC_GET_TYPE(le16_to_cpu(u->rx_data.header.frame_ctl))) {
James Ketrenos2c86c272005-03-23 17:32:29 -06002775 case IEEE80211_FTYPE_MGMT:
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002776 libipw_rx_mgt(priv->ieee,
James Ketrenosee8e3652005-09-14 09:47:29 -05002777 &u->rx_data.header, &stats);
James Ketrenos2c86c272005-03-23 17:32:29 -06002778 break;
2779
2780 case IEEE80211_FTYPE_CTL:
2781 break;
2782
2783 case IEEE80211_FTYPE_DATA:
2784 isr_rx(priv, i, &stats);
2785 break;
2786
2787 }
2788 break;
2789 }
2790
James Ketrenosee8e3652005-09-14 09:47:29 -05002791 increment:
James Ketrenos2c86c272005-03-23 17:32:29 -06002792 /* clear status field associated with this RBD */
2793 rxq->drv[i].status.info.field = 0;
2794
2795 i = (i + 1) % rxq->entries;
2796 }
2797
2798 if (i != s) {
2799 /* backtrack one entry, wrapping to end if at 0 */
2800 rxq->next = (i ? i : rxq->entries) - 1;
2801
2802 write_register(priv->net_dev,
James Ketrenosee8e3652005-09-14 09:47:29 -05002803 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, rxq->next);
James Ketrenos2c86c272005-03-23 17:32:29 -06002804 }
2805}
2806
James Ketrenos2c86c272005-03-23 17:32:29 -06002807/*
2808 * __ipw2100_tx_process
2809 *
2810 * This routine will determine whether the next packet on
2811 * the fw_pend_list has been processed by the firmware yet.
2812 *
2813 * If not, then it does nothing and returns.
2814 *
2815 * If so, then it removes the item from the fw_pend_list, frees
2816 * any associated storage, and places the item back on the
2817 * free list of its source (either msg_free_list or tx_free_list)
2818 *
2819 * TX Queue works as follows:
2820 *
2821 * Read index - points to the next TBD that the firmware will
2822 * process. The firmware will read the data, and once
2823 * done processing, it will advance the Read index.
2824 *
2825 * Write index - driver fills this entry with an constructed TBD
2826 * entry. The Write index is not advanced until the
2827 * packet has been configured.
2828 *
2829 * In between the W and R indexes are the TBDs that have NOT been
2830 * processed. Lagging behind the R index are packets that have
2831 * been processed but have not been freed by the driver.
2832 *
2833 * In order to free old storage, an internal index will be maintained
2834 * that points to the next packet to be freed. When all used
2835 * packets have been freed, the oldest index will be the same as the
2836 * firmware's read index.
2837 *
2838 * The OLDEST index is cached in the variable 'priv->tx_queue.oldest'
2839 *
2840 * Because the TBD structure can not contain arbitrary data, the
2841 * driver must keep an internal queue of cached allocations such that
2842 * it can put that data back into the tx_free_list and msg_free_list
2843 * for use by future command and data packets.
2844 *
2845 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002846static int __ipw2100_tx_process(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06002847{
2848 struct ipw2100_bd_queue *txq = &priv->tx_queue;
James Ketrenosee8e3652005-09-14 09:47:29 -05002849 struct ipw2100_bd *tbd;
James Ketrenos2c86c272005-03-23 17:32:29 -06002850 struct list_head *element;
2851 struct ipw2100_tx_packet *packet;
2852 int descriptors_used;
2853 int e, i;
2854 u32 r, w, frag_num = 0;
2855
2856 if (list_empty(&priv->fw_pend_list))
2857 return 0;
2858
2859 element = priv->fw_pend_list.next;
2860
2861 packet = list_entry(element, struct ipw2100_tx_packet, list);
James Ketrenosee8e3652005-09-14 09:47:29 -05002862 tbd = &txq->drv[packet->index];
James Ketrenos2c86c272005-03-23 17:32:29 -06002863
2864 /* Determine how many TBD entries must be finished... */
2865 switch (packet->type) {
2866 case COMMAND:
2867 /* COMMAND uses only one slot; don't advance */
2868 descriptors_used = 1;
2869 e = txq->oldest;
2870 break;
2871
2872 case DATA:
2873 /* DATA uses two slots; advance and loop position. */
2874 descriptors_used = tbd->num_fragments;
James Ketrenosee8e3652005-09-14 09:47:29 -05002875 frag_num = tbd->num_fragments - 1;
James Ketrenos2c86c272005-03-23 17:32:29 -06002876 e = txq->oldest + frag_num;
2877 e %= txq->entries;
2878 break;
2879
2880 default:
Jiri Benc797b4f72005-08-25 20:03:27 -04002881 printk(KERN_WARNING DRV_NAME ": %s: Bad fw_pend_list entry!\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05002882 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06002883 return 0;
2884 }
2885
2886 /* if the last TBD is not done by NIC yet, then packet is
2887 * not ready to be released.
2888 *
2889 */
2890 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
2891 &r);
2892 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
2893 &w);
2894 if (w != txq->next)
Jiri Benc797b4f72005-08-25 20:03:27 -04002895 printk(KERN_WARNING DRV_NAME ": %s: write index mismatch\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06002896 priv->net_dev->name);
2897
James Ketrenosee8e3652005-09-14 09:47:29 -05002898 /*
James Ketrenos2c86c272005-03-23 17:32:29 -06002899 * txq->next is the index of the last packet written txq->oldest is
2900 * the index of the r is the index of the next packet to be read by
2901 * firmware
2902 */
2903
James Ketrenos2c86c272005-03-23 17:32:29 -06002904 /*
2905 * Quick graphic to help you visualize the following
2906 * if / else statement
2907 *
2908 * ===>| s---->|===============
2909 * e>|
2910 * | a | b | c | d | e | f | g | h | i | j | k | l
2911 * r---->|
2912 * w
2913 *
2914 * w - updated by driver
2915 * r - updated by firmware
2916 * s - start of oldest BD entry (txq->oldest)
2917 * e - end of oldest BD entry
2918 *
2919 */
2920 if (!((r <= w && (e < r || e >= w)) || (e < r && e >= w))) {
2921 IPW_DEBUG_TX("exit - no processed packets ready to release.\n");
2922 return 0;
2923 }
2924
2925 list_del(element);
2926 DEC_STAT(&priv->fw_pend_stat);
2927
Brice Goglin0f52bf92005-12-01 01:41:46 -08002928#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06002929 {
Reinette Chatre21f8a732009-08-18 10:25:05 -07002930 i = txq->oldest;
James Ketrenosee8e3652005-09-14 09:47:29 -05002931 IPW_DEBUG_TX("TX%d V=%p P=%04X T=%04X L=%d\n", i,
2932 &txq->drv[i],
2933 (u32) (txq->nic + i * sizeof(struct ipw2100_bd)),
2934 txq->drv[i].host_addr, txq->drv[i].buf_length);
James Ketrenos2c86c272005-03-23 17:32:29 -06002935
2936 if (packet->type == DATA) {
2937 i = (i + 1) % txq->entries;
2938
James Ketrenosee8e3652005-09-14 09:47:29 -05002939 IPW_DEBUG_TX("TX%d V=%p P=%04X T=%04X L=%d\n", i,
2940 &txq->drv[i],
2941 (u32) (txq->nic + i *
2942 sizeof(struct ipw2100_bd)),
2943 (u32) txq->drv[i].host_addr,
2944 txq->drv[i].buf_length);
James Ketrenos2c86c272005-03-23 17:32:29 -06002945 }
2946 }
2947#endif
2948
2949 switch (packet->type) {
2950 case DATA:
2951 if (txq->drv[txq->oldest].status.info.fields.txType != 0)
Jiri Benc797b4f72005-08-25 20:03:27 -04002952 printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch. "
James Ketrenos2c86c272005-03-23 17:32:29 -06002953 "Expecting DATA TBD but pulled "
2954 "something else: ids %d=%d.\n",
2955 priv->net_dev->name, txq->oldest, packet->index);
2956
2957 /* DATA packet; we have to unmap and free the SKB */
James Ketrenos2c86c272005-03-23 17:32:29 -06002958 for (i = 0; i < frag_num; i++) {
James Ketrenosee8e3652005-09-14 09:47:29 -05002959 tbd = &txq->drv[(packet->index + 1 + i) % txq->entries];
James Ketrenos2c86c272005-03-23 17:32:29 -06002960
James Ketrenosee8e3652005-09-14 09:47:29 -05002961 IPW_DEBUG_TX("TX%d P=%08x L=%d\n",
2962 (packet->index + 1 + i) % txq->entries,
2963 tbd->host_addr, tbd->buf_length);
James Ketrenos2c86c272005-03-23 17:32:29 -06002964
2965 pci_unmap_single(priv->pci_dev,
2966 tbd->host_addr,
James Ketrenosee8e3652005-09-14 09:47:29 -05002967 tbd->buf_length, PCI_DMA_TODEVICE);
James Ketrenos2c86c272005-03-23 17:32:29 -06002968 }
2969
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002970 libipw_txb_free(packet->info.d_struct.txb);
James Ketrenos2c86c272005-03-23 17:32:29 -06002971 packet->info.d_struct.txb = NULL;
2972
2973 list_add_tail(element, &priv->tx_free_list);
2974 INC_STAT(&priv->tx_free_stat);
2975
2976 /* We have a free slot in the Tx queue, so wake up the
2977 * transmit layer if it is stopped. */
James Ketrenos82328352005-08-24 22:33:31 -05002978 if (priv->status & STATUS_ASSOCIATED)
James Ketrenos2c86c272005-03-23 17:32:29 -06002979 netif_wake_queue(priv->net_dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06002980
2981 /* A packet was processed by the hardware, so update the
2982 * watchdog */
2983 priv->net_dev->trans_start = jiffies;
2984
2985 break;
2986
2987 case COMMAND:
2988 if (txq->drv[txq->oldest].status.info.fields.txType != 1)
Jiri Benc797b4f72005-08-25 20:03:27 -04002989 printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch. "
James Ketrenos2c86c272005-03-23 17:32:29 -06002990 "Expecting COMMAND TBD but pulled "
2991 "something else: ids %d=%d.\n",
2992 priv->net_dev->name, txq->oldest, packet->index);
2993
Brice Goglin0f52bf92005-12-01 01:41:46 -08002994#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06002995 if (packet->info.c_struct.cmd->host_command_reg <
Ahmed S. Darwish22d57432007-02-05 18:56:22 +02002996 ARRAY_SIZE(command_types))
James Ketrenosee8e3652005-09-14 09:47:29 -05002997 IPW_DEBUG_TX("Command '%s (%d)' processed: %d.\n",
2998 command_types[packet->info.c_struct.cmd->
2999 host_command_reg],
3000 packet->info.c_struct.cmd->
3001 host_command_reg,
3002 packet->info.c_struct.cmd->cmd_status_reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06003003#endif
3004
3005 list_add_tail(element, &priv->msg_free_list);
3006 INC_STAT(&priv->msg_free_stat);
3007 break;
3008 }
3009
3010 /* advance oldest used TBD pointer to start of next entry */
3011 txq->oldest = (e + 1) % txq->entries;
3012 /* increase available TBDs number */
3013 txq->available += descriptors_used;
3014 SET_STAT(&priv->txq_stat, txq->available);
3015
3016 IPW_DEBUG_TX("packet latency (send to process) %ld jiffies\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05003017 jiffies - packet->jiffy_start);
James Ketrenos2c86c272005-03-23 17:32:29 -06003018
3019 return (!list_empty(&priv->fw_pend_list));
3020}
3021
James Ketrenos2c86c272005-03-23 17:32:29 -06003022static inline void __ipw2100_tx_complete(struct ipw2100_priv *priv)
3023{
3024 int i = 0;
3025
James Ketrenosee8e3652005-09-14 09:47:29 -05003026 while (__ipw2100_tx_process(priv) && i < 200)
3027 i++;
James Ketrenos2c86c272005-03-23 17:32:29 -06003028
3029 if (i == 200) {
Jiri Benc19f7f742005-08-25 20:02:10 -04003030 printk(KERN_WARNING DRV_NAME ": "
James Ketrenos2c86c272005-03-23 17:32:29 -06003031 "%s: Driver is running slow (%d iters).\n",
3032 priv->net_dev->name, i);
3033 }
3034}
3035
Jiri Benc19f7f742005-08-25 20:02:10 -04003036static void ipw2100_tx_send_commands(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06003037{
3038 struct list_head *element;
3039 struct ipw2100_tx_packet *packet;
3040 struct ipw2100_bd_queue *txq = &priv->tx_queue;
3041 struct ipw2100_bd *tbd;
3042 int next = txq->next;
3043
3044 while (!list_empty(&priv->msg_pend_list)) {
3045 /* if there isn't enough space in TBD queue, then
3046 * don't stuff a new one in.
3047 * NOTE: 3 are needed as a command will take one,
3048 * and there is a minimum of 2 that must be
3049 * maintained between the r and w indexes
3050 */
3051 if (txq->available <= 3) {
3052 IPW_DEBUG_TX("no room in tx_queue\n");
3053 break;
3054 }
3055
3056 element = priv->msg_pend_list.next;
3057 list_del(element);
3058 DEC_STAT(&priv->msg_pend_stat);
3059
James Ketrenosee8e3652005-09-14 09:47:29 -05003060 packet = list_entry(element, struct ipw2100_tx_packet, list);
James Ketrenos2c86c272005-03-23 17:32:29 -06003061
3062 IPW_DEBUG_TX("using TBD at virt=%p, phys=%p\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05003063 &txq->drv[txq->next],
3064 (void *)(txq->nic + txq->next *
3065 sizeof(struct ipw2100_bd)));
James Ketrenos2c86c272005-03-23 17:32:29 -06003066
3067 packet->index = txq->next;
3068
3069 tbd = &txq->drv[txq->next];
3070
3071 /* initialize TBD */
3072 tbd->host_addr = packet->info.c_struct.cmd_phys;
3073 tbd->buf_length = sizeof(struct ipw2100_cmd_header);
3074 /* not marking number of fragments causes problems
3075 * with f/w debug version */
3076 tbd->num_fragments = 1;
3077 tbd->status.info.field =
James Ketrenosee8e3652005-09-14 09:47:29 -05003078 IPW_BD_STATUS_TX_FRAME_COMMAND |
3079 IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
James Ketrenos2c86c272005-03-23 17:32:29 -06003080
3081 /* update TBD queue counters */
3082 txq->next++;
3083 txq->next %= txq->entries;
3084 txq->available--;
3085 DEC_STAT(&priv->txq_stat);
3086
3087 list_add_tail(element, &priv->fw_pend_list);
3088 INC_STAT(&priv->fw_pend_stat);
3089 }
3090
3091 if (txq->next != next) {
3092 /* kick off the DMA by notifying firmware the
3093 * write index has moved; make sure TBD stores are sync'd */
3094 wmb();
3095 write_register(priv->net_dev,
3096 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
3097 txq->next);
3098 }
3099}
3100
James Ketrenos2c86c272005-03-23 17:32:29 -06003101/*
Jiri Benc19f7f742005-08-25 20:02:10 -04003102 * ipw2100_tx_send_data
James Ketrenos2c86c272005-03-23 17:32:29 -06003103 *
3104 */
Jiri Benc19f7f742005-08-25 20:02:10 -04003105static void ipw2100_tx_send_data(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06003106{
3107 struct list_head *element;
3108 struct ipw2100_tx_packet *packet;
3109 struct ipw2100_bd_queue *txq = &priv->tx_queue;
3110 struct ipw2100_bd *tbd;
3111 int next = txq->next;
James Ketrenosee8e3652005-09-14 09:47:29 -05003112 int i = 0;
James Ketrenos2c86c272005-03-23 17:32:29 -06003113 struct ipw2100_data_header *ipw_hdr;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003114 struct libipw_hdr_3addr *hdr;
James Ketrenos2c86c272005-03-23 17:32:29 -06003115
3116 while (!list_empty(&priv->tx_pend_list)) {
3117 /* if there isn't enough space in TBD queue, then
3118 * don't stuff a new one in.
3119 * NOTE: 4 are needed as a data will take two,
3120 * and there is a minimum of 2 that must be
3121 * maintained between the r and w indexes
3122 */
3123 element = priv->tx_pend_list.next;
James Ketrenosee8e3652005-09-14 09:47:29 -05003124 packet = list_entry(element, struct ipw2100_tx_packet, list);
James Ketrenos2c86c272005-03-23 17:32:29 -06003125
3126 if (unlikely(1 + packet->info.d_struct.txb->nr_frags >
3127 IPW_MAX_BDS)) {
3128 /* TODO: Support merging buffers if more than
3129 * IPW_MAX_BDS are used */
James Ketrenosee8e3652005-09-14 09:47:29 -05003130 IPW_DEBUG_INFO("%s: Maximum BD theshold exceeded. "
3131 "Increase fragmentation level.\n",
3132 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06003133 }
3134
James Ketrenosee8e3652005-09-14 09:47:29 -05003135 if (txq->available <= 3 + packet->info.d_struct.txb->nr_frags) {
James Ketrenos2c86c272005-03-23 17:32:29 -06003136 IPW_DEBUG_TX("no room in tx_queue\n");
3137 break;
3138 }
3139
3140 list_del(element);
3141 DEC_STAT(&priv->tx_pend_stat);
3142
3143 tbd = &txq->drv[txq->next];
3144
3145 packet->index = txq->next;
3146
3147 ipw_hdr = packet->info.d_struct.data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003148 hdr = (struct libipw_hdr_3addr *)packet->info.d_struct.txb->
James Ketrenosee8e3652005-09-14 09:47:29 -05003149 fragments[0]->data;
James Ketrenos2c86c272005-03-23 17:32:29 -06003150
3151 if (priv->ieee->iw_mode == IW_MODE_INFRA) {
3152 /* To DS: Addr1 = BSSID, Addr2 = SA,
3153 Addr3 = DA */
3154 memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
3155 memcpy(ipw_hdr->dst_addr, hdr->addr3, ETH_ALEN);
3156 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
3157 /* not From/To DS: Addr1 = DA, Addr2 = SA,
3158 Addr3 = BSSID */
3159 memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
3160 memcpy(ipw_hdr->dst_addr, hdr->addr1, ETH_ALEN);
3161 }
3162
3163 ipw_hdr->host_command_reg = SEND;
3164 ipw_hdr->host_command_reg1 = 0;
3165
3166 /* For now we only support host based encryption */
3167 ipw_hdr->needs_encryption = 0;
3168 ipw_hdr->encrypted = packet->info.d_struct.txb->encrypted;
3169 if (packet->info.d_struct.txb->nr_frags > 1)
3170 ipw_hdr->fragment_size =
James Ketrenosee8e3652005-09-14 09:47:29 -05003171 packet->info.d_struct.txb->frag_size -
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003172 LIBIPW_3ADDR_LEN;
James Ketrenos2c86c272005-03-23 17:32:29 -06003173 else
3174 ipw_hdr->fragment_size = 0;
3175
3176 tbd->host_addr = packet->info.d_struct.data_phys;
3177 tbd->buf_length = sizeof(struct ipw2100_data_header);
3178 tbd->num_fragments = 1 + packet->info.d_struct.txb->nr_frags;
3179 tbd->status.info.field =
James Ketrenosee8e3652005-09-14 09:47:29 -05003180 IPW_BD_STATUS_TX_FRAME_802_3 |
3181 IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
James Ketrenos2c86c272005-03-23 17:32:29 -06003182 txq->next++;
3183 txq->next %= txq->entries;
3184
James Ketrenosee8e3652005-09-14 09:47:29 -05003185 IPW_DEBUG_TX("data header tbd TX%d P=%08x L=%d\n",
3186 packet->index, tbd->host_addr, tbd->buf_length);
Brice Goglin0f52bf92005-12-01 01:41:46 -08003187#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06003188 if (packet->info.d_struct.txb->nr_frags > 1)
3189 IPW_DEBUG_FRAG("fragment Tx: %d frames\n",
3190 packet->info.d_struct.txb->nr_frags);
3191#endif
3192
James Ketrenosee8e3652005-09-14 09:47:29 -05003193 for (i = 0; i < packet->info.d_struct.txb->nr_frags; i++) {
3194 tbd = &txq->drv[txq->next];
James Ketrenos2c86c272005-03-23 17:32:29 -06003195 if (i == packet->info.d_struct.txb->nr_frags - 1)
3196 tbd->status.info.field =
James Ketrenosee8e3652005-09-14 09:47:29 -05003197 IPW_BD_STATUS_TX_FRAME_802_3 |
3198 IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
James Ketrenos2c86c272005-03-23 17:32:29 -06003199 else
3200 tbd->status.info.field =
James Ketrenosee8e3652005-09-14 09:47:29 -05003201 IPW_BD_STATUS_TX_FRAME_802_3 |
3202 IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
James Ketrenos2c86c272005-03-23 17:32:29 -06003203
3204 tbd->buf_length = packet->info.d_struct.txb->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003205 fragments[i]->len - LIBIPW_3ADDR_LEN;
James Ketrenos2c86c272005-03-23 17:32:29 -06003206
James Ketrenosee8e3652005-09-14 09:47:29 -05003207 tbd->host_addr = pci_map_single(priv->pci_dev,
3208 packet->info.d_struct.
3209 txb->fragments[i]->
3210 data +
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003211 LIBIPW_3ADDR_LEN,
James Ketrenosee8e3652005-09-14 09:47:29 -05003212 tbd->buf_length,
3213 PCI_DMA_TODEVICE);
James Ketrenos2c86c272005-03-23 17:32:29 -06003214
James Ketrenosee8e3652005-09-14 09:47:29 -05003215 IPW_DEBUG_TX("data frag tbd TX%d P=%08x L=%d\n",
3216 txq->next, tbd->host_addr,
3217 tbd->buf_length);
James Ketrenos2c86c272005-03-23 17:32:29 -06003218
James Ketrenosee8e3652005-09-14 09:47:29 -05003219 pci_dma_sync_single_for_device(priv->pci_dev,
3220 tbd->host_addr,
3221 tbd->buf_length,
3222 PCI_DMA_TODEVICE);
James Ketrenos2c86c272005-03-23 17:32:29 -06003223
3224 txq->next++;
3225 txq->next %= txq->entries;
James Ketrenosee8e3652005-09-14 09:47:29 -05003226 }
James Ketrenos2c86c272005-03-23 17:32:29 -06003227
3228 txq->available -= 1 + packet->info.d_struct.txb->nr_frags;
3229 SET_STAT(&priv->txq_stat, txq->available);
3230
3231 list_add_tail(element, &priv->fw_pend_list);
3232 INC_STAT(&priv->fw_pend_stat);
3233 }
3234
3235 if (txq->next != next) {
3236 /* kick off the DMA by notifying firmware the
3237 * write index has moved; make sure TBD stores are sync'd */
3238 write_register(priv->net_dev,
3239 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
3240 txq->next);
3241 }
James Ketrenosee8e3652005-09-14 09:47:29 -05003242 return;
James Ketrenos2c86c272005-03-23 17:32:29 -06003243}
3244
3245static void ipw2100_irq_tasklet(struct ipw2100_priv *priv)
3246{
3247 struct net_device *dev = priv->net_dev;
3248 unsigned long flags;
3249 u32 inta, tmp;
3250
3251 spin_lock_irqsave(&priv->low_lock, flags);
3252 ipw2100_disable_interrupts(priv);
3253
3254 read_register(dev, IPW_REG_INTA, &inta);
3255
3256 IPW_DEBUG_ISR("enter - INTA: 0x%08lX\n",
3257 (unsigned long)inta & IPW_INTERRUPT_MASK);
3258
3259 priv->in_isr++;
3260 priv->interrupts++;
3261
3262 /* We do not loop and keep polling for more interrupts as this
3263 * is frowned upon and doesn't play nicely with other potentially
3264 * chained IRQs */
3265 IPW_DEBUG_ISR("INTA: 0x%08lX\n",
3266 (unsigned long)inta & IPW_INTERRUPT_MASK);
3267
3268 if (inta & IPW2100_INTA_FATAL_ERROR) {
Jiri Benc797b4f72005-08-25 20:03:27 -04003269 printk(KERN_WARNING DRV_NAME
James Ketrenosee8e3652005-09-14 09:47:29 -05003270 ": Fatal interrupt. Scheduling firmware restart.\n");
James Ketrenos2c86c272005-03-23 17:32:29 -06003271 priv->inta_other++;
James Ketrenosee8e3652005-09-14 09:47:29 -05003272 write_register(dev, IPW_REG_INTA, IPW2100_INTA_FATAL_ERROR);
James Ketrenos2c86c272005-03-23 17:32:29 -06003273
3274 read_nic_dword(dev, IPW_NIC_FATAL_ERROR, &priv->fatal_error);
3275 IPW_DEBUG_INFO("%s: Fatal error value: 0x%08X\n",
3276 priv->net_dev->name, priv->fatal_error);
3277
3278 read_nic_dword(dev, IPW_ERROR_ADDR(priv->fatal_error), &tmp);
3279 IPW_DEBUG_INFO("%s: Fatal error address value: 0x%08X\n",
3280 priv->net_dev->name, tmp);
3281
3282 /* Wake up any sleeping jobs */
3283 schedule_reset(priv);
3284 }
3285
3286 if (inta & IPW2100_INTA_PARITY_ERROR) {
James Ketrenosee8e3652005-09-14 09:47:29 -05003287 printk(KERN_ERR DRV_NAME
3288 ": ***** PARITY ERROR INTERRUPT !!!! \n");
James Ketrenos2c86c272005-03-23 17:32:29 -06003289 priv->inta_other++;
James Ketrenosee8e3652005-09-14 09:47:29 -05003290 write_register(dev, IPW_REG_INTA, IPW2100_INTA_PARITY_ERROR);
James Ketrenos2c86c272005-03-23 17:32:29 -06003291 }
3292
3293 if (inta & IPW2100_INTA_RX_TRANSFER) {
3294 IPW_DEBUG_ISR("RX interrupt\n");
3295
3296 priv->rx_interrupts++;
3297
James Ketrenosee8e3652005-09-14 09:47:29 -05003298 write_register(dev, IPW_REG_INTA, IPW2100_INTA_RX_TRANSFER);
James Ketrenos2c86c272005-03-23 17:32:29 -06003299
3300 __ipw2100_rx_process(priv);
3301 __ipw2100_tx_complete(priv);
3302 }
3303
3304 if (inta & IPW2100_INTA_TX_TRANSFER) {
3305 IPW_DEBUG_ISR("TX interrupt\n");
3306
3307 priv->tx_interrupts++;
3308
James Ketrenosee8e3652005-09-14 09:47:29 -05003309 write_register(dev, IPW_REG_INTA, IPW2100_INTA_TX_TRANSFER);
James Ketrenos2c86c272005-03-23 17:32:29 -06003310
3311 __ipw2100_tx_complete(priv);
Jiri Benc19f7f742005-08-25 20:02:10 -04003312 ipw2100_tx_send_commands(priv);
3313 ipw2100_tx_send_data(priv);
James Ketrenos2c86c272005-03-23 17:32:29 -06003314 }
3315
3316 if (inta & IPW2100_INTA_TX_COMPLETE) {
3317 IPW_DEBUG_ISR("TX complete\n");
3318 priv->inta_other++;
James Ketrenosee8e3652005-09-14 09:47:29 -05003319 write_register(dev, IPW_REG_INTA, IPW2100_INTA_TX_COMPLETE);
James Ketrenos2c86c272005-03-23 17:32:29 -06003320
3321 __ipw2100_tx_complete(priv);
3322 }
3323
3324 if (inta & IPW2100_INTA_EVENT_INTERRUPT) {
3325 /* ipw2100_handle_event(dev); */
3326 priv->inta_other++;
James Ketrenosee8e3652005-09-14 09:47:29 -05003327 write_register(dev, IPW_REG_INTA, IPW2100_INTA_EVENT_INTERRUPT);
James Ketrenos2c86c272005-03-23 17:32:29 -06003328 }
3329
3330 if (inta & IPW2100_INTA_FW_INIT_DONE) {
3331 IPW_DEBUG_ISR("FW init done interrupt\n");
3332 priv->inta_other++;
3333
3334 read_register(dev, IPW_REG_INTA, &tmp);
3335 if (tmp & (IPW2100_INTA_FATAL_ERROR |
3336 IPW2100_INTA_PARITY_ERROR)) {
James Ketrenosee8e3652005-09-14 09:47:29 -05003337 write_register(dev, IPW_REG_INTA,
3338 IPW2100_INTA_FATAL_ERROR |
3339 IPW2100_INTA_PARITY_ERROR);
James Ketrenos2c86c272005-03-23 17:32:29 -06003340 }
3341
James Ketrenosee8e3652005-09-14 09:47:29 -05003342 write_register(dev, IPW_REG_INTA, IPW2100_INTA_FW_INIT_DONE);
James Ketrenos2c86c272005-03-23 17:32:29 -06003343 }
3344
3345 if (inta & IPW2100_INTA_STATUS_CHANGE) {
3346 IPW_DEBUG_ISR("Status change interrupt\n");
3347 priv->inta_other++;
James Ketrenosee8e3652005-09-14 09:47:29 -05003348 write_register(dev, IPW_REG_INTA, IPW2100_INTA_STATUS_CHANGE);
James Ketrenos2c86c272005-03-23 17:32:29 -06003349 }
3350
3351 if (inta & IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE) {
3352 IPW_DEBUG_ISR("slave host mode interrupt\n");
3353 priv->inta_other++;
James Ketrenosee8e3652005-09-14 09:47:29 -05003354 write_register(dev, IPW_REG_INTA,
3355 IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE);
James Ketrenos2c86c272005-03-23 17:32:29 -06003356 }
3357
3358 priv->in_isr--;
3359 ipw2100_enable_interrupts(priv);
3360
3361 spin_unlock_irqrestore(&priv->low_lock, flags);
3362
3363 IPW_DEBUG_ISR("exit\n");
3364}
3365
David Howells7d12e782006-10-05 14:55:46 +01003366static irqreturn_t ipw2100_interrupt(int irq, void *data)
James Ketrenos2c86c272005-03-23 17:32:29 -06003367{
3368 struct ipw2100_priv *priv = data;
3369 u32 inta, inta_mask;
3370
3371 if (!data)
3372 return IRQ_NONE;
3373
James Ketrenosee8e3652005-09-14 09:47:29 -05003374 spin_lock(&priv->low_lock);
James Ketrenos2c86c272005-03-23 17:32:29 -06003375
3376 /* We check to see if we should be ignoring interrupts before
3377 * we touch the hardware. During ucode load if we try and handle
3378 * an interrupt we can cause keyboard problems as well as cause
3379 * the ucode to fail to initialize */
3380 if (!(priv->status & STATUS_INT_ENABLED)) {
3381 /* Shared IRQ */
3382 goto none;
3383 }
3384
3385 read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
3386 read_register(priv->net_dev, IPW_REG_INTA, &inta);
3387
3388 if (inta == 0xFFFFFFFF) {
3389 /* Hardware disappeared */
Jiri Benc797b4f72005-08-25 20:03:27 -04003390 printk(KERN_WARNING DRV_NAME ": IRQ INTA == 0xFFFFFFFF\n");
James Ketrenos2c86c272005-03-23 17:32:29 -06003391 goto none;
3392 }
3393
3394 inta &= IPW_INTERRUPT_MASK;
3395
3396 if (!(inta & inta_mask)) {
3397 /* Shared interrupt */
3398 goto none;
3399 }
3400
3401 /* We disable the hardware interrupt here just to prevent unneeded
3402 * calls to be made. We disable this again within the actual
3403 * work tasklet, so if another part of the code re-enables the
3404 * interrupt, that is fine */
3405 ipw2100_disable_interrupts(priv);
3406
3407 tasklet_schedule(&priv->irq_tasklet);
James Ketrenosee8e3652005-09-14 09:47:29 -05003408 spin_unlock(&priv->low_lock);
James Ketrenos2c86c272005-03-23 17:32:29 -06003409
3410 return IRQ_HANDLED;
James Ketrenosee8e3652005-09-14 09:47:29 -05003411 none:
James Ketrenos2c86c272005-03-23 17:32:29 -06003412 spin_unlock(&priv->low_lock);
3413 return IRQ_NONE;
3414}
3415
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +00003416static netdev_tx_t ipw2100_tx(struct libipw_txb *txb,
3417 struct net_device *dev, int pri)
James Ketrenos2c86c272005-03-23 17:32:29 -06003418{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003419 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06003420 struct list_head *element;
3421 struct ipw2100_tx_packet *packet;
3422 unsigned long flags;
3423
3424 spin_lock_irqsave(&priv->low_lock, flags);
3425
3426 if (!(priv->status & STATUS_ASSOCIATED)) {
3427 IPW_DEBUG_INFO("Can not transmit when not connected.\n");
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00003428 priv->net_dev->stats.tx_carrier_errors++;
James Ketrenos2c86c272005-03-23 17:32:29 -06003429 netif_stop_queue(dev);
3430 goto fail_unlock;
3431 }
3432
3433 if (list_empty(&priv->tx_free_list))
3434 goto fail_unlock;
3435
3436 element = priv->tx_free_list.next;
3437 packet = list_entry(element, struct ipw2100_tx_packet, list);
3438
3439 packet->info.d_struct.txb = txb;
3440
James Ketrenosee8e3652005-09-14 09:47:29 -05003441 IPW_DEBUG_TX("Sending fragment (%d bytes):\n", txb->fragments[0]->len);
3442 printk_buf(IPW_DL_TX, txb->fragments[0]->data, txb->fragments[0]->len);
James Ketrenos2c86c272005-03-23 17:32:29 -06003443
3444 packet->jiffy_start = jiffies;
3445
3446 list_del(element);
3447 DEC_STAT(&priv->tx_free_stat);
3448
3449 list_add_tail(element, &priv->tx_pend_list);
3450 INC_STAT(&priv->tx_pend_stat);
3451
Jiri Benc19f7f742005-08-25 20:02:10 -04003452 ipw2100_tx_send_data(priv);
James Ketrenos2c86c272005-03-23 17:32:29 -06003453
3454 spin_unlock_irqrestore(&priv->low_lock, flags);
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +00003455 return NETDEV_TX_OK;
James Ketrenos2c86c272005-03-23 17:32:29 -06003456
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +00003457fail_unlock:
James Ketrenos2c86c272005-03-23 17:32:29 -06003458 netif_stop_queue(dev);
3459 spin_unlock_irqrestore(&priv->low_lock, flags);
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +00003460 return NETDEV_TX_BUSY;
James Ketrenos2c86c272005-03-23 17:32:29 -06003461}
3462
James Ketrenos2c86c272005-03-23 17:32:29 -06003463static int ipw2100_msg_allocate(struct ipw2100_priv *priv)
3464{
3465 int i, j, err = -EINVAL;
3466 void *v;
3467 dma_addr_t p;
3468
James Ketrenosee8e3652005-09-14 09:47:29 -05003469 priv->msg_buffers =
3470 (struct ipw2100_tx_packet *)kmalloc(IPW_COMMAND_POOL_SIZE *
3471 sizeof(struct
3472 ipw2100_tx_packet),
3473 GFP_KERNEL);
James Ketrenos2c86c272005-03-23 17:32:29 -06003474 if (!priv->msg_buffers) {
Jiri Benc797b4f72005-08-25 20:03:27 -04003475 printk(KERN_ERR DRV_NAME ": %s: PCI alloc failed for msg "
James Ketrenos2c86c272005-03-23 17:32:29 -06003476 "buffers.\n", priv->net_dev->name);
3477 return -ENOMEM;
3478 }
3479
3480 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
James Ketrenosee8e3652005-09-14 09:47:29 -05003481 v = pci_alloc_consistent(priv->pci_dev,
3482 sizeof(struct ipw2100_cmd_header), &p);
James Ketrenos2c86c272005-03-23 17:32:29 -06003483 if (!v) {
Jiri Benc797b4f72005-08-25 20:03:27 -04003484 printk(KERN_ERR DRV_NAME ": "
James Ketrenos2c86c272005-03-23 17:32:29 -06003485 "%s: PCI alloc failed for msg "
James Ketrenosee8e3652005-09-14 09:47:29 -05003486 "buffers.\n", priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06003487 err = -ENOMEM;
3488 break;
3489 }
3490
3491 memset(v, 0, sizeof(struct ipw2100_cmd_header));
3492
3493 priv->msg_buffers[i].type = COMMAND;
3494 priv->msg_buffers[i].info.c_struct.cmd =
James Ketrenosee8e3652005-09-14 09:47:29 -05003495 (struct ipw2100_cmd_header *)v;
James Ketrenos2c86c272005-03-23 17:32:29 -06003496 priv->msg_buffers[i].info.c_struct.cmd_phys = p;
3497 }
3498
3499 if (i == IPW_COMMAND_POOL_SIZE)
3500 return 0;
3501
3502 for (j = 0; j < i; j++) {
James Ketrenosee8e3652005-09-14 09:47:29 -05003503 pci_free_consistent(priv->pci_dev,
3504 sizeof(struct ipw2100_cmd_header),
3505 priv->msg_buffers[j].info.c_struct.cmd,
3506 priv->msg_buffers[j].info.c_struct.
3507 cmd_phys);
James Ketrenos2c86c272005-03-23 17:32:29 -06003508 }
3509
3510 kfree(priv->msg_buffers);
3511 priv->msg_buffers = NULL;
3512
3513 return err;
3514}
3515
3516static int ipw2100_msg_initialize(struct ipw2100_priv *priv)
3517{
3518 int i;
3519
3520 INIT_LIST_HEAD(&priv->msg_free_list);
3521 INIT_LIST_HEAD(&priv->msg_pend_list);
3522
3523 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++)
3524 list_add_tail(&priv->msg_buffers[i].list, &priv->msg_free_list);
3525 SET_STAT(&priv->msg_free_stat, i);
3526
3527 return 0;
3528}
3529
3530static void ipw2100_msg_free(struct ipw2100_priv *priv)
3531{
3532 int i;
3533
3534 if (!priv->msg_buffers)
3535 return;
3536
3537 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
3538 pci_free_consistent(priv->pci_dev,
3539 sizeof(struct ipw2100_cmd_header),
3540 priv->msg_buffers[i].info.c_struct.cmd,
James Ketrenosee8e3652005-09-14 09:47:29 -05003541 priv->msg_buffers[i].info.c_struct.
3542 cmd_phys);
James Ketrenos2c86c272005-03-23 17:32:29 -06003543 }
3544
3545 kfree(priv->msg_buffers);
3546 priv->msg_buffers = NULL;
3547}
3548
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003549static ssize_t show_pci(struct device *d, struct device_attribute *attr,
3550 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003551{
3552 struct pci_dev *pci_dev = container_of(d, struct pci_dev, dev);
3553 char *out = buf;
3554 int i, j;
3555 u32 val;
3556
3557 for (i = 0; i < 16; i++) {
3558 out += sprintf(out, "[%08X] ", i * 16);
3559 for (j = 0; j < 16; j += 4) {
3560 pci_read_config_dword(pci_dev, i * 16 + j, &val);
3561 out += sprintf(out, "%08X ", val);
3562 }
3563 out += sprintf(out, "\n");
3564 }
3565
3566 return out - buf;
3567}
James Ketrenosee8e3652005-09-14 09:47:29 -05003568
James Ketrenos2c86c272005-03-23 17:32:29 -06003569static DEVICE_ATTR(pci, S_IRUGO, show_pci, NULL);
3570
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003571static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
3572 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003573{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003574 struct ipw2100_priv *p = dev_get_drvdata(d);
James Ketrenos2c86c272005-03-23 17:32:29 -06003575 return sprintf(buf, "0x%08x\n", (int)p->config);
3576}
James Ketrenosee8e3652005-09-14 09:47:29 -05003577
James Ketrenos2c86c272005-03-23 17:32:29 -06003578static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
3579
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003580static ssize_t show_status(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05003581 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003582{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003583 struct ipw2100_priv *p = dev_get_drvdata(d);
James Ketrenos2c86c272005-03-23 17:32:29 -06003584 return sprintf(buf, "0x%08x\n", (int)p->status);
3585}
James Ketrenosee8e3652005-09-14 09:47:29 -05003586
James Ketrenos2c86c272005-03-23 17:32:29 -06003587static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
3588
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003589static ssize_t show_capability(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05003590 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003591{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003592 struct ipw2100_priv *p = dev_get_drvdata(d);
James Ketrenos2c86c272005-03-23 17:32:29 -06003593 return sprintf(buf, "0x%08x\n", (int)p->capability);
3594}
James Ketrenos2c86c272005-03-23 17:32:29 -06003595
James Ketrenosee8e3652005-09-14 09:47:29 -05003596static DEVICE_ATTR(capability, S_IRUGO, show_capability, NULL);
James Ketrenos2c86c272005-03-23 17:32:29 -06003597
3598#define IPW2100_REG(x) { IPW_ ##x, #x }
Jiri Bencc4aee8c2005-08-25 20:04:43 -04003599static const struct {
James Ketrenos2c86c272005-03-23 17:32:29 -06003600 u32 addr;
3601 const char *name;
3602} hw_data[] = {
James Ketrenosee8e3652005-09-14 09:47:29 -05003603IPW2100_REG(REG_GP_CNTRL),
3604 IPW2100_REG(REG_GPIO),
3605 IPW2100_REG(REG_INTA),
3606 IPW2100_REG(REG_INTA_MASK), IPW2100_REG(REG_RESET_REG),};
James Ketrenos2c86c272005-03-23 17:32:29 -06003607#define IPW2100_NIC(x, s) { x, #x, s }
Jiri Bencc4aee8c2005-08-25 20:04:43 -04003608static const struct {
James Ketrenos2c86c272005-03-23 17:32:29 -06003609 u32 addr;
3610 const char *name;
3611 size_t size;
3612} nic_data[] = {
James Ketrenosee8e3652005-09-14 09:47:29 -05003613IPW2100_NIC(IPW2100_CONTROL_REG, 2),
3614 IPW2100_NIC(0x210014, 1), IPW2100_NIC(0x210000, 1),};
James Ketrenos2c86c272005-03-23 17:32:29 -06003615#define IPW2100_ORD(x, d) { IPW_ORD_ ##x, #x, d }
Jiri Bencc4aee8c2005-08-25 20:04:43 -04003616static const struct {
James Ketrenos2c86c272005-03-23 17:32:29 -06003617 u8 index;
3618 const char *name;
3619 const char *desc;
3620} ord_data[] = {
James Ketrenosee8e3652005-09-14 09:47:29 -05003621IPW2100_ORD(STAT_TX_HOST_REQUESTS, "requested Host Tx's (MSDU)"),
3622 IPW2100_ORD(STAT_TX_HOST_COMPLETE,
3623 "successful Host Tx's (MSDU)"),
3624 IPW2100_ORD(STAT_TX_DIR_DATA,
3625 "successful Directed Tx's (MSDU)"),
3626 IPW2100_ORD(STAT_TX_DIR_DATA1,
3627 "successful Directed Tx's (MSDU) @ 1MB"),
3628 IPW2100_ORD(STAT_TX_DIR_DATA2,
3629 "successful Directed Tx's (MSDU) @ 2MB"),
3630 IPW2100_ORD(STAT_TX_DIR_DATA5_5,
3631 "successful Directed Tx's (MSDU) @ 5_5MB"),
3632 IPW2100_ORD(STAT_TX_DIR_DATA11,
3633 "successful Directed Tx's (MSDU) @ 11MB"),
3634 IPW2100_ORD(STAT_TX_NODIR_DATA1,
3635 "successful Non_Directed Tx's (MSDU) @ 1MB"),
3636 IPW2100_ORD(STAT_TX_NODIR_DATA2,
3637 "successful Non_Directed Tx's (MSDU) @ 2MB"),
3638 IPW2100_ORD(STAT_TX_NODIR_DATA5_5,
3639 "successful Non_Directed Tx's (MSDU) @ 5.5MB"),
3640 IPW2100_ORD(STAT_TX_NODIR_DATA11,
3641 "successful Non_Directed Tx's (MSDU) @ 11MB"),
3642 IPW2100_ORD(STAT_NULL_DATA, "successful NULL data Tx's"),
3643 IPW2100_ORD(STAT_TX_RTS, "successful Tx RTS"),
3644 IPW2100_ORD(STAT_TX_CTS, "successful Tx CTS"),
3645 IPW2100_ORD(STAT_TX_ACK, "successful Tx ACK"),
3646 IPW2100_ORD(STAT_TX_ASSN, "successful Association Tx's"),
3647 IPW2100_ORD(STAT_TX_ASSN_RESP,
3648 "successful Association response Tx's"),
3649 IPW2100_ORD(STAT_TX_REASSN,
3650 "successful Reassociation Tx's"),
3651 IPW2100_ORD(STAT_TX_REASSN_RESP,
3652 "successful Reassociation response Tx's"),
3653 IPW2100_ORD(STAT_TX_PROBE,
3654 "probes successfully transmitted"),
3655 IPW2100_ORD(STAT_TX_PROBE_RESP,
3656 "probe responses successfully transmitted"),
3657 IPW2100_ORD(STAT_TX_BEACON, "tx beacon"),
3658 IPW2100_ORD(STAT_TX_ATIM, "Tx ATIM"),
3659 IPW2100_ORD(STAT_TX_DISASSN,
3660 "successful Disassociation TX"),
3661 IPW2100_ORD(STAT_TX_AUTH, "successful Authentication Tx"),
3662 IPW2100_ORD(STAT_TX_DEAUTH,
3663 "successful Deauthentication TX"),
3664 IPW2100_ORD(STAT_TX_TOTAL_BYTES,
3665 "Total successful Tx data bytes"),
3666 IPW2100_ORD(STAT_TX_RETRIES, "Tx retries"),
3667 IPW2100_ORD(STAT_TX_RETRY1, "Tx retries at 1MBPS"),
3668 IPW2100_ORD(STAT_TX_RETRY2, "Tx retries at 2MBPS"),
3669 IPW2100_ORD(STAT_TX_RETRY5_5, "Tx retries at 5.5MBPS"),
3670 IPW2100_ORD(STAT_TX_RETRY11, "Tx retries at 11MBPS"),
3671 IPW2100_ORD(STAT_TX_FAILURES, "Tx Failures"),
3672 IPW2100_ORD(STAT_TX_MAX_TRIES_IN_HOP,
3673 "times max tries in a hop failed"),
3674 IPW2100_ORD(STAT_TX_DISASSN_FAIL,
3675 "times disassociation failed"),
3676 IPW2100_ORD(STAT_TX_ERR_CTS, "missed/bad CTS frames"),
3677 IPW2100_ORD(STAT_TX_ERR_ACK, "tx err due to acks"),
3678 IPW2100_ORD(STAT_RX_HOST, "packets passed to host"),
3679 IPW2100_ORD(STAT_RX_DIR_DATA, "directed packets"),
3680 IPW2100_ORD(STAT_RX_DIR_DATA1, "directed packets at 1MB"),
3681 IPW2100_ORD(STAT_RX_DIR_DATA2, "directed packets at 2MB"),
3682 IPW2100_ORD(STAT_RX_DIR_DATA5_5,
3683 "directed packets at 5.5MB"),
3684 IPW2100_ORD(STAT_RX_DIR_DATA11, "directed packets at 11MB"),
3685 IPW2100_ORD(STAT_RX_NODIR_DATA, "nondirected packets"),
3686 IPW2100_ORD(STAT_RX_NODIR_DATA1,
3687 "nondirected packets at 1MB"),
3688 IPW2100_ORD(STAT_RX_NODIR_DATA2,
3689 "nondirected packets at 2MB"),
3690 IPW2100_ORD(STAT_RX_NODIR_DATA5_5,
3691 "nondirected packets at 5.5MB"),
3692 IPW2100_ORD(STAT_RX_NODIR_DATA11,
3693 "nondirected packets at 11MB"),
3694 IPW2100_ORD(STAT_RX_NULL_DATA, "null data rx's"),
3695 IPW2100_ORD(STAT_RX_RTS, "Rx RTS"), IPW2100_ORD(STAT_RX_CTS,
3696 "Rx CTS"),
3697 IPW2100_ORD(STAT_RX_ACK, "Rx ACK"),
3698 IPW2100_ORD(STAT_RX_CFEND, "Rx CF End"),
3699 IPW2100_ORD(STAT_RX_CFEND_ACK, "Rx CF End + CF Ack"),
3700 IPW2100_ORD(STAT_RX_ASSN, "Association Rx's"),
3701 IPW2100_ORD(STAT_RX_ASSN_RESP, "Association response Rx's"),
3702 IPW2100_ORD(STAT_RX_REASSN, "Reassociation Rx's"),
3703 IPW2100_ORD(STAT_RX_REASSN_RESP,
3704 "Reassociation response Rx's"),
3705 IPW2100_ORD(STAT_RX_PROBE, "probe Rx's"),
3706 IPW2100_ORD(STAT_RX_PROBE_RESP, "probe response Rx's"),
3707 IPW2100_ORD(STAT_RX_BEACON, "Rx beacon"),
3708 IPW2100_ORD(STAT_RX_ATIM, "Rx ATIM"),
3709 IPW2100_ORD(STAT_RX_DISASSN, "disassociation Rx"),
3710 IPW2100_ORD(STAT_RX_AUTH, "authentication Rx"),
3711 IPW2100_ORD(STAT_RX_DEAUTH, "deauthentication Rx"),
3712 IPW2100_ORD(STAT_RX_TOTAL_BYTES,
3713 "Total rx data bytes received"),
3714 IPW2100_ORD(STAT_RX_ERR_CRC, "packets with Rx CRC error"),
3715 IPW2100_ORD(STAT_RX_ERR_CRC1, "Rx CRC errors at 1MB"),
3716 IPW2100_ORD(STAT_RX_ERR_CRC2, "Rx CRC errors at 2MB"),
3717 IPW2100_ORD(STAT_RX_ERR_CRC5_5, "Rx CRC errors at 5.5MB"),
3718 IPW2100_ORD(STAT_RX_ERR_CRC11, "Rx CRC errors at 11MB"),
3719 IPW2100_ORD(STAT_RX_DUPLICATE1,
3720 "duplicate rx packets at 1MB"),
3721 IPW2100_ORD(STAT_RX_DUPLICATE2,
3722 "duplicate rx packets at 2MB"),
3723 IPW2100_ORD(STAT_RX_DUPLICATE5_5,
3724 "duplicate rx packets at 5.5MB"),
3725 IPW2100_ORD(STAT_RX_DUPLICATE11,
3726 "duplicate rx packets at 11MB"),
3727 IPW2100_ORD(STAT_RX_DUPLICATE, "duplicate rx packets"),
3728 IPW2100_ORD(PERS_DB_LOCK, "locking fw permanent db"),
3729 IPW2100_ORD(PERS_DB_SIZE, "size of fw permanent db"),
3730 IPW2100_ORD(PERS_DB_ADDR, "address of fw permanent db"),
3731 IPW2100_ORD(STAT_RX_INVALID_PROTOCOL,
3732 "rx frames with invalid protocol"),
3733 IPW2100_ORD(SYS_BOOT_TIME, "Boot time"),
3734 IPW2100_ORD(STAT_RX_NO_BUFFER,
3735 "rx frames rejected due to no buffer"),
3736 IPW2100_ORD(STAT_RX_MISSING_FRAG,
3737 "rx frames dropped due to missing fragment"),
3738 IPW2100_ORD(STAT_RX_ORPHAN_FRAG,
3739 "rx frames dropped due to non-sequential fragment"),
3740 IPW2100_ORD(STAT_RX_ORPHAN_FRAME,
3741 "rx frames dropped due to unmatched 1st frame"),
3742 IPW2100_ORD(STAT_RX_FRAG_AGEOUT,
3743 "rx frames dropped due to uncompleted frame"),
3744 IPW2100_ORD(STAT_RX_ICV_ERRORS,
3745 "ICV errors during decryption"),
3746 IPW2100_ORD(STAT_PSP_SUSPENSION, "times adapter suspended"),
3747 IPW2100_ORD(STAT_PSP_BCN_TIMEOUT, "beacon timeout"),
3748 IPW2100_ORD(STAT_PSP_POLL_TIMEOUT,
3749 "poll response timeouts"),
3750 IPW2100_ORD(STAT_PSP_NONDIR_TIMEOUT,
3751 "timeouts waiting for last {broad,multi}cast pkt"),
3752 IPW2100_ORD(STAT_PSP_RX_DTIMS, "PSP DTIMs received"),
3753 IPW2100_ORD(STAT_PSP_RX_TIMS, "PSP TIMs received"),
3754 IPW2100_ORD(STAT_PSP_STATION_ID, "PSP Station ID"),
3755 IPW2100_ORD(LAST_ASSN_TIME, "RTC time of last association"),
3756 IPW2100_ORD(STAT_PERCENT_MISSED_BCNS,
3757 "current calculation of % missed beacons"),
3758 IPW2100_ORD(STAT_PERCENT_RETRIES,
3759 "current calculation of % missed tx retries"),
3760 IPW2100_ORD(ASSOCIATED_AP_PTR,
3761 "0 if not associated, else pointer to AP table entry"),
3762 IPW2100_ORD(AVAILABLE_AP_CNT,
3763 "AP's decsribed in the AP table"),
3764 IPW2100_ORD(AP_LIST_PTR, "Ptr to list of available APs"),
3765 IPW2100_ORD(STAT_AP_ASSNS, "associations"),
3766 IPW2100_ORD(STAT_ASSN_FAIL, "association failures"),
3767 IPW2100_ORD(STAT_ASSN_RESP_FAIL,
3768 "failures due to response fail"),
3769 IPW2100_ORD(STAT_FULL_SCANS, "full scans"),
3770 IPW2100_ORD(CARD_DISABLED, "Card Disabled"),
3771 IPW2100_ORD(STAT_ROAM_INHIBIT,
3772 "times roaming was inhibited due to activity"),
3773 IPW2100_ORD(RSSI_AT_ASSN,
3774 "RSSI of associated AP at time of association"),
3775 IPW2100_ORD(STAT_ASSN_CAUSE1,
3776 "reassociation: no probe response or TX on hop"),
3777 IPW2100_ORD(STAT_ASSN_CAUSE2,
3778 "reassociation: poor tx/rx quality"),
3779 IPW2100_ORD(STAT_ASSN_CAUSE3,
3780 "reassociation: tx/rx quality (excessive AP load"),
3781 IPW2100_ORD(STAT_ASSN_CAUSE4,
3782 "reassociation: AP RSSI level"),
3783 IPW2100_ORD(STAT_ASSN_CAUSE5,
3784 "reassociations due to load leveling"),
3785 IPW2100_ORD(STAT_AUTH_FAIL, "times authentication failed"),
3786 IPW2100_ORD(STAT_AUTH_RESP_FAIL,
3787 "times authentication response failed"),
3788 IPW2100_ORD(STATION_TABLE_CNT,
3789 "entries in association table"),
3790 IPW2100_ORD(RSSI_AVG_CURR, "Current avg RSSI"),
3791 IPW2100_ORD(POWER_MGMT_MODE, "Power mode - 0=CAM, 1=PSP"),
3792 IPW2100_ORD(COUNTRY_CODE,
3793 "IEEE country code as recv'd from beacon"),
3794 IPW2100_ORD(COUNTRY_CHANNELS,
3795 "channels suported by country"),
3796 IPW2100_ORD(RESET_CNT, "adapter resets (warm)"),
3797 IPW2100_ORD(BEACON_INTERVAL, "Beacon interval"),
3798 IPW2100_ORD(ANTENNA_DIVERSITY,
3799 "TRUE if antenna diversity is disabled"),
3800 IPW2100_ORD(DTIM_PERIOD, "beacon intervals between DTIMs"),
3801 IPW2100_ORD(OUR_FREQ,
3802 "current radio freq lower digits - channel ID"),
3803 IPW2100_ORD(RTC_TIME, "current RTC time"),
3804 IPW2100_ORD(PORT_TYPE, "operating mode"),
3805 IPW2100_ORD(CURRENT_TX_RATE, "current tx rate"),
3806 IPW2100_ORD(SUPPORTED_RATES, "supported tx rates"),
3807 IPW2100_ORD(ATIM_WINDOW, "current ATIM Window"),
3808 IPW2100_ORD(BASIC_RATES, "basic tx rates"),
3809 IPW2100_ORD(NIC_HIGHEST_RATE, "NIC highest tx rate"),
3810 IPW2100_ORD(AP_HIGHEST_RATE, "AP highest tx rate"),
3811 IPW2100_ORD(CAPABILITIES,
3812 "Management frame capability field"),
3813 IPW2100_ORD(AUTH_TYPE, "Type of authentication"),
3814 IPW2100_ORD(RADIO_TYPE, "Adapter card platform type"),
3815 IPW2100_ORD(RTS_THRESHOLD,
3816 "Min packet length for RTS handshaking"),
3817 IPW2100_ORD(INT_MODE, "International mode"),
3818 IPW2100_ORD(FRAGMENTATION_THRESHOLD,
3819 "protocol frag threshold"),
3820 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_START_ADDRESS,
3821 "EEPROM offset in SRAM"),
3822 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_SIZE,
3823 "EEPROM size in SRAM"),
3824 IPW2100_ORD(EEPROM_SKU_CAPABILITY, "EEPROM SKU Capability"),
3825 IPW2100_ORD(EEPROM_IBSS_11B_CHANNELS,
3826 "EEPROM IBSS 11b channel set"),
3827 IPW2100_ORD(MAC_VERSION, "MAC Version"),
3828 IPW2100_ORD(MAC_REVISION, "MAC Revision"),
3829 IPW2100_ORD(RADIO_VERSION, "Radio Version"),
3830 IPW2100_ORD(NIC_MANF_DATE_TIME, "MANF Date/Time STAMP"),
3831 IPW2100_ORD(UCODE_VERSION, "Ucode Version"),};
James Ketrenos2c86c272005-03-23 17:32:29 -06003832
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003833static ssize_t show_registers(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05003834 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003835{
3836 int i;
3837 struct ipw2100_priv *priv = dev_get_drvdata(d);
3838 struct net_device *dev = priv->net_dev;
James Ketrenosee8e3652005-09-14 09:47:29 -05003839 char *out = buf;
James Ketrenos2c86c272005-03-23 17:32:29 -06003840 u32 val = 0;
3841
3842 out += sprintf(out, "%30s [Address ] : Hex\n", "Register");
3843
Ahmed S. Darwish22d57432007-02-05 18:56:22 +02003844 for (i = 0; i < ARRAY_SIZE(hw_data); i++) {
James Ketrenos2c86c272005-03-23 17:32:29 -06003845 read_register(dev, hw_data[i].addr, &val);
3846 out += sprintf(out, "%30s [%08X] : %08X\n",
3847 hw_data[i].name, hw_data[i].addr, val);
3848 }
3849
3850 return out - buf;
3851}
James Ketrenosee8e3652005-09-14 09:47:29 -05003852
James Ketrenos2c86c272005-03-23 17:32:29 -06003853static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL);
3854
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003855static ssize_t show_hardware(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05003856 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003857{
3858 struct ipw2100_priv *priv = dev_get_drvdata(d);
3859 struct net_device *dev = priv->net_dev;
James Ketrenosee8e3652005-09-14 09:47:29 -05003860 char *out = buf;
James Ketrenos2c86c272005-03-23 17:32:29 -06003861 int i;
3862
3863 out += sprintf(out, "%30s [Address ] : Hex\n", "NIC entry");
3864
Ahmed S. Darwish22d57432007-02-05 18:56:22 +02003865 for (i = 0; i < ARRAY_SIZE(nic_data); i++) {
James Ketrenos2c86c272005-03-23 17:32:29 -06003866 u8 tmp8;
3867 u16 tmp16;
3868 u32 tmp32;
3869
3870 switch (nic_data[i].size) {
3871 case 1:
3872 read_nic_byte(dev, nic_data[i].addr, &tmp8);
3873 out += sprintf(out, "%30s [%08X] : %02X\n",
3874 nic_data[i].name, nic_data[i].addr,
3875 tmp8);
3876 break;
3877 case 2:
3878 read_nic_word(dev, nic_data[i].addr, &tmp16);
3879 out += sprintf(out, "%30s [%08X] : %04X\n",
3880 nic_data[i].name, nic_data[i].addr,
3881 tmp16);
3882 break;
3883 case 4:
3884 read_nic_dword(dev, nic_data[i].addr, &tmp32);
3885 out += sprintf(out, "%30s [%08X] : %08X\n",
3886 nic_data[i].name, nic_data[i].addr,
3887 tmp32);
3888 break;
3889 }
3890 }
3891 return out - buf;
3892}
James Ketrenosee8e3652005-09-14 09:47:29 -05003893
James Ketrenos2c86c272005-03-23 17:32:29 -06003894static DEVICE_ATTR(hardware, S_IRUGO, show_hardware, NULL);
3895
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003896static ssize_t show_memory(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05003897 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003898{
3899 struct ipw2100_priv *priv = dev_get_drvdata(d);
3900 struct net_device *dev = priv->net_dev;
3901 static unsigned long loop = 0;
3902 int len = 0;
3903 u32 buffer[4];
3904 int i;
3905 char line[81];
3906
3907 if (loop >= 0x30000)
3908 loop = 0;
3909
3910 /* sysfs provides us PAGE_SIZE buffer */
3911 while (len < PAGE_SIZE - 128 && loop < 0x30000) {
3912
James Ketrenosee8e3652005-09-14 09:47:29 -05003913 if (priv->snapshot[0])
3914 for (i = 0; i < 4; i++)
3915 buffer[i] =
3916 *(u32 *) SNAPSHOT_ADDR(loop + i * 4);
3917 else
3918 for (i = 0; i < 4; i++)
3919 read_nic_dword(dev, loop + i * 4, &buffer[i]);
James Ketrenos2c86c272005-03-23 17:32:29 -06003920
3921 if (priv->dump_raw)
3922 len += sprintf(buf + len,
3923 "%c%c%c%c"
3924 "%c%c%c%c"
3925 "%c%c%c%c"
3926 "%c%c%c%c",
James Ketrenosee8e3652005-09-14 09:47:29 -05003927 ((u8 *) buffer)[0x0],
3928 ((u8 *) buffer)[0x1],
3929 ((u8 *) buffer)[0x2],
3930 ((u8 *) buffer)[0x3],
3931 ((u8 *) buffer)[0x4],
3932 ((u8 *) buffer)[0x5],
3933 ((u8 *) buffer)[0x6],
3934 ((u8 *) buffer)[0x7],
3935 ((u8 *) buffer)[0x8],
3936 ((u8 *) buffer)[0x9],
3937 ((u8 *) buffer)[0xa],
3938 ((u8 *) buffer)[0xb],
3939 ((u8 *) buffer)[0xc],
3940 ((u8 *) buffer)[0xd],
3941 ((u8 *) buffer)[0xe],
3942 ((u8 *) buffer)[0xf]);
James Ketrenos2c86c272005-03-23 17:32:29 -06003943 else
3944 len += sprintf(buf + len, "%s\n",
3945 snprint_line(line, sizeof(line),
James Ketrenosee8e3652005-09-14 09:47:29 -05003946 (u8 *) buffer, 16, loop));
James Ketrenos2c86c272005-03-23 17:32:29 -06003947 loop += 16;
3948 }
3949
3950 return len;
3951}
3952
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003953static ssize_t store_memory(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05003954 const char *buf, size_t count)
James Ketrenos2c86c272005-03-23 17:32:29 -06003955{
3956 struct ipw2100_priv *priv = dev_get_drvdata(d);
3957 struct net_device *dev = priv->net_dev;
3958 const char *p = buf;
3959
Zhu Yi8ed55a42006-01-24 13:49:20 +08003960 (void)dev; /* kill unused-var warning for debug-only code */
Jeff Garzikc2a8fad2005-11-09 00:49:38 -05003961
James Ketrenos2c86c272005-03-23 17:32:29 -06003962 if (count < 1)
3963 return count;
3964
3965 if (p[0] == '1' ||
3966 (count >= 2 && tolower(p[0]) == 'o' && tolower(p[1]) == 'n')) {
3967 IPW_DEBUG_INFO("%s: Setting memory dump to RAW mode.\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05003968 dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06003969 priv->dump_raw = 1;
3970
3971 } else if (p[0] == '0' || (count >= 2 && tolower(p[0]) == 'o' &&
James Ketrenosee8e3652005-09-14 09:47:29 -05003972 tolower(p[1]) == 'f')) {
James Ketrenos2c86c272005-03-23 17:32:29 -06003973 IPW_DEBUG_INFO("%s: Setting memory dump to HEX mode.\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05003974 dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06003975 priv->dump_raw = 0;
3976
3977 } else if (tolower(p[0]) == 'r') {
James Ketrenosee8e3652005-09-14 09:47:29 -05003978 IPW_DEBUG_INFO("%s: Resetting firmware snapshot.\n", dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06003979 ipw2100_snapshot_free(priv);
3980
3981 } else
3982 IPW_DEBUG_INFO("%s: Usage: 0|on = HEX, 1|off = RAW, "
James Ketrenosee8e3652005-09-14 09:47:29 -05003983 "reset = clear memory snapshot\n", dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06003984
3985 return count;
3986}
James Ketrenos2c86c272005-03-23 17:32:29 -06003987
James Ketrenosee8e3652005-09-14 09:47:29 -05003988static DEVICE_ATTR(memory, S_IWUSR | S_IRUGO, show_memory, store_memory);
James Ketrenos2c86c272005-03-23 17:32:29 -06003989
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003990static ssize_t show_ordinals(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05003991 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003992{
3993 struct ipw2100_priv *priv = dev_get_drvdata(d);
3994 u32 val = 0;
3995 int len = 0;
3996 u32 val_len;
3997 static int loop = 0;
3998
James Ketrenos82328352005-08-24 22:33:31 -05003999 if (priv->status & STATUS_RF_KILL_MASK)
4000 return 0;
4001
Ahmed S. Darwish22d57432007-02-05 18:56:22 +02004002 if (loop >= ARRAY_SIZE(ord_data))
James Ketrenos2c86c272005-03-23 17:32:29 -06004003 loop = 0;
4004
4005 /* sysfs provides us PAGE_SIZE buffer */
Ahmed S. Darwish22d57432007-02-05 18:56:22 +02004006 while (len < PAGE_SIZE - 128 && loop < ARRAY_SIZE(ord_data)) {
James Ketrenos2c86c272005-03-23 17:32:29 -06004007 val_len = sizeof(u32);
4008
4009 if (ipw2100_get_ordinal(priv, ord_data[loop].index, &val,
4010 &val_len))
4011 len += sprintf(buf + len, "[0x%02X] = ERROR %s\n",
4012 ord_data[loop].index,
4013 ord_data[loop].desc);
4014 else
4015 len += sprintf(buf + len, "[0x%02X] = 0x%08X %s\n",
4016 ord_data[loop].index, val,
4017 ord_data[loop].desc);
4018 loop++;
4019 }
4020
4021 return len;
4022}
James Ketrenosee8e3652005-09-14 09:47:29 -05004023
James Ketrenos2c86c272005-03-23 17:32:29 -06004024static DEVICE_ATTR(ordinals, S_IRUGO, show_ordinals, NULL);
4025
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004026static ssize_t show_stats(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05004027 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06004028{
4029 struct ipw2100_priv *priv = dev_get_drvdata(d);
James Ketrenosee8e3652005-09-14 09:47:29 -05004030 char *out = buf;
James Ketrenos2c86c272005-03-23 17:32:29 -06004031
4032 out += sprintf(out, "interrupts: %d {tx: %d, rx: %d, other: %d}\n",
4033 priv->interrupts, priv->tx_interrupts,
4034 priv->rx_interrupts, priv->inta_other);
4035 out += sprintf(out, "firmware resets: %d\n", priv->resets);
4036 out += sprintf(out, "firmware hangs: %d\n", priv->hangs);
Brice Goglin0f52bf92005-12-01 01:41:46 -08004037#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06004038 out += sprintf(out, "packet mismatch image: %s\n",
4039 priv->snapshot[0] ? "YES" : "NO");
4040#endif
4041
4042 return out - buf;
4043}
James Ketrenos2c86c272005-03-23 17:32:29 -06004044
James Ketrenosee8e3652005-09-14 09:47:29 -05004045static DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
James Ketrenos2c86c272005-03-23 17:32:29 -06004046
Jiri Bencc4aee8c2005-08-25 20:04:43 -04004047static int ipw2100_switch_mode(struct ipw2100_priv *priv, u32 mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06004048{
4049 int err;
4050
4051 if (mode == priv->ieee->iw_mode)
4052 return 0;
4053
4054 err = ipw2100_disable_adapter(priv);
4055 if (err) {
Jiri Benc797b4f72005-08-25 20:03:27 -04004056 printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06004057 priv->net_dev->name, err);
4058 return err;
4059 }
4060
4061 switch (mode) {
4062 case IW_MODE_INFRA:
4063 priv->net_dev->type = ARPHRD_ETHER;
4064 break;
4065 case IW_MODE_ADHOC:
4066 priv->net_dev->type = ARPHRD_ETHER;
4067 break;
4068#ifdef CONFIG_IPW2100_MONITOR
4069 case IW_MODE_MONITOR:
4070 priv->last_mode = priv->ieee->iw_mode;
Stefan Rompf15745a72006-02-21 18:36:17 +08004071 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
James Ketrenos2c86c272005-03-23 17:32:29 -06004072 break;
James Ketrenosee8e3652005-09-14 09:47:29 -05004073#endif /* CONFIG_IPW2100_MONITOR */
James Ketrenos2c86c272005-03-23 17:32:29 -06004074 }
4075
4076 priv->ieee->iw_mode = mode;
4077
4078#ifdef CONFIG_PM
James Ketrenosee8e3652005-09-14 09:47:29 -05004079 /* Indicate ipw2100_download_firmware download firmware
James Ketrenos2c86c272005-03-23 17:32:29 -06004080 * from disk instead of memory. */
4081 ipw2100_firmware.version = 0;
4082#endif
4083
James Ketrenosee8e3652005-09-14 09:47:29 -05004084 printk(KERN_INFO "%s: Reseting on mode change.\n", priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06004085 priv->reset_backoff = 0;
4086 schedule_reset(priv);
4087
4088 return 0;
4089}
4090
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004091static ssize_t show_internals(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05004092 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06004093{
4094 struct ipw2100_priv *priv = dev_get_drvdata(d);
4095 int len = 0;
4096
James Ketrenosee8e3652005-09-14 09:47:29 -05004097#define DUMP_VAR(x,y) len += sprintf(buf + len, # x ": %" y "\n", priv-> x)
James Ketrenos2c86c272005-03-23 17:32:29 -06004098
4099 if (priv->status & STATUS_ASSOCIATED)
4100 len += sprintf(buf + len, "connected: %lu\n",
4101 get_seconds() - priv->connect_start);
4102 else
4103 len += sprintf(buf + len, "not connected\n");
4104
John W. Linville274bfb82008-10-29 11:35:05 -04004105 DUMP_VAR(ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx], "p");
James Ketrenosee8e3652005-09-14 09:47:29 -05004106 DUMP_VAR(status, "08lx");
4107 DUMP_VAR(config, "08lx");
4108 DUMP_VAR(capability, "08lx");
James Ketrenos2c86c272005-03-23 17:32:29 -06004109
James Ketrenosee8e3652005-09-14 09:47:29 -05004110 len +=
4111 sprintf(buf + len, "last_rtc: %lu\n",
4112 (unsigned long)priv->last_rtc);
James Ketrenos2c86c272005-03-23 17:32:29 -06004113
James Ketrenosee8e3652005-09-14 09:47:29 -05004114 DUMP_VAR(fatal_error, "d");
4115 DUMP_VAR(stop_hang_check, "d");
4116 DUMP_VAR(stop_rf_kill, "d");
4117 DUMP_VAR(messages_sent, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004118
James Ketrenosee8e3652005-09-14 09:47:29 -05004119 DUMP_VAR(tx_pend_stat.value, "d");
4120 DUMP_VAR(tx_pend_stat.hi, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004121
James Ketrenosee8e3652005-09-14 09:47:29 -05004122 DUMP_VAR(tx_free_stat.value, "d");
4123 DUMP_VAR(tx_free_stat.lo, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004124
James Ketrenosee8e3652005-09-14 09:47:29 -05004125 DUMP_VAR(msg_free_stat.value, "d");
4126 DUMP_VAR(msg_free_stat.lo, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004127
James Ketrenosee8e3652005-09-14 09:47:29 -05004128 DUMP_VAR(msg_pend_stat.value, "d");
4129 DUMP_VAR(msg_pend_stat.hi, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004130
James Ketrenosee8e3652005-09-14 09:47:29 -05004131 DUMP_VAR(fw_pend_stat.value, "d");
4132 DUMP_VAR(fw_pend_stat.hi, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004133
James Ketrenosee8e3652005-09-14 09:47:29 -05004134 DUMP_VAR(txq_stat.value, "d");
4135 DUMP_VAR(txq_stat.lo, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004136
James Ketrenosee8e3652005-09-14 09:47:29 -05004137 DUMP_VAR(ieee->scans, "d");
4138 DUMP_VAR(reset_backoff, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004139
4140 return len;
4141}
James Ketrenosee8e3652005-09-14 09:47:29 -05004142
James Ketrenos2c86c272005-03-23 17:32:29 -06004143static DEVICE_ATTR(internals, S_IRUGO, show_internals, NULL);
4144
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004145static ssize_t show_bssinfo(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05004146 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06004147{
4148 struct ipw2100_priv *priv = dev_get_drvdata(d);
4149 char essid[IW_ESSID_MAX_SIZE + 1];
4150 u8 bssid[ETH_ALEN];
4151 u32 chan = 0;
James Ketrenosee8e3652005-09-14 09:47:29 -05004152 char *out = buf;
Hannes Ederb9da9e92009-02-14 11:50:26 +00004153 unsigned int length;
James Ketrenos2c86c272005-03-23 17:32:29 -06004154 int ret;
4155
James Ketrenos82328352005-08-24 22:33:31 -05004156 if (priv->status & STATUS_RF_KILL_MASK)
4157 return 0;
4158
James Ketrenos2c86c272005-03-23 17:32:29 -06004159 memset(essid, 0, sizeof(essid));
4160 memset(bssid, 0, sizeof(bssid));
4161
4162 length = IW_ESSID_MAX_SIZE;
4163 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID, essid, &length);
4164 if (ret)
4165 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4166 __LINE__);
4167
4168 length = sizeof(bssid);
4169 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
4170 bssid, &length);
4171 if (ret)
4172 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4173 __LINE__);
4174
4175 length = sizeof(u32);
4176 ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &length);
4177 if (ret)
4178 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4179 __LINE__);
4180
4181 out += sprintf(out, "ESSID: %s\n", essid);
Johannes Berge1749612008-10-27 15:59:26 -07004182 out += sprintf(out, "BSSID: %pM\n", bssid);
James Ketrenos2c86c272005-03-23 17:32:29 -06004183 out += sprintf(out, "Channel: %d\n", chan);
4184
4185 return out - buf;
4186}
James Ketrenos2c86c272005-03-23 17:32:29 -06004187
James Ketrenosee8e3652005-09-14 09:47:29 -05004188static DEVICE_ATTR(bssinfo, S_IRUGO, show_bssinfo, NULL);
James Ketrenos2c86c272005-03-23 17:32:29 -06004189
Brice Goglin0f52bf92005-12-01 01:41:46 -08004190#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06004191static ssize_t show_debug_level(struct device_driver *d, char *buf)
4192{
4193 return sprintf(buf, "0x%08X\n", ipw2100_debug_level);
4194}
4195
James Ketrenos82328352005-08-24 22:33:31 -05004196static ssize_t store_debug_level(struct device_driver *d,
4197 const char *buf, size_t count)
James Ketrenos2c86c272005-03-23 17:32:29 -06004198{
4199 char *p = (char *)buf;
4200 u32 val;
4201
4202 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
4203 p++;
4204 if (p[0] == 'x' || p[0] == 'X')
4205 p++;
4206 val = simple_strtoul(p, &p, 16);
4207 } else
4208 val = simple_strtoul(p, &p, 10);
4209 if (p == buf)
Zhu Yia1e695a2005-07-04 14:06:00 +08004210 IPW_DEBUG_INFO(": %s is not in hex or decimal form.\n", buf);
James Ketrenos2c86c272005-03-23 17:32:29 -06004211 else
4212 ipw2100_debug_level = val;
4213
4214 return strnlen(buf, count);
4215}
James Ketrenosee8e3652005-09-14 09:47:29 -05004216
James Ketrenos2c86c272005-03-23 17:32:29 -06004217static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, show_debug_level,
4218 store_debug_level);
Brice Goglin0f52bf92005-12-01 01:41:46 -08004219#endif /* CONFIG_IPW2100_DEBUG */
James Ketrenos2c86c272005-03-23 17:32:29 -06004220
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004221static ssize_t show_fatal_error(struct device *d,
James Ketrenosee8e3652005-09-14 09:47:29 -05004222 struct device_attribute *attr, char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06004223{
4224 struct ipw2100_priv *priv = dev_get_drvdata(d);
4225 char *out = buf;
4226 int i;
4227
4228 if (priv->fatal_error)
James Ketrenosee8e3652005-09-14 09:47:29 -05004229 out += sprintf(out, "0x%08X\n", priv->fatal_error);
James Ketrenos2c86c272005-03-23 17:32:29 -06004230 else
4231 out += sprintf(out, "0\n");
4232
4233 for (i = 1; i <= IPW2100_ERROR_QUEUE; i++) {
4234 if (!priv->fatal_errors[(priv->fatal_index - i) %
4235 IPW2100_ERROR_QUEUE])
4236 continue;
4237
4238 out += sprintf(out, "%d. 0x%08X\n", i,
4239 priv->fatal_errors[(priv->fatal_index - i) %
4240 IPW2100_ERROR_QUEUE]);
4241 }
4242
4243 return out - buf;
4244}
4245
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004246static ssize_t store_fatal_error(struct device *d,
James Ketrenosee8e3652005-09-14 09:47:29 -05004247 struct device_attribute *attr, const char *buf,
4248 size_t count)
James Ketrenos2c86c272005-03-23 17:32:29 -06004249{
4250 struct ipw2100_priv *priv = dev_get_drvdata(d);
4251 schedule_reset(priv);
4252 return count;
4253}
James Ketrenos2c86c272005-03-23 17:32:29 -06004254
James Ketrenosee8e3652005-09-14 09:47:29 -05004255static DEVICE_ATTR(fatal_error, S_IWUSR | S_IRUGO, show_fatal_error,
4256 store_fatal_error);
James Ketrenos2c86c272005-03-23 17:32:29 -06004257
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004258static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05004259 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06004260{
4261 struct ipw2100_priv *priv = dev_get_drvdata(d);
4262 return sprintf(buf, "%d\n", priv->ieee->scan_age);
4263}
4264
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004265static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05004266 const char *buf, size_t count)
James Ketrenos2c86c272005-03-23 17:32:29 -06004267{
4268 struct ipw2100_priv *priv = dev_get_drvdata(d);
4269 struct net_device *dev = priv->net_dev;
4270 char buffer[] = "00000000";
4271 unsigned long len =
4272 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
4273 unsigned long val;
4274 char *p = buffer;
4275
Zhu Yi8ed55a42006-01-24 13:49:20 +08004276 (void)dev; /* kill unused-var warning for debug-only code */
Jeff Garzikc2a8fad2005-11-09 00:49:38 -05004277
James Ketrenos2c86c272005-03-23 17:32:29 -06004278 IPW_DEBUG_INFO("enter\n");
4279
4280 strncpy(buffer, buf, len);
4281 buffer[len] = 0;
4282
4283 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
4284 p++;
4285 if (p[0] == 'x' || p[0] == 'X')
4286 p++;
4287 val = simple_strtoul(p, &p, 16);
4288 } else
4289 val = simple_strtoul(p, &p, 10);
4290 if (p == buffer) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004291 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06004292 } else {
4293 priv->ieee->scan_age = val;
4294 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
4295 }
4296
4297 IPW_DEBUG_INFO("exit\n");
4298 return len;
4299}
James Ketrenosee8e3652005-09-14 09:47:29 -05004300
James Ketrenos2c86c272005-03-23 17:32:29 -06004301static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
4302
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004303static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05004304 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06004305{
4306 /* 0 - RF kill not enabled
4307 1 - SW based RF kill active (sysfs)
4308 2 - HW based RF kill active
4309 3 - Both HW and SW baed RF kill active */
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07004310 struct ipw2100_priv *priv = dev_get_drvdata(d);
James Ketrenos2c86c272005-03-23 17:32:29 -06004311 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
James Ketrenosee8e3652005-09-14 09:47:29 -05004312 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos2c86c272005-03-23 17:32:29 -06004313 return sprintf(buf, "%i\n", val);
4314}
4315
4316static int ipw_radio_kill_sw(struct ipw2100_priv *priv, int disable_radio)
4317{
4318 if ((disable_radio ? 1 : 0) ==
4319 (priv->status & STATUS_RF_KILL_SW ? 1 : 0))
James Ketrenosee8e3652005-09-14 09:47:29 -05004320 return 0;
James Ketrenos2c86c272005-03-23 17:32:29 -06004321
4322 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
4323 disable_radio ? "OFF" : "ON");
4324
Ingo Molnar752e3772006-02-28 07:20:54 +08004325 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06004326
4327 if (disable_radio) {
4328 priv->status |= STATUS_RF_KILL_SW;
4329 ipw2100_down(priv);
4330 } else {
4331 priv->status &= ~STATUS_RF_KILL_SW;
4332 if (rf_kill_active(priv)) {
4333 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
4334 "disabled by HW switch\n");
4335 /* Make sure the RF_KILL check timer is running */
4336 priv->stop_rf_kill = 0;
4337 cancel_delayed_work(&priv->rf_kill);
Stephen Hemmingera62056f2007-06-22 21:46:50 -07004338 queue_delayed_work(priv->workqueue, &priv->rf_kill,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05004339 round_jiffies_relative(HZ));
James Ketrenos2c86c272005-03-23 17:32:29 -06004340 } else
4341 schedule_reset(priv);
4342 }
4343
Ingo Molnar752e3772006-02-28 07:20:54 +08004344 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06004345 return 1;
4346}
4347
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004348static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05004349 const char *buf, size_t count)
James Ketrenos2c86c272005-03-23 17:32:29 -06004350{
4351 struct ipw2100_priv *priv = dev_get_drvdata(d);
4352 ipw_radio_kill_sw(priv, buf[0] == '1');
4353 return count;
4354}
James Ketrenos2c86c272005-03-23 17:32:29 -06004355
James Ketrenosee8e3652005-09-14 09:47:29 -05004356static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos2c86c272005-03-23 17:32:29 -06004357
4358static struct attribute *ipw2100_sysfs_entries[] = {
4359 &dev_attr_hardware.attr,
4360 &dev_attr_registers.attr,
4361 &dev_attr_ordinals.attr,
4362 &dev_attr_pci.attr,
4363 &dev_attr_stats.attr,
4364 &dev_attr_internals.attr,
4365 &dev_attr_bssinfo.attr,
4366 &dev_attr_memory.attr,
4367 &dev_attr_scan_age.attr,
4368 &dev_attr_fatal_error.attr,
4369 &dev_attr_rf_kill.attr,
4370 &dev_attr_cfg.attr,
4371 &dev_attr_status.attr,
4372 &dev_attr_capability.attr,
4373 NULL,
4374};
4375
4376static struct attribute_group ipw2100_attribute_group = {
4377 .attrs = ipw2100_sysfs_entries,
4378};
4379
James Ketrenos2c86c272005-03-23 17:32:29 -06004380static int status_queue_allocate(struct ipw2100_priv *priv, int entries)
4381{
4382 struct ipw2100_status_queue *q = &priv->status_queue;
4383
4384 IPW_DEBUG_INFO("enter\n");
4385
4386 q->size = entries * sizeof(struct ipw2100_status);
James Ketrenosee8e3652005-09-14 09:47:29 -05004387 q->drv =
4388 (struct ipw2100_status *)pci_alloc_consistent(priv->pci_dev,
4389 q->size, &q->nic);
James Ketrenos2c86c272005-03-23 17:32:29 -06004390 if (!q->drv) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004391 IPW_DEBUG_WARNING("Can not allocate status queue.\n");
James Ketrenos2c86c272005-03-23 17:32:29 -06004392 return -ENOMEM;
4393 }
4394
4395 memset(q->drv, 0, q->size);
4396
4397 IPW_DEBUG_INFO("exit\n");
4398
4399 return 0;
4400}
4401
4402static void status_queue_free(struct ipw2100_priv *priv)
4403{
4404 IPW_DEBUG_INFO("enter\n");
4405
4406 if (priv->status_queue.drv) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004407 pci_free_consistent(priv->pci_dev, priv->status_queue.size,
4408 priv->status_queue.drv,
4409 priv->status_queue.nic);
James Ketrenos2c86c272005-03-23 17:32:29 -06004410 priv->status_queue.drv = NULL;
4411 }
4412
4413 IPW_DEBUG_INFO("exit\n");
4414}
4415
4416static int bd_queue_allocate(struct ipw2100_priv *priv,
4417 struct ipw2100_bd_queue *q, int entries)
4418{
4419 IPW_DEBUG_INFO("enter\n");
4420
4421 memset(q, 0, sizeof(struct ipw2100_bd_queue));
4422
4423 q->entries = entries;
4424 q->size = entries * sizeof(struct ipw2100_bd);
4425 q->drv = pci_alloc_consistent(priv->pci_dev, q->size, &q->nic);
4426 if (!q->drv) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004427 IPW_DEBUG_INFO
4428 ("can't allocate shared memory for buffer descriptors\n");
James Ketrenos2c86c272005-03-23 17:32:29 -06004429 return -ENOMEM;
4430 }
4431 memset(q->drv, 0, q->size);
4432
4433 IPW_DEBUG_INFO("exit\n");
4434
4435 return 0;
4436}
4437
James Ketrenosee8e3652005-09-14 09:47:29 -05004438static void bd_queue_free(struct ipw2100_priv *priv, struct ipw2100_bd_queue *q)
James Ketrenos2c86c272005-03-23 17:32:29 -06004439{
4440 IPW_DEBUG_INFO("enter\n");
4441
4442 if (!q)
4443 return;
4444
4445 if (q->drv) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004446 pci_free_consistent(priv->pci_dev, q->size, q->drv, q->nic);
James Ketrenos2c86c272005-03-23 17:32:29 -06004447 q->drv = NULL;
4448 }
4449
4450 IPW_DEBUG_INFO("exit\n");
4451}
4452
James Ketrenosee8e3652005-09-14 09:47:29 -05004453static void bd_queue_initialize(struct ipw2100_priv *priv,
4454 struct ipw2100_bd_queue *q, u32 base, u32 size,
4455 u32 r, u32 w)
James Ketrenos2c86c272005-03-23 17:32:29 -06004456{
4457 IPW_DEBUG_INFO("enter\n");
4458
James Ketrenosee8e3652005-09-14 09:47:29 -05004459 IPW_DEBUG_INFO("initializing bd queue at virt=%p, phys=%08x\n", q->drv,
4460 (u32) q->nic);
James Ketrenos2c86c272005-03-23 17:32:29 -06004461
4462 write_register(priv->net_dev, base, q->nic);
4463 write_register(priv->net_dev, size, q->entries);
4464 write_register(priv->net_dev, r, q->oldest);
4465 write_register(priv->net_dev, w, q->next);
4466
4467 IPW_DEBUG_INFO("exit\n");
4468}
4469
4470static void ipw2100_kill_workqueue(struct ipw2100_priv *priv)
4471{
4472 if (priv->workqueue) {
4473 priv->stop_rf_kill = 1;
4474 priv->stop_hang_check = 1;
4475 cancel_delayed_work(&priv->reset_work);
4476 cancel_delayed_work(&priv->security_work);
4477 cancel_delayed_work(&priv->wx_event_work);
4478 cancel_delayed_work(&priv->hang_check);
4479 cancel_delayed_work(&priv->rf_kill);
Dan Williamsd20c6782007-10-10 12:28:07 -04004480 cancel_delayed_work(&priv->scan_event_later);
James Ketrenos2c86c272005-03-23 17:32:29 -06004481 destroy_workqueue(priv->workqueue);
4482 priv->workqueue = NULL;
4483 }
4484}
4485
4486static int ipw2100_tx_allocate(struct ipw2100_priv *priv)
4487{
4488 int i, j, err = -EINVAL;
4489 void *v;
4490 dma_addr_t p;
4491
4492 IPW_DEBUG_INFO("enter\n");
4493
4494 err = bd_queue_allocate(priv, &priv->tx_queue, TX_QUEUE_LENGTH);
4495 if (err) {
4496 IPW_DEBUG_ERROR("%s: failed bd_queue_allocate\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05004497 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06004498 return err;
4499 }
4500
James Ketrenosee8e3652005-09-14 09:47:29 -05004501 priv->tx_buffers =
4502 (struct ipw2100_tx_packet *)kmalloc(TX_PENDED_QUEUE_LENGTH *
4503 sizeof(struct
4504 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 */
4654 priv->rx_buffers = (struct ipw2100_rx_packet *)
4655 kmalloc(RX_QUEUE_LENGTH * sizeof(struct ipw2100_rx_packet),
4656 GFP_KERNEL);
4657 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;
5236} __attribute__ ((packed));
5237
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
James Ketrenos2c86c272005-03-23 17:32:29 -06006105/* Look into using netdev destructor to shutdown ieee80211? */
6106
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
John W. Linvillea3caa992009-08-25 14:12:25 -04006115 dev = alloc_ieee80211(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
John W. Linvillea3caa992009-08-25 14:12:25 -04006428 free_ieee80211(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
Matthew Garrettc26409a2009-11-11 14:36:30 -05006486 /* wiphy_unregister needs to be here, before free_ieee80211 */
6487 wiphy_unregister(priv->ieee->wdev.wiphy);
6488 kfree(priv->ieee->bg_band.channels);
John W. Linvillea3caa992009-08-25 14:12:25 -04006489 free_ieee80211(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
James Ketrenos2c86c272005-03-23 17:32:29 -06006576#define IPW2100_DEV_ID(x) { PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, x }
6577
6578static struct pci_device_id ipw2100_pci_id_table[] __devinitdata = {
James Ketrenosee8e3652005-09-14 09:47:29 -05006579 IPW2100_DEV_ID(0x2520), /* IN 2100A mPCI 3A */
6580 IPW2100_DEV_ID(0x2521), /* IN 2100A mPCI 3B */
6581 IPW2100_DEV_ID(0x2524), /* IN 2100A mPCI 3B */
6582 IPW2100_DEV_ID(0x2525), /* IN 2100A mPCI 3B */
6583 IPW2100_DEV_ID(0x2526), /* IN 2100A mPCI Gen A3 */
6584 IPW2100_DEV_ID(0x2522), /* IN 2100 mPCI 3B */
6585 IPW2100_DEV_ID(0x2523), /* IN 2100 mPCI 3A */
6586 IPW2100_DEV_ID(0x2527), /* IN 2100 mPCI 3B */
6587 IPW2100_DEV_ID(0x2528), /* IN 2100 mPCI 3B */
6588 IPW2100_DEV_ID(0x2529), /* IN 2100 mPCI 3B */
6589 IPW2100_DEV_ID(0x252B), /* IN 2100 mPCI 3A */
6590 IPW2100_DEV_ID(0x252C), /* IN 2100 mPCI 3A */
6591 IPW2100_DEV_ID(0x252D), /* IN 2100 mPCI 3A */
James Ketrenos2c86c272005-03-23 17:32:29 -06006592
James Ketrenosee8e3652005-09-14 09:47:29 -05006593 IPW2100_DEV_ID(0x2550), /* IB 2100A mPCI 3B */
6594 IPW2100_DEV_ID(0x2551), /* IB 2100 mPCI 3B */
6595 IPW2100_DEV_ID(0x2553), /* IB 2100 mPCI 3B */
6596 IPW2100_DEV_ID(0x2554), /* IB 2100 mPCI 3B */
6597 IPW2100_DEV_ID(0x2555), /* IB 2100 mPCI 3B */
James Ketrenos2c86c272005-03-23 17:32:29 -06006598
James Ketrenosee8e3652005-09-14 09:47:29 -05006599 IPW2100_DEV_ID(0x2560), /* DE 2100A mPCI 3A */
6600 IPW2100_DEV_ID(0x2562), /* DE 2100A mPCI 3A */
6601 IPW2100_DEV_ID(0x2563), /* DE 2100A mPCI 3A */
6602 IPW2100_DEV_ID(0x2561), /* DE 2100 mPCI 3A */
6603 IPW2100_DEV_ID(0x2565), /* DE 2100 mPCI 3A */
6604 IPW2100_DEV_ID(0x2566), /* DE 2100 mPCI 3A */
6605 IPW2100_DEV_ID(0x2567), /* DE 2100 mPCI 3A */
James Ketrenos2c86c272005-03-23 17:32:29 -06006606
James Ketrenosee8e3652005-09-14 09:47:29 -05006607 IPW2100_DEV_ID(0x2570), /* GA 2100 mPCI 3B */
James Ketrenos2c86c272005-03-23 17:32:29 -06006608
James Ketrenosee8e3652005-09-14 09:47:29 -05006609 IPW2100_DEV_ID(0x2580), /* TO 2100A mPCI 3B */
6610 IPW2100_DEV_ID(0x2582), /* TO 2100A mPCI 3B */
6611 IPW2100_DEV_ID(0x2583), /* TO 2100A mPCI 3B */
6612 IPW2100_DEV_ID(0x2581), /* TO 2100 mPCI 3B */
6613 IPW2100_DEV_ID(0x2585), /* TO 2100 mPCI 3B */
6614 IPW2100_DEV_ID(0x2586), /* TO 2100 mPCI 3B */
6615 IPW2100_DEV_ID(0x2587), /* TO 2100 mPCI 3B */
James Ketrenos2c86c272005-03-23 17:32:29 -06006616
James Ketrenosee8e3652005-09-14 09:47:29 -05006617 IPW2100_DEV_ID(0x2590), /* SO 2100A mPCI 3B */
6618 IPW2100_DEV_ID(0x2592), /* SO 2100A mPCI 3B */
6619 IPW2100_DEV_ID(0x2591), /* SO 2100 mPCI 3B */
6620 IPW2100_DEV_ID(0x2593), /* SO 2100 mPCI 3B */
6621 IPW2100_DEV_ID(0x2596), /* SO 2100 mPCI 3B */
6622 IPW2100_DEV_ID(0x2598), /* SO 2100 mPCI 3B */
James Ketrenos2c86c272005-03-23 17:32:29 -06006623
James Ketrenosee8e3652005-09-14 09:47:29 -05006624 IPW2100_DEV_ID(0x25A0), /* HP 2100 mPCI 3B */
James Ketrenos2c86c272005-03-23 17:32:29 -06006625 {0,},
6626};
6627
6628MODULE_DEVICE_TABLE(pci, ipw2100_pci_id_table);
6629
6630static struct pci_driver ipw2100_pci_driver = {
6631 .name = DRV_NAME,
6632 .id_table = ipw2100_pci_id_table,
6633 .probe = ipw2100_pci_init_one,
6634 .remove = __devexit_p(ipw2100_pci_remove_one),
6635#ifdef CONFIG_PM
6636 .suspend = ipw2100_suspend,
6637 .resume = ipw2100_resume,
6638#endif
6639};
6640
James Ketrenos2c86c272005-03-23 17:32:29 -06006641/**
6642 * Initialize the ipw2100 driver/module
6643 *
6644 * @returns 0 if ok, < 0 errno node con error.
6645 *
6646 * Note: we cannot init the /proc stuff until the PCI driver is there,
6647 * or we risk an unlikely race condition on someone accessing
6648 * uninitialized data in the PCI dev struct through /proc.
6649 */
6650static int __init ipw2100_init(void)
6651{
6652 int ret;
6653
6654 printk(KERN_INFO DRV_NAME ": %s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
6655 printk(KERN_INFO DRV_NAME ": %s\n", DRV_COPYRIGHT);
6656
Jeff Garzik29917622006-08-19 17:48:59 -04006657 ret = pci_register_driver(&ipw2100_pci_driver);
Jeff Garzikde897882006-10-01 07:31:09 -04006658 if (ret)
6659 goto out;
James Ketrenos2c86c272005-03-23 17:32:29 -06006660
Mark Grossf011e2e2008-02-04 22:30:09 -08006661 pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100",
6662 PM_QOS_DEFAULT_VALUE);
Brice Goglin0f52bf92005-12-01 01:41:46 -08006663#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06006664 ipw2100_debug_level = debug;
Jeff Garzikde897882006-10-01 07:31:09 -04006665 ret = driver_create_file(&ipw2100_pci_driver.driver,
6666 &driver_attr_debug_level);
James Ketrenos2c86c272005-03-23 17:32:29 -06006667#endif
6668
Jeff Garzikde897882006-10-01 07:31:09 -04006669out:
James Ketrenos2c86c272005-03-23 17:32:29 -06006670 return ret;
6671}
6672
James Ketrenos2c86c272005-03-23 17:32:29 -06006673/**
6674 * Cleanup ipw2100 driver registration
6675 */
6676static void __exit ipw2100_exit(void)
6677{
6678 /* FIXME: IPG: check that we have no instances of the devices open */
Brice Goglin0f52bf92005-12-01 01:41:46 -08006679#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06006680 driver_remove_file(&ipw2100_pci_driver.driver,
6681 &driver_attr_debug_level);
6682#endif
6683 pci_unregister_driver(&ipw2100_pci_driver);
Mark Grossf011e2e2008-02-04 22:30:09 -08006684 pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100");
James Ketrenos2c86c272005-03-23 17:32:29 -06006685}
6686
6687module_init(ipw2100_init);
6688module_exit(ipw2100_exit);
6689
James Ketrenos2c86c272005-03-23 17:32:29 -06006690static int ipw2100_wx_get_name(struct net_device *dev,
6691 struct iw_request_info *info,
6692 union iwreq_data *wrqu, char *extra)
6693{
6694 /*
6695 * This can be called at any time. No action lock required
6696 */
6697
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006698 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006699 if (!(priv->status & STATUS_ASSOCIATED))
6700 strcpy(wrqu->name, "unassociated");
6701 else
6702 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
6703
6704 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
6705 return 0;
6706}
6707
James Ketrenos2c86c272005-03-23 17:32:29 -06006708static int ipw2100_wx_set_freq(struct net_device *dev,
6709 struct iw_request_info *info,
6710 union iwreq_data *wrqu, char *extra)
6711{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006712 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006713 struct iw_freq *fwrq = &wrqu->freq;
6714 int err = 0;
6715
6716 if (priv->ieee->iw_mode == IW_MODE_INFRA)
6717 return -EOPNOTSUPP;
6718
Ingo Molnar752e3772006-02-28 07:20:54 +08006719 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006720 if (!(priv->status & STATUS_INITIALIZED)) {
6721 err = -EIO;
6722 goto done;
6723 }
6724
6725 /* if setting by freq convert to channel */
6726 if (fwrq->e == 1) {
James Ketrenosee8e3652005-09-14 09:47:29 -05006727 if ((fwrq->m >= (int)2.412e8 && fwrq->m <= (int)2.487e8)) {
James Ketrenos2c86c272005-03-23 17:32:29 -06006728 int f = fwrq->m / 100000;
6729 int c = 0;
6730
6731 while ((c < REG_MAX_CHANNEL) &&
6732 (f != ipw2100_frequencies[c]))
6733 c++;
6734
6735 /* hack to fall through */
6736 fwrq->e = 0;
6737 fwrq->m = c + 1;
6738 }
6739 }
6740
James Ketrenos82328352005-08-24 22:33:31 -05006741 if (fwrq->e > 0 || fwrq->m > 1000) {
6742 err = -EOPNOTSUPP;
6743 goto done;
6744 } else { /* Set the channel */
James Ketrenos2c86c272005-03-23 17:32:29 -06006745 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
6746 err = ipw2100_set_channel(priv, fwrq->m, 0);
6747 }
6748
James Ketrenosee8e3652005-09-14 09:47:29 -05006749 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08006750 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006751 return err;
6752}
6753
James Ketrenos2c86c272005-03-23 17:32:29 -06006754static int ipw2100_wx_get_freq(struct net_device *dev,
6755 struct iw_request_info *info,
6756 union iwreq_data *wrqu, char *extra)
6757{
6758 /*
6759 * This can be called at any time. No action lock required
6760 */
6761
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006762 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006763
6764 wrqu->freq.e = 0;
6765
6766 /* If we are associated, trying to associate, or have a statically
6767 * configured CHANNEL then return that; otherwise return ANY */
6768 if (priv->config & CFG_STATIC_CHANNEL ||
6769 priv->status & STATUS_ASSOCIATED)
6770 wrqu->freq.m = priv->channel;
6771 else
6772 wrqu->freq.m = 0;
6773
6774 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
6775 return 0;
6776
6777}
6778
6779static int ipw2100_wx_set_mode(struct net_device *dev,
6780 struct iw_request_info *info,
6781 union iwreq_data *wrqu, char *extra)
6782{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006783 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006784 int err = 0;
6785
6786 IPW_DEBUG_WX("SET Mode -> %d \n", wrqu->mode);
6787
6788 if (wrqu->mode == priv->ieee->iw_mode)
6789 return 0;
6790
Ingo Molnar752e3772006-02-28 07:20:54 +08006791 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006792 if (!(priv->status & STATUS_INITIALIZED)) {
6793 err = -EIO;
6794 goto done;
6795 }
6796
6797 switch (wrqu->mode) {
6798#ifdef CONFIG_IPW2100_MONITOR
6799 case IW_MODE_MONITOR:
6800 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
6801 break;
James Ketrenosee8e3652005-09-14 09:47:29 -05006802#endif /* CONFIG_IPW2100_MONITOR */
James Ketrenos2c86c272005-03-23 17:32:29 -06006803 case IW_MODE_ADHOC:
6804 err = ipw2100_switch_mode(priv, IW_MODE_ADHOC);
6805 break;
6806 case IW_MODE_INFRA:
6807 case IW_MODE_AUTO:
6808 default:
6809 err = ipw2100_switch_mode(priv, IW_MODE_INFRA);
6810 break;
6811 }
6812
James Ketrenosee8e3652005-09-14 09:47:29 -05006813 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08006814 mutex_unlock(&priv->action_mutex);
James Ketrenosee8e3652005-09-14 09:47:29 -05006815 return err;
James Ketrenos2c86c272005-03-23 17:32:29 -06006816}
6817
6818static int ipw2100_wx_get_mode(struct net_device *dev,
6819 struct iw_request_info *info,
6820 union iwreq_data *wrqu, char *extra)
6821{
6822 /*
6823 * This can be called at any time. No action lock required
6824 */
6825
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006826 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006827
6828 wrqu->mode = priv->ieee->iw_mode;
6829 IPW_DEBUG_WX("GET Mode -> %d\n", wrqu->mode);
6830
6831 return 0;
6832}
6833
James Ketrenos2c86c272005-03-23 17:32:29 -06006834#define POWER_MODES 5
6835
6836/* Values are in microsecond */
Jiri Bencc4aee8c2005-08-25 20:04:43 -04006837static const s32 timeout_duration[POWER_MODES] = {
James Ketrenos2c86c272005-03-23 17:32:29 -06006838 350000,
6839 250000,
6840 75000,
6841 37000,
6842 25000,
6843};
6844
Jiri Bencc4aee8c2005-08-25 20:04:43 -04006845static const s32 period_duration[POWER_MODES] = {
James Ketrenos2c86c272005-03-23 17:32:29 -06006846 400000,
6847 700000,
6848 1000000,
6849 1000000,
6850 1000000
6851};
6852
6853static int ipw2100_wx_get_range(struct net_device *dev,
6854 struct iw_request_info *info,
6855 union iwreq_data *wrqu, char *extra)
6856{
6857 /*
6858 * This can be called at any time. No action lock required
6859 */
6860
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006861 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006862 struct iw_range *range = (struct iw_range *)extra;
6863 u16 val;
6864 int i, level;
6865
6866 wrqu->data.length = sizeof(*range);
6867 memset(range, 0, sizeof(*range));
6868
6869 /* Let's try to keep this struct in the same order as in
6870 * linux/include/wireless.h
6871 */
6872
6873 /* TODO: See what values we can set, and remove the ones we can't
6874 * set, or fill them with some default data.
6875 */
6876
6877 /* ~5 Mb/s real (802.11b) */
6878 range->throughput = 5 * 1000 * 1000;
6879
James Ketrenosee8e3652005-09-14 09:47:29 -05006880// range->sensitivity; /* signal level threshold range */
James Ketrenos2c86c272005-03-23 17:32:29 -06006881
6882 range->max_qual.qual = 100;
6883 /* TODO: Find real max RSSI and stick here */
6884 range->max_qual.level = 0;
6885 range->max_qual.noise = 0;
James Ketrenosee8e3652005-09-14 09:47:29 -05006886 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos2c86c272005-03-23 17:32:29 -06006887
James Ketrenosee8e3652005-09-14 09:47:29 -05006888 range->avg_qual.qual = 70; /* > 8% missed beacons is 'bad' */
James Ketrenos2c86c272005-03-23 17:32:29 -06006889 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
6890 range->avg_qual.level = 20 + IPW2100_RSSI_TO_DBM;
6891 range->avg_qual.noise = 0;
James Ketrenosee8e3652005-09-14 09:47:29 -05006892 range->avg_qual.updated = 7; /* Updated all three */
James Ketrenos2c86c272005-03-23 17:32:29 -06006893
6894 range->num_bitrates = RATE_COUNT;
6895
6896 for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++) {
6897 range->bitrate[i] = ipw2100_rates_11b[i];
6898 }
6899
6900 range->min_rts = MIN_RTS_THRESHOLD;
6901 range->max_rts = MAX_RTS_THRESHOLD;
6902 range->min_frag = MIN_FRAG_THRESHOLD;
6903 range->max_frag = MAX_FRAG_THRESHOLD;
6904
6905 range->min_pmp = period_duration[0]; /* Minimal PM period */
James Ketrenosee8e3652005-09-14 09:47:29 -05006906 range->max_pmp = period_duration[POWER_MODES - 1]; /* Maximal PM period */
6907 range->min_pmt = timeout_duration[POWER_MODES - 1]; /* Minimal PM timeout */
6908 range->max_pmt = timeout_duration[0]; /* Maximal PM timeout */
James Ketrenos2c86c272005-03-23 17:32:29 -06006909
James Ketrenosee8e3652005-09-14 09:47:29 -05006910 /* How to decode max/min PM period */
James Ketrenos2c86c272005-03-23 17:32:29 -06006911 range->pmp_flags = IW_POWER_PERIOD;
James Ketrenosee8e3652005-09-14 09:47:29 -05006912 /* How to decode max/min PM period */
James Ketrenos2c86c272005-03-23 17:32:29 -06006913 range->pmt_flags = IW_POWER_TIMEOUT;
6914 /* What PM options are supported */
6915 range->pm_capa = IW_POWER_TIMEOUT | IW_POWER_PERIOD;
6916
6917 range->encoding_size[0] = 5;
James Ketrenosee8e3652005-09-14 09:47:29 -05006918 range->encoding_size[1] = 13; /* Different token sizes */
6919 range->num_encoding_sizes = 2; /* Number of entry in the list */
6920 range->max_encoding_tokens = WEP_KEYS; /* Max number of tokens */
6921// range->encoding_login_index; /* token index for login token */
James Ketrenos2c86c272005-03-23 17:32:29 -06006922
6923 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6924 range->txpower_capa = IW_TXPOW_DBM;
6925 range->num_txpower = IW_MAX_TXPOWER;
James Ketrenosee8e3652005-09-14 09:47:29 -05006926 for (i = 0, level = (IPW_TX_POWER_MAX_DBM * 16);
6927 i < IW_MAX_TXPOWER;
6928 i++, level -=
6929 ((IPW_TX_POWER_MAX_DBM -
6930 IPW_TX_POWER_MIN_DBM) * 16) / (IW_MAX_TXPOWER - 1))
James Ketrenos2c86c272005-03-23 17:32:29 -06006931 range->txpower[i] = level / 16;
6932 } else {
6933 range->txpower_capa = 0;
6934 range->num_txpower = 0;
6935 }
6936
James Ketrenos2c86c272005-03-23 17:32:29 -06006937 /* Set the Wireless Extension versions */
6938 range->we_version_compiled = WIRELESS_EXT;
Dan Williams166c3432006-01-09 11:04:31 -05006939 range->we_version_source = 18;
James Ketrenos2c86c272005-03-23 17:32:29 -06006940
James Ketrenosee8e3652005-09-14 09:47:29 -05006941// range->retry_capa; /* What retry options are supported */
6942// range->retry_flags; /* How to decode max/min retry limit */
6943// range->r_time_flags; /* How to decode max/min retry life */
6944// range->min_retry; /* Minimal number of retries */
6945// range->max_retry; /* Maximal number of retries */
6946// range->min_r_time; /* Minimal retry lifetime */
6947// range->max_r_time; /* Maximal retry lifetime */
James Ketrenos2c86c272005-03-23 17:32:29 -06006948
James Ketrenosee8e3652005-09-14 09:47:29 -05006949 range->num_channels = FREQ_COUNT;
James Ketrenos2c86c272005-03-23 17:32:29 -06006950
6951 val = 0;
6952 for (i = 0; i < FREQ_COUNT; i++) {
6953 // TODO: Include only legal frequencies for some countries
James Ketrenosee8e3652005-09-14 09:47:29 -05006954// if (local->channel_mask & (1 << i)) {
6955 range->freq[val].i = i + 1;
6956 range->freq[val].m = ipw2100_frequencies[i] * 100000;
6957 range->freq[val].e = 1;
6958 val++;
6959// }
James Ketrenos2c86c272005-03-23 17:32:29 -06006960 if (val == IW_MAX_FREQUENCIES)
James Ketrenosee8e3652005-09-14 09:47:29 -05006961 break;
James Ketrenos2c86c272005-03-23 17:32:29 -06006962 }
6963 range->num_frequency = val;
6964
James Ketrenoseaf8f53b2005-11-12 12:50:12 -06006965 /* Event capability (kernel + driver) */
6966 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
6967 IW_EVENT_CAPA_MASK(SIOCGIWAP));
6968 range->event_capa[1] = IW_EVENT_CAPA_K_1;
6969
Dan Williams166c3432006-01-09 11:04:31 -05006970 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
6971 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
6972
James Ketrenos2c86c272005-03-23 17:32:29 -06006973 IPW_DEBUG_WX("GET Range\n");
6974
6975 return 0;
6976}
6977
6978static int ipw2100_wx_set_wap(struct net_device *dev,
6979 struct iw_request_info *info,
6980 union iwreq_data *wrqu, char *extra)
6981{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006982 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006983 int err = 0;
6984
6985 static const unsigned char any[] = {
6986 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
6987 };
6988 static const unsigned char off[] = {
6989 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
6990 };
6991
6992 // sanity checks
6993 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
6994 return -EINVAL;
6995
Ingo Molnar752e3772006-02-28 07:20:54 +08006996 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006997 if (!(priv->status & STATUS_INITIALIZED)) {
6998 err = -EIO;
6999 goto done;
7000 }
7001
7002 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
7003 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
7004 /* we disable mandatory BSSID association */
7005 IPW_DEBUG_WX("exit - disable mandatory BSSID\n");
7006 priv->config &= ~CFG_STATIC_BSSID;
7007 err = ipw2100_set_mandatory_bssid(priv, NULL, 0);
7008 goto done;
7009 }
7010
7011 priv->config |= CFG_STATIC_BSSID;
7012 memcpy(priv->mandatory_bssid_mac, wrqu->ap_addr.sa_data, ETH_ALEN);
7013
7014 err = ipw2100_set_mandatory_bssid(priv, wrqu->ap_addr.sa_data, 0);
7015
Johannes Berge1749612008-10-27 15:59:26 -07007016 IPW_DEBUG_WX("SET BSSID -> %pM\n", wrqu->ap_addr.sa_data);
James Ketrenos2c86c272005-03-23 17:32:29 -06007017
James Ketrenosee8e3652005-09-14 09:47:29 -05007018 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007019 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007020 return err;
7021}
7022
7023static int ipw2100_wx_get_wap(struct net_device *dev,
7024 struct iw_request_info *info,
7025 union iwreq_data *wrqu, char *extra)
7026{
7027 /*
7028 * This can be called at any time. No action lock required
7029 */
7030
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007031 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007032
7033 /* If we are associated, trying to associate, or have a statically
7034 * configured BSSID then return that; otherwise return ANY */
James Ketrenosee8e3652005-09-14 09:47:29 -05007035 if (priv->config & CFG_STATIC_BSSID || priv->status & STATUS_ASSOCIATED) {
James Ketrenos2c86c272005-03-23 17:32:29 -06007036 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenos82328352005-08-24 22:33:31 -05007037 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos2c86c272005-03-23 17:32:29 -06007038 } else
7039 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
7040
Johannes Berge1749612008-10-27 15:59:26 -07007041 IPW_DEBUG_WX("Getting WAP BSSID: %pM\n", wrqu->ap_addr.sa_data);
James Ketrenos2c86c272005-03-23 17:32:29 -06007042 return 0;
7043}
7044
7045static int ipw2100_wx_set_essid(struct net_device *dev,
7046 struct iw_request_info *info,
7047 union iwreq_data *wrqu, char *extra)
7048{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007049 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenosee8e3652005-09-14 09:47:29 -05007050 char *essid = ""; /* ANY */
James Ketrenos2c86c272005-03-23 17:32:29 -06007051 int length = 0;
7052 int err = 0;
John W. Linville9387b7c2008-09-30 20:59:05 -04007053 DECLARE_SSID_BUF(ssid);
James Ketrenos2c86c272005-03-23 17:32:29 -06007054
Ingo Molnar752e3772006-02-28 07:20:54 +08007055 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007056 if (!(priv->status & STATUS_INITIALIZED)) {
7057 err = -EIO;
7058 goto done;
7059 }
7060
7061 if (wrqu->essid.flags && wrqu->essid.length) {
Jean Tourrilhes5b63bae2006-08-29 18:00:48 -07007062 length = wrqu->essid.length;
James Ketrenos2c86c272005-03-23 17:32:29 -06007063 essid = extra;
7064 }
7065
7066 if (length == 0) {
7067 IPW_DEBUG_WX("Setting ESSID to ANY\n");
7068 priv->config &= ~CFG_STATIC_ESSID;
7069 err = ipw2100_set_essid(priv, NULL, 0, 0);
7070 goto done;
7071 }
7072
7073 length = min(length, IW_ESSID_MAX_SIZE);
7074
7075 priv->config |= CFG_STATIC_ESSID;
7076
7077 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
7078 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
7079 err = 0;
7080 goto done;
7081 }
7082
John W. Linville9387b7c2008-09-30 20:59:05 -04007083 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n",
7084 print_ssid(ssid, essid, length), length);
James Ketrenos2c86c272005-03-23 17:32:29 -06007085
7086 priv->essid_len = length;
7087 memcpy(priv->essid, essid, priv->essid_len);
7088
7089 err = ipw2100_set_essid(priv, essid, length, 0);
7090
James Ketrenosee8e3652005-09-14 09:47:29 -05007091 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007092 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007093 return err;
7094}
7095
7096static int ipw2100_wx_get_essid(struct net_device *dev,
7097 struct iw_request_info *info,
7098 union iwreq_data *wrqu, char *extra)
7099{
7100 /*
7101 * This can be called at any time. No action lock required
7102 */
7103
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007104 struct ipw2100_priv *priv = libipw_priv(dev);
John W. Linville9387b7c2008-09-30 20:59:05 -04007105 DECLARE_SSID_BUF(ssid);
James Ketrenos2c86c272005-03-23 17:32:29 -06007106
7107 /* If we are associated, trying to associate, or have a statically
7108 * configured ESSID then return that; otherwise return ANY */
James Ketrenosee8e3652005-09-14 09:47:29 -05007109 if (priv->config & CFG_STATIC_ESSID || priv->status & STATUS_ASSOCIATED) {
James Ketrenos2c86c272005-03-23 17:32:29 -06007110 IPW_DEBUG_WX("Getting essid: '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04007111 print_ssid(ssid, priv->essid, priv->essid_len));
James Ketrenos2c86c272005-03-23 17:32:29 -06007112 memcpy(extra, priv->essid, priv->essid_len);
7113 wrqu->essid.length = priv->essid_len;
James Ketrenosee8e3652005-09-14 09:47:29 -05007114 wrqu->essid.flags = 1; /* active */
James Ketrenos2c86c272005-03-23 17:32:29 -06007115 } else {
7116 IPW_DEBUG_WX("Getting essid: ANY\n");
7117 wrqu->essid.length = 0;
James Ketrenosee8e3652005-09-14 09:47:29 -05007118 wrqu->essid.flags = 0; /* active */
James Ketrenos2c86c272005-03-23 17:32:29 -06007119 }
7120
7121 return 0;
7122}
7123
7124static int ipw2100_wx_set_nick(struct net_device *dev,
7125 struct iw_request_info *info,
7126 union iwreq_data *wrqu, char *extra)
7127{
7128 /*
7129 * This can be called at any time. No action lock required
7130 */
7131
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007132 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007133
7134 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
7135 return -E2BIG;
7136
James Ketrenosee8e3652005-09-14 09:47:29 -05007137 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos2c86c272005-03-23 17:32:29 -06007138 memset(priv->nick, 0, sizeof(priv->nick));
James Ketrenosee8e3652005-09-14 09:47:29 -05007139 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos2c86c272005-03-23 17:32:29 -06007140
7141 IPW_DEBUG_WX("SET Nickname -> %s \n", priv->nick);
7142
7143 return 0;
7144}
7145
7146static int ipw2100_wx_get_nick(struct net_device *dev,
7147 struct iw_request_info *info,
7148 union iwreq_data *wrqu, char *extra)
7149{
7150 /*
7151 * This can be called at any time. No action lock required
7152 */
7153
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007154 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007155
Jean Tourrilhes5b63bae2006-08-29 18:00:48 -07007156 wrqu->data.length = strlen(priv->nick);
James Ketrenos2c86c272005-03-23 17:32:29 -06007157 memcpy(extra, priv->nick, wrqu->data.length);
James Ketrenosee8e3652005-09-14 09:47:29 -05007158 wrqu->data.flags = 1; /* active */
James Ketrenos2c86c272005-03-23 17:32:29 -06007159
7160 IPW_DEBUG_WX("GET Nickname -> %s \n", extra);
7161
7162 return 0;
7163}
7164
7165static int ipw2100_wx_set_rate(struct net_device *dev,
7166 struct iw_request_info *info,
7167 union iwreq_data *wrqu, char *extra)
7168{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007169 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007170 u32 target_rate = wrqu->bitrate.value;
7171 u32 rate;
7172 int err = 0;
7173
Ingo Molnar752e3772006-02-28 07:20:54 +08007174 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007175 if (!(priv->status & STATUS_INITIALIZED)) {
7176 err = -EIO;
7177 goto done;
7178 }
7179
7180 rate = 0;
7181
7182 if (target_rate == 1000000 ||
7183 (!wrqu->bitrate.fixed && target_rate > 1000000))
7184 rate |= TX_RATE_1_MBIT;
7185 if (target_rate == 2000000 ||
7186 (!wrqu->bitrate.fixed && target_rate > 2000000))
7187 rate |= TX_RATE_2_MBIT;
7188 if (target_rate == 5500000 ||
7189 (!wrqu->bitrate.fixed && target_rate > 5500000))
7190 rate |= TX_RATE_5_5_MBIT;
7191 if (target_rate == 11000000 ||
7192 (!wrqu->bitrate.fixed && target_rate > 11000000))
7193 rate |= TX_RATE_11_MBIT;
7194 if (rate == 0)
7195 rate = DEFAULT_TX_RATES;
7196
7197 err = ipw2100_set_tx_rates(priv, rate, 0);
7198
7199 IPW_DEBUG_WX("SET Rate -> %04X \n", rate);
James Ketrenosee8e3652005-09-14 09:47:29 -05007200 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007201 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007202 return err;
7203}
7204
James Ketrenos2c86c272005-03-23 17:32:29 -06007205static int ipw2100_wx_get_rate(struct net_device *dev,
7206 struct iw_request_info *info,
7207 union iwreq_data *wrqu, char *extra)
7208{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007209 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007210 int val;
Hannes Ederb9da9e92009-02-14 11:50:26 +00007211 unsigned int len = sizeof(val);
James Ketrenos2c86c272005-03-23 17:32:29 -06007212 int err = 0;
7213
7214 if (!(priv->status & STATUS_ENABLED) ||
7215 priv->status & STATUS_RF_KILL_MASK ||
7216 !(priv->status & STATUS_ASSOCIATED)) {
7217 wrqu->bitrate.value = 0;
7218 return 0;
7219 }
7220
Ingo Molnar752e3772006-02-28 07:20:54 +08007221 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007222 if (!(priv->status & STATUS_INITIALIZED)) {
7223 err = -EIO;
7224 goto done;
7225 }
7226
7227 err = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &val, &len);
7228 if (err) {
7229 IPW_DEBUG_WX("failed querying ordinals.\n");
Julia Lawall80c42af2008-07-21 09:58:11 +02007230 goto done;
James Ketrenos2c86c272005-03-23 17:32:29 -06007231 }
7232
7233 switch (val & TX_RATE_MASK) {
7234 case TX_RATE_1_MBIT:
7235 wrqu->bitrate.value = 1000000;
7236 break;
7237 case TX_RATE_2_MBIT:
7238 wrqu->bitrate.value = 2000000;
7239 break;
7240 case TX_RATE_5_5_MBIT:
7241 wrqu->bitrate.value = 5500000;
7242 break;
7243 case TX_RATE_11_MBIT:
7244 wrqu->bitrate.value = 11000000;
7245 break;
7246 default:
7247 wrqu->bitrate.value = 0;
7248 }
7249
7250 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
7251
James Ketrenosee8e3652005-09-14 09:47:29 -05007252 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007253 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007254 return err;
7255}
7256
7257static int ipw2100_wx_set_rts(struct net_device *dev,
7258 struct iw_request_info *info,
7259 union iwreq_data *wrqu, char *extra)
7260{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007261 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007262 int value, err;
7263
7264 /* Auto RTS not yet supported */
7265 if (wrqu->rts.fixed == 0)
7266 return -EINVAL;
7267
Ingo Molnar752e3772006-02-28 07:20:54 +08007268 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007269 if (!(priv->status & STATUS_INITIALIZED)) {
7270 err = -EIO;
7271 goto done;
7272 }
7273
7274 if (wrqu->rts.disabled)
7275 value = priv->rts_threshold | RTS_DISABLED;
7276 else {
James Ketrenosee8e3652005-09-14 09:47:29 -05007277 if (wrqu->rts.value < 1 || wrqu->rts.value > 2304) {
James Ketrenos2c86c272005-03-23 17:32:29 -06007278 err = -EINVAL;
7279 goto done;
7280 }
7281 value = wrqu->rts.value;
7282 }
7283
7284 err = ipw2100_set_rts_threshold(priv, value);
7285
7286 IPW_DEBUG_WX("SET RTS Threshold -> 0x%08X \n", value);
James Ketrenosee8e3652005-09-14 09:47:29 -05007287 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007288 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007289 return err;
7290}
7291
7292static int ipw2100_wx_get_rts(struct net_device *dev,
7293 struct iw_request_info *info,
7294 union iwreq_data *wrqu, char *extra)
7295{
7296 /*
7297 * This can be called at any time. No action lock required
7298 */
7299
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007300 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007301
7302 wrqu->rts.value = priv->rts_threshold & ~RTS_DISABLED;
James Ketrenosee8e3652005-09-14 09:47:29 -05007303 wrqu->rts.fixed = 1; /* no auto select */
James Ketrenos2c86c272005-03-23 17:32:29 -06007304
7305 /* If RTS is set to the default value, then it is disabled */
7306 wrqu->rts.disabled = (priv->rts_threshold & RTS_DISABLED) ? 1 : 0;
7307
7308 IPW_DEBUG_WX("GET RTS Threshold -> 0x%08X \n", wrqu->rts.value);
7309
7310 return 0;
7311}
7312
7313static int ipw2100_wx_set_txpow(struct net_device *dev,
7314 struct iw_request_info *info,
7315 union iwreq_data *wrqu, char *extra)
7316{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007317 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007318 int err = 0, value;
Zhu Yib6e4da72006-01-24 13:49:32 +08007319
7320 if (ipw_radio_kill_sw(priv, wrqu->txpower.disabled))
7321 return -EINPROGRESS;
James Ketrenos2c86c272005-03-23 17:32:29 -06007322
7323 if (priv->ieee->iw_mode != IW_MODE_ADHOC)
Zhu Yib6e4da72006-01-24 13:49:32 +08007324 return 0;
7325
7326 if ((wrqu->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
James Ketrenos2c86c272005-03-23 17:32:29 -06007327 return -EINVAL;
7328
Zhu Yib6e4da72006-01-24 13:49:32 +08007329 if (wrqu->txpower.fixed == 0)
James Ketrenos2c86c272005-03-23 17:32:29 -06007330 value = IPW_TX_POWER_DEFAULT;
7331 else {
7332 if (wrqu->txpower.value < IPW_TX_POWER_MIN_DBM ||
7333 wrqu->txpower.value > IPW_TX_POWER_MAX_DBM)
7334 return -EINVAL;
7335
Liu Hongf75459e2005-07-13 12:29:21 -05007336 value = wrqu->txpower.value;
James Ketrenos2c86c272005-03-23 17:32:29 -06007337 }
7338
Ingo Molnar752e3772006-02-28 07:20:54 +08007339 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007340 if (!(priv->status & STATUS_INITIALIZED)) {
7341 err = -EIO;
7342 goto done;
7343 }
7344
7345 err = ipw2100_set_tx_power(priv, value);
7346
7347 IPW_DEBUG_WX("SET TX Power -> %d \n", value);
7348
James Ketrenosee8e3652005-09-14 09:47:29 -05007349 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007350 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007351 return err;
7352}
7353
7354static int ipw2100_wx_get_txpow(struct net_device *dev,
7355 struct iw_request_info *info,
7356 union iwreq_data *wrqu, char *extra)
7357{
7358 /*
7359 * This can be called at any time. No action lock required
7360 */
7361
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007362 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007363
Zhu Yib6e4da72006-01-24 13:49:32 +08007364 wrqu->txpower.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
James Ketrenos2c86c272005-03-23 17:32:29 -06007365
7366 if (priv->tx_power == IPW_TX_POWER_DEFAULT) {
Zhu Yib6e4da72006-01-24 13:49:32 +08007367 wrqu->txpower.fixed = 0;
7368 wrqu->txpower.value = IPW_TX_POWER_MAX_DBM;
James Ketrenos2c86c272005-03-23 17:32:29 -06007369 } else {
Zhu Yib6e4da72006-01-24 13:49:32 +08007370 wrqu->txpower.fixed = 1;
7371 wrqu->txpower.value = priv->tx_power;
James Ketrenos2c86c272005-03-23 17:32:29 -06007372 }
7373
Zhu Yib6e4da72006-01-24 13:49:32 +08007374 wrqu->txpower.flags = IW_TXPOW_DBM;
James Ketrenos2c86c272005-03-23 17:32:29 -06007375
Zhu Yib6e4da72006-01-24 13:49:32 +08007376 IPW_DEBUG_WX("GET TX Power -> %d \n", wrqu->txpower.value);
James Ketrenos2c86c272005-03-23 17:32:29 -06007377
7378 return 0;
7379}
7380
7381static int ipw2100_wx_set_frag(struct net_device *dev,
7382 struct iw_request_info *info,
7383 union iwreq_data *wrqu, char *extra)
7384{
7385 /*
7386 * This can be called at any time. No action lock required
7387 */
7388
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007389 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007390
7391 if (!wrqu->frag.fixed)
7392 return -EINVAL;
7393
7394 if (wrqu->frag.disabled) {
7395 priv->frag_threshold |= FRAG_DISABLED;
7396 priv->ieee->fts = DEFAULT_FTS;
7397 } else {
7398 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
7399 wrqu->frag.value > MAX_FRAG_THRESHOLD)
7400 return -EINVAL;
7401
7402 priv->ieee->fts = wrqu->frag.value & ~0x1;
7403 priv->frag_threshold = priv->ieee->fts;
7404 }
7405
7406 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", priv->ieee->fts);
7407
7408 return 0;
7409}
7410
7411static int ipw2100_wx_get_frag(struct net_device *dev,
7412 struct iw_request_info *info,
7413 union iwreq_data *wrqu, char *extra)
7414{
7415 /*
7416 * This can be called at any time. No action lock required
7417 */
7418
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007419 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007420 wrqu->frag.value = priv->frag_threshold & ~FRAG_DISABLED;
7421 wrqu->frag.fixed = 0; /* no auto select */
7422 wrqu->frag.disabled = (priv->frag_threshold & FRAG_DISABLED) ? 1 : 0;
7423
7424 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
7425
7426 return 0;
7427}
7428
7429static int ipw2100_wx_set_retry(struct net_device *dev,
7430 struct iw_request_info *info,
7431 union iwreq_data *wrqu, char *extra)
7432{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007433 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007434 int err = 0;
7435
James Ketrenosee8e3652005-09-14 09:47:29 -05007436 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
James Ketrenos2c86c272005-03-23 17:32:29 -06007437 return -EINVAL;
7438
7439 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
7440 return 0;
7441
Ingo Molnar752e3772006-02-28 07:20:54 +08007442 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007443 if (!(priv->status & STATUS_INITIALIZED)) {
7444 err = -EIO;
7445 goto done;
7446 }
7447
Jean Tourrilhes5b63bae2006-08-29 18:00:48 -07007448 if (wrqu->retry.flags & IW_RETRY_SHORT) {
James Ketrenos2c86c272005-03-23 17:32:29 -06007449 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7450 IPW_DEBUG_WX("SET Short Retry Limit -> %d \n",
James Ketrenosee8e3652005-09-14 09:47:29 -05007451 wrqu->retry.value);
James Ketrenos2c86c272005-03-23 17:32:29 -06007452 goto done;
7453 }
7454
Jean Tourrilhes5b63bae2006-08-29 18:00:48 -07007455 if (wrqu->retry.flags & IW_RETRY_LONG) {
James Ketrenos2c86c272005-03-23 17:32:29 -06007456 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7457 IPW_DEBUG_WX("SET Long Retry Limit -> %d \n",
James Ketrenosee8e3652005-09-14 09:47:29 -05007458 wrqu->retry.value);
James Ketrenos2c86c272005-03-23 17:32:29 -06007459 goto done;
7460 }
7461
7462 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7463 if (!err)
7464 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7465
7466 IPW_DEBUG_WX("SET Both Retry Limits -> %d \n", wrqu->retry.value);
7467
James Ketrenosee8e3652005-09-14 09:47:29 -05007468 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007469 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007470 return err;
7471}
7472
7473static int ipw2100_wx_get_retry(struct net_device *dev,
7474 struct iw_request_info *info,
7475 union iwreq_data *wrqu, char *extra)
7476{
7477 /*
7478 * This can be called at any time. No action lock required
7479 */
7480
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007481 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007482
James Ketrenosee8e3652005-09-14 09:47:29 -05007483 wrqu->retry.disabled = 0; /* can't be disabled */
James Ketrenos2c86c272005-03-23 17:32:29 -06007484
James Ketrenosee8e3652005-09-14 09:47:29 -05007485 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME)
James Ketrenos2c86c272005-03-23 17:32:29 -06007486 return -EINVAL;
7487
Jean Tourrilhes5b63bae2006-08-29 18:00:48 -07007488 if (wrqu->retry.flags & IW_RETRY_LONG) {
7489 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
James Ketrenos2c86c272005-03-23 17:32:29 -06007490 wrqu->retry.value = priv->long_retry_limit;
7491 } else {
7492 wrqu->retry.flags =
7493 (priv->short_retry_limit !=
7494 priv->long_retry_limit) ?
Jean Tourrilhes5b63bae2006-08-29 18:00:48 -07007495 IW_RETRY_LIMIT | IW_RETRY_SHORT : IW_RETRY_LIMIT;
James Ketrenos2c86c272005-03-23 17:32:29 -06007496
7497 wrqu->retry.value = priv->short_retry_limit;
7498 }
7499
7500 IPW_DEBUG_WX("GET Retry -> %d \n", wrqu->retry.value);
7501
7502 return 0;
7503}
7504
7505static int ipw2100_wx_set_scan(struct net_device *dev,
7506 struct iw_request_info *info,
7507 union iwreq_data *wrqu, char *extra)
7508{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007509 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007510 int err = 0;
7511
Ingo Molnar752e3772006-02-28 07:20:54 +08007512 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007513 if (!(priv->status & STATUS_INITIALIZED)) {
7514 err = -EIO;
7515 goto done;
7516 }
7517
7518 IPW_DEBUG_WX("Initiating scan...\n");
Dan Williamsd20c6782007-10-10 12:28:07 -04007519
7520 priv->user_requested_scan = 1;
James Ketrenosee8e3652005-09-14 09:47:29 -05007521 if (ipw2100_set_scan_options(priv) || ipw2100_start_scan(priv)) {
James Ketrenos2c86c272005-03-23 17:32:29 -06007522 IPW_DEBUG_WX("Start scan failed.\n");
7523
7524 /* TODO: Mark a scan as pending so when hardware initialized
7525 * a scan starts */
7526 }
7527
James Ketrenosee8e3652005-09-14 09:47:29 -05007528 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007529 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007530 return err;
7531}
7532
7533static int ipw2100_wx_get_scan(struct net_device *dev,
7534 struct iw_request_info *info,
7535 union iwreq_data *wrqu, char *extra)
7536{
7537 /*
7538 * This can be called at any time. No action lock required
7539 */
7540
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007541 struct ipw2100_priv *priv = libipw_priv(dev);
7542 return libipw_wx_get_scan(priv->ieee, info, wrqu, extra);
James Ketrenos2c86c272005-03-23 17:32:29 -06007543}
7544
James Ketrenos2c86c272005-03-23 17:32:29 -06007545/*
7546 * Implementation based on code in hostap-driver v0.1.3 hostap_ioctl.c
7547 */
7548static int ipw2100_wx_set_encode(struct net_device *dev,
7549 struct iw_request_info *info,
7550 union iwreq_data *wrqu, char *key)
7551{
7552 /*
7553 * No check of STATUS_INITIALIZED required
7554 */
7555
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007556 struct ipw2100_priv *priv = libipw_priv(dev);
7557 return libipw_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenos2c86c272005-03-23 17:32:29 -06007558}
7559
7560static int ipw2100_wx_get_encode(struct net_device *dev,
7561 struct iw_request_info *info,
7562 union iwreq_data *wrqu, char *key)
7563{
7564 /*
7565 * This can be called at any time. No action lock required
7566 */
7567
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007568 struct ipw2100_priv *priv = libipw_priv(dev);
7569 return libipw_wx_get_encode(priv->ieee, info, wrqu, key);
James Ketrenos2c86c272005-03-23 17:32:29 -06007570}
7571
7572static int ipw2100_wx_set_power(struct net_device *dev,
James Ketrenosee8e3652005-09-14 09:47:29 -05007573 struct iw_request_info *info,
7574 union iwreq_data *wrqu, char *extra)
James Ketrenos2c86c272005-03-23 17:32:29 -06007575{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007576 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007577 int err = 0;
7578
Ingo Molnar752e3772006-02-28 07:20:54 +08007579 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007580 if (!(priv->status & STATUS_INITIALIZED)) {
7581 err = -EIO;
7582 goto done;
7583 }
7584
7585 if (wrqu->power.disabled) {
7586 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
7587 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
7588 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
7589 goto done;
7590 }
7591
7592 switch (wrqu->power.flags & IW_POWER_MODE) {
James Ketrenosee8e3652005-09-14 09:47:29 -05007593 case IW_POWER_ON: /* If not specified */
7594 case IW_POWER_MODE: /* If set all mask */
Jean Delvarec03983a2007-10-19 23:22:55 +02007595 case IW_POWER_ALL_R: /* If explicitly state all */
James Ketrenos2c86c272005-03-23 17:32:29 -06007596 break;
James Ketrenosee8e3652005-09-14 09:47:29 -05007597 default: /* Otherwise we don't support it */
James Ketrenos2c86c272005-03-23 17:32:29 -06007598 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
7599 wrqu->power.flags);
7600 err = -EOPNOTSUPP;
7601 goto done;
7602 }
7603
7604 /* If the user hasn't specified a power management mode yet, default
7605 * to BATTERY */
7606 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
7607 err = ipw2100_set_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
7608
James Ketrenosee8e3652005-09-14 09:47:29 -05007609 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
James Ketrenos2c86c272005-03-23 17:32:29 -06007610
James Ketrenosee8e3652005-09-14 09:47:29 -05007611 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007612 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007613 return err;
7614
7615}
7616
7617static int ipw2100_wx_get_power(struct net_device *dev,
James Ketrenosee8e3652005-09-14 09:47:29 -05007618 struct iw_request_info *info,
7619 union iwreq_data *wrqu, char *extra)
James Ketrenos2c86c272005-03-23 17:32:29 -06007620{
7621 /*
7622 * This can be called at any time. No action lock required
7623 */
7624
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007625 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007626
James Ketrenos82328352005-08-24 22:33:31 -05007627 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos2c86c272005-03-23 17:32:29 -06007628 wrqu->power.disabled = 1;
James Ketrenos82328352005-08-24 22:33:31 -05007629 else {
James Ketrenos2c86c272005-03-23 17:32:29 -06007630 wrqu->power.disabled = 0;
7631 wrqu->power.flags = 0;
7632 }
7633
7634 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
7635
7636 return 0;
7637}
7638
James Ketrenos82328352005-08-24 22:33:31 -05007639/*
7640 * WE-18 WPA support
7641 */
7642
7643/* SIOCSIWGENIE */
7644static int ipw2100_wx_set_genie(struct net_device *dev,
7645 struct iw_request_info *info,
7646 union iwreq_data *wrqu, char *extra)
7647{
7648
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007649 struct ipw2100_priv *priv = libipw_priv(dev);
7650 struct libipw_device *ieee = priv->ieee;
James Ketrenos82328352005-08-24 22:33:31 -05007651 u8 *buf;
7652
7653 if (!ieee->wpa_enabled)
7654 return -EOPNOTSUPP;
7655
7656 if (wrqu->data.length > MAX_WPA_IE_LEN ||
7657 (wrqu->data.length && extra == NULL))
7658 return -EINVAL;
7659
7660 if (wrqu->data.length) {
Eric Sesterhennc3a9392e2006-10-23 22:20:15 +02007661 buf = kmemdup(extra, wrqu->data.length, GFP_KERNEL);
James Ketrenos82328352005-08-24 22:33:31 -05007662 if (buf == NULL)
7663 return -ENOMEM;
7664
James Ketrenos82328352005-08-24 22:33:31 -05007665 kfree(ieee->wpa_ie);
7666 ieee->wpa_ie = buf;
7667 ieee->wpa_ie_len = wrqu->data.length;
7668 } else {
7669 kfree(ieee->wpa_ie);
7670 ieee->wpa_ie = NULL;
7671 ieee->wpa_ie_len = 0;
7672 }
7673
7674 ipw2100_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
7675
7676 return 0;
7677}
7678
7679/* SIOCGIWGENIE */
7680static int ipw2100_wx_get_genie(struct net_device *dev,
7681 struct iw_request_info *info,
7682 union iwreq_data *wrqu, char *extra)
7683{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007684 struct ipw2100_priv *priv = libipw_priv(dev);
7685 struct libipw_device *ieee = priv->ieee;
James Ketrenos82328352005-08-24 22:33:31 -05007686
7687 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
7688 wrqu->data.length = 0;
7689 return 0;
7690 }
7691
7692 if (wrqu->data.length < ieee->wpa_ie_len)
7693 return -E2BIG;
7694
7695 wrqu->data.length = ieee->wpa_ie_len;
7696 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
7697
7698 return 0;
7699}
7700
7701/* SIOCSIWAUTH */
7702static int ipw2100_wx_set_auth(struct net_device *dev,
7703 struct iw_request_info *info,
7704 union iwreq_data *wrqu, char *extra)
7705{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007706 struct ipw2100_priv *priv = libipw_priv(dev);
7707 struct libipw_device *ieee = priv->ieee;
James Ketrenos82328352005-08-24 22:33:31 -05007708 struct iw_param *param = &wrqu->param;
John W. Linville274bfb82008-10-29 11:35:05 -04007709 struct lib80211_crypt_data *crypt;
James Ketrenos82328352005-08-24 22:33:31 -05007710 unsigned long flags;
7711 int ret = 0;
7712
7713 switch (param->flags & IW_AUTH_INDEX) {
7714 case IW_AUTH_WPA_VERSION:
7715 case IW_AUTH_CIPHER_PAIRWISE:
7716 case IW_AUTH_CIPHER_GROUP:
7717 case IW_AUTH_KEY_MGMT:
7718 /*
7719 * ipw2200 does not use these parameters
7720 */
7721 break;
7722
7723 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04007724 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00007725 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenos82328352005-08-24 22:33:31 -05007726 break;
James Ketrenos82328352005-08-24 22:33:31 -05007727
7728 flags = crypt->ops->get_flags(crypt->priv);
7729
7730 if (param->value)
7731 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
7732 else
7733 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
7734
7735 crypt->ops->set_flags(flags, crypt->priv);
7736
7737 break;
7738
7739 case IW_AUTH_DROP_UNENCRYPTED:{
7740 /* HACK:
7741 *
7742 * wpa_supplicant calls set_wpa_enabled when the driver
7743 * is loaded and unloaded, regardless of if WPA is being
7744 * used. No other calls are made which can be used to
7745 * determine if encryption will be used or not prior to
7746 * association being expected. If encryption is not being
7747 * used, drop_unencrypted is set to false, else true -- we
7748 * can use this to determine if the CAP_PRIVACY_ON bit should
7749 * be set.
7750 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007751 struct libipw_security sec = {
James Ketrenos82328352005-08-24 22:33:31 -05007752 .flags = SEC_ENABLED,
7753 .enabled = param->value,
7754 };
7755 priv->ieee->drop_unencrypted = param->value;
7756 /* We only change SEC_LEVEL for open mode. Others
7757 * are set by ipw_wpa_set_encryption.
7758 */
7759 if (!param->value) {
7760 sec.flags |= SEC_LEVEL;
7761 sec.level = SEC_LEVEL_0;
7762 } else {
7763 sec.flags |= SEC_LEVEL;
7764 sec.level = SEC_LEVEL_1;
7765 }
7766 if (priv->ieee->set_security)
7767 priv->ieee->set_security(priv->ieee->dev, &sec);
7768 break;
7769 }
7770
7771 case IW_AUTH_80211_AUTH_ALG:
7772 ret = ipw2100_wpa_set_auth_algs(priv, param->value);
7773 break;
7774
7775 case IW_AUTH_WPA_ENABLED:
7776 ret = ipw2100_wpa_enable(priv, param->value);
7777 break;
7778
7779 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
7780 ieee->ieee802_1x = param->value;
7781 break;
7782
7783 //case IW_AUTH_ROAMING_CONTROL:
7784 case IW_AUTH_PRIVACY_INVOKED:
7785 ieee->privacy_invoked = param->value;
7786 break;
7787
7788 default:
7789 return -EOPNOTSUPP;
7790 }
7791 return ret;
7792}
7793
7794/* SIOCGIWAUTH */
7795static int ipw2100_wx_get_auth(struct net_device *dev,
7796 struct iw_request_info *info,
7797 union iwreq_data *wrqu, char *extra)
7798{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007799 struct ipw2100_priv *priv = libipw_priv(dev);
7800 struct libipw_device *ieee = priv->ieee;
John W. Linville274bfb82008-10-29 11:35:05 -04007801 struct lib80211_crypt_data *crypt;
James Ketrenos82328352005-08-24 22:33:31 -05007802 struct iw_param *param = &wrqu->param;
7803 int ret = 0;
7804
7805 switch (param->flags & IW_AUTH_INDEX) {
7806 case IW_AUTH_WPA_VERSION:
7807 case IW_AUTH_CIPHER_PAIRWISE:
7808 case IW_AUTH_CIPHER_GROUP:
7809 case IW_AUTH_KEY_MGMT:
7810 /*
7811 * wpa_supplicant will control these internally
7812 */
7813 ret = -EOPNOTSUPP;
7814 break;
7815
7816 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04007817 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos82328352005-08-24 22:33:31 -05007818 if (!crypt || !crypt->ops->get_flags) {
7819 IPW_DEBUG_WARNING("Can't get TKIP countermeasures: "
7820 "crypt not set!\n");
7821 break;
7822 }
7823
7824 param->value = (crypt->ops->get_flags(crypt->priv) &
7825 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
7826
7827 break;
7828
7829 case IW_AUTH_DROP_UNENCRYPTED:
7830 param->value = ieee->drop_unencrypted;
7831 break;
7832
7833 case IW_AUTH_80211_AUTH_ALG:
25b645b2005-07-12 15:45:30 -05007834 param->value = priv->ieee->sec.auth_mode;
James Ketrenos82328352005-08-24 22:33:31 -05007835 break;
7836
7837 case IW_AUTH_WPA_ENABLED:
7838 param->value = ieee->wpa_enabled;
7839 break;
7840
7841 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
7842 param->value = ieee->ieee802_1x;
7843 break;
7844
7845 case IW_AUTH_ROAMING_CONTROL:
7846 case IW_AUTH_PRIVACY_INVOKED:
7847 param->value = ieee->privacy_invoked;
7848 break;
7849
7850 default:
7851 return -EOPNOTSUPP;
7852 }
7853 return 0;
7854}
7855
7856/* SIOCSIWENCODEEXT */
7857static int ipw2100_wx_set_encodeext(struct net_device *dev,
7858 struct iw_request_info *info,
7859 union iwreq_data *wrqu, char *extra)
7860{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007861 struct ipw2100_priv *priv = libipw_priv(dev);
7862 return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenos82328352005-08-24 22:33:31 -05007863}
7864
7865/* SIOCGIWENCODEEXT */
7866static int ipw2100_wx_get_encodeext(struct net_device *dev,
7867 struct iw_request_info *info,
7868 union iwreq_data *wrqu, char *extra)
7869{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007870 struct ipw2100_priv *priv = libipw_priv(dev);
7871 return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenos82328352005-08-24 22:33:31 -05007872}
7873
7874/* SIOCSIWMLME */
7875static int ipw2100_wx_set_mlme(struct net_device *dev,
7876 struct iw_request_info *info,
7877 union iwreq_data *wrqu, char *extra)
7878{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007879 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos82328352005-08-24 22:33:31 -05007880 struct iw_mlme *mlme = (struct iw_mlme *)extra;
Al Viro1edd3a52007-12-21 00:15:18 -05007881 __le16 reason;
James Ketrenos82328352005-08-24 22:33:31 -05007882
7883 reason = cpu_to_le16(mlme->reason_code);
7884
7885 switch (mlme->cmd) {
7886 case IW_MLME_DEAUTH:
7887 // silently ignore
7888 break;
7889
7890 case IW_MLME_DISASSOC:
7891 ipw2100_disassociate_bssid(priv);
7892 break;
7893
7894 default:
7895 return -EOPNOTSUPP;
7896 }
7897 return 0;
7898}
James Ketrenos2c86c272005-03-23 17:32:29 -06007899
7900/*
7901 *
7902 * IWPRIV handlers
7903 *
7904 */
7905#ifdef CONFIG_IPW2100_MONITOR
7906static int ipw2100_wx_set_promisc(struct net_device *dev,
7907 struct iw_request_info *info,
7908 union iwreq_data *wrqu, char *extra)
7909{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007910 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007911 int *parms = (int *)extra;
7912 int enable = (parms[0] > 0);
7913 int err = 0;
7914
Ingo Molnar752e3772006-02-28 07:20:54 +08007915 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007916 if (!(priv->status & STATUS_INITIALIZED)) {
7917 err = -EIO;
7918 goto done;
7919 }
7920
7921 if (enable) {
7922 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7923 err = ipw2100_set_channel(priv, parms[1], 0);
7924 goto done;
7925 }
7926 priv->channel = parms[1];
7927 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
7928 } else {
7929 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
7930 err = ipw2100_switch_mode(priv, priv->last_mode);
7931 }
James Ketrenosee8e3652005-09-14 09:47:29 -05007932 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007933 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007934 return err;
7935}
7936
7937static int ipw2100_wx_reset(struct net_device *dev,
7938 struct iw_request_info *info,
7939 union iwreq_data *wrqu, char *extra)
7940{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007941 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007942 if (priv->status & STATUS_INITIALIZED)
7943 schedule_reset(priv);
7944 return 0;
7945}
7946
7947#endif
7948
7949static int ipw2100_wx_set_powermode(struct net_device *dev,
7950 struct iw_request_info *info,
7951 union iwreq_data *wrqu, char *extra)
7952{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007953 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007954 int err = 0, mode = *(int *)extra;
7955
Ingo Molnar752e3772006-02-28 07:20:54 +08007956 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007957 if (!(priv->status & STATUS_INITIALIZED)) {
7958 err = -EIO;
7959 goto done;
7960 }
7961
Zhu Yi9f3b2412007-07-12 16:09:24 +08007962 if ((mode < 0) || (mode > POWER_MODES))
James Ketrenos2c86c272005-03-23 17:32:29 -06007963 mode = IPW_POWER_AUTO;
7964
Zhu Yi9f3b2412007-07-12 16:09:24 +08007965 if (IPW_POWER_LEVEL(priv->power_mode) != mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06007966 err = ipw2100_set_power_mode(priv, mode);
James Ketrenosee8e3652005-09-14 09:47:29 -05007967 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007968 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007969 return err;
7970}
7971
7972#define MAX_POWER_STRING 80
7973static int ipw2100_wx_get_powermode(struct net_device *dev,
7974 struct iw_request_info *info,
7975 union iwreq_data *wrqu, char *extra)
7976{
7977 /*
7978 * This can be called at any time. No action lock required
7979 */
7980
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007981 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007982 int level = IPW_POWER_LEVEL(priv->power_mode);
7983 s32 timeout, period;
7984
7985 if (!(priv->power_mode & IPW_POWER_ENABLED)) {
7986 snprintf(extra, MAX_POWER_STRING,
7987 "Power save level: %d (Off)", level);
7988 } else {
7989 switch (level) {
7990 case IPW_POWER_MODE_CAM:
7991 snprintf(extra, MAX_POWER_STRING,
7992 "Power save level: %d (None)", level);
7993 break;
7994 case IPW_POWER_AUTO:
James Ketrenosee8e3652005-09-14 09:47:29 -05007995 snprintf(extra, MAX_POWER_STRING,
Zhu Yi9f3b2412007-07-12 16:09:24 +08007996 "Power save level: %d (Auto)", level);
James Ketrenos2c86c272005-03-23 17:32:29 -06007997 break;
7998 default:
7999 timeout = timeout_duration[level - 1] / 1000;
8000 period = period_duration[level - 1] / 1000;
8001 snprintf(extra, MAX_POWER_STRING,
8002 "Power save level: %d "
8003 "(Timeout %dms, Period %dms)",
8004 level, timeout, period);
8005 }
8006 }
8007
8008 wrqu->data.length = strlen(extra) + 1;
8009
8010 return 0;
8011}
8012
James Ketrenos2c86c272005-03-23 17:32:29 -06008013static int ipw2100_wx_set_preamble(struct net_device *dev,
8014 struct iw_request_info *info,
8015 union iwreq_data *wrqu, char *extra)
8016{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008017 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06008018 int err, mode = *(int *)extra;
8019
Ingo Molnar752e3772006-02-28 07:20:54 +08008020 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06008021 if (!(priv->status & STATUS_INITIALIZED)) {
8022 err = -EIO;
8023 goto done;
8024 }
8025
8026 if (mode == 1)
8027 priv->config |= CFG_LONG_PREAMBLE;
8028 else if (mode == 0)
8029 priv->config &= ~CFG_LONG_PREAMBLE;
8030 else {
8031 err = -EINVAL;
8032 goto done;
8033 }
8034
8035 err = ipw2100_system_config(priv, 0);
8036
James Ketrenosee8e3652005-09-14 09:47:29 -05008037 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08008038 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06008039 return err;
8040}
8041
8042static int ipw2100_wx_get_preamble(struct net_device *dev,
James Ketrenosee8e3652005-09-14 09:47:29 -05008043 struct iw_request_info *info,
8044 union iwreq_data *wrqu, char *extra)
James Ketrenos2c86c272005-03-23 17:32:29 -06008045{
8046 /*
8047 * This can be called at any time. No action lock required
8048 */
8049
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008050 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06008051
8052 if (priv->config & CFG_LONG_PREAMBLE)
8053 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
8054 else
8055 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
8056
8057 return 0;
8058}
8059
James Ketrenos82328352005-08-24 22:33:31 -05008060#ifdef CONFIG_IPW2100_MONITOR
8061static int ipw2100_wx_set_crc_check(struct net_device *dev,
8062 struct iw_request_info *info,
8063 union iwreq_data *wrqu, char *extra)
James Ketrenos2c86c272005-03-23 17:32:29 -06008064{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008065 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos82328352005-08-24 22:33:31 -05008066 int err, mode = *(int *)extra;
8067
Ingo Molnar752e3772006-02-28 07:20:54 +08008068 mutex_lock(&priv->action_mutex);
James Ketrenos82328352005-08-24 22:33:31 -05008069 if (!(priv->status & STATUS_INITIALIZED)) {
8070 err = -EIO;
8071 goto done;
8072 }
8073
8074 if (mode == 1)
8075 priv->config |= CFG_CRC_CHECK;
8076 else if (mode == 0)
8077 priv->config &= ~CFG_CRC_CHECK;
8078 else {
8079 err = -EINVAL;
8080 goto done;
8081 }
8082 err = 0;
8083
8084 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08008085 mutex_unlock(&priv->action_mutex);
James Ketrenos82328352005-08-24 22:33:31 -05008086 return err;
8087}
8088
8089static int ipw2100_wx_get_crc_check(struct net_device *dev,
8090 struct iw_request_info *info,
8091 union iwreq_data *wrqu, char *extra)
8092{
8093 /*
8094 * This can be called at any time. No action lock required
8095 */
8096
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008097 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos82328352005-08-24 22:33:31 -05008098
8099 if (priv->config & CFG_CRC_CHECK)
8100 snprintf(wrqu->name, IFNAMSIZ, "CRC checked (1)");
8101 else
8102 snprintf(wrqu->name, IFNAMSIZ, "CRC ignored (0)");
8103
8104 return 0;
8105}
8106#endif /* CONFIG_IPW2100_MONITOR */
8107
James Ketrenosee8e3652005-09-14 09:47:29 -05008108static iw_handler ipw2100_wx_handlers[] = {
8109 NULL, /* SIOCSIWCOMMIT */
8110 ipw2100_wx_get_name, /* SIOCGIWNAME */
8111 NULL, /* SIOCSIWNWID */
8112 NULL, /* SIOCGIWNWID */
8113 ipw2100_wx_set_freq, /* SIOCSIWFREQ */
8114 ipw2100_wx_get_freq, /* SIOCGIWFREQ */
8115 ipw2100_wx_set_mode, /* SIOCSIWMODE */
8116 ipw2100_wx_get_mode, /* SIOCGIWMODE */
8117 NULL, /* SIOCSIWSENS */
8118 NULL, /* SIOCGIWSENS */
8119 NULL, /* SIOCSIWRANGE */
8120 ipw2100_wx_get_range, /* SIOCGIWRANGE */
8121 NULL, /* SIOCSIWPRIV */
8122 NULL, /* SIOCGIWPRIV */
8123 NULL, /* SIOCSIWSTATS */
8124 NULL, /* SIOCGIWSTATS */
8125 NULL, /* SIOCSIWSPY */
8126 NULL, /* SIOCGIWSPY */
8127 NULL, /* SIOCGIWTHRSPY */
8128 NULL, /* SIOCWIWTHRSPY */
8129 ipw2100_wx_set_wap, /* SIOCSIWAP */
8130 ipw2100_wx_get_wap, /* SIOCGIWAP */
James Ketrenos82328352005-08-24 22:33:31 -05008131 ipw2100_wx_set_mlme, /* SIOCSIWMLME */
James Ketrenosee8e3652005-09-14 09:47:29 -05008132 NULL, /* SIOCGIWAPLIST -- deprecated */
8133 ipw2100_wx_set_scan, /* SIOCSIWSCAN */
8134 ipw2100_wx_get_scan, /* SIOCGIWSCAN */
8135 ipw2100_wx_set_essid, /* SIOCSIWESSID */
8136 ipw2100_wx_get_essid, /* SIOCGIWESSID */
8137 ipw2100_wx_set_nick, /* SIOCSIWNICKN */
8138 ipw2100_wx_get_nick, /* SIOCGIWNICKN */
8139 NULL, /* -- hole -- */
8140 NULL, /* -- hole -- */
8141 ipw2100_wx_set_rate, /* SIOCSIWRATE */
8142 ipw2100_wx_get_rate, /* SIOCGIWRATE */
8143 ipw2100_wx_set_rts, /* SIOCSIWRTS */
8144 ipw2100_wx_get_rts, /* SIOCGIWRTS */
8145 ipw2100_wx_set_frag, /* SIOCSIWFRAG */
8146 ipw2100_wx_get_frag, /* SIOCGIWFRAG */
8147 ipw2100_wx_set_txpow, /* SIOCSIWTXPOW */
8148 ipw2100_wx_get_txpow, /* SIOCGIWTXPOW */
8149 ipw2100_wx_set_retry, /* SIOCSIWRETRY */
8150 ipw2100_wx_get_retry, /* SIOCGIWRETRY */
8151 ipw2100_wx_set_encode, /* SIOCSIWENCODE */
8152 ipw2100_wx_get_encode, /* SIOCGIWENCODE */
8153 ipw2100_wx_set_power, /* SIOCSIWPOWER */
8154 ipw2100_wx_get_power, /* SIOCGIWPOWER */
James Ketrenos82328352005-08-24 22:33:31 -05008155 NULL, /* -- hole -- */
8156 NULL, /* -- hole -- */
8157 ipw2100_wx_set_genie, /* SIOCSIWGENIE */
8158 ipw2100_wx_get_genie, /* SIOCGIWGENIE */
8159 ipw2100_wx_set_auth, /* SIOCSIWAUTH */
8160 ipw2100_wx_get_auth, /* SIOCGIWAUTH */
8161 ipw2100_wx_set_encodeext, /* SIOCSIWENCODEEXT */
8162 ipw2100_wx_get_encodeext, /* SIOCGIWENCODEEXT */
8163 NULL, /* SIOCSIWPMKSA */
James Ketrenos2c86c272005-03-23 17:32:29 -06008164};
8165
8166#define IPW2100_PRIV_SET_MONITOR SIOCIWFIRSTPRIV
8167#define IPW2100_PRIV_RESET SIOCIWFIRSTPRIV+1
8168#define IPW2100_PRIV_SET_POWER SIOCIWFIRSTPRIV+2
8169#define IPW2100_PRIV_GET_POWER SIOCIWFIRSTPRIV+3
8170#define IPW2100_PRIV_SET_LONGPREAMBLE SIOCIWFIRSTPRIV+4
8171#define IPW2100_PRIV_GET_LONGPREAMBLE SIOCIWFIRSTPRIV+5
James Ketrenos82328352005-08-24 22:33:31 -05008172#define IPW2100_PRIV_SET_CRC_CHECK SIOCIWFIRSTPRIV+6
8173#define IPW2100_PRIV_GET_CRC_CHECK SIOCIWFIRSTPRIV+7
James Ketrenos2c86c272005-03-23 17:32:29 -06008174
8175static const struct iw_priv_args ipw2100_private_args[] = {
8176
8177#ifdef CONFIG_IPW2100_MONITOR
8178 {
James Ketrenosee8e3652005-09-14 09:47:29 -05008179 IPW2100_PRIV_SET_MONITOR,
8180 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
James Ketrenos2c86c272005-03-23 17:32:29 -06008181 {
James Ketrenosee8e3652005-09-14 09:47:29 -05008182 IPW2100_PRIV_RESET,
8183 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
8184#endif /* CONFIG_IPW2100_MONITOR */
James Ketrenos2c86c272005-03-23 17:32:29 -06008185
8186 {
James Ketrenosee8e3652005-09-14 09:47:29 -05008187 IPW2100_PRIV_SET_POWER,
8188 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_power"},
James Ketrenos2c86c272005-03-23 17:32:29 -06008189 {
James Ketrenosee8e3652005-09-14 09:47:29 -05008190 IPW2100_PRIV_GET_POWER,
8191 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_POWER_STRING,
8192 "get_power"},
James Ketrenos2c86c272005-03-23 17:32:29 -06008193 {
James Ketrenosee8e3652005-09-14 09:47:29 -05008194 IPW2100_PRIV_SET_LONGPREAMBLE,
8195 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_preamble"},
James Ketrenos2c86c272005-03-23 17:32:29 -06008196 {
James Ketrenosee8e3652005-09-14 09:47:29 -05008197 IPW2100_PRIV_GET_LONGPREAMBLE,
8198 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_preamble"},
James Ketrenos82328352005-08-24 22:33:31 -05008199#ifdef CONFIG_IPW2100_MONITOR
8200 {
8201 IPW2100_PRIV_SET_CRC_CHECK,
8202 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_crc_check"},
8203 {
8204 IPW2100_PRIV_GET_CRC_CHECK,
8205 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_crc_check"},
8206#endif /* CONFIG_IPW2100_MONITOR */
James Ketrenos2c86c272005-03-23 17:32:29 -06008207};
8208
8209static iw_handler ipw2100_private_handler[] = {
8210#ifdef CONFIG_IPW2100_MONITOR
8211 ipw2100_wx_set_promisc,
8212 ipw2100_wx_reset,
James Ketrenosee8e3652005-09-14 09:47:29 -05008213#else /* CONFIG_IPW2100_MONITOR */
James Ketrenos2c86c272005-03-23 17:32:29 -06008214 NULL,
8215 NULL,
James Ketrenosee8e3652005-09-14 09:47:29 -05008216#endif /* CONFIG_IPW2100_MONITOR */
James Ketrenos2c86c272005-03-23 17:32:29 -06008217 ipw2100_wx_set_powermode,
8218 ipw2100_wx_get_powermode,
8219 ipw2100_wx_set_preamble,
8220 ipw2100_wx_get_preamble,
James Ketrenos82328352005-08-24 22:33:31 -05008221#ifdef CONFIG_IPW2100_MONITOR
8222 ipw2100_wx_set_crc_check,
8223 ipw2100_wx_get_crc_check,
8224#else /* CONFIG_IPW2100_MONITOR */
8225 NULL,
8226 NULL,
8227#endif /* CONFIG_IPW2100_MONITOR */
James Ketrenos2c86c272005-03-23 17:32:29 -06008228};
8229
James Ketrenos2c86c272005-03-23 17:32:29 -06008230/*
8231 * Get wireless statistics.
8232 * Called by /proc/net/wireless
8233 * Also called by SIOCGIWSTATS
8234 */
James Ketrenosee8e3652005-09-14 09:47:29 -05008235static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device *dev)
James Ketrenos2c86c272005-03-23 17:32:29 -06008236{
8237 enum {
8238 POOR = 30,
8239 FAIR = 60,
8240 GOOD = 80,
8241 VERY_GOOD = 90,
8242 EXCELLENT = 95,
8243 PERFECT = 100
8244 };
8245 int rssi_qual;
8246 int tx_qual;
8247 int beacon_qual;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008248 int quality;
James Ketrenos2c86c272005-03-23 17:32:29 -06008249
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008250 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06008251 struct iw_statistics *wstats;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008252 u32 rssi, tx_retries, missed_beacons, tx_failures;
James Ketrenos2c86c272005-03-23 17:32:29 -06008253 u32 ord_len = sizeof(u32);
8254
8255 if (!priv)
James Ketrenosee8e3652005-09-14 09:47:29 -05008256 return (struct iw_statistics *)NULL;
James Ketrenos2c86c272005-03-23 17:32:29 -06008257
8258 wstats = &priv->wstats;
8259
8260 /* if hw is disabled, then ipw2100_get_ordinal() can't be called.
8261 * ipw2100_wx_wireless_stats seems to be called before fw is
8262 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
8263 * and associated; if not associcated, the values are all meaningless
8264 * anyway, so set them all to NULL and INVALID */
8265 if (!(priv->status & STATUS_ASSOCIATED)) {
8266 wstats->miss.beacon = 0;
8267 wstats->discard.retries = 0;
8268 wstats->qual.qual = 0;
8269 wstats->qual.level = 0;
8270 wstats->qual.noise = 0;
8271 wstats->qual.updated = 7;
8272 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
James Ketrenosee8e3652005-09-14 09:47:29 -05008273 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos2c86c272005-03-23 17:32:29 -06008274 return wstats;
8275 }
8276
8277 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_MISSED_BCNS,
8278 &missed_beacons, &ord_len))
8279 goto fail_get_ordinal;
8280
James Ketrenosee8e3652005-09-14 09:47:29 -05008281 /* If we don't have a connection the quality and level is 0 */
James Ketrenos2c86c272005-03-23 17:32:29 -06008282 if (!(priv->status & STATUS_ASSOCIATED)) {
8283 wstats->qual.qual = 0;
8284 wstats->qual.level = 0;
8285 } else {
8286 if (ipw2100_get_ordinal(priv, IPW_ORD_RSSI_AVG_CURR,
8287 &rssi, &ord_len))
8288 goto fail_get_ordinal;
8289 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8290 if (rssi < 10)
8291 rssi_qual = rssi * POOR / 10;
8292 else if (rssi < 15)
8293 rssi_qual = (rssi - 10) * (FAIR - POOR) / 5 + POOR;
8294 else if (rssi < 20)
8295 rssi_qual = (rssi - 15) * (GOOD - FAIR) / 5 + FAIR;
8296 else if (rssi < 30)
8297 rssi_qual = (rssi - 20) * (VERY_GOOD - GOOD) /
James Ketrenosee8e3652005-09-14 09:47:29 -05008298 10 + GOOD;
James Ketrenos2c86c272005-03-23 17:32:29 -06008299 else
8300 rssi_qual = (rssi - 30) * (PERFECT - VERY_GOOD) /
James Ketrenosee8e3652005-09-14 09:47:29 -05008301 10 + VERY_GOOD;
James Ketrenos2c86c272005-03-23 17:32:29 -06008302
8303 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_RETRIES,
8304 &tx_retries, &ord_len))
8305 goto fail_get_ordinal;
8306
8307 if (tx_retries > 75)
8308 tx_qual = (90 - tx_retries) * POOR / 15;
8309 else if (tx_retries > 70)
8310 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
8311 else if (tx_retries > 65)
8312 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
8313 else if (tx_retries > 50)
8314 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
James Ketrenosee8e3652005-09-14 09:47:29 -05008315 15 + GOOD;
James Ketrenos2c86c272005-03-23 17:32:29 -06008316 else
8317 tx_qual = (50 - tx_retries) *
James Ketrenosee8e3652005-09-14 09:47:29 -05008318 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
James Ketrenos2c86c272005-03-23 17:32:29 -06008319
8320 if (missed_beacons > 50)
8321 beacon_qual = (60 - missed_beacons) * POOR / 10;
8322 else if (missed_beacons > 40)
8323 beacon_qual = (50 - missed_beacons) * (FAIR - POOR) /
James Ketrenosee8e3652005-09-14 09:47:29 -05008324 10 + POOR;
James Ketrenos2c86c272005-03-23 17:32:29 -06008325 else if (missed_beacons > 32)
8326 beacon_qual = (40 - missed_beacons) * (GOOD - FAIR) /
James Ketrenosee8e3652005-09-14 09:47:29 -05008327 18 + FAIR;
James Ketrenos2c86c272005-03-23 17:32:29 -06008328 else if (missed_beacons > 20)
8329 beacon_qual = (32 - missed_beacons) *
James Ketrenosee8e3652005-09-14 09:47:29 -05008330 (VERY_GOOD - GOOD) / 20 + GOOD;
James Ketrenos2c86c272005-03-23 17:32:29 -06008331 else
8332 beacon_qual = (20 - missed_beacons) *
James Ketrenosee8e3652005-09-14 09:47:29 -05008333 (PERFECT - VERY_GOOD) / 20 + VERY_GOOD;
James Ketrenos2c86c272005-03-23 17:32:29 -06008334
Reinette Chatre21f8a732009-08-18 10:25:05 -07008335 quality = min(tx_qual, rssi_qual);
8336 quality = min(beacon_qual, quality);
James Ketrenos2c86c272005-03-23 17:32:29 -06008337
Brice Goglin0f52bf92005-12-01 01:41:46 -08008338#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06008339 if (beacon_qual == quality)
8340 IPW_DEBUG_WX("Quality clamped by Missed Beacons\n");
8341 else if (tx_qual == quality)
8342 IPW_DEBUG_WX("Quality clamped by Tx Retries\n");
8343 else if (quality != 100)
8344 IPW_DEBUG_WX("Quality clamped by Signal Strength\n");
8345 else
8346 IPW_DEBUG_WX("Quality not clamped.\n");
8347#endif
8348
8349 wstats->qual.qual = quality;
8350 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8351 }
8352
8353 wstats->qual.noise = 0;
8354 wstats->qual.updated = 7;
8355 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
8356
James Ketrenosee8e3652005-09-14 09:47:29 -05008357 /* FIXME: this is percent and not a # */
James Ketrenos2c86c272005-03-23 17:32:29 -06008358 wstats->miss.beacon = missed_beacons;
8359
8360 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURES,
8361 &tx_failures, &ord_len))
8362 goto fail_get_ordinal;
8363 wstats->discard.retries = tx_failures;
8364
8365 return wstats;
8366
James Ketrenosee8e3652005-09-14 09:47:29 -05008367 fail_get_ordinal:
James Ketrenos2c86c272005-03-23 17:32:29 -06008368 IPW_DEBUG_WX("failed querying ordinals.\n");
8369
James Ketrenosee8e3652005-09-14 09:47:29 -05008370 return (struct iw_statistics *)NULL;
James Ketrenos2c86c272005-03-23 17:32:29 -06008371}
8372
James Ketrenoseaf8f53b2005-11-12 12:50:12 -06008373static struct iw_handler_def ipw2100_wx_handler_def = {
8374 .standard = ipw2100_wx_handlers,
Denis Chengff8ac602007-09-02 18:30:18 +08008375 .num_standard = ARRAY_SIZE(ipw2100_wx_handlers),
8376 .num_private = ARRAY_SIZE(ipw2100_private_handler),
8377 .num_private_args = ARRAY_SIZE(ipw2100_private_args),
James Ketrenoseaf8f53b2005-11-12 12:50:12 -06008378 .private = (iw_handler *) ipw2100_private_handler,
8379 .private_args = (struct iw_priv_args *)ipw2100_private_args,
8380 .get_wireless_stats = ipw2100_wx_wireless_stats,
8381};
8382
David Howellsc4028952006-11-22 14:57:56 +00008383static void ipw2100_wx_event_work(struct work_struct *work)
James Ketrenos2c86c272005-03-23 17:32:29 -06008384{
David Howellsc4028952006-11-22 14:57:56 +00008385 struct ipw2100_priv *priv =
8386 container_of(work, struct ipw2100_priv, wx_event_work.work);
James Ketrenos2c86c272005-03-23 17:32:29 -06008387 union iwreq_data wrqu;
Hannes Ederb9da9e92009-02-14 11:50:26 +00008388 unsigned int len = ETH_ALEN;
James Ketrenos2c86c272005-03-23 17:32:29 -06008389
8390 if (priv->status & STATUS_STOPPING)
8391 return;
8392
Ingo Molnar752e3772006-02-28 07:20:54 +08008393 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06008394
8395 IPW_DEBUG_WX("enter\n");
8396
Ingo Molnar752e3772006-02-28 07:20:54 +08008397 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06008398
8399 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
8400
8401 /* Fetch BSSID from the hardware */
8402 if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) ||
8403 priv->status & STATUS_RF_KILL_MASK ||
8404 ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
James Ketrenosee8e3652005-09-14 09:47:29 -05008405 &priv->bssid, &len)) {
James Ketrenos2c86c272005-03-23 17:32:29 -06008406 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
8407 } else {
8408 /* We now have the BSSID, so can finish setting to the full
8409 * associated state */
8410 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos82328352005-08-24 22:33:31 -05008411 memcpy(priv->ieee->bssid, priv->bssid, ETH_ALEN);
James Ketrenos2c86c272005-03-23 17:32:29 -06008412 priv->status &= ~STATUS_ASSOCIATING;
8413 priv->status |= STATUS_ASSOCIATED;
8414 netif_carrier_on(priv->net_dev);
James Ketrenos82328352005-08-24 22:33:31 -05008415 netif_wake_queue(priv->net_dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06008416 }
8417
8418 if (!(priv->status & STATUS_ASSOCIATED)) {
8419 IPW_DEBUG_WX("Configuring ESSID\n");
Ingo Molnar752e3772006-02-28 07:20:54 +08008420 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06008421 /* This is a disassociation event, so kick the firmware to
8422 * look for another AP */
8423 if (priv->config & CFG_STATIC_ESSID)
James Ketrenosee8e3652005-09-14 09:47:29 -05008424 ipw2100_set_essid(priv, priv->essid, priv->essid_len,
8425 0);
James Ketrenos2c86c272005-03-23 17:32:29 -06008426 else
8427 ipw2100_set_essid(priv, NULL, 0, 0);
Ingo Molnar752e3772006-02-28 07:20:54 +08008428 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06008429 }
8430
8431 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
8432}
8433
8434#define IPW2100_FW_MAJOR_VERSION 1
8435#define IPW2100_FW_MINOR_VERSION 3
8436
8437#define IPW2100_FW_MINOR(x) ((x & 0xff) >> 8)
8438#define IPW2100_FW_MAJOR(x) (x & 0xff)
8439
8440#define IPW2100_FW_VERSION ((IPW2100_FW_MINOR_VERSION << 8) | \
8441 IPW2100_FW_MAJOR_VERSION)
8442
8443#define IPW2100_FW_PREFIX "ipw2100-" __stringify(IPW2100_FW_MAJOR_VERSION) \
8444"." __stringify(IPW2100_FW_MINOR_VERSION)
8445
8446#define IPW2100_FW_NAME(x) IPW2100_FW_PREFIX "" x ".fw"
8447
James Ketrenos2c86c272005-03-23 17:32:29 -06008448/*
8449
8450BINARY FIRMWARE HEADER FORMAT
8451
8452offset length desc
84530 2 version
84542 2 mode == 0:BSS,1:IBSS,2:MONITOR
84554 4 fw_len
84568 4 uc_len
8457C fw_len firmware data
845812 + fw_len uc_len microcode data
8459
8460*/
8461
8462struct ipw2100_fw_header {
8463 short version;
8464 short mode;
8465 unsigned int fw_size;
8466 unsigned int uc_size;
8467} __attribute__ ((packed));
8468
James Ketrenos2c86c272005-03-23 17:32:29 -06008469static int ipw2100_mod_firmware_load(struct ipw2100_fw *fw)
8470{
8471 struct ipw2100_fw_header *h =
James Ketrenosee8e3652005-09-14 09:47:29 -05008472 (struct ipw2100_fw_header *)fw->fw_entry->data;
James Ketrenos2c86c272005-03-23 17:32:29 -06008473
8474 if (IPW2100_FW_MAJOR(h->version) != IPW2100_FW_MAJOR_VERSION) {
Jiri Benc797b4f72005-08-25 20:03:27 -04008475 printk(KERN_WARNING DRV_NAME ": Firmware image not compatible "
James Ketrenos2c86c272005-03-23 17:32:29 -06008476 "(detected version id of %u). "
8477 "See Documentation/networking/README.ipw2100\n",
8478 h->version);
8479 return 1;
8480 }
8481
8482 fw->version = h->version;
8483 fw->fw.data = fw->fw_entry->data + sizeof(struct ipw2100_fw_header);
8484 fw->fw.size = h->fw_size;
8485 fw->uc.data = fw->fw.data + h->fw_size;
8486 fw->uc.size = h->uc_size;
8487
8488 return 0;
8489}
8490
Jiri Bencc4aee8c2005-08-25 20:04:43 -04008491static int ipw2100_get_firmware(struct ipw2100_priv *priv,
8492 struct ipw2100_fw *fw)
James Ketrenos2c86c272005-03-23 17:32:29 -06008493{
8494 char *fw_name;
8495 int rc;
8496
8497 IPW_DEBUG_INFO("%s: Using hotplug firmware load.\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05008498 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06008499
8500 switch (priv->ieee->iw_mode) {
8501 case IW_MODE_ADHOC:
8502 fw_name = IPW2100_FW_NAME("-i");
8503 break;
8504#ifdef CONFIG_IPW2100_MONITOR
8505 case IW_MODE_MONITOR:
8506 fw_name = IPW2100_FW_NAME("-p");
8507 break;
8508#endif
8509 case IW_MODE_INFRA:
8510 default:
8511 fw_name = IPW2100_FW_NAME("");
8512 break;
8513 }
8514
8515 rc = request_firmware(&fw->fw_entry, fw_name, &priv->pci_dev->dev);
8516
8517 if (rc < 0) {
Jiri Benc797b4f72005-08-25 20:03:27 -04008518 printk(KERN_ERR DRV_NAME ": "
James Ketrenos2c86c272005-03-23 17:32:29 -06008519 "%s: Firmware '%s' not available or load failed.\n",
8520 priv->net_dev->name, fw_name);
8521 return rc;
8522 }
Jiri Bencaaa4d302005-06-07 14:58:41 +02008523 IPW_DEBUG_INFO("firmware data %p size %zd\n", fw->fw_entry->data,
James Ketrenosee8e3652005-09-14 09:47:29 -05008524 fw->fw_entry->size);
James Ketrenos2c86c272005-03-23 17:32:29 -06008525
8526 ipw2100_mod_firmware_load(fw);
8527
8528 return 0;
8529}
8530
Ben Hutchingsa278ea32009-11-07 21:58:47 +00008531MODULE_FIRMWARE(IPW2100_FW_NAME("-i"));
8532#ifdef CONFIG_IPW2100_MONITOR
8533MODULE_FIRMWARE(IPW2100_FW_NAME("-p"));
8534#endif
8535MODULE_FIRMWARE(IPW2100_FW_NAME(""));
8536
Jiri Bencc4aee8c2005-08-25 20:04:43 -04008537static void ipw2100_release_firmware(struct ipw2100_priv *priv,
8538 struct ipw2100_fw *fw)
James Ketrenos2c86c272005-03-23 17:32:29 -06008539{
8540 fw->version = 0;
8541 if (fw->fw_entry)
8542 release_firmware(fw->fw_entry);
8543 fw->fw_entry = NULL;
8544}
8545
Jiri Bencc4aee8c2005-08-25 20:04:43 -04008546static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf,
8547 size_t max)
James Ketrenos2c86c272005-03-23 17:32:29 -06008548{
8549 char ver[MAX_FW_VERSION_LEN];
8550 u32 len = MAX_FW_VERSION_LEN;
8551 u32 tmp;
8552 int i;
8553 /* firmware version is an ascii string (max len of 14) */
James Ketrenosee8e3652005-09-14 09:47:29 -05008554 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_FW_VER_NUM, ver, &len))
James Ketrenos2c86c272005-03-23 17:32:29 -06008555 return -EIO;
8556 tmp = max;
8557 if (len >= max)
8558 len = max - 1;
8559 for (i = 0; i < len; i++)
8560 buf[i] = ver[i];
8561 buf[i] = '\0';
8562 return tmp;
8563}
8564
Jiri Bencc4aee8c2005-08-25 20:04:43 -04008565static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf,
8566 size_t max)
James Ketrenos2c86c272005-03-23 17:32:29 -06008567{
8568 u32 ver;
8569 u32 len = sizeof(ver);
8570 /* microcode version is a 32 bit integer */
James Ketrenosee8e3652005-09-14 09:47:29 -05008571 if (ipw2100_get_ordinal(priv, IPW_ORD_UCODE_VERSION, &ver, &len))
James Ketrenos2c86c272005-03-23 17:32:29 -06008572 return -EIO;
8573 return snprintf(buf, max, "%08X", ver);
8574}
8575
8576/*
8577 * On exit, the firmware will have been freed from the fw list
8578 */
James Ketrenosee8e3652005-09-14 09:47:29 -05008579static int ipw2100_fw_download(struct ipw2100_priv *priv, struct ipw2100_fw *fw)
James Ketrenos2c86c272005-03-23 17:32:29 -06008580{
8581 /* firmware is constructed of N contiguous entries, each entry is
8582 * structured as:
8583 *
8584 * offset sie desc
8585 * 0 4 address to write to
8586 * 4 2 length of data run
James Ketrenosee8e3652005-09-14 09:47:29 -05008587 * 6 length data
James Ketrenos2c86c272005-03-23 17:32:29 -06008588 */
8589 unsigned int addr;
8590 unsigned short len;
8591
8592 const unsigned char *firmware_data = fw->fw.data;
8593 unsigned int firmware_data_left = fw->fw.size;
8594
8595 while (firmware_data_left > 0) {
James Ketrenosee8e3652005-09-14 09:47:29 -05008596 addr = *(u32 *) (firmware_data);
8597 firmware_data += 4;
James Ketrenos2c86c272005-03-23 17:32:29 -06008598 firmware_data_left -= 4;
8599
James Ketrenosee8e3652005-09-14 09:47:29 -05008600 len = *(u16 *) (firmware_data);
8601 firmware_data += 2;
James Ketrenos2c86c272005-03-23 17:32:29 -06008602 firmware_data_left -= 2;
8603
8604 if (len > 32) {
Jiri Benc797b4f72005-08-25 20:03:27 -04008605 printk(KERN_ERR DRV_NAME ": "
James Ketrenos2c86c272005-03-23 17:32:29 -06008606 "Invalid firmware run-length of %d bytes\n",
8607 len);
8608 return -EINVAL;
8609 }
8610
8611 write_nic_memory(priv->net_dev, addr, len, firmware_data);
James Ketrenosee8e3652005-09-14 09:47:29 -05008612 firmware_data += len;
James Ketrenos2c86c272005-03-23 17:32:29 -06008613 firmware_data_left -= len;
8614 }
8615
8616 return 0;
8617}
8618
8619struct symbol_alive_response {
8620 u8 cmd_id;
8621 u8 seq_num;
8622 u8 ucode_rev;
8623 u8 eeprom_valid;
8624 u16 valid_flags;
8625 u8 IEEE_addr[6];
8626 u16 flags;
8627 u16 pcb_rev;
8628 u16 clock_settle_time; // 1us LSB
8629 u16 powerup_settle_time; // 1us LSB
8630 u16 hop_settle_time; // 1us LSB
8631 u8 date[3]; // month, day, year
8632 u8 time[2]; // hours, minutes
8633 u8 ucode_valid;
8634};
8635
Jiri Bencc4aee8c2005-08-25 20:04:43 -04008636static int ipw2100_ucode_download(struct ipw2100_priv *priv,
8637 struct ipw2100_fw *fw)
James Ketrenos2c86c272005-03-23 17:32:29 -06008638{
8639 struct net_device *dev = priv->net_dev;
8640 const unsigned char *microcode_data = fw->uc.data;
8641 unsigned int microcode_data_left = fw->uc.size;
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008642 void __iomem *reg = (void __iomem *)dev->base_addr;
James Ketrenos2c86c272005-03-23 17:32:29 -06008643
8644 struct symbol_alive_response response;
8645 int i, j;
8646 u8 data;
8647
8648 /* Symbol control */
8649 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008650 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008651 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008652 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008653
8654 /* HW config */
8655 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008656 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008657 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008658 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008659
8660 /* EN_CS_ACCESS bit to reset control store pointer */
8661 write_nic_byte(dev, 0x210000, 0x40);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008662 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008663 write_nic_byte(dev, 0x210000, 0x0);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008664 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008665 write_nic_byte(dev, 0x210000, 0x40);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008666 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008667
8668 /* copy microcode from buffer into Symbol */
8669
8670 while (microcode_data_left > 0) {
8671 write_nic_byte(dev, 0x210010, *microcode_data++);
8672 write_nic_byte(dev, 0x210010, *microcode_data++);
8673 microcode_data_left -= 2;
8674 }
8675
8676 /* EN_CS_ACCESS bit to reset the control store pointer */
8677 write_nic_byte(dev, 0x210000, 0x0);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008678 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008679
8680 /* Enable System (Reg 0)
8681 * first enable causes garbage in RX FIFO */
8682 write_nic_byte(dev, 0x210000, 0x0);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008683 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008684 write_nic_byte(dev, 0x210000, 0x80);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008685 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008686
8687 /* Reset External Baseband Reg */
8688 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008689 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008690 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008691 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008692
8693 /* HW Config (Reg 5) */
8694 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008695 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008696 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008697 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008698
8699 /* Enable System (Reg 0)
8700 * second enable should be OK */
8701 write_nic_byte(dev, 0x210000, 0x00); // clear enable system
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008702 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008703 write_nic_byte(dev, 0x210000, 0x80); // set enable system
8704
8705 /* check Symbol is enabled - upped this from 5 as it wasn't always
8706 * catching the update */
8707 for (i = 0; i < 10; i++) {
8708 udelay(10);
8709
8710 /* check Dino is enabled bit */
8711 read_nic_byte(dev, 0x210000, &data);
8712 if (data & 0x1)
8713 break;
8714 }
8715
8716 if (i == 10) {
Jiri Benc797b4f72005-08-25 20:03:27 -04008717 printk(KERN_ERR DRV_NAME ": %s: Error initializing Symbol\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06008718 dev->name);
8719 return -EIO;
8720 }
8721
8722 /* Get Symbol alive response */
8723 for (i = 0; i < 30; i++) {
8724 /* Read alive response structure */
8725 for (j = 0;
James Ketrenosee8e3652005-09-14 09:47:29 -05008726 j < (sizeof(struct symbol_alive_response) >> 1); j++)
8727 read_nic_word(dev, 0x210004, ((u16 *) & response) + j);
James Ketrenos2c86c272005-03-23 17:32:29 -06008728
James Ketrenosee8e3652005-09-14 09:47:29 -05008729 if ((response.cmd_id == 1) && (response.ucode_valid == 0x1))
James Ketrenos2c86c272005-03-23 17:32:29 -06008730 break;
8731 udelay(10);
8732 }
8733
8734 if (i == 30) {
James Ketrenosee8e3652005-09-14 09:47:29 -05008735 printk(KERN_ERR DRV_NAME
8736 ": %s: No response from Symbol - hw not alive\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06008737 dev->name);
James Ketrenosee8e3652005-09-14 09:47:29 -05008738 printk_buf(IPW_DL_ERROR, (u8 *) & response, sizeof(response));
James Ketrenos2c86c272005-03-23 17:32:29 -06008739 return -EIO;
8740 }
8741
8742 return 0;
8743}