blob: 18ebd602670d1fa9f716de1de675248f196e56bb [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
Mark Grossed771342010-05-06 01:59:26 +0200177struct pm_qos_request_list *ipw2100_pm_qos_req;
178
James Ketrenos2c86c272005-03-23 17:32:29 -0600179/* Debugging stuff */
Brice Goglin0f52bf92005-12-01 01:41:46 -0800180#ifdef CONFIG_IPW2100_DEBUG
Robert P. J. Dayae800312007-01-31 02:39:40 -0500181#define IPW2100_RX_DEBUG /* Reception debugging */
James Ketrenos2c86c272005-03-23 17:32:29 -0600182#endif
183
184MODULE_DESCRIPTION(DRV_DESCRIPTION);
185MODULE_VERSION(DRV_VERSION);
186MODULE_AUTHOR(DRV_COPYRIGHT);
187MODULE_LICENSE("GPL");
188
189static int debug = 0;
Reinette Chatre21f8a732009-08-18 10:25:05 -0700190static int network_mode = 0;
James Ketrenos2c86c272005-03-23 17:32:29 -0600191static int channel = 0;
Tim Gardner5c7f9b72008-10-14 10:38:03 -0600192static int associate = 0;
James Ketrenos2c86c272005-03-23 17:32:29 -0600193static int disable = 0;
194#ifdef CONFIG_PM
195static struct ipw2100_fw ipw2100_firmware;
196#endif
197
198#include <linux/moduleparam.h>
199module_param(debug, int, 0444);
Reinette Chatre21f8a732009-08-18 10:25:05 -0700200module_param_named(mode, network_mode, int, 0444);
James Ketrenos2c86c272005-03-23 17:32:29 -0600201module_param(channel, int, 0444);
202module_param(associate, int, 0444);
203module_param(disable, int, 0444);
204
205MODULE_PARM_DESC(debug, "debug level");
206MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
207MODULE_PARM_DESC(channel, "channel");
Tim Gardner5c7f9b72008-10-14 10:38:03 -0600208MODULE_PARM_DESC(associate, "auto associate when scanning (default off)");
James Ketrenos2c86c272005-03-23 17:32:29 -0600209MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
210
Jiri Bencc4aee8c2005-08-25 20:04:43 -0400211static u32 ipw2100_debug_level = IPW_DL_NONE;
212
Brice Goglin0f52bf92005-12-01 01:41:46 -0800213#ifdef CONFIG_IPW2100_DEBUG
Jiri Bencc4aee8c2005-08-25 20:04:43 -0400214#define IPW_DEBUG(level, message...) \
215do { \
216 if (ipw2100_debug_level & (level)) { \
217 printk(KERN_DEBUG "ipw2100: %c %s ", \
Harvey Harrisonc94c93d2008-07-28 23:01:34 -0700218 in_interrupt() ? 'I' : 'U', __func__); \
Jiri Bencc4aee8c2005-08-25 20:04:43 -0400219 printk(message); \
220 } \
221} while (0)
222#else
223#define IPW_DEBUG(level, message...) do {} while (0)
Brice Goglin0f52bf92005-12-01 01:41:46 -0800224#endif /* CONFIG_IPW2100_DEBUG */
James Ketrenos2c86c272005-03-23 17:32:29 -0600225
Brice Goglin0f52bf92005-12-01 01:41:46 -0800226#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -0600227static const char *command_types[] = {
228 "undefined",
James Ketrenosee8e3652005-09-14 09:47:29 -0500229 "unused", /* HOST_ATTENTION */
James Ketrenos2c86c272005-03-23 17:32:29 -0600230 "HOST_COMPLETE",
James Ketrenosee8e3652005-09-14 09:47:29 -0500231 "unused", /* SLEEP */
232 "unused", /* HOST_POWER_DOWN */
James Ketrenos2c86c272005-03-23 17:32:29 -0600233 "unused",
234 "SYSTEM_CONFIG",
James Ketrenosee8e3652005-09-14 09:47:29 -0500235 "unused", /* SET_IMR */
James Ketrenos2c86c272005-03-23 17:32:29 -0600236 "SSID",
237 "MANDATORY_BSSID",
238 "AUTHENTICATION_TYPE",
239 "ADAPTER_ADDRESS",
240 "PORT_TYPE",
241 "INTERNATIONAL_MODE",
242 "CHANNEL",
243 "RTS_THRESHOLD",
244 "FRAG_THRESHOLD",
245 "POWER_MODE",
246 "TX_RATES",
247 "BASIC_TX_RATES",
248 "WEP_KEY_INFO",
249 "unused",
250 "unused",
251 "unused",
252 "unused",
253 "WEP_KEY_INDEX",
254 "WEP_FLAGS",
255 "ADD_MULTICAST",
256 "CLEAR_ALL_MULTICAST",
257 "BEACON_INTERVAL",
258 "ATIM_WINDOW",
259 "CLEAR_STATISTICS",
260 "undefined",
261 "undefined",
262 "undefined",
263 "undefined",
264 "TX_POWER_INDEX",
265 "undefined",
266 "undefined",
267 "undefined",
268 "undefined",
269 "undefined",
270 "undefined",
271 "BROADCAST_SCAN",
272 "CARD_DISABLE",
273 "PREFERRED_BSSID",
274 "SET_SCAN_OPTIONS",
275 "SCAN_DWELL_TIME",
276 "SWEEP_TABLE",
277 "AP_OR_STATION_TABLE",
278 "GROUP_ORDINALS",
279 "SHORT_RETRY_LIMIT",
280 "LONG_RETRY_LIMIT",
James Ketrenosee8e3652005-09-14 09:47:29 -0500281 "unused", /* SAVE_CALIBRATION */
282 "unused", /* RESTORE_CALIBRATION */
James Ketrenos2c86c272005-03-23 17:32:29 -0600283 "undefined",
284 "undefined",
285 "undefined",
286 "HOST_PRE_POWER_DOWN",
James Ketrenosee8e3652005-09-14 09:47:29 -0500287 "unused", /* HOST_INTERRUPT_COALESCING */
James Ketrenos2c86c272005-03-23 17:32:29 -0600288 "undefined",
289 "CARD_DISABLE_PHY_OFF",
James Ketrenosee8e3652005-09-14 09:47:29 -0500290 "MSDU_TX_RATES" "undefined",
James Ketrenos2c86c272005-03-23 17:32:29 -0600291 "undefined",
292 "SET_STATION_STAT_BITS",
293 "CLEAR_STATIONS_STAT_BITS",
294 "LEAP_ROGUE_MODE",
295 "SET_SECURITY_INFORMATION",
296 "DISASSOCIATION_BSSID",
297 "SET_WPA_ASS_IE"
298};
299#endif
300
Matthew Garrettc26409a2009-11-11 14:36:30 -0500301#define WEXT_USECHANNELS 1
302
303static const long ipw2100_frequencies[] = {
304 2412, 2417, 2422, 2427,
305 2432, 2437, 2442, 2447,
306 2452, 2457, 2462, 2467,
307 2472, 2484
308};
309
310#define FREQ_COUNT ARRAY_SIZE(ipw2100_frequencies)
311
312static const long ipw2100_rates_11b[] = {
313 1000000,
314 2000000,
315 5500000,
316 11000000
317};
318
319static struct ieee80211_rate ipw2100_bg_rates[] = {
320 { .bitrate = 10 },
321 { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
322 { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
323 { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
324};
325
326#define RATE_COUNT ARRAY_SIZE(ipw2100_rates_11b)
327
James Ketrenos2c86c272005-03-23 17:32:29 -0600328/* Pre-decl until we get the code solid and then we can clean it up */
Jiri Benc19f7f742005-08-25 20:02:10 -0400329static void ipw2100_tx_send_commands(struct ipw2100_priv *priv);
330static void ipw2100_tx_send_data(struct ipw2100_priv *priv);
James Ketrenos2c86c272005-03-23 17:32:29 -0600331static int ipw2100_adapter_setup(struct ipw2100_priv *priv);
332
333static void ipw2100_queues_initialize(struct ipw2100_priv *priv);
334static void ipw2100_queues_free(struct ipw2100_priv *priv);
335static int ipw2100_queues_allocate(struct ipw2100_priv *priv);
336
Jiri Bencc4aee8c2005-08-25 20:04:43 -0400337static int ipw2100_fw_download(struct ipw2100_priv *priv,
338 struct ipw2100_fw *fw);
339static int ipw2100_get_firmware(struct ipw2100_priv *priv,
340 struct ipw2100_fw *fw);
341static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf,
342 size_t max);
343static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf,
344 size_t max);
345static void ipw2100_release_firmware(struct ipw2100_priv *priv,
346 struct ipw2100_fw *fw);
347static int ipw2100_ucode_download(struct ipw2100_priv *priv,
348 struct ipw2100_fw *fw);
David Howellsc4028952006-11-22 14:57:56 +0000349static void ipw2100_wx_event_work(struct work_struct *work);
James Ketrenosee8e3652005-09-14 09:47:29 -0500350static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device *dev);
Jiri Bencc4aee8c2005-08-25 20:04:43 -0400351static struct iw_handler_def ipw2100_wx_handler_def;
352
James Ketrenosee8e3652005-09-14 09:47:29 -0500353static inline void read_register(struct net_device *dev, u32 reg, u32 * val)
James Ketrenos2c86c272005-03-23 17:32:29 -0600354{
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +0100355 *val = readl((void __iomem *)(dev->base_addr + reg));
James Ketrenos2c86c272005-03-23 17:32:29 -0600356 IPW_DEBUG_IO("r: 0x%08X => 0x%08X\n", reg, *val);
357}
358
359static inline void write_register(struct net_device *dev, u32 reg, u32 val)
360{
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +0100361 writel(val, (void __iomem *)(dev->base_addr + reg));
James Ketrenos2c86c272005-03-23 17:32:29 -0600362 IPW_DEBUG_IO("w: 0x%08X <= 0x%08X\n", reg, val);
363}
364
James Ketrenosee8e3652005-09-14 09:47:29 -0500365static inline void read_register_word(struct net_device *dev, u32 reg,
366 u16 * val)
James Ketrenos2c86c272005-03-23 17:32:29 -0600367{
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +0100368 *val = readw((void __iomem *)(dev->base_addr + reg));
James Ketrenos2c86c272005-03-23 17:32:29 -0600369 IPW_DEBUG_IO("r: 0x%08X => %04X\n", reg, *val);
370}
371
James Ketrenosee8e3652005-09-14 09:47:29 -0500372static inline void read_register_byte(struct net_device *dev, u32 reg, u8 * val)
James Ketrenos2c86c272005-03-23 17:32:29 -0600373{
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +0100374 *val = readb((void __iomem *)(dev->base_addr + reg));
James Ketrenos2c86c272005-03-23 17:32:29 -0600375 IPW_DEBUG_IO("r: 0x%08X => %02X\n", reg, *val);
376}
377
378static inline void write_register_word(struct net_device *dev, u32 reg, u16 val)
379{
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +0100380 writew(val, (void __iomem *)(dev->base_addr + reg));
James Ketrenos2c86c272005-03-23 17:32:29 -0600381 IPW_DEBUG_IO("w: 0x%08X <= %04X\n", reg, val);
382}
383
James Ketrenos2c86c272005-03-23 17:32:29 -0600384static inline void write_register_byte(struct net_device *dev, u32 reg, u8 val)
385{
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +0100386 writeb(val, (void __iomem *)(dev->base_addr + reg));
James Ketrenos2c86c272005-03-23 17:32:29 -0600387 IPW_DEBUG_IO("w: 0x%08X =< %02X\n", reg, val);
388}
389
James Ketrenosee8e3652005-09-14 09:47:29 -0500390static inline void read_nic_dword(struct net_device *dev, u32 addr, u32 * val)
James Ketrenos2c86c272005-03-23 17:32:29 -0600391{
392 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
393 addr & IPW_REG_INDIRECT_ADDR_MASK);
394 read_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
395}
396
397static inline void write_nic_dword(struct net_device *dev, u32 addr, u32 val)
398{
399 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
400 addr & IPW_REG_INDIRECT_ADDR_MASK);
401 write_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
402}
403
James Ketrenosee8e3652005-09-14 09:47:29 -0500404static inline void read_nic_word(struct net_device *dev, u32 addr, u16 * val)
James Ketrenos2c86c272005-03-23 17:32:29 -0600405{
406 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
407 addr & IPW_REG_INDIRECT_ADDR_MASK);
408 read_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
409}
410
411static inline void write_nic_word(struct net_device *dev, u32 addr, u16 val)
412{
413 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
414 addr & IPW_REG_INDIRECT_ADDR_MASK);
415 write_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
416}
417
James Ketrenosee8e3652005-09-14 09:47:29 -0500418static inline void read_nic_byte(struct net_device *dev, u32 addr, u8 * val)
James Ketrenos2c86c272005-03-23 17:32:29 -0600419{
420 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
421 addr & IPW_REG_INDIRECT_ADDR_MASK);
422 read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
423}
424
425static inline void write_nic_byte(struct net_device *dev, u32 addr, u8 val)
426{
427 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
428 addr & IPW_REG_INDIRECT_ADDR_MASK);
429 write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
430}
431
432static inline void write_nic_auto_inc_address(struct net_device *dev, u32 addr)
433{
434 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS,
435 addr & IPW_REG_INDIRECT_ADDR_MASK);
436}
437
438static inline void write_nic_dword_auto_inc(struct net_device *dev, u32 val)
439{
440 write_register(dev, IPW_REG_AUTOINCREMENT_DATA, val);
441}
442
Arjan van de Ven858119e2006-01-14 13:20:43 -0800443static void write_nic_memory(struct net_device *dev, u32 addr, u32 len,
James Ketrenosee8e3652005-09-14 09:47:29 -0500444 const u8 * buf)
James Ketrenos2c86c272005-03-23 17:32:29 -0600445{
446 u32 aligned_addr;
447 u32 aligned_len;
448 u32 dif_len;
449 u32 i;
450
451 /* read first nibble byte by byte */
452 aligned_addr = addr & (~0x3);
453 dif_len = addr - aligned_addr;
454 if (dif_len) {
455 /* Start reading at aligned_addr + dif_len */
456 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
457 aligned_addr);
458 for (i = dif_len; i < 4; i++, buf++)
James Ketrenosee8e3652005-09-14 09:47:29 -0500459 write_register_byte(dev,
460 IPW_REG_INDIRECT_ACCESS_DATA + i,
461 *buf);
James Ketrenos2c86c272005-03-23 17:32:29 -0600462
463 len -= dif_len;
464 aligned_addr += 4;
465 }
466
467 /* read DWs through autoincrement registers */
James Ketrenosee8e3652005-09-14 09:47:29 -0500468 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS, aligned_addr);
James Ketrenos2c86c272005-03-23 17:32:29 -0600469 aligned_len = len & (~0x3);
470 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
James Ketrenosee8e3652005-09-14 09:47:29 -0500471 write_register(dev, IPW_REG_AUTOINCREMENT_DATA, *(u32 *) buf);
James Ketrenos2c86c272005-03-23 17:32:29 -0600472
473 /* copy the last nibble */
474 dif_len = len - aligned_len;
475 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr);
476 for (i = 0; i < dif_len; i++, buf++)
James Ketrenosee8e3652005-09-14 09:47:29 -0500477 write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA + i,
478 *buf);
James Ketrenos2c86c272005-03-23 17:32:29 -0600479}
480
Arjan van de Ven858119e2006-01-14 13:20:43 -0800481static void read_nic_memory(struct net_device *dev, u32 addr, u32 len,
James Ketrenosee8e3652005-09-14 09:47:29 -0500482 u8 * buf)
James Ketrenos2c86c272005-03-23 17:32:29 -0600483{
484 u32 aligned_addr;
485 u32 aligned_len;
486 u32 dif_len;
487 u32 i;
488
489 /* read first nibble byte by byte */
490 aligned_addr = addr & (~0x3);
491 dif_len = addr - aligned_addr;
492 if (dif_len) {
493 /* Start reading at aligned_addr + dif_len */
494 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
495 aligned_addr);
496 for (i = dif_len; i < 4; i++, buf++)
James Ketrenosee8e3652005-09-14 09:47:29 -0500497 read_register_byte(dev,
498 IPW_REG_INDIRECT_ACCESS_DATA + i,
499 buf);
James Ketrenos2c86c272005-03-23 17:32:29 -0600500
501 len -= dif_len;
502 aligned_addr += 4;
503 }
504
505 /* read DWs through autoincrement registers */
James Ketrenosee8e3652005-09-14 09:47:29 -0500506 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS, aligned_addr);
James Ketrenos2c86c272005-03-23 17:32:29 -0600507 aligned_len = len & (~0x3);
508 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
James Ketrenosee8e3652005-09-14 09:47:29 -0500509 read_register(dev, IPW_REG_AUTOINCREMENT_DATA, (u32 *) buf);
James Ketrenos2c86c272005-03-23 17:32:29 -0600510
511 /* copy the last nibble */
512 dif_len = len - aligned_len;
James Ketrenosee8e3652005-09-14 09:47:29 -0500513 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr);
James Ketrenos2c86c272005-03-23 17:32:29 -0600514 for (i = 0; i < dif_len; i++, buf++)
James Ketrenosee8e3652005-09-14 09:47:29 -0500515 read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA + i, buf);
James Ketrenos2c86c272005-03-23 17:32:29 -0600516}
517
518static inline int ipw2100_hw_is_adapter_in_system(struct net_device *dev)
519{
520 return (dev->base_addr &&
James Ketrenosee8e3652005-09-14 09:47:29 -0500521 (readl
522 ((void __iomem *)(dev->base_addr +
523 IPW_REG_DOA_DEBUG_AREA_START))
James Ketrenos2c86c272005-03-23 17:32:29 -0600524 == IPW_DATA_DOA_DEBUG_VALUE));
525}
526
Jiri Bencc4aee8c2005-08-25 20:04:43 -0400527static int ipw2100_get_ordinal(struct ipw2100_priv *priv, u32 ord,
James Ketrenosee8e3652005-09-14 09:47:29 -0500528 void *val, u32 * len)
James Ketrenos2c86c272005-03-23 17:32:29 -0600529{
530 struct ipw2100_ordinals *ordinals = &priv->ordinals;
531 u32 addr;
532 u32 field_info;
533 u16 field_len;
534 u16 field_count;
535 u32 total_length;
536
537 if (ordinals->table1_addr == 0) {
Jiri Benc797b4f72005-08-25 20:03:27 -0400538 printk(KERN_WARNING DRV_NAME ": attempt to use fw ordinals "
James Ketrenos2c86c272005-03-23 17:32:29 -0600539 "before they have been loaded.\n");
540 return -EINVAL;
541 }
542
543 if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
544 if (*len < IPW_ORD_TAB_1_ENTRY_SIZE) {
545 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
546
Jiri Benc797b4f72005-08-25 20:03:27 -0400547 printk(KERN_WARNING DRV_NAME
Jiri Bencaaa4d302005-06-07 14:58:41 +0200548 ": ordinal buffer length too small, need %zd\n",
James Ketrenos2c86c272005-03-23 17:32:29 -0600549 IPW_ORD_TAB_1_ENTRY_SIZE);
550
551 return -EINVAL;
552 }
553
James Ketrenosee8e3652005-09-14 09:47:29 -0500554 read_nic_dword(priv->net_dev,
555 ordinals->table1_addr + (ord << 2), &addr);
James Ketrenos2c86c272005-03-23 17:32:29 -0600556 read_nic_dword(priv->net_dev, addr, val);
557
558 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
559
560 return 0;
561 }
562
563 if (IS_ORDINAL_TABLE_TWO(ordinals, ord)) {
564
565 ord -= IPW_START_ORD_TAB_2;
566
567 /* get the address of statistic */
James Ketrenosee8e3652005-09-14 09:47:29 -0500568 read_nic_dword(priv->net_dev,
569 ordinals->table2_addr + (ord << 3), &addr);
James Ketrenos2c86c272005-03-23 17:32:29 -0600570
571 /* get the second DW of statistics ;
572 * two 16-bit words - first is length, second is count */
573 read_nic_dword(priv->net_dev,
574 ordinals->table2_addr + (ord << 3) + sizeof(u32),
575 &field_info);
576
577 /* get each entry length */
James Ketrenosee8e3652005-09-14 09:47:29 -0500578 field_len = *((u16 *) & field_info);
James Ketrenos2c86c272005-03-23 17:32:29 -0600579
580 /* get number of entries */
James Ketrenosee8e3652005-09-14 09:47:29 -0500581 field_count = *(((u16 *) & field_info) + 1);
James Ketrenos2c86c272005-03-23 17:32:29 -0600582
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200583 /* abort if no enough memory */
James Ketrenos2c86c272005-03-23 17:32:29 -0600584 total_length = field_len * field_count;
585 if (total_length > *len) {
586 *len = total_length;
587 return -EINVAL;
588 }
589
590 *len = total_length;
591 if (!total_length)
592 return 0;
593
594 /* read the ordinal data from the SRAM */
595 read_nic_memory(priv->net_dev, addr, total_length, val);
596
597 return 0;
598 }
599
Jiri Benc797b4f72005-08-25 20:03:27 -0400600 printk(KERN_WARNING DRV_NAME ": ordinal %d neither in table 1 nor "
James Ketrenos2c86c272005-03-23 17:32:29 -0600601 "in table 2\n", ord);
602
603 return -EINVAL;
604}
605
James Ketrenosee8e3652005-09-14 09:47:29 -0500606static int ipw2100_set_ordinal(struct ipw2100_priv *priv, u32 ord, u32 * val,
607 u32 * len)
James Ketrenos2c86c272005-03-23 17:32:29 -0600608{
609 struct ipw2100_ordinals *ordinals = &priv->ordinals;
610 u32 addr;
611
612 if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
613 if (*len != IPW_ORD_TAB_1_ENTRY_SIZE) {
614 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
615 IPW_DEBUG_INFO("wrong size\n");
616 return -EINVAL;
617 }
618
James Ketrenosee8e3652005-09-14 09:47:29 -0500619 read_nic_dword(priv->net_dev,
620 ordinals->table1_addr + (ord << 2), &addr);
James Ketrenos2c86c272005-03-23 17:32:29 -0600621
622 write_nic_dword(priv->net_dev, addr, *val);
623
624 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
625
626 return 0;
627 }
628
629 IPW_DEBUG_INFO("wrong table\n");
630 if (IS_ORDINAL_TABLE_TWO(ordinals, ord))
631 return -EINVAL;
632
633 return -EINVAL;
634}
635
636static char *snprint_line(char *buf, size_t count,
James Ketrenosee8e3652005-09-14 09:47:29 -0500637 const u8 * data, u32 len, u32 ofs)
James Ketrenos2c86c272005-03-23 17:32:29 -0600638{
639 int out, i, j, l;
640 char c;
641
642 out = snprintf(buf, count, "%08X", ofs);
643
644 for (l = 0, i = 0; i < 2; i++) {
645 out += snprintf(buf + out, count - out, " ");
646 for (j = 0; j < 8 && l < len; j++, l++)
647 out += snprintf(buf + out, count - out, "%02X ",
648 data[(i * 8 + j)]);
649 for (; j < 8; j++)
650 out += snprintf(buf + out, count - out, " ");
651 }
652
653 out += snprintf(buf + out, count - out, " ");
654 for (l = 0, i = 0; i < 2; i++) {
655 out += snprintf(buf + out, count - out, " ");
656 for (j = 0; j < 8 && l < len; j++, l++) {
657 c = data[(i * 8 + j)];
658 if (!isascii(c) || !isprint(c))
659 c = '.';
660
661 out += snprintf(buf + out, count - out, "%c", c);
662 }
663
664 for (; j < 8; j++)
665 out += snprintf(buf + out, count - out, " ");
666 }
667
668 return buf;
669}
670
James Ketrenosee8e3652005-09-14 09:47:29 -0500671static void printk_buf(int level, const u8 * data, u32 len)
James Ketrenos2c86c272005-03-23 17:32:29 -0600672{
673 char line[81];
674 u32 ofs = 0;
675 if (!(ipw2100_debug_level & level))
676 return;
677
678 while (len) {
679 printk(KERN_DEBUG "%s\n",
680 snprint_line(line, sizeof(line), &data[ofs],
681 min(len, 16U), ofs));
682 ofs += 16;
683 len -= min(len, 16U);
684 }
685}
686
James Ketrenos2c86c272005-03-23 17:32:29 -0600687#define MAX_RESET_BACKOFF 10
688
Arjan van de Ven858119e2006-01-14 13:20:43 -0800689static void schedule_reset(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -0600690{
691 unsigned long now = get_seconds();
692
693 /* If we haven't received a reset request within the backoff period,
694 * then we can reset the backoff interval so this reset occurs
695 * immediately */
696 if (priv->reset_backoff &&
697 (now - priv->last_reset > priv->reset_backoff))
698 priv->reset_backoff = 0;
699
700 priv->last_reset = get_seconds();
701
702 if (!(priv->status & STATUS_RESET_PENDING)) {
703 IPW_DEBUG_INFO("%s: Scheduling firmware restart (%ds).\n",
704 priv->net_dev->name, priv->reset_backoff);
705 netif_carrier_off(priv->net_dev);
706 netif_stop_queue(priv->net_dev);
707 priv->status |= STATUS_RESET_PENDING;
708 if (priv->reset_backoff)
709 queue_delayed_work(priv->workqueue, &priv->reset_work,
710 priv->reset_backoff * HZ);
711 else
David Howellsc4028952006-11-22 14:57:56 +0000712 queue_delayed_work(priv->workqueue, &priv->reset_work,
713 0);
James Ketrenos2c86c272005-03-23 17:32:29 -0600714
715 if (priv->reset_backoff < MAX_RESET_BACKOFF)
716 priv->reset_backoff++;
717
718 wake_up_interruptible(&priv->wait_command_queue);
719 } else
720 IPW_DEBUG_INFO("%s: Firmware restart already in progress.\n",
721 priv->net_dev->name);
722
723}
724
725#define HOST_COMPLETE_TIMEOUT (2 * HZ)
726static int ipw2100_hw_send_command(struct ipw2100_priv *priv,
James Ketrenosee8e3652005-09-14 09:47:29 -0500727 struct host_command *cmd)
James Ketrenos2c86c272005-03-23 17:32:29 -0600728{
729 struct list_head *element;
730 struct ipw2100_tx_packet *packet;
731 unsigned long flags;
732 int err = 0;
733
734 IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n",
735 command_types[cmd->host_command], cmd->host_command,
736 cmd->host_command_length);
James Ketrenosee8e3652005-09-14 09:47:29 -0500737 printk_buf(IPW_DL_HC, (u8 *) cmd->host_command_parameters,
James Ketrenos2c86c272005-03-23 17:32:29 -0600738 cmd->host_command_length);
739
740 spin_lock_irqsave(&priv->low_lock, flags);
741
742 if (priv->fatal_error) {
James Ketrenosee8e3652005-09-14 09:47:29 -0500743 IPW_DEBUG_INFO
744 ("Attempt to send command while hardware in fatal error condition.\n");
James Ketrenos2c86c272005-03-23 17:32:29 -0600745 err = -EIO;
746 goto fail_unlock;
747 }
748
749 if (!(priv->status & STATUS_RUNNING)) {
James Ketrenosee8e3652005-09-14 09:47:29 -0500750 IPW_DEBUG_INFO
751 ("Attempt to send command while hardware is not running.\n");
James Ketrenos2c86c272005-03-23 17:32:29 -0600752 err = -EIO;
753 goto fail_unlock;
754 }
755
756 if (priv->status & STATUS_CMD_ACTIVE) {
James Ketrenosee8e3652005-09-14 09:47:29 -0500757 IPW_DEBUG_INFO
758 ("Attempt to send command while another command is pending.\n");
James Ketrenos2c86c272005-03-23 17:32:29 -0600759 err = -EBUSY;
760 goto fail_unlock;
761 }
762
763 if (list_empty(&priv->msg_free_list)) {
764 IPW_DEBUG_INFO("no available msg buffers\n");
765 goto fail_unlock;
766 }
767
768 priv->status |= STATUS_CMD_ACTIVE;
769 priv->messages_sent++;
770
771 element = priv->msg_free_list.next;
772
773 packet = list_entry(element, struct ipw2100_tx_packet, list);
774 packet->jiffy_start = jiffies;
775
776 /* initialize the firmware command packet */
777 packet->info.c_struct.cmd->host_command_reg = cmd->host_command;
778 packet->info.c_struct.cmd->host_command_reg1 = cmd->host_command1;
James Ketrenosee8e3652005-09-14 09:47:29 -0500779 packet->info.c_struct.cmd->host_command_len_reg =
780 cmd->host_command_length;
James Ketrenos2c86c272005-03-23 17:32:29 -0600781 packet->info.c_struct.cmd->sequence = cmd->host_command_sequence;
782
783 memcpy(packet->info.c_struct.cmd->host_command_params_reg,
784 cmd->host_command_parameters,
785 sizeof(packet->info.c_struct.cmd->host_command_params_reg));
786
787 list_del(element);
788 DEC_STAT(&priv->msg_free_stat);
789
790 list_add_tail(element, &priv->msg_pend_list);
791 INC_STAT(&priv->msg_pend_stat);
792
Jiri Benc19f7f742005-08-25 20:02:10 -0400793 ipw2100_tx_send_commands(priv);
794 ipw2100_tx_send_data(priv);
James Ketrenos2c86c272005-03-23 17:32:29 -0600795
796 spin_unlock_irqrestore(&priv->low_lock, flags);
797
798 /*
799 * We must wait for this command to complete before another
800 * command can be sent... but if we wait more than 3 seconds
801 * then there is a problem.
802 */
803
James Ketrenosee8e3652005-09-14 09:47:29 -0500804 err =
805 wait_event_interruptible_timeout(priv->wait_command_queue,
806 !(priv->
807 status & STATUS_CMD_ACTIVE),
808 HOST_COMPLETE_TIMEOUT);
James Ketrenos2c86c272005-03-23 17:32:29 -0600809
810 if (err == 0) {
811 IPW_DEBUG_INFO("Command completion failed out after %dms.\n",
James Ketrenos82328352005-08-24 22:33:31 -0500812 1000 * (HOST_COMPLETE_TIMEOUT / HZ));
James Ketrenos2c86c272005-03-23 17:32:29 -0600813 priv->fatal_error = IPW2100_ERR_MSG_TIMEOUT;
814 priv->status &= ~STATUS_CMD_ACTIVE;
815 schedule_reset(priv);
816 return -EIO;
817 }
818
819 if (priv->fatal_error) {
Jiri Benc797b4f72005-08-25 20:03:27 -0400820 printk(KERN_WARNING DRV_NAME ": %s: firmware fatal error\n",
James Ketrenos2c86c272005-03-23 17:32:29 -0600821 priv->net_dev->name);
822 return -EIO;
823 }
824
825 /* !!!!! HACK TEST !!!!!
826 * When lots of debug trace statements are enabled, the driver
827 * doesn't seem to have as many firmware restart cycles...
828 *
829 * As a test, we're sticking in a 1/100s delay here */
Nishanth Aravamudan3173c892005-09-11 02:09:55 -0700830 schedule_timeout_uninterruptible(msecs_to_jiffies(10));
James Ketrenos2c86c272005-03-23 17:32:29 -0600831
832 return 0;
833
James Ketrenosee8e3652005-09-14 09:47:29 -0500834 fail_unlock:
James Ketrenos2c86c272005-03-23 17:32:29 -0600835 spin_unlock_irqrestore(&priv->low_lock, flags);
836
837 return err;
838}
839
James Ketrenos2c86c272005-03-23 17:32:29 -0600840/*
841 * Verify the values and data access of the hardware
842 * No locks needed or used. No functions called.
843 */
844static int ipw2100_verify(struct ipw2100_priv *priv)
845{
846 u32 data1, data2;
847 u32 address;
848
849 u32 val1 = 0x76543210;
850 u32 val2 = 0xFEDCBA98;
851
852 /* Domain 0 check - all values should be DOA_DEBUG */
853 for (address = IPW_REG_DOA_DEBUG_AREA_START;
James Ketrenosee8e3652005-09-14 09:47:29 -0500854 address < IPW_REG_DOA_DEBUG_AREA_END; address += sizeof(u32)) {
James Ketrenos2c86c272005-03-23 17:32:29 -0600855 read_register(priv->net_dev, address, &data1);
856 if (data1 != IPW_DATA_DOA_DEBUG_VALUE)
857 return -EIO;
858 }
859
860 /* Domain 1 check - use arbitrary read/write compare */
861 for (address = 0; address < 5; address++) {
862 /* The memory area is not used now */
863 write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
864 val1);
865 write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
866 val2);
867 read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
868 &data1);
869 read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
870 &data2);
871 if (val1 == data1 && val2 == data2)
872 return 0;
873 }
874
875 return -EIO;
876}
877
878/*
879 *
880 * Loop until the CARD_DISABLED bit is the same value as the
881 * supplied parameter
882 *
883 * TODO: See if it would be more efficient to do a wait/wake
884 * cycle and have the completion event trigger the wakeup
885 *
886 */
887#define IPW_CARD_DISABLE_COMPLETE_WAIT 100 // 100 milli
888static int ipw2100_wait_for_card_state(struct ipw2100_priv *priv, int state)
889{
890 int i;
891 u32 card_state;
892 u32 len = sizeof(card_state);
893 int err;
894
895 for (i = 0; i <= IPW_CARD_DISABLE_COMPLETE_WAIT * 1000; i += 50) {
896 err = ipw2100_get_ordinal(priv, IPW_ORD_CARD_DISABLED,
897 &card_state, &len);
898 if (err) {
899 IPW_DEBUG_INFO("Query of CARD_DISABLED ordinal "
900 "failed.\n");
901 return 0;
902 }
903
904 /* We'll break out if either the HW state says it is
905 * in the state we want, or if HOST_COMPLETE command
906 * finishes */
907 if ((card_state == state) ||
908 ((priv->status & STATUS_ENABLED) ?
909 IPW_HW_STATE_ENABLED : IPW_HW_STATE_DISABLED) == state) {
910 if (state == IPW_HW_STATE_ENABLED)
911 priv->status |= STATUS_ENABLED;
912 else
913 priv->status &= ~STATUS_ENABLED;
914
915 return 0;
916 }
917
918 udelay(50);
919 }
920
921 IPW_DEBUG_INFO("ipw2100_wait_for_card_state to %s state timed out\n",
922 state ? "DISABLED" : "ENABLED");
923 return -EIO;
924}
925
James Ketrenos2c86c272005-03-23 17:32:29 -0600926/*********************************************************************
927 Procedure : sw_reset_and_clock
928 Purpose : Asserts s/w reset, asserts clock initialization
929 and waits for clock stabilization
930 ********************************************************************/
931static int sw_reset_and_clock(struct ipw2100_priv *priv)
932{
933 int i;
934 u32 r;
935
936 // assert s/w reset
937 write_register(priv->net_dev, IPW_REG_RESET_REG,
938 IPW_AUX_HOST_RESET_REG_SW_RESET);
939
940 // wait for clock stabilization
941 for (i = 0; i < 1000; i++) {
942 udelay(IPW_WAIT_RESET_ARC_COMPLETE_DELAY);
943
944 // check clock ready bit
945 read_register(priv->net_dev, IPW_REG_RESET_REG, &r);
946 if (r & IPW_AUX_HOST_RESET_REG_PRINCETON_RESET)
947 break;
948 }
949
950 if (i == 1000)
951 return -EIO; // TODO: better error value
952
953 /* set "initialization complete" bit to move adapter to
954 * D0 state */
955 write_register(priv->net_dev, IPW_REG_GP_CNTRL,
956 IPW_AUX_HOST_GP_CNTRL_BIT_INIT_DONE);
957
958 /* wait for clock stabilization */
959 for (i = 0; i < 10000; i++) {
960 udelay(IPW_WAIT_CLOCK_STABILIZATION_DELAY * 4);
961
962 /* check clock ready bit */
963 read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
964 if (r & IPW_AUX_HOST_GP_CNTRL_BIT_CLOCK_READY)
965 break;
966 }
967
968 if (i == 10000)
969 return -EIO; /* TODO: better error value */
970
James Ketrenos2c86c272005-03-23 17:32:29 -0600971 /* set D0 standby bit */
972 read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
973 write_register(priv->net_dev, IPW_REG_GP_CNTRL,
974 r | IPW_AUX_HOST_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos2c86c272005-03-23 17:32:29 -0600975
976 return 0;
977}
978
979/*********************************************************************
Pavel Machek8724a112005-06-20 14:28:43 -0700980 Procedure : ipw2100_download_firmware
James Ketrenos2c86c272005-03-23 17:32:29 -0600981 Purpose : Initiaze adapter after power on.
982 The sequence is:
983 1. assert s/w reset first!
984 2. awake clocks & wait for clock stabilization
985 3. hold ARC (don't ask me why...)
986 4. load Dino ucode and reset/clock init again
987 5. zero-out shared mem
988 6. download f/w
989 *******************************************************************/
990static int ipw2100_download_firmware(struct ipw2100_priv *priv)
991{
992 u32 address;
993 int err;
994
995#ifndef CONFIG_PM
996 /* Fetch the firmware and microcode */
997 struct ipw2100_fw ipw2100_firmware;
998#endif
999
1000 if (priv->fatal_error) {
1001 IPW_DEBUG_ERROR("%s: ipw2100_download_firmware called after "
James Ketrenosee8e3652005-09-14 09:47:29 -05001002 "fatal error %d. Interface must be brought down.\n",
1003 priv->net_dev->name, priv->fatal_error);
James Ketrenos2c86c272005-03-23 17:32:29 -06001004 return -EINVAL;
1005 }
James Ketrenos2c86c272005-03-23 17:32:29 -06001006#ifdef CONFIG_PM
1007 if (!ipw2100_firmware.version) {
1008 err = ipw2100_get_firmware(priv, &ipw2100_firmware);
1009 if (err) {
1010 IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001011 priv->net_dev->name, err);
James Ketrenos2c86c272005-03-23 17:32:29 -06001012 priv->fatal_error = IPW2100_ERR_FW_LOAD;
1013 goto fail;
1014 }
1015 }
1016#else
1017 err = ipw2100_get_firmware(priv, &ipw2100_firmware);
1018 if (err) {
1019 IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001020 priv->net_dev->name, err);
James Ketrenos2c86c272005-03-23 17:32:29 -06001021 priv->fatal_error = IPW2100_ERR_FW_LOAD;
1022 goto fail;
1023 }
1024#endif
1025 priv->firmware_version = ipw2100_firmware.version;
1026
1027 /* s/w reset and clock stabilization */
1028 err = sw_reset_and_clock(priv);
1029 if (err) {
1030 IPW_DEBUG_ERROR("%s: sw_reset_and_clock failed: %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001031 priv->net_dev->name, err);
James Ketrenos2c86c272005-03-23 17:32:29 -06001032 goto fail;
1033 }
1034
1035 err = ipw2100_verify(priv);
1036 if (err) {
1037 IPW_DEBUG_ERROR("%s: ipw2100_verify failed: %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001038 priv->net_dev->name, err);
James Ketrenos2c86c272005-03-23 17:32:29 -06001039 goto fail;
1040 }
1041
1042 /* Hold ARC */
1043 write_nic_dword(priv->net_dev,
James Ketrenosee8e3652005-09-14 09:47:29 -05001044 IPW_INTERNAL_REGISTER_HALT_AND_RESET, 0x80000000);
James Ketrenos2c86c272005-03-23 17:32:29 -06001045
1046 /* allow ARC to run */
1047 write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
1048
1049 /* load microcode */
1050 err = ipw2100_ucode_download(priv, &ipw2100_firmware);
1051 if (err) {
Jiri Benc797b4f72005-08-25 20:03:27 -04001052 printk(KERN_ERR DRV_NAME ": %s: Error loading microcode: %d\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06001053 priv->net_dev->name, err);
1054 goto fail;
1055 }
1056
1057 /* release ARC */
1058 write_nic_dword(priv->net_dev,
James Ketrenosee8e3652005-09-14 09:47:29 -05001059 IPW_INTERNAL_REGISTER_HALT_AND_RESET, 0x00000000);
James Ketrenos2c86c272005-03-23 17:32:29 -06001060
1061 /* s/w reset and clock stabilization (again!!!) */
1062 err = sw_reset_and_clock(priv);
1063 if (err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001064 printk(KERN_ERR DRV_NAME
1065 ": %s: sw_reset_and_clock failed: %d\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06001066 priv->net_dev->name, err);
1067 goto fail;
1068 }
1069
1070 /* load f/w */
1071 err = ipw2100_fw_download(priv, &ipw2100_firmware);
1072 if (err) {
1073 IPW_DEBUG_ERROR("%s: Error loading firmware: %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001074 priv->net_dev->name, err);
James Ketrenos2c86c272005-03-23 17:32:29 -06001075 goto fail;
1076 }
James Ketrenos2c86c272005-03-23 17:32:29 -06001077#ifndef CONFIG_PM
1078 /*
1079 * When the .resume method of the driver is called, the other
1080 * part of the system, i.e. the ide driver could still stay in
1081 * the suspend stage. This prevents us from loading the firmware
1082 * from the disk. --YZ
1083 */
1084
1085 /* free any storage allocated for firmware image */
1086 ipw2100_release_firmware(priv, &ipw2100_firmware);
1087#endif
1088
1089 /* zero out Domain 1 area indirectly (Si requirement) */
1090 for (address = IPW_HOST_FW_SHARED_AREA0;
1091 address < IPW_HOST_FW_SHARED_AREA0_END; address += 4)
1092 write_nic_dword(priv->net_dev, address, 0);
1093 for (address = IPW_HOST_FW_SHARED_AREA1;
1094 address < IPW_HOST_FW_SHARED_AREA1_END; address += 4)
1095 write_nic_dword(priv->net_dev, address, 0);
1096 for (address = IPW_HOST_FW_SHARED_AREA2;
1097 address < IPW_HOST_FW_SHARED_AREA2_END; address += 4)
1098 write_nic_dword(priv->net_dev, address, 0);
1099 for (address = IPW_HOST_FW_SHARED_AREA3;
1100 address < IPW_HOST_FW_SHARED_AREA3_END; address += 4)
1101 write_nic_dword(priv->net_dev, address, 0);
1102 for (address = IPW_HOST_FW_INTERRUPT_AREA;
1103 address < IPW_HOST_FW_INTERRUPT_AREA_END; address += 4)
1104 write_nic_dword(priv->net_dev, address, 0);
1105
1106 return 0;
1107
James Ketrenosee8e3652005-09-14 09:47:29 -05001108 fail:
James Ketrenos2c86c272005-03-23 17:32:29 -06001109 ipw2100_release_firmware(priv, &ipw2100_firmware);
1110 return err;
1111}
1112
1113static inline void ipw2100_enable_interrupts(struct ipw2100_priv *priv)
1114{
1115 if (priv->status & STATUS_INT_ENABLED)
1116 return;
1117 priv->status |= STATUS_INT_ENABLED;
1118 write_register(priv->net_dev, IPW_REG_INTA_MASK, IPW_INTERRUPT_MASK);
1119}
1120
1121static inline void ipw2100_disable_interrupts(struct ipw2100_priv *priv)
1122{
1123 if (!(priv->status & STATUS_INT_ENABLED))
1124 return;
1125 priv->status &= ~STATUS_INT_ENABLED;
1126 write_register(priv->net_dev, IPW_REG_INTA_MASK, 0x0);
1127}
1128
James Ketrenos2c86c272005-03-23 17:32:29 -06001129static void ipw2100_initialize_ordinals(struct ipw2100_priv *priv)
1130{
1131 struct ipw2100_ordinals *ord = &priv->ordinals;
1132
1133 IPW_DEBUG_INFO("enter\n");
1134
1135 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_1,
1136 &ord->table1_addr);
1137
1138 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_2,
1139 &ord->table2_addr);
1140
1141 read_nic_dword(priv->net_dev, ord->table1_addr, &ord->table1_size);
1142 read_nic_dword(priv->net_dev, ord->table2_addr, &ord->table2_size);
1143
1144 ord->table2_size &= 0x0000FFFF;
1145
1146 IPW_DEBUG_INFO("table 1 size: %d\n", ord->table1_size);
1147 IPW_DEBUG_INFO("table 2 size: %d\n", ord->table2_size);
1148 IPW_DEBUG_INFO("exit\n");
1149}
1150
1151static inline void ipw2100_hw_set_gpio(struct ipw2100_priv *priv)
1152{
1153 u32 reg = 0;
1154 /*
1155 * Set GPIO 3 writable by FW; GPIO 1 writable
1156 * by driver and enable clock
1157 */
1158 reg = (IPW_BIT_GPIO_GPIO3_MASK | IPW_BIT_GPIO_GPIO1_ENABLE |
1159 IPW_BIT_GPIO_LED_OFF);
1160 write_register(priv->net_dev, IPW_REG_GPIO, reg);
1161}
1162
Arjan van de Ven858119e2006-01-14 13:20:43 -08001163static int rf_kill_active(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06001164{
1165#define MAX_RF_KILL_CHECKS 5
1166#define RF_KILL_CHECK_DELAY 40
James Ketrenos2c86c272005-03-23 17:32:29 -06001167
1168 unsigned short value = 0;
1169 u32 reg = 0;
1170 int i;
1171
1172 if (!(priv->hw_features & HW_FEATURE_RFKILL)) {
Matthew Garrettc26409a2009-11-11 14:36:30 -05001173 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, false);
James Ketrenos2c86c272005-03-23 17:32:29 -06001174 priv->status &= ~STATUS_RF_KILL_HW;
1175 return 0;
1176 }
1177
1178 for (i = 0; i < MAX_RF_KILL_CHECKS; i++) {
1179 udelay(RF_KILL_CHECK_DELAY);
1180 read_register(priv->net_dev, IPW_REG_GPIO, &reg);
1181 value = (value << 1) | ((reg & IPW_BIT_GPIO_RF_KILL) ? 0 : 1);
1182 }
1183
Matthew Garrettc26409a2009-11-11 14:36:30 -05001184 if (value == 0) {
1185 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
James Ketrenos2c86c272005-03-23 17:32:29 -06001186 priv->status |= STATUS_RF_KILL_HW;
Matthew Garrettc26409a2009-11-11 14:36:30 -05001187 } else {
1188 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, false);
James Ketrenos2c86c272005-03-23 17:32:29 -06001189 priv->status &= ~STATUS_RF_KILL_HW;
Matthew Garrettc26409a2009-11-11 14:36:30 -05001190 }
James Ketrenos2c86c272005-03-23 17:32:29 -06001191
1192 return (value == 0);
1193}
1194
1195static int ipw2100_get_hw_features(struct ipw2100_priv *priv)
1196{
1197 u32 addr, len;
1198 u32 val;
1199
1200 /*
1201 * EEPROM_SRAM_DB_START_ADDRESS using ordinal in ordinal table 1
1202 */
1203 len = sizeof(addr);
James Ketrenosee8e3652005-09-14 09:47:29 -05001204 if (ipw2100_get_ordinal
1205 (priv, IPW_ORD_EEPROM_SRAM_DB_BLOCK_START_ADDRESS, &addr, &len)) {
James Ketrenos2c86c272005-03-23 17:32:29 -06001206 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001207 __LINE__);
James Ketrenos2c86c272005-03-23 17:32:29 -06001208 return -EIO;
1209 }
1210
1211 IPW_DEBUG_INFO("EEPROM address: %08X\n", addr);
1212
1213 /*
1214 * EEPROM version is the byte at offset 0xfd in firmware
1215 * We read 4 bytes, then shift out the byte we actually want */
1216 read_nic_dword(priv->net_dev, addr + 0xFC, &val);
1217 priv->eeprom_version = (val >> 24) & 0xFF;
1218 IPW_DEBUG_INFO("EEPROM version: %d\n", priv->eeprom_version);
1219
James Ketrenosee8e3652005-09-14 09:47:29 -05001220 /*
James Ketrenos2c86c272005-03-23 17:32:29 -06001221 * HW RF Kill enable is bit 0 in byte at offset 0x21 in firmware
1222 *
1223 * notice that the EEPROM bit is reverse polarity, i.e.
1224 * bit = 0 signifies HW RF kill switch is supported
1225 * bit = 1 signifies HW RF kill switch is NOT supported
1226 */
1227 read_nic_dword(priv->net_dev, addr + 0x20, &val);
1228 if (!((val >> 24) & 0x01))
1229 priv->hw_features |= HW_FEATURE_RFKILL;
1230
1231 IPW_DEBUG_INFO("HW RF Kill: %ssupported.\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001232 (priv->hw_features & HW_FEATURE_RFKILL) ? "" : "not ");
James Ketrenos2c86c272005-03-23 17:32:29 -06001233
1234 return 0;
1235}
1236
1237/*
1238 * Start firmware execution after power on and intialization
1239 * The sequence is:
1240 * 1. Release ARC
1241 * 2. Wait for f/w initialization completes;
1242 */
1243static int ipw2100_start_adapter(struct ipw2100_priv *priv)
1244{
James Ketrenos2c86c272005-03-23 17:32:29 -06001245 int i;
1246 u32 inta, inta_mask, gpio;
1247
1248 IPW_DEBUG_INFO("enter\n");
1249
1250 if (priv->status & STATUS_RUNNING)
1251 return 0;
1252
1253 /*
1254 * Initialize the hw - drive adapter to DO state by setting
1255 * init_done bit. Wait for clk_ready bit and Download
1256 * fw & dino ucode
1257 */
1258 if (ipw2100_download_firmware(priv)) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001259 printk(KERN_ERR DRV_NAME
1260 ": %s: Failed to power on the adapter.\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06001261 priv->net_dev->name);
1262 return -EIO;
1263 }
1264
1265 /* Clear the Tx, Rx and Msg queues and the r/w indexes
1266 * in the firmware RBD and TBD ring queue */
1267 ipw2100_queues_initialize(priv);
1268
1269 ipw2100_hw_set_gpio(priv);
1270
1271 /* TODO -- Look at disabling interrupts here to make sure none
1272 * get fired during FW initialization */
1273
1274 /* Release ARC - clear reset bit */
1275 write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
1276
1277 /* wait for f/w intialization complete */
1278 IPW_DEBUG_FW("Waiting for f/w initialization to complete...\n");
1279 i = 5000;
1280 do {
Nishanth Aravamudan3173c892005-09-11 02:09:55 -07001281 schedule_timeout_uninterruptible(msecs_to_jiffies(40));
James Ketrenos2c86c272005-03-23 17:32:29 -06001282 /* Todo... wait for sync command ... */
1283
1284 read_register(priv->net_dev, IPW_REG_INTA, &inta);
1285
1286 /* check "init done" bit */
1287 if (inta & IPW2100_INTA_FW_INIT_DONE) {
1288 /* reset "init done" bit */
1289 write_register(priv->net_dev, IPW_REG_INTA,
1290 IPW2100_INTA_FW_INIT_DONE);
1291 break;
1292 }
1293
1294 /* check error conditions : we check these after the firmware
1295 * check so that if there is an error, the interrupt handler
1296 * will see it and the adapter will be reset */
1297 if (inta &
1298 (IPW2100_INTA_FATAL_ERROR | IPW2100_INTA_PARITY_ERROR)) {
1299 /* clear error conditions */
1300 write_register(priv->net_dev, IPW_REG_INTA,
1301 IPW2100_INTA_FATAL_ERROR |
1302 IPW2100_INTA_PARITY_ERROR);
1303 }
Roel Kluina2a1c3e2007-11-05 23:55:02 +01001304 } while (--i);
James Ketrenos2c86c272005-03-23 17:32:29 -06001305
1306 /* Clear out any pending INTAs since we aren't supposed to have
1307 * interrupts enabled at this point... */
1308 read_register(priv->net_dev, IPW_REG_INTA, &inta);
1309 read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
1310 inta &= IPW_INTERRUPT_MASK;
1311 /* Clear out any pending interrupts */
1312 if (inta & inta_mask)
1313 write_register(priv->net_dev, IPW_REG_INTA, inta);
1314
1315 IPW_DEBUG_FW("f/w initialization complete: %s\n",
1316 i ? "SUCCESS" : "FAILED");
1317
1318 if (!i) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001319 printk(KERN_WARNING DRV_NAME
1320 ": %s: Firmware did not initialize.\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06001321 priv->net_dev->name);
1322 return -EIO;
1323 }
1324
1325 /* allow firmware to write to GPIO1 & GPIO3 */
1326 read_register(priv->net_dev, IPW_REG_GPIO, &gpio);
1327
1328 gpio |= (IPW_BIT_GPIO_GPIO1_MASK | IPW_BIT_GPIO_GPIO3_MASK);
1329
1330 write_register(priv->net_dev, IPW_REG_GPIO, gpio);
1331
1332 /* Ready to receive commands */
1333 priv->status |= STATUS_RUNNING;
1334
1335 /* The adapter has been reset; we are not associated */
1336 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
1337
1338 IPW_DEBUG_INFO("exit\n");
1339
1340 return 0;
1341}
1342
1343static inline void ipw2100_reset_fatalerror(struct ipw2100_priv *priv)
1344{
1345 if (!priv->fatal_error)
1346 return;
1347
1348 priv->fatal_errors[priv->fatal_index++] = priv->fatal_error;
1349 priv->fatal_index %= IPW2100_ERROR_QUEUE;
1350 priv->fatal_error = 0;
1351}
1352
James Ketrenos2c86c272005-03-23 17:32:29 -06001353/* NOTE: Our interrupt is disabled when this method is called */
1354static int ipw2100_power_cycle_adapter(struct ipw2100_priv *priv)
1355{
1356 u32 reg;
1357 int i;
1358
1359 IPW_DEBUG_INFO("Power cycling the hardware.\n");
1360
1361 ipw2100_hw_set_gpio(priv);
1362
1363 /* Step 1. Stop Master Assert */
1364 write_register(priv->net_dev, IPW_REG_RESET_REG,
1365 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
1366
1367 /* Step 2. Wait for stop Master Assert
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02001368 * (not more than 50us, otherwise ret error */
James Ketrenos2c86c272005-03-23 17:32:29 -06001369 i = 5;
1370 do {
1371 udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
1372 read_register(priv->net_dev, IPW_REG_RESET_REG, &reg);
1373
1374 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
1375 break;
Roel Kluina2a1c3e2007-11-05 23:55:02 +01001376 } while (--i);
James Ketrenos2c86c272005-03-23 17:32:29 -06001377
1378 priv->status &= ~STATUS_RESET_PENDING;
1379
1380 if (!i) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001381 IPW_DEBUG_INFO
1382 ("exit - waited too long for master assert stop\n");
James Ketrenos2c86c272005-03-23 17:32:29 -06001383 return -EIO;
1384 }
1385
1386 write_register(priv->net_dev, IPW_REG_RESET_REG,
1387 IPW_AUX_HOST_RESET_REG_SW_RESET);
1388
James Ketrenos2c86c272005-03-23 17:32:29 -06001389 /* Reset any fatal_error conditions */
1390 ipw2100_reset_fatalerror(priv);
1391
1392 /* At this point, the adapter is now stopped and disabled */
1393 priv->status &= ~(STATUS_RUNNING | STATUS_ASSOCIATING |
1394 STATUS_ASSOCIATED | STATUS_ENABLED);
1395
1396 return 0;
1397}
1398
1399/*
1400 * Send the CARD_DISABLE_PHY_OFF comamnd to the card to disable it
1401 *
1402 * After disabling, if the card was associated, a STATUS_ASSN_LOST will be sent.
1403 *
1404 * STATUS_CARD_DISABLE_NOTIFICATION will be sent regardless of
1405 * if STATUS_ASSN_LOST is sent.
1406 */
1407static int ipw2100_hw_phy_off(struct ipw2100_priv *priv)
1408{
1409
1410#define HW_PHY_OFF_LOOP_DELAY (HZ / 5000)
1411
1412 struct host_command cmd = {
1413 .host_command = CARD_DISABLE_PHY_OFF,
1414 .host_command_sequence = 0,
1415 .host_command_length = 0,
1416 };
1417 int err, i;
1418 u32 val1, val2;
1419
1420 IPW_DEBUG_HC("CARD_DISABLE_PHY_OFF\n");
1421
1422 /* Turn off the radio */
1423 err = ipw2100_hw_send_command(priv, &cmd);
1424 if (err)
1425 return err;
1426
1427 for (i = 0; i < 2500; i++) {
1428 read_nic_dword(priv->net_dev, IPW2100_CONTROL_REG, &val1);
1429 read_nic_dword(priv->net_dev, IPW2100_COMMAND, &val2);
1430
1431 if ((val1 & IPW2100_CONTROL_PHY_OFF) &&
1432 (val2 & IPW2100_COMMAND_PHY_OFF))
1433 return 0;
1434
Nishanth Aravamudan3173c892005-09-11 02:09:55 -07001435 schedule_timeout_uninterruptible(HW_PHY_OFF_LOOP_DELAY);
James Ketrenos2c86c272005-03-23 17:32:29 -06001436 }
1437
1438 return -EIO;
1439}
1440
James Ketrenos2c86c272005-03-23 17:32:29 -06001441static int ipw2100_enable_adapter(struct ipw2100_priv *priv)
1442{
1443 struct host_command cmd = {
1444 .host_command = HOST_COMPLETE,
1445 .host_command_sequence = 0,
1446 .host_command_length = 0
1447 };
1448 int err = 0;
1449
1450 IPW_DEBUG_HC("HOST_COMPLETE\n");
1451
1452 if (priv->status & STATUS_ENABLED)
1453 return 0;
1454
Ingo Molnar752e3772006-02-28 07:20:54 +08001455 mutex_lock(&priv->adapter_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06001456
1457 if (rf_kill_active(priv)) {
1458 IPW_DEBUG_HC("Command aborted due to RF kill active.\n");
1459 goto fail_up;
1460 }
1461
1462 err = ipw2100_hw_send_command(priv, &cmd);
1463 if (err) {
1464 IPW_DEBUG_INFO("Failed to send HOST_COMPLETE command\n");
1465 goto fail_up;
1466 }
1467
1468 err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_ENABLED);
1469 if (err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001470 IPW_DEBUG_INFO("%s: card not responding to init command.\n",
1471 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001472 goto fail_up;
1473 }
1474
1475 if (priv->stop_hang_check) {
1476 priv->stop_hang_check = 0;
1477 queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2);
1478 }
1479
James Ketrenosee8e3652005-09-14 09:47:29 -05001480 fail_up:
Ingo Molnar752e3772006-02-28 07:20:54 +08001481 mutex_unlock(&priv->adapter_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06001482 return err;
1483}
1484
1485static int ipw2100_hw_stop_adapter(struct ipw2100_priv *priv)
1486{
Nishanth Aravamudan3173c892005-09-11 02:09:55 -07001487#define HW_POWER_DOWN_DELAY (msecs_to_jiffies(100))
James Ketrenos2c86c272005-03-23 17:32:29 -06001488
1489 struct host_command cmd = {
1490 .host_command = HOST_PRE_POWER_DOWN,
1491 .host_command_sequence = 0,
1492 .host_command_length = 0,
1493 };
1494 int err, i;
1495 u32 reg;
1496
1497 if (!(priv->status & STATUS_RUNNING))
1498 return 0;
1499
1500 priv->status |= STATUS_STOPPING;
1501
1502 /* We can only shut down the card if the firmware is operational. So,
1503 * if we haven't reset since a fatal_error, then we can not send the
1504 * shutdown commands. */
1505 if (!priv->fatal_error) {
1506 /* First, make sure the adapter is enabled so that the PHY_OFF
1507 * command can shut it down */
1508 ipw2100_enable_adapter(priv);
1509
1510 err = ipw2100_hw_phy_off(priv);
1511 if (err)
James Ketrenosee8e3652005-09-14 09:47:29 -05001512 printk(KERN_WARNING DRV_NAME
1513 ": Error disabling radio %d\n", err);
James Ketrenos2c86c272005-03-23 17:32:29 -06001514
1515 /*
1516 * If in D0-standby mode going directly to D3 may cause a
1517 * PCI bus violation. Therefore we must change out of the D0
1518 * state.
1519 *
1520 * Sending the PREPARE_FOR_POWER_DOWN will restrict the
1521 * hardware from going into standby mode and will transition
Andreas Mohrd6e05ed2006-06-26 18:35:02 +02001522 * out of D0-standby if it is already in that state.
James Ketrenos2c86c272005-03-23 17:32:29 -06001523 *
1524 * STATUS_PREPARE_POWER_DOWN_COMPLETE will be sent by the
1525 * driver upon completion. Once received, the driver can
1526 * proceed to the D3 state.
1527 *
1528 * Prepare for power down command to fw. This command would
1529 * take HW out of D0-standby and prepare it for D3 state.
1530 *
1531 * Currently FW does not support event notification for this
1532 * event. Therefore, skip waiting for it. Just wait a fixed
1533 * 100ms
1534 */
1535 IPW_DEBUG_HC("HOST_PRE_POWER_DOWN\n");
1536
1537 err = ipw2100_hw_send_command(priv, &cmd);
1538 if (err)
Jiri Benc797b4f72005-08-25 20:03:27 -04001539 printk(KERN_WARNING DRV_NAME ": "
James Ketrenos2c86c272005-03-23 17:32:29 -06001540 "%s: Power down command failed: Error %d\n",
1541 priv->net_dev->name, err);
Nishanth Aravamudan3173c892005-09-11 02:09:55 -07001542 else
1543 schedule_timeout_uninterruptible(HW_POWER_DOWN_DELAY);
James Ketrenos2c86c272005-03-23 17:32:29 -06001544 }
1545
1546 priv->status &= ~STATUS_ENABLED;
1547
1548 /*
1549 * Set GPIO 3 writable by FW; GPIO 1 writable
1550 * by driver and enable clock
1551 */
1552 ipw2100_hw_set_gpio(priv);
1553
1554 /*
1555 * Power down adapter. Sequence:
1556 * 1. Stop master assert (RESET_REG[9]=1)
1557 * 2. Wait for stop master (RESET_REG[8]==1)
1558 * 3. S/w reset assert (RESET_REG[7] = 1)
1559 */
1560
1561 /* Stop master assert */
1562 write_register(priv->net_dev, IPW_REG_RESET_REG,
1563 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
1564
1565 /* wait stop master not more than 50 usec.
1566 * Otherwise return error. */
1567 for (i = 5; i > 0; i--) {
1568 udelay(10);
1569
1570 /* Check master stop bit */
1571 read_register(priv->net_dev, IPW_REG_RESET_REG, &reg);
1572
1573 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
1574 break;
1575 }
1576
1577 if (i == 0)
Jiri Benc797b4f72005-08-25 20:03:27 -04001578 printk(KERN_WARNING DRV_NAME
James Ketrenos2c86c272005-03-23 17:32:29 -06001579 ": %s: Could now power down adapter.\n",
1580 priv->net_dev->name);
1581
1582 /* assert s/w reset */
1583 write_register(priv->net_dev, IPW_REG_RESET_REG,
1584 IPW_AUX_HOST_RESET_REG_SW_RESET);
1585
1586 priv->status &= ~(STATUS_RUNNING | STATUS_STOPPING);
1587
1588 return 0;
1589}
1590
James Ketrenos2c86c272005-03-23 17:32:29 -06001591static int ipw2100_disable_adapter(struct ipw2100_priv *priv)
1592{
1593 struct host_command cmd = {
1594 .host_command = CARD_DISABLE,
1595 .host_command_sequence = 0,
1596 .host_command_length = 0
1597 };
1598 int err = 0;
1599
1600 IPW_DEBUG_HC("CARD_DISABLE\n");
1601
1602 if (!(priv->status & STATUS_ENABLED))
1603 return 0;
1604
1605 /* Make sure we clear the associated state */
1606 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1607
1608 if (!priv->stop_hang_check) {
1609 priv->stop_hang_check = 1;
1610 cancel_delayed_work(&priv->hang_check);
1611 }
1612
Ingo Molnar752e3772006-02-28 07:20:54 +08001613 mutex_lock(&priv->adapter_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06001614
1615 err = ipw2100_hw_send_command(priv, &cmd);
1616 if (err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001617 printk(KERN_WARNING DRV_NAME
1618 ": exit - failed to send CARD_DISABLE command\n");
James Ketrenos2c86c272005-03-23 17:32:29 -06001619 goto fail_up;
1620 }
1621
1622 err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_DISABLED);
1623 if (err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001624 printk(KERN_WARNING DRV_NAME
1625 ": exit - card failed to change to DISABLED\n");
James Ketrenos2c86c272005-03-23 17:32:29 -06001626 goto fail_up;
1627 }
1628
1629 IPW_DEBUG_INFO("TODO: implement scan state machine\n");
1630
James Ketrenosee8e3652005-09-14 09:47:29 -05001631 fail_up:
Ingo Molnar752e3772006-02-28 07:20:54 +08001632 mutex_unlock(&priv->adapter_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06001633 return err;
1634}
1635
Jiri Bencc4aee8c2005-08-25 20:04:43 -04001636static int ipw2100_set_scan_options(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06001637{
1638 struct host_command cmd = {
1639 .host_command = SET_SCAN_OPTIONS,
1640 .host_command_sequence = 0,
1641 .host_command_length = 8
1642 };
1643 int err;
1644
1645 IPW_DEBUG_INFO("enter\n");
1646
1647 IPW_DEBUG_SCAN("setting scan options\n");
1648
1649 cmd.host_command_parameters[0] = 0;
1650
1651 if (!(priv->config & CFG_ASSOCIATE))
1652 cmd.host_command_parameters[0] |= IPW_SCAN_NOASSOCIATE;
25b645b2005-07-12 15:45:30 -05001653 if ((priv->ieee->sec.flags & SEC_ENABLED) && priv->ieee->sec.enabled)
James Ketrenos2c86c272005-03-23 17:32:29 -06001654 cmd.host_command_parameters[0] |= IPW_SCAN_MIXED_CELL;
1655 if (priv->config & CFG_PASSIVE_SCAN)
1656 cmd.host_command_parameters[0] |= IPW_SCAN_PASSIVE;
1657
1658 cmd.host_command_parameters[1] = priv->channel_mask;
1659
1660 err = ipw2100_hw_send_command(priv, &cmd);
1661
1662 IPW_DEBUG_HC("SET_SCAN_OPTIONS 0x%04X\n",
1663 cmd.host_command_parameters[0]);
1664
1665 return err;
1666}
1667
Jiri Bencc4aee8c2005-08-25 20:04:43 -04001668static int ipw2100_start_scan(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06001669{
1670 struct host_command cmd = {
1671 .host_command = BROADCAST_SCAN,
1672 .host_command_sequence = 0,
1673 .host_command_length = 4
1674 };
1675 int err;
1676
1677 IPW_DEBUG_HC("START_SCAN\n");
1678
1679 cmd.host_command_parameters[0] = 0;
1680
1681 /* No scanning if in monitor mode */
1682 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
1683 return 1;
1684
1685 if (priv->status & STATUS_SCANNING) {
1686 IPW_DEBUG_SCAN("Scan requested while already in scan...\n");
1687 return 0;
1688 }
1689
1690 IPW_DEBUG_INFO("enter\n");
1691
1692 /* Not clearing here; doing so makes iwlist always return nothing...
1693 *
1694 * We should modify the table logic to use aging tables vs. clearing
1695 * the table on each scan start.
1696 */
1697 IPW_DEBUG_SCAN("starting scan\n");
1698
1699 priv->status |= STATUS_SCANNING;
1700 err = ipw2100_hw_send_command(priv, &cmd);
1701 if (err)
1702 priv->status &= ~STATUS_SCANNING;
1703
1704 IPW_DEBUG_INFO("exit\n");
1705
1706 return err;
1707}
1708
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001709static const struct libipw_geo ipw_geos[] = {
Zhu Yibe6b3b12006-01-24 13:49:08 +08001710 { /* Restricted */
1711 "---",
1712 .bg_channels = 14,
1713 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
1714 {2427, 4}, {2432, 5}, {2437, 6},
1715 {2442, 7}, {2447, 8}, {2452, 9},
1716 {2457, 10}, {2462, 11}, {2467, 12},
1717 {2472, 13}, {2484, 14}},
1718 },
1719};
1720
James Ketrenos2c86c272005-03-23 17:32:29 -06001721static int ipw2100_up(struct ipw2100_priv *priv, int deferred)
1722{
1723 unsigned long flags;
1724 int rc = 0;
1725 u32 lock;
1726 u32 ord_len = sizeof(lock);
1727
Dan Williamsc3d72b92009-02-11 13:26:06 -05001728 /* Age scan list entries found before suspend */
1729 if (priv->suspend_time) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001730 libipw_networks_age(priv->ieee, priv->suspend_time);
Dan Williamsc3d72b92009-02-11 13:26:06 -05001731 priv->suspend_time = 0;
1732 }
1733
1734 /* Quiet if manually disabled. */
James Ketrenos2c86c272005-03-23 17:32:29 -06001735 if (priv->status & STATUS_RF_KILL_SW) {
1736 IPW_DEBUG_INFO("%s: Radio is disabled by Manual Disable "
1737 "switch\n", priv->net_dev->name);
1738 return 0;
1739 }
1740
Arjan van de Ven5c875792006-09-30 23:27:17 -07001741 /* the ipw2100 hardware really doesn't want power management delays
1742 * longer than 175usec
1743 */
Mark Grossed771342010-05-06 01:59:26 +02001744 pm_qos_update_request(ipw2100_pm_qos_req, 175);
Arjan van de Ven5c875792006-09-30 23:27:17 -07001745
James Ketrenos2c86c272005-03-23 17:32:29 -06001746 /* If the interrupt is enabled, turn it off... */
1747 spin_lock_irqsave(&priv->low_lock, flags);
1748 ipw2100_disable_interrupts(priv);
1749
1750 /* Reset any fatal_error conditions */
1751 ipw2100_reset_fatalerror(priv);
1752 spin_unlock_irqrestore(&priv->low_lock, flags);
1753
1754 if (priv->status & STATUS_POWERED ||
1755 (priv->status & STATUS_RESET_PENDING)) {
1756 /* Power cycle the card ... */
1757 if (ipw2100_power_cycle_adapter(priv)) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001758 printk(KERN_WARNING DRV_NAME
1759 ": %s: Could not cycle adapter.\n",
1760 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001761 rc = 1;
1762 goto exit;
1763 }
1764 } else
1765 priv->status |= STATUS_POWERED;
1766
Pavel Machek8724a112005-06-20 14:28:43 -07001767 /* Load the firmware, start the clocks, etc. */
James Ketrenos2c86c272005-03-23 17:32:29 -06001768 if (ipw2100_start_adapter(priv)) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001769 printk(KERN_ERR DRV_NAME
1770 ": %s: Failed to start the firmware.\n",
1771 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001772 rc = 1;
1773 goto exit;
1774 }
1775
1776 ipw2100_initialize_ordinals(priv);
1777
1778 /* Determine capabilities of this particular HW configuration */
1779 if (ipw2100_get_hw_features(priv)) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001780 printk(KERN_ERR DRV_NAME
1781 ": %s: Failed to determine HW features.\n",
1782 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001783 rc = 1;
1784 goto exit;
1785 }
1786
Zhu Yibe6b3b12006-01-24 13:49:08 +08001787 /* Initialize the geo */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001788 if (libipw_set_geo(priv->ieee, &ipw_geos[0])) {
Zhu Yibe6b3b12006-01-24 13:49:08 +08001789 printk(KERN_WARNING DRV_NAME "Could not set geo\n");
1790 return 0;
1791 }
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001792 priv->ieee->freq_band = LIBIPW_24GHZ_BAND;
Zhu Yibe6b3b12006-01-24 13:49:08 +08001793
James Ketrenos2c86c272005-03-23 17:32:29 -06001794 lock = LOCK_NONE;
1795 if (ipw2100_set_ordinal(priv, IPW_ORD_PERS_DB_LOCK, &lock, &ord_len)) {
James Ketrenosee8e3652005-09-14 09:47:29 -05001796 printk(KERN_ERR DRV_NAME
1797 ": %s: Failed to clear ordinal lock.\n",
1798 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001799 rc = 1;
1800 goto exit;
1801 }
1802
1803 priv->status &= ~STATUS_SCANNING;
1804
1805 if (rf_kill_active(priv)) {
1806 printk(KERN_INFO "%s: Radio is disabled by RF switch.\n",
1807 priv->net_dev->name);
1808
1809 if (priv->stop_rf_kill) {
1810 priv->stop_rf_kill = 0;
Stephen Hemmingera62056f2007-06-22 21:46:50 -07001811 queue_delayed_work(priv->workqueue, &priv->rf_kill,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05001812 round_jiffies_relative(HZ));
James Ketrenos2c86c272005-03-23 17:32:29 -06001813 }
1814
1815 deferred = 1;
1816 }
1817
1818 /* Turn on the interrupt so that commands can be processed */
1819 ipw2100_enable_interrupts(priv);
1820
1821 /* Send all of the commands that must be sent prior to
1822 * HOST_COMPLETE */
1823 if (ipw2100_adapter_setup(priv)) {
Jiri Benc797b4f72005-08-25 20:03:27 -04001824 printk(KERN_ERR DRV_NAME ": %s: Failed to start the card.\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05001825 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001826 rc = 1;
1827 goto exit;
1828 }
1829
1830 if (!deferred) {
1831 /* Enable the adapter - sends HOST_COMPLETE */
1832 if (ipw2100_enable_adapter(priv)) {
Jiri Benc797b4f72005-08-25 20:03:27 -04001833 printk(KERN_ERR DRV_NAME ": "
James Ketrenosee8e3652005-09-14 09:47:29 -05001834 "%s: failed in call to enable adapter.\n",
1835 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001836 ipw2100_hw_stop_adapter(priv);
1837 rc = 1;
1838 goto exit;
1839 }
1840
James Ketrenos2c86c272005-03-23 17:32:29 -06001841 /* Start a scan . . . */
1842 ipw2100_set_scan_options(priv);
1843 ipw2100_start_scan(priv);
1844 }
1845
James Ketrenosee8e3652005-09-14 09:47:29 -05001846 exit:
James Ketrenos2c86c272005-03-23 17:32:29 -06001847 return rc;
1848}
1849
James Ketrenos2c86c272005-03-23 17:32:29 -06001850static void ipw2100_down(struct ipw2100_priv *priv)
1851{
1852 unsigned long flags;
1853 union iwreq_data wrqu = {
1854 .ap_addr = {
James Ketrenosee8e3652005-09-14 09:47:29 -05001855 .sa_family = ARPHRD_ETHER}
James Ketrenos2c86c272005-03-23 17:32:29 -06001856 };
1857 int associated = priv->status & STATUS_ASSOCIATED;
1858
1859 /* Kill the RF switch timer */
1860 if (!priv->stop_rf_kill) {
1861 priv->stop_rf_kill = 1;
1862 cancel_delayed_work(&priv->rf_kill);
1863 }
1864
Nick Andrew44072452009-01-03 18:52:40 +11001865 /* Kill the firmware hang check timer */
James Ketrenos2c86c272005-03-23 17:32:29 -06001866 if (!priv->stop_hang_check) {
1867 priv->stop_hang_check = 1;
1868 cancel_delayed_work(&priv->hang_check);
1869 }
1870
1871 /* Kill any pending resets */
1872 if (priv->status & STATUS_RESET_PENDING)
1873 cancel_delayed_work(&priv->reset_work);
1874
1875 /* Make sure the interrupt is on so that FW commands will be
1876 * processed correctly */
1877 spin_lock_irqsave(&priv->low_lock, flags);
1878 ipw2100_enable_interrupts(priv);
1879 spin_unlock_irqrestore(&priv->low_lock, flags);
1880
1881 if (ipw2100_hw_stop_adapter(priv))
Jiri Benc797b4f72005-08-25 20:03:27 -04001882 printk(KERN_ERR DRV_NAME ": %s: Error stopping adapter.\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06001883 priv->net_dev->name);
1884
1885 /* Do not disable the interrupt until _after_ we disable
1886 * the adaptor. Otherwise the CARD_DISABLE command will never
1887 * be ack'd by the firmware */
1888 spin_lock_irqsave(&priv->low_lock, flags);
1889 ipw2100_disable_interrupts(priv);
1890 spin_unlock_irqrestore(&priv->low_lock, flags);
1891
Mark Grossed771342010-05-06 01:59:26 +02001892 pm_qos_update_request(ipw2100_pm_qos_req, PM_QOS_DEFAULT_VALUE);
Arjan van de Ven5c875792006-09-30 23:27:17 -07001893
James Ketrenos2c86c272005-03-23 17:32:29 -06001894 /* We have to signal any supplicant if we are disassociating */
1895 if (associated)
1896 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1897
1898 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1899 netif_carrier_off(priv->net_dev);
1900 netif_stop_queue(priv->net_dev);
1901}
1902
Matthew Garrettc26409a2009-11-11 14:36:30 -05001903/* Called by register_netdev() */
1904static int ipw2100_net_init(struct net_device *dev)
1905{
1906 struct ipw2100_priv *priv = libipw_priv(dev);
1907 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
1908 struct wireless_dev *wdev = &priv->ieee->wdev;
1909 int ret;
1910 int i;
1911
1912 ret = ipw2100_up(priv, 1);
1913 if (ret)
1914 return ret;
1915
1916 memcpy(wdev->wiphy->perm_addr, priv->mac_addr, ETH_ALEN);
1917
1918 /* fill-out priv->ieee->bg_band */
1919 if (geo->bg_channels) {
1920 struct ieee80211_supported_band *bg_band = &priv->ieee->bg_band;
1921
1922 bg_band->band = IEEE80211_BAND_2GHZ;
1923 bg_band->n_channels = geo->bg_channels;
1924 bg_band->channels =
1925 kzalloc(geo->bg_channels *
1926 sizeof(struct ieee80211_channel), GFP_KERNEL);
1927 /* translate geo->bg to bg_band.channels */
1928 for (i = 0; i < geo->bg_channels; i++) {
1929 bg_band->channels[i].band = IEEE80211_BAND_2GHZ;
1930 bg_band->channels[i].center_freq = geo->bg[i].freq;
1931 bg_band->channels[i].hw_value = geo->bg[i].channel;
1932 bg_band->channels[i].max_power = geo->bg[i].max_power;
1933 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY)
1934 bg_band->channels[i].flags |=
1935 IEEE80211_CHAN_PASSIVE_SCAN;
1936 if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS)
1937 bg_band->channels[i].flags |=
1938 IEEE80211_CHAN_NO_IBSS;
1939 if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)
1940 bg_band->channels[i].flags |=
1941 IEEE80211_CHAN_RADAR;
1942 /* No equivalent for LIBIPW_CH_80211H_RULES,
1943 LIBIPW_CH_UNIFORM_SPREADING, or
1944 LIBIPW_CH_B_ONLY... */
1945 }
1946 /* point at bitrate info */
1947 bg_band->bitrates = ipw2100_bg_rates;
1948 bg_band->n_bitrates = RATE_COUNT;
1949
1950 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = bg_band;
1951 }
1952
1953 set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev);
1954 if (wiphy_register(wdev->wiphy)) {
1955 ipw2100_down(priv);
1956 return -EIO;
1957 }
1958 return 0;
1959}
1960
David Howellsc4028952006-11-22 14:57:56 +00001961static void ipw2100_reset_adapter(struct work_struct *work)
James Ketrenos2c86c272005-03-23 17:32:29 -06001962{
David Howellsc4028952006-11-22 14:57:56 +00001963 struct ipw2100_priv *priv =
1964 container_of(work, struct ipw2100_priv, reset_work.work);
James Ketrenos2c86c272005-03-23 17:32:29 -06001965 unsigned long flags;
1966 union iwreq_data wrqu = {
1967 .ap_addr = {
James Ketrenosee8e3652005-09-14 09:47:29 -05001968 .sa_family = ARPHRD_ETHER}
James Ketrenos2c86c272005-03-23 17:32:29 -06001969 };
1970 int associated = priv->status & STATUS_ASSOCIATED;
1971
1972 spin_lock_irqsave(&priv->low_lock, flags);
Zhu Yia1e695a2005-07-04 14:06:00 +08001973 IPW_DEBUG_INFO(": %s: Restarting adapter.\n", priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06001974 priv->resets++;
1975 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1976 priv->status |= STATUS_SECURITY_UPDATED;
1977
1978 /* Force a power cycle even if interface hasn't been opened
1979 * yet */
1980 cancel_delayed_work(&priv->reset_work);
1981 priv->status |= STATUS_RESET_PENDING;
1982 spin_unlock_irqrestore(&priv->low_lock, flags);
1983
Ingo Molnar752e3772006-02-28 07:20:54 +08001984 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06001985 /* stop timed checks so that they don't interfere with reset */
1986 priv->stop_hang_check = 1;
1987 cancel_delayed_work(&priv->hang_check);
1988
1989 /* We have to signal any supplicant if we are disassociating */
1990 if (associated)
1991 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1992
1993 ipw2100_up(priv, 0);
Ingo Molnar752e3772006-02-28 07:20:54 +08001994 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06001995
1996}
1997
James Ketrenos2c86c272005-03-23 17:32:29 -06001998static void isr_indicate_associated(struct ipw2100_priv *priv, u32 status)
1999{
2000
2001#define MAC_ASSOCIATION_READ_DELAY (HZ)
Hannes Ederb9da9e92009-02-14 11:50:26 +00002002 int ret;
2003 unsigned int len, essid_len;
James Ketrenos2c86c272005-03-23 17:32:29 -06002004 char essid[IW_ESSID_MAX_SIZE];
2005 u32 txrate;
2006 u32 chan;
2007 char *txratename;
James Ketrenosee8e3652005-09-14 09:47:29 -05002008 u8 bssid[ETH_ALEN];
John W. Linville9387b7c2008-09-30 20:59:05 -04002009 DECLARE_SSID_BUF(ssid);
James Ketrenos2c86c272005-03-23 17:32:29 -06002010
2011 /*
2012 * TBD: BSSID is usually 00:00:00:00:00:00 here and not
2013 * an actual MAC of the AP. Seems like FW sets this
2014 * address too late. Read it later and expose through
2015 * /proc or schedule a later task to query and update
2016 */
2017
2018 essid_len = IW_ESSID_MAX_SIZE;
2019 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID,
2020 essid, &essid_len);
2021 if (ret) {
2022 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05002023 __LINE__);
James Ketrenos2c86c272005-03-23 17:32:29 -06002024 return;
2025 }
2026
2027 len = sizeof(u32);
James Ketrenosee8e3652005-09-14 09:47:29 -05002028 ret = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &txrate, &len);
James Ketrenos2c86c272005-03-23 17:32:29 -06002029 if (ret) {
2030 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05002031 __LINE__);
James Ketrenos2c86c272005-03-23 17:32:29 -06002032 return;
2033 }
2034
2035 len = sizeof(u32);
2036 ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &len);
2037 if (ret) {
2038 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05002039 __LINE__);
James Ketrenos2c86c272005-03-23 17:32:29 -06002040 return;
2041 }
2042 len = ETH_ALEN;
James Ketrenosee8e3652005-09-14 09:47:29 -05002043 ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID, &bssid, &len);
James Ketrenos2c86c272005-03-23 17:32:29 -06002044 if (ret) {
2045 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05002046 __LINE__);
James Ketrenos2c86c272005-03-23 17:32:29 -06002047 return;
2048 }
2049 memcpy(priv->ieee->bssid, bssid, ETH_ALEN);
2050
James Ketrenos2c86c272005-03-23 17:32:29 -06002051 switch (txrate) {
2052 case TX_RATE_1_MBIT:
2053 txratename = "1Mbps";
2054 break;
2055 case TX_RATE_2_MBIT:
2056 txratename = "2Mbsp";
2057 break;
2058 case TX_RATE_5_5_MBIT:
2059 txratename = "5.5Mbps";
2060 break;
2061 case TX_RATE_11_MBIT:
2062 txratename = "11Mbps";
2063 break;
2064 default:
2065 IPW_DEBUG_INFO("Unknown rate: %d\n", txrate);
2066 txratename = "unknown rate";
2067 break;
2068 }
2069
Johannes Berge1749612008-10-27 15:59:26 -07002070 IPW_DEBUG_INFO("%s: Associated with '%s' at %s, channel %d (BSSID=%pM)\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04002071 priv->net_dev->name, print_ssid(ssid, essid, essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07002072 txratename, chan, bssid);
James Ketrenos2c86c272005-03-23 17:32:29 -06002073
2074 /* now we copy read ssid into dev */
2075 if (!(priv->config & CFG_STATIC_ESSID)) {
James Ketrenosee8e3652005-09-14 09:47:29 -05002076 priv->essid_len = min((u8) essid_len, (u8) IW_ESSID_MAX_SIZE);
James Ketrenos2c86c272005-03-23 17:32:29 -06002077 memcpy(priv->essid, essid, priv->essid_len);
2078 }
2079 priv->channel = chan;
2080 memcpy(priv->bssid, bssid, ETH_ALEN);
2081
2082 priv->status |= STATUS_ASSOCIATING;
2083 priv->connect_start = get_seconds();
2084
2085 queue_delayed_work(priv->workqueue, &priv->wx_event_work, HZ / 10);
2086}
2087
Jiri Bencc4aee8c2005-08-25 20:04:43 -04002088static int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid,
2089 int length, int batch_mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06002090{
2091 int ssid_len = min(length, IW_ESSID_MAX_SIZE);
2092 struct host_command cmd = {
2093 .host_command = SSID,
2094 .host_command_sequence = 0,
2095 .host_command_length = ssid_len
2096 };
2097 int err;
John W. Linville9387b7c2008-09-30 20:59:05 -04002098 DECLARE_SSID_BUF(ssid);
James Ketrenos2c86c272005-03-23 17:32:29 -06002099
John W. Linville9387b7c2008-09-30 20:59:05 -04002100 IPW_DEBUG_HC("SSID: '%s'\n", print_ssid(ssid, essid, ssid_len));
James Ketrenos2c86c272005-03-23 17:32:29 -06002101
2102 if (ssid_len)
James Ketrenos82328352005-08-24 22:33:31 -05002103 memcpy(cmd.host_command_parameters, essid, ssid_len);
James Ketrenos2c86c272005-03-23 17:32:29 -06002104
2105 if (!batch_mode) {
2106 err = ipw2100_disable_adapter(priv);
2107 if (err)
2108 return err;
2109 }
2110
2111 /* Bug in FW currently doesn't honor bit 0 in SET_SCAN_OPTIONS to
2112 * disable auto association -- so we cheat by setting a bogus SSID */
2113 if (!ssid_len && !(priv->config & CFG_ASSOCIATE)) {
2114 int i;
James Ketrenosee8e3652005-09-14 09:47:29 -05002115 u8 *bogus = (u8 *) cmd.host_command_parameters;
James Ketrenos2c86c272005-03-23 17:32:29 -06002116 for (i = 0; i < IW_ESSID_MAX_SIZE; i++)
2117 bogus[i] = 0x18 + i;
2118 cmd.host_command_length = IW_ESSID_MAX_SIZE;
2119 }
2120
2121 /* NOTE: We always send the SSID command even if the provided ESSID is
2122 * the same as what we currently think is set. */
2123
2124 err = ipw2100_hw_send_command(priv, &cmd);
2125 if (!err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05002126 memset(priv->essid + ssid_len, 0, IW_ESSID_MAX_SIZE - ssid_len);
James Ketrenos2c86c272005-03-23 17:32:29 -06002127 memcpy(priv->essid, essid, ssid_len);
2128 priv->essid_len = ssid_len;
2129 }
2130
2131 if (!batch_mode) {
2132 if (ipw2100_enable_adapter(priv))
2133 err = -EIO;
2134 }
2135
2136 return err;
2137}
2138
2139static void isr_indicate_association_lost(struct ipw2100_priv *priv, u32 status)
2140{
John W. Linville9387b7c2008-09-30 20:59:05 -04002141 DECLARE_SSID_BUF(ssid);
2142
James Ketrenos2c86c272005-03-23 17:32:29 -06002143 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
Frans Pop9fd1ea42010-03-24 19:46:31 +01002144 "disassociated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04002145 print_ssid(ssid, priv->essid, priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07002146 priv->bssid);
James Ketrenos2c86c272005-03-23 17:32:29 -06002147
2148 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
2149
2150 if (priv->status & STATUS_STOPPING) {
2151 IPW_DEBUG_INFO("Card is stopping itself, discard ASSN_LOST.\n");
2152 return;
2153 }
2154
2155 memset(priv->bssid, 0, ETH_ALEN);
2156 memset(priv->ieee->bssid, 0, ETH_ALEN);
2157
2158 netif_carrier_off(priv->net_dev);
2159 netif_stop_queue(priv->net_dev);
2160
2161 if (!(priv->status & STATUS_RUNNING))
2162 return;
2163
2164 if (priv->status & STATUS_SECURITY_UPDATED)
David Howellsc4028952006-11-22 14:57:56 +00002165 queue_delayed_work(priv->workqueue, &priv->security_work, 0);
James Ketrenos2c86c272005-03-23 17:32:29 -06002166
David Howellsc4028952006-11-22 14:57:56 +00002167 queue_delayed_work(priv->workqueue, &priv->wx_event_work, 0);
James Ketrenos2c86c272005-03-23 17:32:29 -06002168}
2169
2170static void isr_indicate_rf_kill(struct ipw2100_priv *priv, u32 status)
2171{
2172 IPW_DEBUG_INFO("%s: RF Kill state changed to radio OFF.\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05002173 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06002174
2175 /* RF_KILL is now enabled (else we wouldn't be here) */
Matthew Garrettc26409a2009-11-11 14:36:30 -05002176 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
James Ketrenos2c86c272005-03-23 17:32:29 -06002177 priv->status |= STATUS_RF_KILL_HW;
2178
James Ketrenos2c86c272005-03-23 17:32:29 -06002179 /* Make sure the RF Kill check timer is running */
2180 priv->stop_rf_kill = 0;
2181 cancel_delayed_work(&priv->rf_kill);
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05002182 queue_delayed_work(priv->workqueue, &priv->rf_kill,
2183 round_jiffies_relative(HZ));
James Ketrenos2c86c272005-03-23 17:32:29 -06002184}
2185
Dan Williamsd20c6782007-10-10 12:28:07 -04002186static void send_scan_event(void *data)
2187{
2188 struct ipw2100_priv *priv = data;
2189 union iwreq_data wrqu;
2190
2191 wrqu.data.length = 0;
2192 wrqu.data.flags = 0;
2193 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
2194}
2195
2196static void ipw2100_scan_event_later(struct work_struct *work)
2197{
2198 send_scan_event(container_of(work, struct ipw2100_priv,
2199 scan_event_later.work));
2200}
2201
2202static void ipw2100_scan_event_now(struct work_struct *work)
2203{
2204 send_scan_event(container_of(work, struct ipw2100_priv,
2205 scan_event_now));
2206}
2207
James Ketrenos2c86c272005-03-23 17:32:29 -06002208static void isr_scan_complete(struct ipw2100_priv *priv, u32 status)
2209{
2210 IPW_DEBUG_SCAN("scan complete\n");
2211 /* Age the scan results... */
2212 priv->ieee->scans++;
2213 priv->status &= ~STATUS_SCANNING;
Dan Williamsd20c6782007-10-10 12:28:07 -04002214
2215 /* Only userspace-requested scan completion events go out immediately */
2216 if (!priv->user_requested_scan) {
2217 if (!delayed_work_pending(&priv->scan_event_later))
2218 queue_delayed_work(priv->workqueue,
2219 &priv->scan_event_later,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05002220 round_jiffies_relative(msecs_to_jiffies(4000)));
Dan Williamsd20c6782007-10-10 12:28:07 -04002221 } else {
2222 priv->user_requested_scan = 0;
2223 cancel_delayed_work(&priv->scan_event_later);
2224 queue_work(priv->workqueue, &priv->scan_event_now);
2225 }
James Ketrenos2c86c272005-03-23 17:32:29 -06002226}
2227
Brice Goglin0f52bf92005-12-01 01:41:46 -08002228#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06002229#define IPW2100_HANDLER(v, f) { v, f, # v }
2230struct ipw2100_status_indicator {
2231 int status;
James Ketrenosee8e3652005-09-14 09:47:29 -05002232 void (*cb) (struct ipw2100_priv * priv, u32 status);
James Ketrenos2c86c272005-03-23 17:32:29 -06002233 char *name;
2234};
2235#else
2236#define IPW2100_HANDLER(v, f) { v, f }
2237struct ipw2100_status_indicator {
2238 int status;
James Ketrenosee8e3652005-09-14 09:47:29 -05002239 void (*cb) (struct ipw2100_priv * priv, u32 status);
James Ketrenos2c86c272005-03-23 17:32:29 -06002240};
Brice Goglin0f52bf92005-12-01 01:41:46 -08002241#endif /* CONFIG_IPW2100_DEBUG */
James Ketrenos2c86c272005-03-23 17:32:29 -06002242
2243static void isr_indicate_scanning(struct ipw2100_priv *priv, u32 status)
2244{
2245 IPW_DEBUG_SCAN("Scanning...\n");
2246 priv->status |= STATUS_SCANNING;
2247}
2248
Jiri Bencc4aee8c2005-08-25 20:04:43 -04002249static const struct ipw2100_status_indicator status_handlers[] = {
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01002250 IPW2100_HANDLER(IPW_STATE_INITIALIZED, NULL),
2251 IPW2100_HANDLER(IPW_STATE_COUNTRY_FOUND, NULL),
James Ketrenos2c86c272005-03-23 17:32:29 -06002252 IPW2100_HANDLER(IPW_STATE_ASSOCIATED, isr_indicate_associated),
2253 IPW2100_HANDLER(IPW_STATE_ASSN_LOST, isr_indicate_association_lost),
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01002254 IPW2100_HANDLER(IPW_STATE_ASSN_CHANGED, NULL),
James Ketrenos2c86c272005-03-23 17:32:29 -06002255 IPW2100_HANDLER(IPW_STATE_SCAN_COMPLETE, isr_scan_complete),
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01002256 IPW2100_HANDLER(IPW_STATE_ENTERED_PSP, NULL),
2257 IPW2100_HANDLER(IPW_STATE_LEFT_PSP, NULL),
James Ketrenos2c86c272005-03-23 17:32:29 -06002258 IPW2100_HANDLER(IPW_STATE_RF_KILL, isr_indicate_rf_kill),
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01002259 IPW2100_HANDLER(IPW_STATE_DISABLED, NULL),
2260 IPW2100_HANDLER(IPW_STATE_POWER_DOWN, NULL),
James Ketrenos2c86c272005-03-23 17:32:29 -06002261 IPW2100_HANDLER(IPW_STATE_SCANNING, isr_indicate_scanning),
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01002262 IPW2100_HANDLER(-1, NULL)
James Ketrenos2c86c272005-03-23 17:32:29 -06002263};
2264
James Ketrenos2c86c272005-03-23 17:32:29 -06002265static void isr_status_change(struct ipw2100_priv *priv, int status)
2266{
2267 int i;
2268
2269 if (status == IPW_STATE_SCANNING &&
2270 priv->status & STATUS_ASSOCIATED &&
2271 !(priv->status & STATUS_SCANNING)) {
2272 IPW_DEBUG_INFO("Scan detected while associated, with "
2273 "no scan request. Restarting firmware.\n");
2274
2275 /* Wake up any sleeping jobs */
2276 schedule_reset(priv);
2277 }
2278
2279 for (i = 0; status_handlers[i].status != -1; i++) {
2280 if (status == status_handlers[i].status) {
2281 IPW_DEBUG_NOTIF("Status change: %s\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05002282 status_handlers[i].name);
James Ketrenos2c86c272005-03-23 17:32:29 -06002283 if (status_handlers[i].cb)
2284 status_handlers[i].cb(priv, status);
2285 priv->wstats.status = status;
2286 return;
2287 }
2288 }
2289
2290 IPW_DEBUG_NOTIF("unknown status received: %04x\n", status);
2291}
2292
James Ketrenosee8e3652005-09-14 09:47:29 -05002293static void isr_rx_complete_command(struct ipw2100_priv *priv,
2294 struct ipw2100_cmd_header *cmd)
James Ketrenos2c86c272005-03-23 17:32:29 -06002295{
Brice Goglin0f52bf92005-12-01 01:41:46 -08002296#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06002297 if (cmd->host_command_reg < ARRAY_SIZE(command_types)) {
2298 IPW_DEBUG_HC("Command completed '%s (%d)'\n",
2299 command_types[cmd->host_command_reg],
2300 cmd->host_command_reg);
2301 }
2302#endif
2303 if (cmd->host_command_reg == HOST_COMPLETE)
2304 priv->status |= STATUS_ENABLED;
2305
2306 if (cmd->host_command_reg == CARD_DISABLE)
2307 priv->status &= ~STATUS_ENABLED;
2308
2309 priv->status &= ~STATUS_CMD_ACTIVE;
2310
2311 wake_up_interruptible(&priv->wait_command_queue);
2312}
2313
Brice Goglin0f52bf92005-12-01 01:41:46 -08002314#ifdef CONFIG_IPW2100_DEBUG
Jiri Bencc4aee8c2005-08-25 20:04:43 -04002315static const char *frame_types[] = {
James Ketrenos2c86c272005-03-23 17:32:29 -06002316 "COMMAND_STATUS_VAL",
2317 "STATUS_CHANGE_VAL",
2318 "P80211_DATA_VAL",
2319 "P8023_DATA_VAL",
2320 "HOST_NOTIFICATION_VAL"
2321};
2322#endif
2323
Arjan van de Ven858119e2006-01-14 13:20:43 -08002324static int ipw2100_alloc_skb(struct ipw2100_priv *priv,
James Ketrenosee8e3652005-09-14 09:47:29 -05002325 struct ipw2100_rx_packet *packet)
James Ketrenos2c86c272005-03-23 17:32:29 -06002326{
2327 packet->skb = dev_alloc_skb(sizeof(struct ipw2100_rx));
2328 if (!packet->skb)
2329 return -ENOMEM;
2330
2331 packet->rxp = (struct ipw2100_rx *)packet->skb->data;
2332 packet->dma_addr = pci_map_single(priv->pci_dev, packet->skb->data,
2333 sizeof(struct ipw2100_rx),
2334 PCI_DMA_FROMDEVICE);
2335 /* NOTE: pci_map_single does not return an error code, and 0 is a valid
2336 * dma_addr */
2337
2338 return 0;
2339}
2340
James Ketrenos2c86c272005-03-23 17:32:29 -06002341#define SEARCH_ERROR 0xffffffff
2342#define SEARCH_FAIL 0xfffffffe
2343#define SEARCH_SUCCESS 0xfffffff0
2344#define SEARCH_DISCARD 0
2345#define SEARCH_SNAPSHOT 1
2346
2347#define SNAPSHOT_ADDR(ofs) (priv->snapshot[((ofs) >> 12) & 0xff] + ((ofs) & 0xfff))
Zhu Yi3c5eca52006-01-24 13:49:26 +08002348static void ipw2100_snapshot_free(struct ipw2100_priv *priv)
2349{
2350 int i;
2351 if (!priv->snapshot[0])
2352 return;
2353 for (i = 0; i < 0x30; i++)
2354 kfree(priv->snapshot[i]);
2355 priv->snapshot[0] = NULL;
2356}
2357
Robert P. J. Dayae800312007-01-31 02:39:40 -05002358#ifdef IPW2100_DEBUG_C3
Arjan van de Ven858119e2006-01-14 13:20:43 -08002359static int ipw2100_snapshot_alloc(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06002360{
2361 int i;
2362 if (priv->snapshot[0])
2363 return 1;
2364 for (i = 0; i < 0x30; i++) {
Robert P. J. Day5cbded52006-12-13 00:35:56 -08002365 priv->snapshot[i] = kmalloc(0x1000, GFP_ATOMIC);
James Ketrenos2c86c272005-03-23 17:32:29 -06002366 if (!priv->snapshot[i]) {
2367 IPW_DEBUG_INFO("%s: Error allocating snapshot "
James Ketrenosee8e3652005-09-14 09:47:29 -05002368 "buffer %d\n", priv->net_dev->name, i);
James Ketrenos2c86c272005-03-23 17:32:29 -06002369 while (i > 0)
2370 kfree(priv->snapshot[--i]);
2371 priv->snapshot[0] = NULL;
2372 return 0;
2373 }
2374 }
2375
2376 return 1;
2377}
2378
Arjan van de Ven858119e2006-01-14 13:20:43 -08002379static u32 ipw2100_match_buf(struct ipw2100_priv *priv, u8 * in_buf,
James Ketrenos2c86c272005-03-23 17:32:29 -06002380 size_t len, int mode)
2381{
2382 u32 i, j;
2383 u32 tmp;
2384 u8 *s, *d;
2385 u32 ret;
2386
2387 s = in_buf;
2388 if (mode == SEARCH_SNAPSHOT) {
2389 if (!ipw2100_snapshot_alloc(priv))
2390 mode = SEARCH_DISCARD;
2391 }
2392
2393 for (ret = SEARCH_FAIL, i = 0; i < 0x30000; i += 4) {
2394 read_nic_dword(priv->net_dev, i, &tmp);
2395 if (mode == SEARCH_SNAPSHOT)
James Ketrenosee8e3652005-09-14 09:47:29 -05002396 *(u32 *) SNAPSHOT_ADDR(i) = tmp;
James Ketrenos2c86c272005-03-23 17:32:29 -06002397 if (ret == SEARCH_FAIL) {
James Ketrenosee8e3652005-09-14 09:47:29 -05002398 d = (u8 *) & tmp;
James Ketrenos2c86c272005-03-23 17:32:29 -06002399 for (j = 0; j < 4; j++) {
2400 if (*s != *d) {
2401 s = in_buf;
2402 continue;
2403 }
2404
2405 s++;
2406 d++;
2407
2408 if ((s - in_buf) == len)
2409 ret = (i + j) - len + 1;
2410 }
2411 } else if (mode == SEARCH_DISCARD)
2412 return ret;
2413 }
2414
2415 return ret;
2416}
Zhu Yi3c5eca52006-01-24 13:49:26 +08002417#endif
James Ketrenos2c86c272005-03-23 17:32:29 -06002418
2419/*
2420 *
2421 * 0) Disconnect the SKB from the firmware (just unmap)
2422 * 1) Pack the ETH header into the SKB
2423 * 2) Pass the SKB to the network stack
2424 *
2425 * When packet is provided by the firmware, it contains the following:
2426 *
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002427 * . libipw_hdr
2428 * . libipw_snap_hdr
James Ketrenos2c86c272005-03-23 17:32:29 -06002429 *
2430 * The size of the constructed ethernet
2431 *
2432 */
Robert P. J. Dayae800312007-01-31 02:39:40 -05002433#ifdef IPW2100_RX_DEBUG
Jiri Bencc4aee8c2005-08-25 20:04:43 -04002434static u8 packet_data[IPW_RX_NIC_BUFFER_LENGTH];
James Ketrenos2c86c272005-03-23 17:32:29 -06002435#endif
2436
Arjan van de Ven858119e2006-01-14 13:20:43 -08002437static void ipw2100_corruption_detected(struct ipw2100_priv *priv, int i)
James Ketrenos2c86c272005-03-23 17:32:29 -06002438{
Robert P. J. Dayae800312007-01-31 02:39:40 -05002439#ifdef IPW2100_DEBUG_C3
James Ketrenos2c86c272005-03-23 17:32:29 -06002440 struct ipw2100_status *status = &priv->status_queue.drv[i];
2441 u32 match, reg;
2442 int j;
2443#endif
James Ketrenos2c86c272005-03-23 17:32:29 -06002444
Zhu Yia1e695a2005-07-04 14:06:00 +08002445 IPW_DEBUG_INFO(": PCI latency error detected at 0x%04zX.\n",
2446 i * sizeof(struct ipw2100_status));
James Ketrenos2c86c272005-03-23 17:32:29 -06002447
Robert P. J. Dayae800312007-01-31 02:39:40 -05002448#ifdef IPW2100_DEBUG_C3
Nick Andrew877d0312009-01-26 11:06:57 +01002449 /* Halt the firmware so we can get a good image */
James Ketrenos2c86c272005-03-23 17:32:29 -06002450 write_register(priv->net_dev, IPW_REG_RESET_REG,
2451 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
2452 j = 5;
2453 do {
2454 udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
2455 read_register(priv->net_dev, IPW_REG_RESET_REG, &reg);
2456
2457 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
2458 break;
James Ketrenosee8e3652005-09-14 09:47:29 -05002459 } while (j--);
James Ketrenos2c86c272005-03-23 17:32:29 -06002460
James Ketrenosee8e3652005-09-14 09:47:29 -05002461 match = ipw2100_match_buf(priv, (u8 *) status,
James Ketrenos2c86c272005-03-23 17:32:29 -06002462 sizeof(struct ipw2100_status),
2463 SEARCH_SNAPSHOT);
2464 if (match < SEARCH_SUCCESS)
2465 IPW_DEBUG_INFO("%s: DMA status match in Firmware at "
2466 "offset 0x%06X, length %d:\n",
2467 priv->net_dev->name, match,
2468 sizeof(struct ipw2100_status));
2469 else
2470 IPW_DEBUG_INFO("%s: No DMA status match in "
2471 "Firmware.\n", priv->net_dev->name);
2472
James Ketrenosee8e3652005-09-14 09:47:29 -05002473 printk_buf((u8 *) priv->status_queue.drv,
James Ketrenos2c86c272005-03-23 17:32:29 -06002474 sizeof(struct ipw2100_status) * RX_QUEUE_LENGTH);
2475#endif
2476
2477 priv->fatal_error = IPW2100_ERR_C3_CORRUPTION;
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002478 priv->net_dev->stats.rx_errors++;
James Ketrenos2c86c272005-03-23 17:32:29 -06002479 schedule_reset(priv);
2480}
2481
Arjan van de Ven858119e2006-01-14 13:20:43 -08002482static void isr_rx(struct ipw2100_priv *priv, int i,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002483 struct libipw_rx_stats *stats)
James Ketrenos2c86c272005-03-23 17:32:29 -06002484{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002485 struct net_device *dev = priv->net_dev;
James Ketrenos2c86c272005-03-23 17:32:29 -06002486 struct ipw2100_status *status = &priv->status_queue.drv[i];
2487 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
2488
2489 IPW_DEBUG_RX("Handler...\n");
2490
2491 if (unlikely(status->frame_size > skb_tailroom(packet->skb))) {
2492 IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!"
2493 " Dropping.\n",
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002494 dev->name,
James Ketrenos2c86c272005-03-23 17:32:29 -06002495 status->frame_size, skb_tailroom(packet->skb));
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002496 dev->stats.rx_errors++;
James Ketrenos2c86c272005-03-23 17:32:29 -06002497 return;
2498 }
2499
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002500 if (unlikely(!netif_running(dev))) {
2501 dev->stats.rx_errors++;
James Ketrenos2c86c272005-03-23 17:32:29 -06002502 priv->wstats.discard.misc++;
2503 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
2504 return;
2505 }
James Ketrenos2c86c272005-03-23 17:32:29 -06002506
2507 if (unlikely(priv->ieee->iw_mode != IW_MODE_MONITOR &&
James Ketrenosee8e3652005-09-14 09:47:29 -05002508 !(priv->status & STATUS_ASSOCIATED))) {
James Ketrenos2c86c272005-03-23 17:32:29 -06002509 IPW_DEBUG_DROP("Dropping packet while not associated.\n");
2510 priv->wstats.discard.misc++;
2511 return;
2512 }
2513
James Ketrenos2c86c272005-03-23 17:32:29 -06002514 pci_unmap_single(priv->pci_dev,
2515 packet->dma_addr,
James Ketrenosee8e3652005-09-14 09:47:29 -05002516 sizeof(struct ipw2100_rx), PCI_DMA_FROMDEVICE);
James Ketrenos2c86c272005-03-23 17:32:29 -06002517
2518 skb_put(packet->skb, status->frame_size);
2519
Robert P. J. Dayae800312007-01-31 02:39:40 -05002520#ifdef IPW2100_RX_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06002521 /* Make a copy of the frame so we can dump it to the logs if
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002522 * libipw_rx fails */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002523 skb_copy_from_linear_data(packet->skb, packet_data,
2524 min_t(u32, status->frame_size,
2525 IPW_RX_NIC_BUFFER_LENGTH));
James Ketrenos2c86c272005-03-23 17:32:29 -06002526#endif
2527
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002528 if (!libipw_rx(priv->ieee, packet->skb, stats)) {
Robert P. J. Dayae800312007-01-31 02:39:40 -05002529#ifdef IPW2100_RX_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06002530 IPW_DEBUG_DROP("%s: Non consumed packet:\n",
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002531 dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06002532 printk_buf(IPW_DL_DROP, packet_data, status->frame_size);
2533#endif
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002534 dev->stats.rx_errors++;
James Ketrenos2c86c272005-03-23 17:32:29 -06002535
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002536 /* libipw_rx failed, so it didn't free the SKB */
James Ketrenos2c86c272005-03-23 17:32:29 -06002537 dev_kfree_skb_any(packet->skb);
2538 packet->skb = NULL;
2539 }
2540
2541 /* We need to allocate a new SKB and attach it to the RDB. */
2542 if (unlikely(ipw2100_alloc_skb(priv, packet))) {
Jiri Benc797b4f72005-08-25 20:03:27 -04002543 printk(KERN_WARNING DRV_NAME ": "
James Ketrenosee8e3652005-09-14 09:47:29 -05002544 "%s: Unable to allocate SKB onto RBD ring - disabling "
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002545 "adapter.\n", dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06002546 /* TODO: schedule adapter shutdown */
2547 IPW_DEBUG_INFO("TODO: Shutdown adapter...\n");
2548 }
2549
2550 /* Update the RDB entry */
2551 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
2552}
2553
Stefan Rompf15745a72006-02-21 18:36:17 +08002554#ifdef CONFIG_IPW2100_MONITOR
2555
2556static void isr_rx_monitor(struct ipw2100_priv *priv, int i,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002557 struct libipw_rx_stats *stats)
Stefan Rompf15745a72006-02-21 18:36:17 +08002558{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002559 struct net_device *dev = priv->net_dev;
Stefan Rompf15745a72006-02-21 18:36:17 +08002560 struct ipw2100_status *status = &priv->status_queue.drv[i];
2561 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
2562
Stefan Rompf15745a72006-02-21 18:36:17 +08002563 /* Magic struct that slots into the radiotap header -- no reason
2564 * to build this manually element by element, we can write it much
2565 * more efficiently than we can parse it. ORDER MATTERS HERE */
2566 struct ipw_rt_hdr {
2567 struct ieee80211_radiotap_header rt_hdr;
2568 s8 rt_dbmsignal; /* signal in dbM, kluged to signed */
2569 } *ipw_rt;
2570
Zhu Yicae16292006-02-21 18:41:14 +08002571 IPW_DEBUG_RX("Handler...\n");
2572
2573 if (unlikely(status->frame_size > skb_tailroom(packet->skb) -
2574 sizeof(struct ipw_rt_hdr))) {
Stefan Rompf15745a72006-02-21 18:36:17 +08002575 IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!"
2576 " Dropping.\n",
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002577 dev->name,
Zhu Yicae16292006-02-21 18:41:14 +08002578 status->frame_size,
2579 skb_tailroom(packet->skb));
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002580 dev->stats.rx_errors++;
Stefan Rompf15745a72006-02-21 18:36:17 +08002581 return;
2582 }
2583
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002584 if (unlikely(!netif_running(dev))) {
2585 dev->stats.rx_errors++;
Stefan Rompf15745a72006-02-21 18:36:17 +08002586 priv->wstats.discard.misc++;
2587 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
2588 return;
2589 }
2590
2591 if (unlikely(priv->config & CFG_CRC_CHECK &&
2592 status->flags & IPW_STATUS_FLAG_CRC_ERROR)) {
2593 IPW_DEBUG_RX("CRC error in packet. Dropping.\n");
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002594 dev->stats.rx_errors++;
Stefan Rompf15745a72006-02-21 18:36:17 +08002595 return;
2596 }
2597
Zhu Yicae16292006-02-21 18:41:14 +08002598 pci_unmap_single(priv->pci_dev, packet->dma_addr,
Stefan Rompf15745a72006-02-21 18:36:17 +08002599 sizeof(struct ipw2100_rx), PCI_DMA_FROMDEVICE);
2600 memmove(packet->skb->data + sizeof(struct ipw_rt_hdr),
2601 packet->skb->data, status->frame_size);
2602
2603 ipw_rt = (struct ipw_rt_hdr *) packet->skb->data;
2604
2605 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
2606 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
Al Viro1edd3a52007-12-21 00:15:18 -05002607 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total hdr+data */
Stefan Rompf15745a72006-02-21 18:36:17 +08002608
Al Viro1edd3a52007-12-21 00:15:18 -05002609 ipw_rt->rt_hdr.it_present = cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
Stefan Rompf15745a72006-02-21 18:36:17 +08002610
2611 ipw_rt->rt_dbmsignal = status->rssi + IPW2100_RSSI_TO_DBM;
2612
2613 skb_put(packet->skb, status->frame_size + sizeof(struct ipw_rt_hdr));
2614
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002615 if (!libipw_rx(priv->ieee, packet->skb, stats)) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002616 dev->stats.rx_errors++;
Stefan Rompf15745a72006-02-21 18:36:17 +08002617
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002618 /* libipw_rx failed, so it didn't free the SKB */
Stefan Rompf15745a72006-02-21 18:36:17 +08002619 dev_kfree_skb_any(packet->skb);
2620 packet->skb = NULL;
2621 }
2622
2623 /* We need to allocate a new SKB and attach it to the RDB. */
2624 if (unlikely(ipw2100_alloc_skb(priv, packet))) {
2625 IPW_DEBUG_WARNING(
2626 "%s: Unable to allocate SKB onto RBD ring - disabling "
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00002627 "adapter.\n", dev->name);
Stefan Rompf15745a72006-02-21 18:36:17 +08002628 /* TODO: schedule adapter shutdown */
2629 IPW_DEBUG_INFO("TODO: Shutdown adapter...\n");
2630 }
2631
2632 /* Update the RDB entry */
2633 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
2634}
2635
2636#endif
2637
Arjan van de Ven858119e2006-01-14 13:20:43 -08002638static int ipw2100_corruption_check(struct ipw2100_priv *priv, int i)
James Ketrenos2c86c272005-03-23 17:32:29 -06002639{
2640 struct ipw2100_status *status = &priv->status_queue.drv[i];
2641 struct ipw2100_rx *u = priv->rx_buffers[i].rxp;
2642 u16 frame_type = status->status_fields & STATUS_TYPE_MASK;
2643
2644 switch (frame_type) {
2645 case COMMAND_STATUS_VAL:
2646 return (status->frame_size != sizeof(u->rx_data.command));
2647 case STATUS_CHANGE_VAL:
2648 return (status->frame_size != sizeof(u->rx_data.status));
2649 case HOST_NOTIFICATION_VAL:
2650 return (status->frame_size < sizeof(u->rx_data.notification));
2651 case P80211_DATA_VAL:
2652 case P8023_DATA_VAL:
2653#ifdef CONFIG_IPW2100_MONITOR
2654 return 0;
2655#else
Al Viro1edd3a52007-12-21 00:15:18 -05002656 switch (WLAN_FC_GET_TYPE(le16_to_cpu(u->rx_data.header.frame_ctl))) {
James Ketrenos2c86c272005-03-23 17:32:29 -06002657 case IEEE80211_FTYPE_MGMT:
2658 case IEEE80211_FTYPE_CTL:
2659 return 0;
2660 case IEEE80211_FTYPE_DATA:
2661 return (status->frame_size >
2662 IPW_MAX_802_11_PAYLOAD_LENGTH);
2663 }
2664#endif
2665 }
2666
2667 return 1;
2668}
2669
2670/*
2671 * ipw2100 interrupts are disabled at this point, and the ISR
2672 * is the only code that calls this method. So, we do not need
2673 * to play with any locks.
2674 *
2675 * RX Queue works as follows:
2676 *
2677 * Read index - firmware places packet in entry identified by the
2678 * Read index and advances Read index. In this manner,
2679 * Read index will always point to the next packet to
2680 * be filled--but not yet valid.
2681 *
2682 * Write index - driver fills this entry with an unused RBD entry.
2683 * This entry has not filled by the firmware yet.
2684 *
2685 * In between the W and R indexes are the RBDs that have been received
2686 * but not yet processed.
2687 *
2688 * The process of handling packets will start at WRITE + 1 and advance
2689 * until it reaches the READ index.
2690 *
2691 * The WRITE index is cached in the variable 'priv->rx_queue.next'.
2692 *
2693 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002694static void __ipw2100_rx_process(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06002695{
2696 struct ipw2100_bd_queue *rxq = &priv->rx_queue;
2697 struct ipw2100_status_queue *sq = &priv->status_queue;
2698 struct ipw2100_rx_packet *packet;
2699 u16 frame_type;
2700 u32 r, w, i, s;
2701 struct ipw2100_rx *u;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002702 struct libipw_rx_stats stats = {
James Ketrenos2c86c272005-03-23 17:32:29 -06002703 .mac_time = jiffies,
2704 };
2705
2706 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_READ_INDEX, &r);
2707 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, &w);
2708
2709 if (r >= rxq->entries) {
2710 IPW_DEBUG_RX("exit - bad read index\n");
2711 return;
2712 }
2713
2714 i = (rxq->next + 1) % rxq->entries;
2715 s = i;
2716 while (i != r) {
2717 /* IPW_DEBUG_RX("r = %d : w = %d : processing = %d\n",
2718 r, rxq->next, i); */
2719
2720 packet = &priv->rx_buffers[i];
2721
2722 /* Sync the DMA for the STATUS buffer so CPU is sure to get
2723 * the correct values */
James Ketrenosee8e3652005-09-14 09:47:29 -05002724 pci_dma_sync_single_for_cpu(priv->pci_dev,
2725 sq->nic +
2726 sizeof(struct ipw2100_status) * i,
2727 sizeof(struct ipw2100_status),
2728 PCI_DMA_FROMDEVICE);
James Ketrenos2c86c272005-03-23 17:32:29 -06002729
2730 /* Sync the DMA for the RX buffer so CPU is sure to get
2731 * the correct values */
2732 pci_dma_sync_single_for_cpu(priv->pci_dev, packet->dma_addr,
2733 sizeof(struct ipw2100_rx),
2734 PCI_DMA_FROMDEVICE);
2735
2736 if (unlikely(ipw2100_corruption_check(priv, i))) {
2737 ipw2100_corruption_detected(priv, i);
2738 goto increment;
2739 }
2740
2741 u = packet->rxp;
James Ketrenosee8e3652005-09-14 09:47:29 -05002742 frame_type = sq->drv[i].status_fields & STATUS_TYPE_MASK;
James Ketrenos2c86c272005-03-23 17:32:29 -06002743 stats.rssi = sq->drv[i].rssi + IPW2100_RSSI_TO_DBM;
2744 stats.len = sq->drv[i].frame_size;
2745
2746 stats.mask = 0;
2747 if (stats.rssi != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002748 stats.mask |= LIBIPW_STATMASK_RSSI;
2749 stats.freq = LIBIPW_24GHZ_BAND;
James Ketrenos2c86c272005-03-23 17:32:29 -06002750
James Ketrenosee8e3652005-09-14 09:47:29 -05002751 IPW_DEBUG_RX("%s: '%s' frame type received (%d).\n",
2752 priv->net_dev->name, frame_types[frame_type],
2753 stats.len);
James Ketrenos2c86c272005-03-23 17:32:29 -06002754
2755 switch (frame_type) {
2756 case COMMAND_STATUS_VAL:
2757 /* Reset Rx watchdog */
James Ketrenosee8e3652005-09-14 09:47:29 -05002758 isr_rx_complete_command(priv, &u->rx_data.command);
James Ketrenos2c86c272005-03-23 17:32:29 -06002759 break;
2760
2761 case STATUS_CHANGE_VAL:
2762 isr_status_change(priv, u->rx_data.status);
2763 break;
2764
2765 case P80211_DATA_VAL:
2766 case P8023_DATA_VAL:
2767#ifdef CONFIG_IPW2100_MONITOR
2768 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Stefan Rompf15745a72006-02-21 18:36:17 +08002769 isr_rx_monitor(priv, i, &stats);
James Ketrenos2c86c272005-03-23 17:32:29 -06002770 break;
2771 }
2772#endif
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002773 if (stats.len < sizeof(struct libipw_hdr_3addr))
James Ketrenos2c86c272005-03-23 17:32:29 -06002774 break;
Al Viro1edd3a52007-12-21 00:15:18 -05002775 switch (WLAN_FC_GET_TYPE(le16_to_cpu(u->rx_data.header.frame_ctl))) {
James Ketrenos2c86c272005-03-23 17:32:29 -06002776 case IEEE80211_FTYPE_MGMT:
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002777 libipw_rx_mgt(priv->ieee,
James Ketrenosee8e3652005-09-14 09:47:29 -05002778 &u->rx_data.header, &stats);
James Ketrenos2c86c272005-03-23 17:32:29 -06002779 break;
2780
2781 case IEEE80211_FTYPE_CTL:
2782 break;
2783
2784 case IEEE80211_FTYPE_DATA:
2785 isr_rx(priv, i, &stats);
2786 break;
2787
2788 }
2789 break;
2790 }
2791
James Ketrenosee8e3652005-09-14 09:47:29 -05002792 increment:
James Ketrenos2c86c272005-03-23 17:32:29 -06002793 /* clear status field associated with this RBD */
2794 rxq->drv[i].status.info.field = 0;
2795
2796 i = (i + 1) % rxq->entries;
2797 }
2798
2799 if (i != s) {
2800 /* backtrack one entry, wrapping to end if at 0 */
2801 rxq->next = (i ? i : rxq->entries) - 1;
2802
2803 write_register(priv->net_dev,
James Ketrenosee8e3652005-09-14 09:47:29 -05002804 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, rxq->next);
James Ketrenos2c86c272005-03-23 17:32:29 -06002805 }
2806}
2807
James Ketrenos2c86c272005-03-23 17:32:29 -06002808/*
2809 * __ipw2100_tx_process
2810 *
2811 * This routine will determine whether the next packet on
2812 * the fw_pend_list has been processed by the firmware yet.
2813 *
2814 * If not, then it does nothing and returns.
2815 *
2816 * If so, then it removes the item from the fw_pend_list, frees
2817 * any associated storage, and places the item back on the
2818 * free list of its source (either msg_free_list or tx_free_list)
2819 *
2820 * TX Queue works as follows:
2821 *
2822 * Read index - points to the next TBD that the firmware will
2823 * process. The firmware will read the data, and once
2824 * done processing, it will advance the Read index.
2825 *
2826 * Write index - driver fills this entry with an constructed TBD
2827 * entry. The Write index is not advanced until the
2828 * packet has been configured.
2829 *
2830 * In between the W and R indexes are the TBDs that have NOT been
2831 * processed. Lagging behind the R index are packets that have
2832 * been processed but have not been freed by the driver.
2833 *
2834 * In order to free old storage, an internal index will be maintained
2835 * that points to the next packet to be freed. When all used
2836 * packets have been freed, the oldest index will be the same as the
2837 * firmware's read index.
2838 *
2839 * The OLDEST index is cached in the variable 'priv->tx_queue.oldest'
2840 *
2841 * Because the TBD structure can not contain arbitrary data, the
2842 * driver must keep an internal queue of cached allocations such that
2843 * it can put that data back into the tx_free_list and msg_free_list
2844 * for use by future command and data packets.
2845 *
2846 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002847static int __ipw2100_tx_process(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06002848{
2849 struct ipw2100_bd_queue *txq = &priv->tx_queue;
James Ketrenosee8e3652005-09-14 09:47:29 -05002850 struct ipw2100_bd *tbd;
James Ketrenos2c86c272005-03-23 17:32:29 -06002851 struct list_head *element;
2852 struct ipw2100_tx_packet *packet;
2853 int descriptors_used;
2854 int e, i;
2855 u32 r, w, frag_num = 0;
2856
2857 if (list_empty(&priv->fw_pend_list))
2858 return 0;
2859
2860 element = priv->fw_pend_list.next;
2861
2862 packet = list_entry(element, struct ipw2100_tx_packet, list);
James Ketrenosee8e3652005-09-14 09:47:29 -05002863 tbd = &txq->drv[packet->index];
James Ketrenos2c86c272005-03-23 17:32:29 -06002864
2865 /* Determine how many TBD entries must be finished... */
2866 switch (packet->type) {
2867 case COMMAND:
2868 /* COMMAND uses only one slot; don't advance */
2869 descriptors_used = 1;
2870 e = txq->oldest;
2871 break;
2872
2873 case DATA:
2874 /* DATA uses two slots; advance and loop position. */
2875 descriptors_used = tbd->num_fragments;
James Ketrenosee8e3652005-09-14 09:47:29 -05002876 frag_num = tbd->num_fragments - 1;
James Ketrenos2c86c272005-03-23 17:32:29 -06002877 e = txq->oldest + frag_num;
2878 e %= txq->entries;
2879 break;
2880
2881 default:
Jiri Benc797b4f72005-08-25 20:03:27 -04002882 printk(KERN_WARNING DRV_NAME ": %s: Bad fw_pend_list entry!\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05002883 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06002884 return 0;
2885 }
2886
2887 /* if the last TBD is not done by NIC yet, then packet is
2888 * not ready to be released.
2889 *
2890 */
2891 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
2892 &r);
2893 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
2894 &w);
2895 if (w != txq->next)
Jiri Benc797b4f72005-08-25 20:03:27 -04002896 printk(KERN_WARNING DRV_NAME ": %s: write index mismatch\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06002897 priv->net_dev->name);
2898
James Ketrenosee8e3652005-09-14 09:47:29 -05002899 /*
James Ketrenos2c86c272005-03-23 17:32:29 -06002900 * txq->next is the index of the last packet written txq->oldest is
2901 * the index of the r is the index of the next packet to be read by
2902 * firmware
2903 */
2904
James Ketrenos2c86c272005-03-23 17:32:29 -06002905 /*
2906 * Quick graphic to help you visualize the following
2907 * if / else statement
2908 *
2909 * ===>| s---->|===============
2910 * e>|
2911 * | a | b | c | d | e | f | g | h | i | j | k | l
2912 * r---->|
2913 * w
2914 *
2915 * w - updated by driver
2916 * r - updated by firmware
2917 * s - start of oldest BD entry (txq->oldest)
2918 * e - end of oldest BD entry
2919 *
2920 */
2921 if (!((r <= w && (e < r || e >= w)) || (e < r && e >= w))) {
2922 IPW_DEBUG_TX("exit - no processed packets ready to release.\n");
2923 return 0;
2924 }
2925
2926 list_del(element);
2927 DEC_STAT(&priv->fw_pend_stat);
2928
Brice Goglin0f52bf92005-12-01 01:41:46 -08002929#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06002930 {
Reinette Chatre21f8a732009-08-18 10:25:05 -07002931 i = txq->oldest;
James Ketrenosee8e3652005-09-14 09:47:29 -05002932 IPW_DEBUG_TX("TX%d V=%p P=%04X T=%04X L=%d\n", i,
2933 &txq->drv[i],
2934 (u32) (txq->nic + i * sizeof(struct ipw2100_bd)),
2935 txq->drv[i].host_addr, txq->drv[i].buf_length);
James Ketrenos2c86c272005-03-23 17:32:29 -06002936
2937 if (packet->type == DATA) {
2938 i = (i + 1) % txq->entries;
2939
James Ketrenosee8e3652005-09-14 09:47:29 -05002940 IPW_DEBUG_TX("TX%d V=%p P=%04X T=%04X L=%d\n", i,
2941 &txq->drv[i],
2942 (u32) (txq->nic + i *
2943 sizeof(struct ipw2100_bd)),
2944 (u32) txq->drv[i].host_addr,
2945 txq->drv[i].buf_length);
James Ketrenos2c86c272005-03-23 17:32:29 -06002946 }
2947 }
2948#endif
2949
2950 switch (packet->type) {
2951 case DATA:
2952 if (txq->drv[txq->oldest].status.info.fields.txType != 0)
Jiri Benc797b4f72005-08-25 20:03:27 -04002953 printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch. "
James Ketrenos2c86c272005-03-23 17:32:29 -06002954 "Expecting DATA TBD but pulled "
2955 "something else: ids %d=%d.\n",
2956 priv->net_dev->name, txq->oldest, packet->index);
2957
2958 /* DATA packet; we have to unmap and free the SKB */
James Ketrenos2c86c272005-03-23 17:32:29 -06002959 for (i = 0; i < frag_num; i++) {
James Ketrenosee8e3652005-09-14 09:47:29 -05002960 tbd = &txq->drv[(packet->index + 1 + i) % txq->entries];
James Ketrenos2c86c272005-03-23 17:32:29 -06002961
James Ketrenosee8e3652005-09-14 09:47:29 -05002962 IPW_DEBUG_TX("TX%d P=%08x L=%d\n",
2963 (packet->index + 1 + i) % txq->entries,
2964 tbd->host_addr, tbd->buf_length);
James Ketrenos2c86c272005-03-23 17:32:29 -06002965
2966 pci_unmap_single(priv->pci_dev,
2967 tbd->host_addr,
James Ketrenosee8e3652005-09-14 09:47:29 -05002968 tbd->buf_length, PCI_DMA_TODEVICE);
James Ketrenos2c86c272005-03-23 17:32:29 -06002969 }
2970
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002971 libipw_txb_free(packet->info.d_struct.txb);
James Ketrenos2c86c272005-03-23 17:32:29 -06002972 packet->info.d_struct.txb = NULL;
2973
2974 list_add_tail(element, &priv->tx_free_list);
2975 INC_STAT(&priv->tx_free_stat);
2976
2977 /* We have a free slot in the Tx queue, so wake up the
2978 * transmit layer if it is stopped. */
James Ketrenos82328352005-08-24 22:33:31 -05002979 if (priv->status & STATUS_ASSOCIATED)
James Ketrenos2c86c272005-03-23 17:32:29 -06002980 netif_wake_queue(priv->net_dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06002981
2982 /* A packet was processed by the hardware, so update the
2983 * watchdog */
2984 priv->net_dev->trans_start = jiffies;
2985
2986 break;
2987
2988 case COMMAND:
2989 if (txq->drv[txq->oldest].status.info.fields.txType != 1)
Jiri Benc797b4f72005-08-25 20:03:27 -04002990 printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch. "
James Ketrenos2c86c272005-03-23 17:32:29 -06002991 "Expecting COMMAND TBD but pulled "
2992 "something else: ids %d=%d.\n",
2993 priv->net_dev->name, txq->oldest, packet->index);
2994
Brice Goglin0f52bf92005-12-01 01:41:46 -08002995#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06002996 if (packet->info.c_struct.cmd->host_command_reg <
Ahmed S. Darwish22d57432007-02-05 18:56:22 +02002997 ARRAY_SIZE(command_types))
James Ketrenosee8e3652005-09-14 09:47:29 -05002998 IPW_DEBUG_TX("Command '%s (%d)' processed: %d.\n",
2999 command_types[packet->info.c_struct.cmd->
3000 host_command_reg],
3001 packet->info.c_struct.cmd->
3002 host_command_reg,
3003 packet->info.c_struct.cmd->cmd_status_reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06003004#endif
3005
3006 list_add_tail(element, &priv->msg_free_list);
3007 INC_STAT(&priv->msg_free_stat);
3008 break;
3009 }
3010
3011 /* advance oldest used TBD pointer to start of next entry */
3012 txq->oldest = (e + 1) % txq->entries;
3013 /* increase available TBDs number */
3014 txq->available += descriptors_used;
3015 SET_STAT(&priv->txq_stat, txq->available);
3016
3017 IPW_DEBUG_TX("packet latency (send to process) %ld jiffies\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05003018 jiffies - packet->jiffy_start);
James Ketrenos2c86c272005-03-23 17:32:29 -06003019
3020 return (!list_empty(&priv->fw_pend_list));
3021}
3022
James Ketrenos2c86c272005-03-23 17:32:29 -06003023static inline void __ipw2100_tx_complete(struct ipw2100_priv *priv)
3024{
3025 int i = 0;
3026
James Ketrenosee8e3652005-09-14 09:47:29 -05003027 while (__ipw2100_tx_process(priv) && i < 200)
3028 i++;
James Ketrenos2c86c272005-03-23 17:32:29 -06003029
3030 if (i == 200) {
Jiri Benc19f7f742005-08-25 20:02:10 -04003031 printk(KERN_WARNING DRV_NAME ": "
James Ketrenos2c86c272005-03-23 17:32:29 -06003032 "%s: Driver is running slow (%d iters).\n",
3033 priv->net_dev->name, i);
3034 }
3035}
3036
Jiri Benc19f7f742005-08-25 20:02:10 -04003037static void ipw2100_tx_send_commands(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06003038{
3039 struct list_head *element;
3040 struct ipw2100_tx_packet *packet;
3041 struct ipw2100_bd_queue *txq = &priv->tx_queue;
3042 struct ipw2100_bd *tbd;
3043 int next = txq->next;
3044
3045 while (!list_empty(&priv->msg_pend_list)) {
3046 /* if there isn't enough space in TBD queue, then
3047 * don't stuff a new one in.
3048 * NOTE: 3 are needed as a command will take one,
3049 * and there is a minimum of 2 that must be
3050 * maintained between the r and w indexes
3051 */
3052 if (txq->available <= 3) {
3053 IPW_DEBUG_TX("no room in tx_queue\n");
3054 break;
3055 }
3056
3057 element = priv->msg_pend_list.next;
3058 list_del(element);
3059 DEC_STAT(&priv->msg_pend_stat);
3060
James Ketrenosee8e3652005-09-14 09:47:29 -05003061 packet = list_entry(element, struct ipw2100_tx_packet, list);
James Ketrenos2c86c272005-03-23 17:32:29 -06003062
3063 IPW_DEBUG_TX("using TBD at virt=%p, phys=%p\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05003064 &txq->drv[txq->next],
3065 (void *)(txq->nic + txq->next *
3066 sizeof(struct ipw2100_bd)));
James Ketrenos2c86c272005-03-23 17:32:29 -06003067
3068 packet->index = txq->next;
3069
3070 tbd = &txq->drv[txq->next];
3071
3072 /* initialize TBD */
3073 tbd->host_addr = packet->info.c_struct.cmd_phys;
3074 tbd->buf_length = sizeof(struct ipw2100_cmd_header);
3075 /* not marking number of fragments causes problems
3076 * with f/w debug version */
3077 tbd->num_fragments = 1;
3078 tbd->status.info.field =
James Ketrenosee8e3652005-09-14 09:47:29 -05003079 IPW_BD_STATUS_TX_FRAME_COMMAND |
3080 IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
James Ketrenos2c86c272005-03-23 17:32:29 -06003081
3082 /* update TBD queue counters */
3083 txq->next++;
3084 txq->next %= txq->entries;
3085 txq->available--;
3086 DEC_STAT(&priv->txq_stat);
3087
3088 list_add_tail(element, &priv->fw_pend_list);
3089 INC_STAT(&priv->fw_pend_stat);
3090 }
3091
3092 if (txq->next != next) {
3093 /* kick off the DMA by notifying firmware the
3094 * write index has moved; make sure TBD stores are sync'd */
3095 wmb();
3096 write_register(priv->net_dev,
3097 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
3098 txq->next);
3099 }
3100}
3101
James Ketrenos2c86c272005-03-23 17:32:29 -06003102/*
Jiri Benc19f7f742005-08-25 20:02:10 -04003103 * ipw2100_tx_send_data
James Ketrenos2c86c272005-03-23 17:32:29 -06003104 *
3105 */
Jiri Benc19f7f742005-08-25 20:02:10 -04003106static void ipw2100_tx_send_data(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06003107{
3108 struct list_head *element;
3109 struct ipw2100_tx_packet *packet;
3110 struct ipw2100_bd_queue *txq = &priv->tx_queue;
3111 struct ipw2100_bd *tbd;
3112 int next = txq->next;
James Ketrenosee8e3652005-09-14 09:47:29 -05003113 int i = 0;
James Ketrenos2c86c272005-03-23 17:32:29 -06003114 struct ipw2100_data_header *ipw_hdr;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003115 struct libipw_hdr_3addr *hdr;
James Ketrenos2c86c272005-03-23 17:32:29 -06003116
3117 while (!list_empty(&priv->tx_pend_list)) {
3118 /* if there isn't enough space in TBD queue, then
3119 * don't stuff a new one in.
3120 * NOTE: 4 are needed as a data will take two,
3121 * and there is a minimum of 2 that must be
3122 * maintained between the r and w indexes
3123 */
3124 element = priv->tx_pend_list.next;
James Ketrenosee8e3652005-09-14 09:47:29 -05003125 packet = list_entry(element, struct ipw2100_tx_packet, list);
James Ketrenos2c86c272005-03-23 17:32:29 -06003126
3127 if (unlikely(1 + packet->info.d_struct.txb->nr_frags >
3128 IPW_MAX_BDS)) {
3129 /* TODO: Support merging buffers if more than
3130 * IPW_MAX_BDS are used */
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02003131 IPW_DEBUG_INFO("%s: Maximum BD threshold exceeded. "
James Ketrenosee8e3652005-09-14 09:47:29 -05003132 "Increase fragmentation level.\n",
3133 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06003134 }
3135
James Ketrenosee8e3652005-09-14 09:47:29 -05003136 if (txq->available <= 3 + packet->info.d_struct.txb->nr_frags) {
James Ketrenos2c86c272005-03-23 17:32:29 -06003137 IPW_DEBUG_TX("no room in tx_queue\n");
3138 break;
3139 }
3140
3141 list_del(element);
3142 DEC_STAT(&priv->tx_pend_stat);
3143
3144 tbd = &txq->drv[txq->next];
3145
3146 packet->index = txq->next;
3147
3148 ipw_hdr = packet->info.d_struct.data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003149 hdr = (struct libipw_hdr_3addr *)packet->info.d_struct.txb->
James Ketrenosee8e3652005-09-14 09:47:29 -05003150 fragments[0]->data;
James Ketrenos2c86c272005-03-23 17:32:29 -06003151
3152 if (priv->ieee->iw_mode == IW_MODE_INFRA) {
3153 /* To DS: Addr1 = BSSID, Addr2 = SA,
3154 Addr3 = DA */
3155 memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
3156 memcpy(ipw_hdr->dst_addr, hdr->addr3, ETH_ALEN);
3157 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
3158 /* not From/To DS: Addr1 = DA, Addr2 = SA,
3159 Addr3 = BSSID */
3160 memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
3161 memcpy(ipw_hdr->dst_addr, hdr->addr1, ETH_ALEN);
3162 }
3163
3164 ipw_hdr->host_command_reg = SEND;
3165 ipw_hdr->host_command_reg1 = 0;
3166
3167 /* For now we only support host based encryption */
3168 ipw_hdr->needs_encryption = 0;
3169 ipw_hdr->encrypted = packet->info.d_struct.txb->encrypted;
3170 if (packet->info.d_struct.txb->nr_frags > 1)
3171 ipw_hdr->fragment_size =
James Ketrenosee8e3652005-09-14 09:47:29 -05003172 packet->info.d_struct.txb->frag_size -
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003173 LIBIPW_3ADDR_LEN;
James Ketrenos2c86c272005-03-23 17:32:29 -06003174 else
3175 ipw_hdr->fragment_size = 0;
3176
3177 tbd->host_addr = packet->info.d_struct.data_phys;
3178 tbd->buf_length = sizeof(struct ipw2100_data_header);
3179 tbd->num_fragments = 1 + packet->info.d_struct.txb->nr_frags;
3180 tbd->status.info.field =
James Ketrenosee8e3652005-09-14 09:47:29 -05003181 IPW_BD_STATUS_TX_FRAME_802_3 |
3182 IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
James Ketrenos2c86c272005-03-23 17:32:29 -06003183 txq->next++;
3184 txq->next %= txq->entries;
3185
James Ketrenosee8e3652005-09-14 09:47:29 -05003186 IPW_DEBUG_TX("data header tbd TX%d P=%08x L=%d\n",
3187 packet->index, tbd->host_addr, tbd->buf_length);
Brice Goglin0f52bf92005-12-01 01:41:46 -08003188#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06003189 if (packet->info.d_struct.txb->nr_frags > 1)
3190 IPW_DEBUG_FRAG("fragment Tx: %d frames\n",
3191 packet->info.d_struct.txb->nr_frags);
3192#endif
3193
James Ketrenosee8e3652005-09-14 09:47:29 -05003194 for (i = 0; i < packet->info.d_struct.txb->nr_frags; i++) {
3195 tbd = &txq->drv[txq->next];
James Ketrenos2c86c272005-03-23 17:32:29 -06003196 if (i == packet->info.d_struct.txb->nr_frags - 1)
3197 tbd->status.info.field =
James Ketrenosee8e3652005-09-14 09:47:29 -05003198 IPW_BD_STATUS_TX_FRAME_802_3 |
3199 IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
James Ketrenos2c86c272005-03-23 17:32:29 -06003200 else
3201 tbd->status.info.field =
James Ketrenosee8e3652005-09-14 09:47:29 -05003202 IPW_BD_STATUS_TX_FRAME_802_3 |
3203 IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
James Ketrenos2c86c272005-03-23 17:32:29 -06003204
3205 tbd->buf_length = packet->info.d_struct.txb->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003206 fragments[i]->len - LIBIPW_3ADDR_LEN;
James Ketrenos2c86c272005-03-23 17:32:29 -06003207
James Ketrenosee8e3652005-09-14 09:47:29 -05003208 tbd->host_addr = pci_map_single(priv->pci_dev,
3209 packet->info.d_struct.
3210 txb->fragments[i]->
3211 data +
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003212 LIBIPW_3ADDR_LEN,
James Ketrenosee8e3652005-09-14 09:47:29 -05003213 tbd->buf_length,
3214 PCI_DMA_TODEVICE);
James Ketrenos2c86c272005-03-23 17:32:29 -06003215
James Ketrenosee8e3652005-09-14 09:47:29 -05003216 IPW_DEBUG_TX("data frag tbd TX%d P=%08x L=%d\n",
3217 txq->next, tbd->host_addr,
3218 tbd->buf_length);
James Ketrenos2c86c272005-03-23 17:32:29 -06003219
James Ketrenosee8e3652005-09-14 09:47:29 -05003220 pci_dma_sync_single_for_device(priv->pci_dev,
3221 tbd->host_addr,
3222 tbd->buf_length,
3223 PCI_DMA_TODEVICE);
James Ketrenos2c86c272005-03-23 17:32:29 -06003224
3225 txq->next++;
3226 txq->next %= txq->entries;
James Ketrenosee8e3652005-09-14 09:47:29 -05003227 }
James Ketrenos2c86c272005-03-23 17:32:29 -06003228
3229 txq->available -= 1 + packet->info.d_struct.txb->nr_frags;
3230 SET_STAT(&priv->txq_stat, txq->available);
3231
3232 list_add_tail(element, &priv->fw_pend_list);
3233 INC_STAT(&priv->fw_pend_stat);
3234 }
3235
3236 if (txq->next != next) {
3237 /* kick off the DMA by notifying firmware the
3238 * write index has moved; make sure TBD stores are sync'd */
3239 write_register(priv->net_dev,
3240 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
3241 txq->next);
3242 }
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
Frans Pop9fd1ea42010-03-24 19:46:31 +01003288 ": ***** 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 =
Joe Perchesefe4c452010-05-31 20:23:15 -07003470 kmalloc(IPW_COMMAND_POOL_SIZE * sizeof(struct ipw2100_tx_packet),
3471 GFP_KERNEL);
James Ketrenos2c86c272005-03-23 17:32:29 -06003472 if (!priv->msg_buffers) {
Jiri Benc797b4f72005-08-25 20:03:27 -04003473 printk(KERN_ERR DRV_NAME ": %s: PCI alloc failed for msg "
James Ketrenos2c86c272005-03-23 17:32:29 -06003474 "buffers.\n", priv->net_dev->name);
3475 return -ENOMEM;
3476 }
3477
3478 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
James Ketrenosee8e3652005-09-14 09:47:29 -05003479 v = pci_alloc_consistent(priv->pci_dev,
3480 sizeof(struct ipw2100_cmd_header), &p);
James Ketrenos2c86c272005-03-23 17:32:29 -06003481 if (!v) {
Jiri Benc797b4f72005-08-25 20:03:27 -04003482 printk(KERN_ERR DRV_NAME ": "
James Ketrenos2c86c272005-03-23 17:32:29 -06003483 "%s: PCI alloc failed for msg "
James Ketrenosee8e3652005-09-14 09:47:29 -05003484 "buffers.\n", priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06003485 err = -ENOMEM;
3486 break;
3487 }
3488
3489 memset(v, 0, sizeof(struct ipw2100_cmd_header));
3490
3491 priv->msg_buffers[i].type = COMMAND;
3492 priv->msg_buffers[i].info.c_struct.cmd =
James Ketrenosee8e3652005-09-14 09:47:29 -05003493 (struct ipw2100_cmd_header *)v;
James Ketrenos2c86c272005-03-23 17:32:29 -06003494 priv->msg_buffers[i].info.c_struct.cmd_phys = p;
3495 }
3496
3497 if (i == IPW_COMMAND_POOL_SIZE)
3498 return 0;
3499
3500 for (j = 0; j < i; j++) {
James Ketrenosee8e3652005-09-14 09:47:29 -05003501 pci_free_consistent(priv->pci_dev,
3502 sizeof(struct ipw2100_cmd_header),
3503 priv->msg_buffers[j].info.c_struct.cmd,
3504 priv->msg_buffers[j].info.c_struct.
3505 cmd_phys);
James Ketrenos2c86c272005-03-23 17:32:29 -06003506 }
3507
3508 kfree(priv->msg_buffers);
3509 priv->msg_buffers = NULL;
3510
3511 return err;
3512}
3513
3514static int ipw2100_msg_initialize(struct ipw2100_priv *priv)
3515{
3516 int i;
3517
3518 INIT_LIST_HEAD(&priv->msg_free_list);
3519 INIT_LIST_HEAD(&priv->msg_pend_list);
3520
3521 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++)
3522 list_add_tail(&priv->msg_buffers[i].list, &priv->msg_free_list);
3523 SET_STAT(&priv->msg_free_stat, i);
3524
3525 return 0;
3526}
3527
3528static void ipw2100_msg_free(struct ipw2100_priv *priv)
3529{
3530 int i;
3531
3532 if (!priv->msg_buffers)
3533 return;
3534
3535 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
3536 pci_free_consistent(priv->pci_dev,
3537 sizeof(struct ipw2100_cmd_header),
3538 priv->msg_buffers[i].info.c_struct.cmd,
James Ketrenosee8e3652005-09-14 09:47:29 -05003539 priv->msg_buffers[i].info.c_struct.
3540 cmd_phys);
James Ketrenos2c86c272005-03-23 17:32:29 -06003541 }
3542
3543 kfree(priv->msg_buffers);
3544 priv->msg_buffers = NULL;
3545}
3546
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003547static ssize_t show_pci(struct device *d, struct device_attribute *attr,
3548 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003549{
3550 struct pci_dev *pci_dev = container_of(d, struct pci_dev, dev);
3551 char *out = buf;
3552 int i, j;
3553 u32 val;
3554
3555 for (i = 0; i < 16; i++) {
3556 out += sprintf(out, "[%08X] ", i * 16);
3557 for (j = 0; j < 16; j += 4) {
3558 pci_read_config_dword(pci_dev, i * 16 + j, &val);
3559 out += sprintf(out, "%08X ", val);
3560 }
3561 out += sprintf(out, "\n");
3562 }
3563
3564 return out - buf;
3565}
James Ketrenosee8e3652005-09-14 09:47:29 -05003566
James Ketrenos2c86c272005-03-23 17:32:29 -06003567static DEVICE_ATTR(pci, S_IRUGO, show_pci, NULL);
3568
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003569static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
3570 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003571{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003572 struct ipw2100_priv *p = dev_get_drvdata(d);
James Ketrenos2c86c272005-03-23 17:32:29 -06003573 return sprintf(buf, "0x%08x\n", (int)p->config);
3574}
James Ketrenosee8e3652005-09-14 09:47:29 -05003575
James Ketrenos2c86c272005-03-23 17:32:29 -06003576static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
3577
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003578static ssize_t show_status(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05003579 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003580{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003581 struct ipw2100_priv *p = dev_get_drvdata(d);
James Ketrenos2c86c272005-03-23 17:32:29 -06003582 return sprintf(buf, "0x%08x\n", (int)p->status);
3583}
James Ketrenosee8e3652005-09-14 09:47:29 -05003584
James Ketrenos2c86c272005-03-23 17:32:29 -06003585static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
3586
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003587static ssize_t show_capability(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05003588 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003589{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003590 struct ipw2100_priv *p = dev_get_drvdata(d);
James Ketrenos2c86c272005-03-23 17:32:29 -06003591 return sprintf(buf, "0x%08x\n", (int)p->capability);
3592}
James Ketrenos2c86c272005-03-23 17:32:29 -06003593
James Ketrenosee8e3652005-09-14 09:47:29 -05003594static DEVICE_ATTR(capability, S_IRUGO, show_capability, NULL);
James Ketrenos2c86c272005-03-23 17:32:29 -06003595
3596#define IPW2100_REG(x) { IPW_ ##x, #x }
Jiri Bencc4aee8c2005-08-25 20:04:43 -04003597static const struct {
James Ketrenos2c86c272005-03-23 17:32:29 -06003598 u32 addr;
3599 const char *name;
3600} hw_data[] = {
James Ketrenosee8e3652005-09-14 09:47:29 -05003601IPW2100_REG(REG_GP_CNTRL),
3602 IPW2100_REG(REG_GPIO),
3603 IPW2100_REG(REG_INTA),
3604 IPW2100_REG(REG_INTA_MASK), IPW2100_REG(REG_RESET_REG),};
James Ketrenos2c86c272005-03-23 17:32:29 -06003605#define IPW2100_NIC(x, s) { x, #x, s }
Jiri Bencc4aee8c2005-08-25 20:04:43 -04003606static const struct {
James Ketrenos2c86c272005-03-23 17:32:29 -06003607 u32 addr;
3608 const char *name;
3609 size_t size;
3610} nic_data[] = {
James Ketrenosee8e3652005-09-14 09:47:29 -05003611IPW2100_NIC(IPW2100_CONTROL_REG, 2),
3612 IPW2100_NIC(0x210014, 1), IPW2100_NIC(0x210000, 1),};
James Ketrenos2c86c272005-03-23 17:32:29 -06003613#define IPW2100_ORD(x, d) { IPW_ORD_ ##x, #x, d }
Jiri Bencc4aee8c2005-08-25 20:04:43 -04003614static const struct {
James Ketrenos2c86c272005-03-23 17:32:29 -06003615 u8 index;
3616 const char *name;
3617 const char *desc;
3618} ord_data[] = {
James Ketrenosee8e3652005-09-14 09:47:29 -05003619IPW2100_ORD(STAT_TX_HOST_REQUESTS, "requested Host Tx's (MSDU)"),
3620 IPW2100_ORD(STAT_TX_HOST_COMPLETE,
3621 "successful Host Tx's (MSDU)"),
3622 IPW2100_ORD(STAT_TX_DIR_DATA,
3623 "successful Directed Tx's (MSDU)"),
3624 IPW2100_ORD(STAT_TX_DIR_DATA1,
3625 "successful Directed Tx's (MSDU) @ 1MB"),
3626 IPW2100_ORD(STAT_TX_DIR_DATA2,
3627 "successful Directed Tx's (MSDU) @ 2MB"),
3628 IPW2100_ORD(STAT_TX_DIR_DATA5_5,
3629 "successful Directed Tx's (MSDU) @ 5_5MB"),
3630 IPW2100_ORD(STAT_TX_DIR_DATA11,
3631 "successful Directed Tx's (MSDU) @ 11MB"),
3632 IPW2100_ORD(STAT_TX_NODIR_DATA1,
3633 "successful Non_Directed Tx's (MSDU) @ 1MB"),
3634 IPW2100_ORD(STAT_TX_NODIR_DATA2,
3635 "successful Non_Directed Tx's (MSDU) @ 2MB"),
3636 IPW2100_ORD(STAT_TX_NODIR_DATA5_5,
3637 "successful Non_Directed Tx's (MSDU) @ 5.5MB"),
3638 IPW2100_ORD(STAT_TX_NODIR_DATA11,
3639 "successful Non_Directed Tx's (MSDU) @ 11MB"),
3640 IPW2100_ORD(STAT_NULL_DATA, "successful NULL data Tx's"),
3641 IPW2100_ORD(STAT_TX_RTS, "successful Tx RTS"),
3642 IPW2100_ORD(STAT_TX_CTS, "successful Tx CTS"),
3643 IPW2100_ORD(STAT_TX_ACK, "successful Tx ACK"),
3644 IPW2100_ORD(STAT_TX_ASSN, "successful Association Tx's"),
3645 IPW2100_ORD(STAT_TX_ASSN_RESP,
3646 "successful Association response Tx's"),
3647 IPW2100_ORD(STAT_TX_REASSN,
3648 "successful Reassociation Tx's"),
3649 IPW2100_ORD(STAT_TX_REASSN_RESP,
3650 "successful Reassociation response Tx's"),
3651 IPW2100_ORD(STAT_TX_PROBE,
3652 "probes successfully transmitted"),
3653 IPW2100_ORD(STAT_TX_PROBE_RESP,
3654 "probe responses successfully transmitted"),
3655 IPW2100_ORD(STAT_TX_BEACON, "tx beacon"),
3656 IPW2100_ORD(STAT_TX_ATIM, "Tx ATIM"),
3657 IPW2100_ORD(STAT_TX_DISASSN,
3658 "successful Disassociation TX"),
3659 IPW2100_ORD(STAT_TX_AUTH, "successful Authentication Tx"),
3660 IPW2100_ORD(STAT_TX_DEAUTH,
3661 "successful Deauthentication TX"),
3662 IPW2100_ORD(STAT_TX_TOTAL_BYTES,
3663 "Total successful Tx data bytes"),
3664 IPW2100_ORD(STAT_TX_RETRIES, "Tx retries"),
3665 IPW2100_ORD(STAT_TX_RETRY1, "Tx retries at 1MBPS"),
3666 IPW2100_ORD(STAT_TX_RETRY2, "Tx retries at 2MBPS"),
3667 IPW2100_ORD(STAT_TX_RETRY5_5, "Tx retries at 5.5MBPS"),
3668 IPW2100_ORD(STAT_TX_RETRY11, "Tx retries at 11MBPS"),
3669 IPW2100_ORD(STAT_TX_FAILURES, "Tx Failures"),
3670 IPW2100_ORD(STAT_TX_MAX_TRIES_IN_HOP,
3671 "times max tries in a hop failed"),
3672 IPW2100_ORD(STAT_TX_DISASSN_FAIL,
3673 "times disassociation failed"),
3674 IPW2100_ORD(STAT_TX_ERR_CTS, "missed/bad CTS frames"),
3675 IPW2100_ORD(STAT_TX_ERR_ACK, "tx err due to acks"),
3676 IPW2100_ORD(STAT_RX_HOST, "packets passed to host"),
3677 IPW2100_ORD(STAT_RX_DIR_DATA, "directed packets"),
3678 IPW2100_ORD(STAT_RX_DIR_DATA1, "directed packets at 1MB"),
3679 IPW2100_ORD(STAT_RX_DIR_DATA2, "directed packets at 2MB"),
3680 IPW2100_ORD(STAT_RX_DIR_DATA5_5,
3681 "directed packets at 5.5MB"),
3682 IPW2100_ORD(STAT_RX_DIR_DATA11, "directed packets at 11MB"),
3683 IPW2100_ORD(STAT_RX_NODIR_DATA, "nondirected packets"),
3684 IPW2100_ORD(STAT_RX_NODIR_DATA1,
3685 "nondirected packets at 1MB"),
3686 IPW2100_ORD(STAT_RX_NODIR_DATA2,
3687 "nondirected packets at 2MB"),
3688 IPW2100_ORD(STAT_RX_NODIR_DATA5_5,
3689 "nondirected packets at 5.5MB"),
3690 IPW2100_ORD(STAT_RX_NODIR_DATA11,
3691 "nondirected packets at 11MB"),
3692 IPW2100_ORD(STAT_RX_NULL_DATA, "null data rx's"),
3693 IPW2100_ORD(STAT_RX_RTS, "Rx RTS"), IPW2100_ORD(STAT_RX_CTS,
3694 "Rx CTS"),
3695 IPW2100_ORD(STAT_RX_ACK, "Rx ACK"),
3696 IPW2100_ORD(STAT_RX_CFEND, "Rx CF End"),
3697 IPW2100_ORD(STAT_RX_CFEND_ACK, "Rx CF End + CF Ack"),
3698 IPW2100_ORD(STAT_RX_ASSN, "Association Rx's"),
3699 IPW2100_ORD(STAT_RX_ASSN_RESP, "Association response Rx's"),
3700 IPW2100_ORD(STAT_RX_REASSN, "Reassociation Rx's"),
3701 IPW2100_ORD(STAT_RX_REASSN_RESP,
3702 "Reassociation response Rx's"),
3703 IPW2100_ORD(STAT_RX_PROBE, "probe Rx's"),
3704 IPW2100_ORD(STAT_RX_PROBE_RESP, "probe response Rx's"),
3705 IPW2100_ORD(STAT_RX_BEACON, "Rx beacon"),
3706 IPW2100_ORD(STAT_RX_ATIM, "Rx ATIM"),
3707 IPW2100_ORD(STAT_RX_DISASSN, "disassociation Rx"),
3708 IPW2100_ORD(STAT_RX_AUTH, "authentication Rx"),
3709 IPW2100_ORD(STAT_RX_DEAUTH, "deauthentication Rx"),
3710 IPW2100_ORD(STAT_RX_TOTAL_BYTES,
3711 "Total rx data bytes received"),
3712 IPW2100_ORD(STAT_RX_ERR_CRC, "packets with Rx CRC error"),
3713 IPW2100_ORD(STAT_RX_ERR_CRC1, "Rx CRC errors at 1MB"),
3714 IPW2100_ORD(STAT_RX_ERR_CRC2, "Rx CRC errors at 2MB"),
3715 IPW2100_ORD(STAT_RX_ERR_CRC5_5, "Rx CRC errors at 5.5MB"),
3716 IPW2100_ORD(STAT_RX_ERR_CRC11, "Rx CRC errors at 11MB"),
3717 IPW2100_ORD(STAT_RX_DUPLICATE1,
3718 "duplicate rx packets at 1MB"),
3719 IPW2100_ORD(STAT_RX_DUPLICATE2,
3720 "duplicate rx packets at 2MB"),
3721 IPW2100_ORD(STAT_RX_DUPLICATE5_5,
3722 "duplicate rx packets at 5.5MB"),
3723 IPW2100_ORD(STAT_RX_DUPLICATE11,
3724 "duplicate rx packets at 11MB"),
3725 IPW2100_ORD(STAT_RX_DUPLICATE, "duplicate rx packets"),
3726 IPW2100_ORD(PERS_DB_LOCK, "locking fw permanent db"),
3727 IPW2100_ORD(PERS_DB_SIZE, "size of fw permanent db"),
3728 IPW2100_ORD(PERS_DB_ADDR, "address of fw permanent db"),
3729 IPW2100_ORD(STAT_RX_INVALID_PROTOCOL,
3730 "rx frames with invalid protocol"),
3731 IPW2100_ORD(SYS_BOOT_TIME, "Boot time"),
3732 IPW2100_ORD(STAT_RX_NO_BUFFER,
3733 "rx frames rejected due to no buffer"),
3734 IPW2100_ORD(STAT_RX_MISSING_FRAG,
3735 "rx frames dropped due to missing fragment"),
3736 IPW2100_ORD(STAT_RX_ORPHAN_FRAG,
3737 "rx frames dropped due to non-sequential fragment"),
3738 IPW2100_ORD(STAT_RX_ORPHAN_FRAME,
3739 "rx frames dropped due to unmatched 1st frame"),
3740 IPW2100_ORD(STAT_RX_FRAG_AGEOUT,
3741 "rx frames dropped due to uncompleted frame"),
3742 IPW2100_ORD(STAT_RX_ICV_ERRORS,
3743 "ICV errors during decryption"),
3744 IPW2100_ORD(STAT_PSP_SUSPENSION, "times adapter suspended"),
3745 IPW2100_ORD(STAT_PSP_BCN_TIMEOUT, "beacon timeout"),
3746 IPW2100_ORD(STAT_PSP_POLL_TIMEOUT,
3747 "poll response timeouts"),
3748 IPW2100_ORD(STAT_PSP_NONDIR_TIMEOUT,
3749 "timeouts waiting for last {broad,multi}cast pkt"),
3750 IPW2100_ORD(STAT_PSP_RX_DTIMS, "PSP DTIMs received"),
3751 IPW2100_ORD(STAT_PSP_RX_TIMS, "PSP TIMs received"),
3752 IPW2100_ORD(STAT_PSP_STATION_ID, "PSP Station ID"),
3753 IPW2100_ORD(LAST_ASSN_TIME, "RTC time of last association"),
3754 IPW2100_ORD(STAT_PERCENT_MISSED_BCNS,
3755 "current calculation of % missed beacons"),
3756 IPW2100_ORD(STAT_PERCENT_RETRIES,
3757 "current calculation of % missed tx retries"),
3758 IPW2100_ORD(ASSOCIATED_AP_PTR,
3759 "0 if not associated, else pointer to AP table entry"),
3760 IPW2100_ORD(AVAILABLE_AP_CNT,
3761 "AP's decsribed in the AP table"),
3762 IPW2100_ORD(AP_LIST_PTR, "Ptr to list of available APs"),
3763 IPW2100_ORD(STAT_AP_ASSNS, "associations"),
3764 IPW2100_ORD(STAT_ASSN_FAIL, "association failures"),
3765 IPW2100_ORD(STAT_ASSN_RESP_FAIL,
3766 "failures due to response fail"),
3767 IPW2100_ORD(STAT_FULL_SCANS, "full scans"),
3768 IPW2100_ORD(CARD_DISABLED, "Card Disabled"),
3769 IPW2100_ORD(STAT_ROAM_INHIBIT,
3770 "times roaming was inhibited due to activity"),
3771 IPW2100_ORD(RSSI_AT_ASSN,
3772 "RSSI of associated AP at time of association"),
3773 IPW2100_ORD(STAT_ASSN_CAUSE1,
3774 "reassociation: no probe response or TX on hop"),
3775 IPW2100_ORD(STAT_ASSN_CAUSE2,
3776 "reassociation: poor tx/rx quality"),
3777 IPW2100_ORD(STAT_ASSN_CAUSE3,
3778 "reassociation: tx/rx quality (excessive AP load"),
3779 IPW2100_ORD(STAT_ASSN_CAUSE4,
3780 "reassociation: AP RSSI level"),
3781 IPW2100_ORD(STAT_ASSN_CAUSE5,
3782 "reassociations due to load leveling"),
3783 IPW2100_ORD(STAT_AUTH_FAIL, "times authentication failed"),
3784 IPW2100_ORD(STAT_AUTH_RESP_FAIL,
3785 "times authentication response failed"),
3786 IPW2100_ORD(STATION_TABLE_CNT,
3787 "entries in association table"),
3788 IPW2100_ORD(RSSI_AVG_CURR, "Current avg RSSI"),
3789 IPW2100_ORD(POWER_MGMT_MODE, "Power mode - 0=CAM, 1=PSP"),
3790 IPW2100_ORD(COUNTRY_CODE,
3791 "IEEE country code as recv'd from beacon"),
3792 IPW2100_ORD(COUNTRY_CHANNELS,
3793 "channels suported by country"),
3794 IPW2100_ORD(RESET_CNT, "adapter resets (warm)"),
3795 IPW2100_ORD(BEACON_INTERVAL, "Beacon interval"),
3796 IPW2100_ORD(ANTENNA_DIVERSITY,
3797 "TRUE if antenna diversity is disabled"),
3798 IPW2100_ORD(DTIM_PERIOD, "beacon intervals between DTIMs"),
3799 IPW2100_ORD(OUR_FREQ,
3800 "current radio freq lower digits - channel ID"),
3801 IPW2100_ORD(RTC_TIME, "current RTC time"),
3802 IPW2100_ORD(PORT_TYPE, "operating mode"),
3803 IPW2100_ORD(CURRENT_TX_RATE, "current tx rate"),
3804 IPW2100_ORD(SUPPORTED_RATES, "supported tx rates"),
3805 IPW2100_ORD(ATIM_WINDOW, "current ATIM Window"),
3806 IPW2100_ORD(BASIC_RATES, "basic tx rates"),
3807 IPW2100_ORD(NIC_HIGHEST_RATE, "NIC highest tx rate"),
3808 IPW2100_ORD(AP_HIGHEST_RATE, "AP highest tx rate"),
3809 IPW2100_ORD(CAPABILITIES,
3810 "Management frame capability field"),
3811 IPW2100_ORD(AUTH_TYPE, "Type of authentication"),
3812 IPW2100_ORD(RADIO_TYPE, "Adapter card platform type"),
3813 IPW2100_ORD(RTS_THRESHOLD,
3814 "Min packet length for RTS handshaking"),
3815 IPW2100_ORD(INT_MODE, "International mode"),
3816 IPW2100_ORD(FRAGMENTATION_THRESHOLD,
3817 "protocol frag threshold"),
3818 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_START_ADDRESS,
3819 "EEPROM offset in SRAM"),
3820 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_SIZE,
3821 "EEPROM size in SRAM"),
3822 IPW2100_ORD(EEPROM_SKU_CAPABILITY, "EEPROM SKU Capability"),
3823 IPW2100_ORD(EEPROM_IBSS_11B_CHANNELS,
3824 "EEPROM IBSS 11b channel set"),
3825 IPW2100_ORD(MAC_VERSION, "MAC Version"),
3826 IPW2100_ORD(MAC_REVISION, "MAC Revision"),
3827 IPW2100_ORD(RADIO_VERSION, "Radio Version"),
3828 IPW2100_ORD(NIC_MANF_DATE_TIME, "MANF Date/Time STAMP"),
3829 IPW2100_ORD(UCODE_VERSION, "Ucode Version"),};
James Ketrenos2c86c272005-03-23 17:32:29 -06003830
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003831static ssize_t show_registers(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05003832 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003833{
3834 int i;
3835 struct ipw2100_priv *priv = dev_get_drvdata(d);
3836 struct net_device *dev = priv->net_dev;
James Ketrenosee8e3652005-09-14 09:47:29 -05003837 char *out = buf;
James Ketrenos2c86c272005-03-23 17:32:29 -06003838 u32 val = 0;
3839
3840 out += sprintf(out, "%30s [Address ] : Hex\n", "Register");
3841
Ahmed S. Darwish22d57432007-02-05 18:56:22 +02003842 for (i = 0; i < ARRAY_SIZE(hw_data); i++) {
James Ketrenos2c86c272005-03-23 17:32:29 -06003843 read_register(dev, hw_data[i].addr, &val);
3844 out += sprintf(out, "%30s [%08X] : %08X\n",
3845 hw_data[i].name, hw_data[i].addr, val);
3846 }
3847
3848 return out - buf;
3849}
James Ketrenosee8e3652005-09-14 09:47:29 -05003850
James Ketrenos2c86c272005-03-23 17:32:29 -06003851static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL);
3852
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003853static ssize_t show_hardware(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05003854 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003855{
3856 struct ipw2100_priv *priv = dev_get_drvdata(d);
3857 struct net_device *dev = priv->net_dev;
James Ketrenosee8e3652005-09-14 09:47:29 -05003858 char *out = buf;
James Ketrenos2c86c272005-03-23 17:32:29 -06003859 int i;
3860
3861 out += sprintf(out, "%30s [Address ] : Hex\n", "NIC entry");
3862
Ahmed S. Darwish22d57432007-02-05 18:56:22 +02003863 for (i = 0; i < ARRAY_SIZE(nic_data); i++) {
James Ketrenos2c86c272005-03-23 17:32:29 -06003864 u8 tmp8;
3865 u16 tmp16;
3866 u32 tmp32;
3867
3868 switch (nic_data[i].size) {
3869 case 1:
3870 read_nic_byte(dev, nic_data[i].addr, &tmp8);
3871 out += sprintf(out, "%30s [%08X] : %02X\n",
3872 nic_data[i].name, nic_data[i].addr,
3873 tmp8);
3874 break;
3875 case 2:
3876 read_nic_word(dev, nic_data[i].addr, &tmp16);
3877 out += sprintf(out, "%30s [%08X] : %04X\n",
3878 nic_data[i].name, nic_data[i].addr,
3879 tmp16);
3880 break;
3881 case 4:
3882 read_nic_dword(dev, nic_data[i].addr, &tmp32);
3883 out += sprintf(out, "%30s [%08X] : %08X\n",
3884 nic_data[i].name, nic_data[i].addr,
3885 tmp32);
3886 break;
3887 }
3888 }
3889 return out - buf;
3890}
James Ketrenosee8e3652005-09-14 09:47:29 -05003891
James Ketrenos2c86c272005-03-23 17:32:29 -06003892static DEVICE_ATTR(hardware, S_IRUGO, show_hardware, NULL);
3893
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003894static ssize_t show_memory(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05003895 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003896{
3897 struct ipw2100_priv *priv = dev_get_drvdata(d);
3898 struct net_device *dev = priv->net_dev;
3899 static unsigned long loop = 0;
3900 int len = 0;
3901 u32 buffer[4];
3902 int i;
3903 char line[81];
3904
3905 if (loop >= 0x30000)
3906 loop = 0;
3907
3908 /* sysfs provides us PAGE_SIZE buffer */
3909 while (len < PAGE_SIZE - 128 && loop < 0x30000) {
3910
James Ketrenosee8e3652005-09-14 09:47:29 -05003911 if (priv->snapshot[0])
3912 for (i = 0; i < 4; i++)
3913 buffer[i] =
3914 *(u32 *) SNAPSHOT_ADDR(loop + i * 4);
3915 else
3916 for (i = 0; i < 4; i++)
3917 read_nic_dword(dev, loop + i * 4, &buffer[i]);
James Ketrenos2c86c272005-03-23 17:32:29 -06003918
3919 if (priv->dump_raw)
3920 len += sprintf(buf + len,
3921 "%c%c%c%c"
3922 "%c%c%c%c"
3923 "%c%c%c%c"
3924 "%c%c%c%c",
James Ketrenosee8e3652005-09-14 09:47:29 -05003925 ((u8 *) buffer)[0x0],
3926 ((u8 *) buffer)[0x1],
3927 ((u8 *) buffer)[0x2],
3928 ((u8 *) buffer)[0x3],
3929 ((u8 *) buffer)[0x4],
3930 ((u8 *) buffer)[0x5],
3931 ((u8 *) buffer)[0x6],
3932 ((u8 *) buffer)[0x7],
3933 ((u8 *) buffer)[0x8],
3934 ((u8 *) buffer)[0x9],
3935 ((u8 *) buffer)[0xa],
3936 ((u8 *) buffer)[0xb],
3937 ((u8 *) buffer)[0xc],
3938 ((u8 *) buffer)[0xd],
3939 ((u8 *) buffer)[0xe],
3940 ((u8 *) buffer)[0xf]);
James Ketrenos2c86c272005-03-23 17:32:29 -06003941 else
3942 len += sprintf(buf + len, "%s\n",
3943 snprint_line(line, sizeof(line),
James Ketrenosee8e3652005-09-14 09:47:29 -05003944 (u8 *) buffer, 16, loop));
James Ketrenos2c86c272005-03-23 17:32:29 -06003945 loop += 16;
3946 }
3947
3948 return len;
3949}
3950
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003951static ssize_t store_memory(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05003952 const char *buf, size_t count)
James Ketrenos2c86c272005-03-23 17:32:29 -06003953{
3954 struct ipw2100_priv *priv = dev_get_drvdata(d);
3955 struct net_device *dev = priv->net_dev;
3956 const char *p = buf;
3957
Zhu Yi8ed55a42006-01-24 13:49:20 +08003958 (void)dev; /* kill unused-var warning for debug-only code */
Jeff Garzikc2a8fad2005-11-09 00:49:38 -05003959
James Ketrenos2c86c272005-03-23 17:32:29 -06003960 if (count < 1)
3961 return count;
3962
3963 if (p[0] == '1' ||
3964 (count >= 2 && tolower(p[0]) == 'o' && tolower(p[1]) == 'n')) {
3965 IPW_DEBUG_INFO("%s: Setting memory dump to RAW mode.\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05003966 dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06003967 priv->dump_raw = 1;
3968
3969 } else if (p[0] == '0' || (count >= 2 && tolower(p[0]) == 'o' &&
James Ketrenosee8e3652005-09-14 09:47:29 -05003970 tolower(p[1]) == 'f')) {
James Ketrenos2c86c272005-03-23 17:32:29 -06003971 IPW_DEBUG_INFO("%s: Setting memory dump to HEX mode.\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05003972 dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06003973 priv->dump_raw = 0;
3974
3975 } else if (tolower(p[0]) == 'r') {
James Ketrenosee8e3652005-09-14 09:47:29 -05003976 IPW_DEBUG_INFO("%s: Resetting firmware snapshot.\n", dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06003977 ipw2100_snapshot_free(priv);
3978
3979 } else
3980 IPW_DEBUG_INFO("%s: Usage: 0|on = HEX, 1|off = RAW, "
James Ketrenosee8e3652005-09-14 09:47:29 -05003981 "reset = clear memory snapshot\n", dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06003982
3983 return count;
3984}
James Ketrenos2c86c272005-03-23 17:32:29 -06003985
James Ketrenosee8e3652005-09-14 09:47:29 -05003986static DEVICE_ATTR(memory, S_IWUSR | S_IRUGO, show_memory, store_memory);
James Ketrenos2c86c272005-03-23 17:32:29 -06003987
Andrew Mortonedfc43f2005-06-20 14:30:35 -07003988static ssize_t show_ordinals(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05003989 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06003990{
3991 struct ipw2100_priv *priv = dev_get_drvdata(d);
3992 u32 val = 0;
3993 int len = 0;
3994 u32 val_len;
3995 static int loop = 0;
3996
James Ketrenos82328352005-08-24 22:33:31 -05003997 if (priv->status & STATUS_RF_KILL_MASK)
3998 return 0;
3999
Ahmed S. Darwish22d57432007-02-05 18:56:22 +02004000 if (loop >= ARRAY_SIZE(ord_data))
James Ketrenos2c86c272005-03-23 17:32:29 -06004001 loop = 0;
4002
4003 /* sysfs provides us PAGE_SIZE buffer */
Ahmed S. Darwish22d57432007-02-05 18:56:22 +02004004 while (len < PAGE_SIZE - 128 && loop < ARRAY_SIZE(ord_data)) {
James Ketrenos2c86c272005-03-23 17:32:29 -06004005 val_len = sizeof(u32);
4006
4007 if (ipw2100_get_ordinal(priv, ord_data[loop].index, &val,
4008 &val_len))
4009 len += sprintf(buf + len, "[0x%02X] = ERROR %s\n",
4010 ord_data[loop].index,
4011 ord_data[loop].desc);
4012 else
4013 len += sprintf(buf + len, "[0x%02X] = 0x%08X %s\n",
4014 ord_data[loop].index, val,
4015 ord_data[loop].desc);
4016 loop++;
4017 }
4018
4019 return len;
4020}
James Ketrenosee8e3652005-09-14 09:47:29 -05004021
James Ketrenos2c86c272005-03-23 17:32:29 -06004022static DEVICE_ATTR(ordinals, S_IRUGO, show_ordinals, NULL);
4023
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004024static ssize_t show_stats(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05004025 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06004026{
4027 struct ipw2100_priv *priv = dev_get_drvdata(d);
James Ketrenosee8e3652005-09-14 09:47:29 -05004028 char *out = buf;
James Ketrenos2c86c272005-03-23 17:32:29 -06004029
4030 out += sprintf(out, "interrupts: %d {tx: %d, rx: %d, other: %d}\n",
4031 priv->interrupts, priv->tx_interrupts,
4032 priv->rx_interrupts, priv->inta_other);
4033 out += sprintf(out, "firmware resets: %d\n", priv->resets);
4034 out += sprintf(out, "firmware hangs: %d\n", priv->hangs);
Brice Goglin0f52bf92005-12-01 01:41:46 -08004035#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06004036 out += sprintf(out, "packet mismatch image: %s\n",
4037 priv->snapshot[0] ? "YES" : "NO");
4038#endif
4039
4040 return out - buf;
4041}
James Ketrenos2c86c272005-03-23 17:32:29 -06004042
James Ketrenosee8e3652005-09-14 09:47:29 -05004043static DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
James Ketrenos2c86c272005-03-23 17:32:29 -06004044
Jiri Bencc4aee8c2005-08-25 20:04:43 -04004045static int ipw2100_switch_mode(struct ipw2100_priv *priv, u32 mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06004046{
4047 int err;
4048
4049 if (mode == priv->ieee->iw_mode)
4050 return 0;
4051
4052 err = ipw2100_disable_adapter(priv);
4053 if (err) {
Jiri Benc797b4f72005-08-25 20:03:27 -04004054 printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06004055 priv->net_dev->name, err);
4056 return err;
4057 }
4058
4059 switch (mode) {
4060 case IW_MODE_INFRA:
4061 priv->net_dev->type = ARPHRD_ETHER;
4062 break;
4063 case IW_MODE_ADHOC:
4064 priv->net_dev->type = ARPHRD_ETHER;
4065 break;
4066#ifdef CONFIG_IPW2100_MONITOR
4067 case IW_MODE_MONITOR:
4068 priv->last_mode = priv->ieee->iw_mode;
Stefan Rompf15745a72006-02-21 18:36:17 +08004069 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
James Ketrenos2c86c272005-03-23 17:32:29 -06004070 break;
James Ketrenosee8e3652005-09-14 09:47:29 -05004071#endif /* CONFIG_IPW2100_MONITOR */
James Ketrenos2c86c272005-03-23 17:32:29 -06004072 }
4073
4074 priv->ieee->iw_mode = mode;
4075
4076#ifdef CONFIG_PM
James Ketrenosee8e3652005-09-14 09:47:29 -05004077 /* Indicate ipw2100_download_firmware download firmware
James Ketrenos2c86c272005-03-23 17:32:29 -06004078 * from disk instead of memory. */
4079 ipw2100_firmware.version = 0;
4080#endif
4081
James Ketrenosee8e3652005-09-14 09:47:29 -05004082 printk(KERN_INFO "%s: Reseting on mode change.\n", priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06004083 priv->reset_backoff = 0;
4084 schedule_reset(priv);
4085
4086 return 0;
4087}
4088
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004089static ssize_t show_internals(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05004090 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06004091{
4092 struct ipw2100_priv *priv = dev_get_drvdata(d);
4093 int len = 0;
4094
James Ketrenosee8e3652005-09-14 09:47:29 -05004095#define DUMP_VAR(x,y) len += sprintf(buf + len, # x ": %" y "\n", priv-> x)
James Ketrenos2c86c272005-03-23 17:32:29 -06004096
4097 if (priv->status & STATUS_ASSOCIATED)
4098 len += sprintf(buf + len, "connected: %lu\n",
4099 get_seconds() - priv->connect_start);
4100 else
4101 len += sprintf(buf + len, "not connected\n");
4102
John W. Linville274bfb82008-10-29 11:35:05 -04004103 DUMP_VAR(ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx], "p");
James Ketrenosee8e3652005-09-14 09:47:29 -05004104 DUMP_VAR(status, "08lx");
4105 DUMP_VAR(config, "08lx");
4106 DUMP_VAR(capability, "08lx");
James Ketrenos2c86c272005-03-23 17:32:29 -06004107
James Ketrenosee8e3652005-09-14 09:47:29 -05004108 len +=
4109 sprintf(buf + len, "last_rtc: %lu\n",
4110 (unsigned long)priv->last_rtc);
James Ketrenos2c86c272005-03-23 17:32:29 -06004111
James Ketrenosee8e3652005-09-14 09:47:29 -05004112 DUMP_VAR(fatal_error, "d");
4113 DUMP_VAR(stop_hang_check, "d");
4114 DUMP_VAR(stop_rf_kill, "d");
4115 DUMP_VAR(messages_sent, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004116
James Ketrenosee8e3652005-09-14 09:47:29 -05004117 DUMP_VAR(tx_pend_stat.value, "d");
4118 DUMP_VAR(tx_pend_stat.hi, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004119
James Ketrenosee8e3652005-09-14 09:47:29 -05004120 DUMP_VAR(tx_free_stat.value, "d");
4121 DUMP_VAR(tx_free_stat.lo, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004122
James Ketrenosee8e3652005-09-14 09:47:29 -05004123 DUMP_VAR(msg_free_stat.value, "d");
4124 DUMP_VAR(msg_free_stat.lo, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004125
James Ketrenosee8e3652005-09-14 09:47:29 -05004126 DUMP_VAR(msg_pend_stat.value, "d");
4127 DUMP_VAR(msg_pend_stat.hi, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004128
James Ketrenosee8e3652005-09-14 09:47:29 -05004129 DUMP_VAR(fw_pend_stat.value, "d");
4130 DUMP_VAR(fw_pend_stat.hi, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004131
James Ketrenosee8e3652005-09-14 09:47:29 -05004132 DUMP_VAR(txq_stat.value, "d");
4133 DUMP_VAR(txq_stat.lo, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004134
James Ketrenosee8e3652005-09-14 09:47:29 -05004135 DUMP_VAR(ieee->scans, "d");
4136 DUMP_VAR(reset_backoff, "d");
James Ketrenos2c86c272005-03-23 17:32:29 -06004137
4138 return len;
4139}
James Ketrenosee8e3652005-09-14 09:47:29 -05004140
James Ketrenos2c86c272005-03-23 17:32:29 -06004141static DEVICE_ATTR(internals, S_IRUGO, show_internals, NULL);
4142
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004143static ssize_t show_bssinfo(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05004144 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06004145{
4146 struct ipw2100_priv *priv = dev_get_drvdata(d);
4147 char essid[IW_ESSID_MAX_SIZE + 1];
4148 u8 bssid[ETH_ALEN];
4149 u32 chan = 0;
James Ketrenosee8e3652005-09-14 09:47:29 -05004150 char *out = buf;
Hannes Ederb9da9e92009-02-14 11:50:26 +00004151 unsigned int length;
James Ketrenos2c86c272005-03-23 17:32:29 -06004152 int ret;
4153
James Ketrenos82328352005-08-24 22:33:31 -05004154 if (priv->status & STATUS_RF_KILL_MASK)
4155 return 0;
4156
James Ketrenos2c86c272005-03-23 17:32:29 -06004157 memset(essid, 0, sizeof(essid));
4158 memset(bssid, 0, sizeof(bssid));
4159
4160 length = IW_ESSID_MAX_SIZE;
4161 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID, essid, &length);
4162 if (ret)
4163 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4164 __LINE__);
4165
4166 length = sizeof(bssid);
4167 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
4168 bssid, &length);
4169 if (ret)
4170 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4171 __LINE__);
4172
4173 length = sizeof(u32);
4174 ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &length);
4175 if (ret)
4176 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4177 __LINE__);
4178
4179 out += sprintf(out, "ESSID: %s\n", essid);
Johannes Berge1749612008-10-27 15:59:26 -07004180 out += sprintf(out, "BSSID: %pM\n", bssid);
James Ketrenos2c86c272005-03-23 17:32:29 -06004181 out += sprintf(out, "Channel: %d\n", chan);
4182
4183 return out - buf;
4184}
James Ketrenos2c86c272005-03-23 17:32:29 -06004185
James Ketrenosee8e3652005-09-14 09:47:29 -05004186static DEVICE_ATTR(bssinfo, S_IRUGO, show_bssinfo, NULL);
James Ketrenos2c86c272005-03-23 17:32:29 -06004187
Brice Goglin0f52bf92005-12-01 01:41:46 -08004188#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06004189static ssize_t show_debug_level(struct device_driver *d, char *buf)
4190{
4191 return sprintf(buf, "0x%08X\n", ipw2100_debug_level);
4192}
4193
James Ketrenos82328352005-08-24 22:33:31 -05004194static ssize_t store_debug_level(struct device_driver *d,
4195 const char *buf, size_t count)
James Ketrenos2c86c272005-03-23 17:32:29 -06004196{
4197 char *p = (char *)buf;
4198 u32 val;
4199
4200 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
4201 p++;
4202 if (p[0] == 'x' || p[0] == 'X')
4203 p++;
4204 val = simple_strtoul(p, &p, 16);
4205 } else
4206 val = simple_strtoul(p, &p, 10);
4207 if (p == buf)
Zhu Yia1e695a2005-07-04 14:06:00 +08004208 IPW_DEBUG_INFO(": %s is not in hex or decimal form.\n", buf);
James Ketrenos2c86c272005-03-23 17:32:29 -06004209 else
4210 ipw2100_debug_level = val;
4211
4212 return strnlen(buf, count);
4213}
James Ketrenosee8e3652005-09-14 09:47:29 -05004214
James Ketrenos2c86c272005-03-23 17:32:29 -06004215static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, show_debug_level,
4216 store_debug_level);
Brice Goglin0f52bf92005-12-01 01:41:46 -08004217#endif /* CONFIG_IPW2100_DEBUG */
James Ketrenos2c86c272005-03-23 17:32:29 -06004218
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004219static ssize_t show_fatal_error(struct device *d,
James Ketrenosee8e3652005-09-14 09:47:29 -05004220 struct device_attribute *attr, char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06004221{
4222 struct ipw2100_priv *priv = dev_get_drvdata(d);
4223 char *out = buf;
4224 int i;
4225
4226 if (priv->fatal_error)
James Ketrenosee8e3652005-09-14 09:47:29 -05004227 out += sprintf(out, "0x%08X\n", priv->fatal_error);
James Ketrenos2c86c272005-03-23 17:32:29 -06004228 else
4229 out += sprintf(out, "0\n");
4230
4231 for (i = 1; i <= IPW2100_ERROR_QUEUE; i++) {
4232 if (!priv->fatal_errors[(priv->fatal_index - i) %
4233 IPW2100_ERROR_QUEUE])
4234 continue;
4235
4236 out += sprintf(out, "%d. 0x%08X\n", i,
4237 priv->fatal_errors[(priv->fatal_index - i) %
4238 IPW2100_ERROR_QUEUE]);
4239 }
4240
4241 return out - buf;
4242}
4243
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004244static ssize_t store_fatal_error(struct device *d,
James Ketrenosee8e3652005-09-14 09:47:29 -05004245 struct device_attribute *attr, const char *buf,
4246 size_t count)
James Ketrenos2c86c272005-03-23 17:32:29 -06004247{
4248 struct ipw2100_priv *priv = dev_get_drvdata(d);
4249 schedule_reset(priv);
4250 return count;
4251}
James Ketrenos2c86c272005-03-23 17:32:29 -06004252
James Ketrenosee8e3652005-09-14 09:47:29 -05004253static DEVICE_ATTR(fatal_error, S_IWUSR | S_IRUGO, show_fatal_error,
4254 store_fatal_error);
James Ketrenos2c86c272005-03-23 17:32:29 -06004255
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004256static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05004257 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06004258{
4259 struct ipw2100_priv *priv = dev_get_drvdata(d);
4260 return sprintf(buf, "%d\n", priv->ieee->scan_age);
4261}
4262
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004263static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05004264 const char *buf, size_t count)
James Ketrenos2c86c272005-03-23 17:32:29 -06004265{
4266 struct ipw2100_priv *priv = dev_get_drvdata(d);
4267 struct net_device *dev = priv->net_dev;
4268 char buffer[] = "00000000";
4269 unsigned long len =
4270 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
4271 unsigned long val;
4272 char *p = buffer;
4273
Zhu Yi8ed55a42006-01-24 13:49:20 +08004274 (void)dev; /* kill unused-var warning for debug-only code */
Jeff Garzikc2a8fad2005-11-09 00:49:38 -05004275
James Ketrenos2c86c272005-03-23 17:32:29 -06004276 IPW_DEBUG_INFO("enter\n");
4277
4278 strncpy(buffer, buf, len);
4279 buffer[len] = 0;
4280
4281 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
4282 p++;
4283 if (p[0] == 'x' || p[0] == 'X')
4284 p++;
4285 val = simple_strtoul(p, &p, 16);
4286 } else
4287 val = simple_strtoul(p, &p, 10);
4288 if (p == buffer) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004289 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06004290 } else {
4291 priv->ieee->scan_age = val;
4292 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
4293 }
4294
4295 IPW_DEBUG_INFO("exit\n");
4296 return len;
4297}
James Ketrenosee8e3652005-09-14 09:47:29 -05004298
James Ketrenos2c86c272005-03-23 17:32:29 -06004299static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
4300
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004301static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05004302 char *buf)
James Ketrenos2c86c272005-03-23 17:32:29 -06004303{
4304 /* 0 - RF kill not enabled
4305 1 - SW based RF kill active (sysfs)
4306 2 - HW based RF kill active
4307 3 - Both HW and SW baed RF kill active */
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07004308 struct ipw2100_priv *priv = dev_get_drvdata(d);
James Ketrenos2c86c272005-03-23 17:32:29 -06004309 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
James Ketrenosee8e3652005-09-14 09:47:29 -05004310 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos2c86c272005-03-23 17:32:29 -06004311 return sprintf(buf, "%i\n", val);
4312}
4313
4314static int ipw_radio_kill_sw(struct ipw2100_priv *priv, int disable_radio)
4315{
4316 if ((disable_radio ? 1 : 0) ==
4317 (priv->status & STATUS_RF_KILL_SW ? 1 : 0))
James Ketrenosee8e3652005-09-14 09:47:29 -05004318 return 0;
James Ketrenos2c86c272005-03-23 17:32:29 -06004319
4320 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
4321 disable_radio ? "OFF" : "ON");
4322
Ingo Molnar752e3772006-02-28 07:20:54 +08004323 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06004324
4325 if (disable_radio) {
4326 priv->status |= STATUS_RF_KILL_SW;
4327 ipw2100_down(priv);
4328 } else {
4329 priv->status &= ~STATUS_RF_KILL_SW;
4330 if (rf_kill_active(priv)) {
4331 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
4332 "disabled by HW switch\n");
4333 /* Make sure the RF_KILL check timer is running */
4334 priv->stop_rf_kill = 0;
4335 cancel_delayed_work(&priv->rf_kill);
Stephen Hemmingera62056f2007-06-22 21:46:50 -07004336 queue_delayed_work(priv->workqueue, &priv->rf_kill,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05004337 round_jiffies_relative(HZ));
James Ketrenos2c86c272005-03-23 17:32:29 -06004338 } else
4339 schedule_reset(priv);
4340 }
4341
Ingo Molnar752e3772006-02-28 07:20:54 +08004342 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06004343 return 1;
4344}
4345
Andrew Mortonedfc43f2005-06-20 14:30:35 -07004346static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
James Ketrenosee8e3652005-09-14 09:47:29 -05004347 const char *buf, size_t count)
James Ketrenos2c86c272005-03-23 17:32:29 -06004348{
4349 struct ipw2100_priv *priv = dev_get_drvdata(d);
4350 ipw_radio_kill_sw(priv, buf[0] == '1');
4351 return count;
4352}
James Ketrenos2c86c272005-03-23 17:32:29 -06004353
James Ketrenosee8e3652005-09-14 09:47:29 -05004354static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos2c86c272005-03-23 17:32:29 -06004355
4356static struct attribute *ipw2100_sysfs_entries[] = {
4357 &dev_attr_hardware.attr,
4358 &dev_attr_registers.attr,
4359 &dev_attr_ordinals.attr,
4360 &dev_attr_pci.attr,
4361 &dev_attr_stats.attr,
4362 &dev_attr_internals.attr,
4363 &dev_attr_bssinfo.attr,
4364 &dev_attr_memory.attr,
4365 &dev_attr_scan_age.attr,
4366 &dev_attr_fatal_error.attr,
4367 &dev_attr_rf_kill.attr,
4368 &dev_attr_cfg.attr,
4369 &dev_attr_status.attr,
4370 &dev_attr_capability.attr,
4371 NULL,
4372};
4373
4374static struct attribute_group ipw2100_attribute_group = {
4375 .attrs = ipw2100_sysfs_entries,
4376};
4377
James Ketrenos2c86c272005-03-23 17:32:29 -06004378static int status_queue_allocate(struct ipw2100_priv *priv, int entries)
4379{
4380 struct ipw2100_status_queue *q = &priv->status_queue;
4381
4382 IPW_DEBUG_INFO("enter\n");
4383
4384 q->size = entries * sizeof(struct ipw2100_status);
James Ketrenosee8e3652005-09-14 09:47:29 -05004385 q->drv =
4386 (struct ipw2100_status *)pci_alloc_consistent(priv->pci_dev,
4387 q->size, &q->nic);
James Ketrenos2c86c272005-03-23 17:32:29 -06004388 if (!q->drv) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004389 IPW_DEBUG_WARNING("Can not allocate status queue.\n");
James Ketrenos2c86c272005-03-23 17:32:29 -06004390 return -ENOMEM;
4391 }
4392
4393 memset(q->drv, 0, q->size);
4394
4395 IPW_DEBUG_INFO("exit\n");
4396
4397 return 0;
4398}
4399
4400static void status_queue_free(struct ipw2100_priv *priv)
4401{
4402 IPW_DEBUG_INFO("enter\n");
4403
4404 if (priv->status_queue.drv) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004405 pci_free_consistent(priv->pci_dev, priv->status_queue.size,
4406 priv->status_queue.drv,
4407 priv->status_queue.nic);
James Ketrenos2c86c272005-03-23 17:32:29 -06004408 priv->status_queue.drv = NULL;
4409 }
4410
4411 IPW_DEBUG_INFO("exit\n");
4412}
4413
4414static int bd_queue_allocate(struct ipw2100_priv *priv,
4415 struct ipw2100_bd_queue *q, int entries)
4416{
4417 IPW_DEBUG_INFO("enter\n");
4418
4419 memset(q, 0, sizeof(struct ipw2100_bd_queue));
4420
4421 q->entries = entries;
4422 q->size = entries * sizeof(struct ipw2100_bd);
4423 q->drv = pci_alloc_consistent(priv->pci_dev, q->size, &q->nic);
4424 if (!q->drv) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004425 IPW_DEBUG_INFO
4426 ("can't allocate shared memory for buffer descriptors\n");
James Ketrenos2c86c272005-03-23 17:32:29 -06004427 return -ENOMEM;
4428 }
4429 memset(q->drv, 0, q->size);
4430
4431 IPW_DEBUG_INFO("exit\n");
4432
4433 return 0;
4434}
4435
James Ketrenosee8e3652005-09-14 09:47:29 -05004436static void bd_queue_free(struct ipw2100_priv *priv, struct ipw2100_bd_queue *q)
James Ketrenos2c86c272005-03-23 17:32:29 -06004437{
4438 IPW_DEBUG_INFO("enter\n");
4439
4440 if (!q)
4441 return;
4442
4443 if (q->drv) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004444 pci_free_consistent(priv->pci_dev, q->size, q->drv, q->nic);
James Ketrenos2c86c272005-03-23 17:32:29 -06004445 q->drv = NULL;
4446 }
4447
4448 IPW_DEBUG_INFO("exit\n");
4449}
4450
James Ketrenosee8e3652005-09-14 09:47:29 -05004451static void bd_queue_initialize(struct ipw2100_priv *priv,
4452 struct ipw2100_bd_queue *q, u32 base, u32 size,
4453 u32 r, u32 w)
James Ketrenos2c86c272005-03-23 17:32:29 -06004454{
4455 IPW_DEBUG_INFO("enter\n");
4456
James Ketrenosee8e3652005-09-14 09:47:29 -05004457 IPW_DEBUG_INFO("initializing bd queue at virt=%p, phys=%08x\n", q->drv,
4458 (u32) q->nic);
James Ketrenos2c86c272005-03-23 17:32:29 -06004459
4460 write_register(priv->net_dev, base, q->nic);
4461 write_register(priv->net_dev, size, q->entries);
4462 write_register(priv->net_dev, r, q->oldest);
4463 write_register(priv->net_dev, w, q->next);
4464
4465 IPW_DEBUG_INFO("exit\n");
4466}
4467
4468static void ipw2100_kill_workqueue(struct ipw2100_priv *priv)
4469{
4470 if (priv->workqueue) {
4471 priv->stop_rf_kill = 1;
4472 priv->stop_hang_check = 1;
4473 cancel_delayed_work(&priv->reset_work);
4474 cancel_delayed_work(&priv->security_work);
4475 cancel_delayed_work(&priv->wx_event_work);
4476 cancel_delayed_work(&priv->hang_check);
4477 cancel_delayed_work(&priv->rf_kill);
Dan Williamsd20c6782007-10-10 12:28:07 -04004478 cancel_delayed_work(&priv->scan_event_later);
James Ketrenos2c86c272005-03-23 17:32:29 -06004479 destroy_workqueue(priv->workqueue);
4480 priv->workqueue = NULL;
4481 }
4482}
4483
4484static int ipw2100_tx_allocate(struct ipw2100_priv *priv)
4485{
4486 int i, j, err = -EINVAL;
4487 void *v;
4488 dma_addr_t p;
4489
4490 IPW_DEBUG_INFO("enter\n");
4491
4492 err = bd_queue_allocate(priv, &priv->tx_queue, TX_QUEUE_LENGTH);
4493 if (err) {
4494 IPW_DEBUG_ERROR("%s: failed bd_queue_allocate\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05004495 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06004496 return err;
4497 }
4498
James Ketrenosee8e3652005-09-14 09:47:29 -05004499 priv->tx_buffers =
Joe Perchesefe4c452010-05-31 20:23:15 -07004500 kmalloc(TX_PENDED_QUEUE_LENGTH * sizeof(struct ipw2100_tx_packet),
4501 GFP_ATOMIC);
James Ketrenos2c86c272005-03-23 17:32:29 -06004502 if (!priv->tx_buffers) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004503 printk(KERN_ERR DRV_NAME
4504 ": %s: alloc failed form tx buffers.\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06004505 priv->net_dev->name);
4506 bd_queue_free(priv, &priv->tx_queue);
4507 return -ENOMEM;
4508 }
4509
4510 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004511 v = pci_alloc_consistent(priv->pci_dev,
4512 sizeof(struct ipw2100_data_header),
4513 &p);
James Ketrenos2c86c272005-03-23 17:32:29 -06004514 if (!v) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004515 printk(KERN_ERR DRV_NAME
4516 ": %s: PCI alloc failed for tx " "buffers.\n",
4517 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06004518 err = -ENOMEM;
4519 break;
4520 }
4521
4522 priv->tx_buffers[i].type = DATA;
James Ketrenosee8e3652005-09-14 09:47:29 -05004523 priv->tx_buffers[i].info.d_struct.data =
4524 (struct ipw2100_data_header *)v;
James Ketrenos2c86c272005-03-23 17:32:29 -06004525 priv->tx_buffers[i].info.d_struct.data_phys = p;
4526 priv->tx_buffers[i].info.d_struct.txb = NULL;
4527 }
4528
4529 if (i == TX_PENDED_QUEUE_LENGTH)
4530 return 0;
4531
4532 for (j = 0; j < i; j++) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004533 pci_free_consistent(priv->pci_dev,
4534 sizeof(struct ipw2100_data_header),
4535 priv->tx_buffers[j].info.d_struct.data,
4536 priv->tx_buffers[j].info.d_struct.
4537 data_phys);
James Ketrenos2c86c272005-03-23 17:32:29 -06004538 }
4539
4540 kfree(priv->tx_buffers);
4541 priv->tx_buffers = NULL;
4542
4543 return err;
4544}
4545
4546static void ipw2100_tx_initialize(struct ipw2100_priv *priv)
4547{
4548 int i;
4549
4550 IPW_DEBUG_INFO("enter\n");
4551
4552 /*
4553 * reinitialize packet info lists
4554 */
4555 INIT_LIST_HEAD(&priv->fw_pend_list);
4556 INIT_STAT(&priv->fw_pend_stat);
4557
4558 /*
4559 * reinitialize lists
4560 */
4561 INIT_LIST_HEAD(&priv->tx_pend_list);
4562 INIT_LIST_HEAD(&priv->tx_free_list);
4563 INIT_STAT(&priv->tx_pend_stat);
4564 INIT_STAT(&priv->tx_free_stat);
4565
4566 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4567 /* We simply drop any SKBs that have been queued for
4568 * transmit */
4569 if (priv->tx_buffers[i].info.d_struct.txb) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004570 libipw_txb_free(priv->tx_buffers[i].info.d_struct.
James Ketrenosee8e3652005-09-14 09:47:29 -05004571 txb);
James Ketrenos2c86c272005-03-23 17:32:29 -06004572 priv->tx_buffers[i].info.d_struct.txb = NULL;
4573 }
4574
4575 list_add_tail(&priv->tx_buffers[i].list, &priv->tx_free_list);
4576 }
4577
4578 SET_STAT(&priv->tx_free_stat, i);
4579
4580 priv->tx_queue.oldest = 0;
4581 priv->tx_queue.available = priv->tx_queue.entries;
4582 priv->tx_queue.next = 0;
4583 INIT_STAT(&priv->txq_stat);
4584 SET_STAT(&priv->txq_stat, priv->tx_queue.available);
4585
4586 bd_queue_initialize(priv, &priv->tx_queue,
4587 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_BASE,
4588 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_SIZE,
4589 IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
4590 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX);
4591
4592 IPW_DEBUG_INFO("exit\n");
4593
4594}
4595
4596static void ipw2100_tx_free(struct ipw2100_priv *priv)
4597{
4598 int i;
4599
4600 IPW_DEBUG_INFO("enter\n");
4601
4602 bd_queue_free(priv, &priv->tx_queue);
4603
4604 if (!priv->tx_buffers)
4605 return;
4606
4607 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4608 if (priv->tx_buffers[i].info.d_struct.txb) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004609 libipw_txb_free(priv->tx_buffers[i].info.d_struct.
James Ketrenosee8e3652005-09-14 09:47:29 -05004610 txb);
James Ketrenos2c86c272005-03-23 17:32:29 -06004611 priv->tx_buffers[i].info.d_struct.txb = NULL;
4612 }
4613 if (priv->tx_buffers[i].info.d_struct.data)
James Ketrenosee8e3652005-09-14 09:47:29 -05004614 pci_free_consistent(priv->pci_dev,
4615 sizeof(struct ipw2100_data_header),
4616 priv->tx_buffers[i].info.d_struct.
4617 data,
4618 priv->tx_buffers[i].info.d_struct.
4619 data_phys);
James Ketrenos2c86c272005-03-23 17:32:29 -06004620 }
4621
4622 kfree(priv->tx_buffers);
4623 priv->tx_buffers = NULL;
4624
4625 IPW_DEBUG_INFO("exit\n");
4626}
4627
James Ketrenos2c86c272005-03-23 17:32:29 -06004628static int ipw2100_rx_allocate(struct ipw2100_priv *priv)
4629{
4630 int i, j, err = -EINVAL;
4631
4632 IPW_DEBUG_INFO("enter\n");
4633
4634 err = bd_queue_allocate(priv, &priv->rx_queue, RX_QUEUE_LENGTH);
4635 if (err) {
4636 IPW_DEBUG_INFO("failed bd_queue_allocate\n");
4637 return err;
4638 }
4639
4640 err = status_queue_allocate(priv, RX_QUEUE_LENGTH);
4641 if (err) {
4642 IPW_DEBUG_INFO("failed status_queue_allocate\n");
4643 bd_queue_free(priv, &priv->rx_queue);
4644 return err;
4645 }
4646
4647 /*
4648 * allocate packets
4649 */
Joe Perchesefe4c452010-05-31 20:23:15 -07004650 priv->rx_buffers = kmalloc(RX_QUEUE_LENGTH *
4651 sizeof(struct ipw2100_rx_packet),
4652 GFP_KERNEL);
James Ketrenos2c86c272005-03-23 17:32:29 -06004653 if (!priv->rx_buffers) {
4654 IPW_DEBUG_INFO("can't allocate rx packet buffer table\n");
4655
4656 bd_queue_free(priv, &priv->rx_queue);
4657
4658 status_queue_free(priv);
4659
4660 return -ENOMEM;
4661 }
4662
4663 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4664 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
4665
4666 err = ipw2100_alloc_skb(priv, packet);
4667 if (unlikely(err)) {
4668 err = -ENOMEM;
4669 break;
4670 }
4671
4672 /* The BD holds the cache aligned address */
4673 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
4674 priv->rx_queue.drv[i].buf_length = IPW_RX_NIC_BUFFER_LENGTH;
4675 priv->status_queue.drv[i].status_fields = 0;
4676 }
4677
4678 if (i == RX_QUEUE_LENGTH)
4679 return 0;
4680
4681 for (j = 0; j < i; j++) {
4682 pci_unmap_single(priv->pci_dev, priv->rx_buffers[j].dma_addr,
4683 sizeof(struct ipw2100_rx_packet),
4684 PCI_DMA_FROMDEVICE);
4685 dev_kfree_skb(priv->rx_buffers[j].skb);
4686 }
4687
4688 kfree(priv->rx_buffers);
4689 priv->rx_buffers = NULL;
4690
4691 bd_queue_free(priv, &priv->rx_queue);
4692
4693 status_queue_free(priv);
4694
4695 return err;
4696}
4697
4698static void ipw2100_rx_initialize(struct ipw2100_priv *priv)
4699{
4700 IPW_DEBUG_INFO("enter\n");
4701
4702 priv->rx_queue.oldest = 0;
4703 priv->rx_queue.available = priv->rx_queue.entries - 1;
4704 priv->rx_queue.next = priv->rx_queue.entries - 1;
4705
4706 INIT_STAT(&priv->rxq_stat);
4707 SET_STAT(&priv->rxq_stat, priv->rx_queue.available);
4708
4709 bd_queue_initialize(priv, &priv->rx_queue,
4710 IPW_MEM_HOST_SHARED_RX_BD_BASE,
4711 IPW_MEM_HOST_SHARED_RX_BD_SIZE,
4712 IPW_MEM_HOST_SHARED_RX_READ_INDEX,
4713 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX);
4714
4715 /* set up the status queue */
4716 write_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_STATUS_BASE,
4717 priv->status_queue.nic);
4718
4719 IPW_DEBUG_INFO("exit\n");
4720}
4721
4722static void ipw2100_rx_free(struct ipw2100_priv *priv)
4723{
4724 int i;
4725
4726 IPW_DEBUG_INFO("enter\n");
4727
4728 bd_queue_free(priv, &priv->rx_queue);
4729 status_queue_free(priv);
4730
4731 if (!priv->rx_buffers)
4732 return;
4733
4734 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4735 if (priv->rx_buffers[i].rxp) {
4736 pci_unmap_single(priv->pci_dev,
4737 priv->rx_buffers[i].dma_addr,
4738 sizeof(struct ipw2100_rx),
4739 PCI_DMA_FROMDEVICE);
4740 dev_kfree_skb(priv->rx_buffers[i].skb);
4741 }
4742 }
4743
4744 kfree(priv->rx_buffers);
4745 priv->rx_buffers = NULL;
4746
4747 IPW_DEBUG_INFO("exit\n");
4748}
4749
4750static int ipw2100_read_mac_address(struct ipw2100_priv *priv)
4751{
4752 u32 length = ETH_ALEN;
Joe Perches0795af52007-10-03 17:59:30 -07004753 u8 addr[ETH_ALEN];
James Ketrenos2c86c272005-03-23 17:32:29 -06004754
4755 int err;
4756
Joe Perches0795af52007-10-03 17:59:30 -07004757 err = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ADAPTER_MAC, addr, &length);
James Ketrenos2c86c272005-03-23 17:32:29 -06004758 if (err) {
4759 IPW_DEBUG_INFO("MAC address read failed\n");
4760 return -EIO;
4761 }
James Ketrenos2c86c272005-03-23 17:32:29 -06004762
Joe Perches0795af52007-10-03 17:59:30 -07004763 memcpy(priv->net_dev->dev_addr, addr, ETH_ALEN);
Johannes Berge1749612008-10-27 15:59:26 -07004764 IPW_DEBUG_INFO("card MAC is %pM\n", priv->net_dev->dev_addr);
James Ketrenos2c86c272005-03-23 17:32:29 -06004765
4766 return 0;
4767}
4768
4769/********************************************************************
4770 *
4771 * Firmware Commands
4772 *
4773 ********************************************************************/
4774
Jiri Bencc4aee8c2005-08-25 20:04:43 -04004775static int ipw2100_set_mac_address(struct ipw2100_priv *priv, int batch_mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06004776{
4777 struct host_command cmd = {
4778 .host_command = ADAPTER_ADDRESS,
4779 .host_command_sequence = 0,
4780 .host_command_length = ETH_ALEN
4781 };
4782 int err;
4783
4784 IPW_DEBUG_HC("SET_MAC_ADDRESS\n");
4785
4786 IPW_DEBUG_INFO("enter\n");
4787
4788 if (priv->config & CFG_CUSTOM_MAC) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004789 memcpy(cmd.host_command_parameters, priv->mac_addr, ETH_ALEN);
James Ketrenos2c86c272005-03-23 17:32:29 -06004790 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
4791 } else
4792 memcpy(cmd.host_command_parameters, priv->net_dev->dev_addr,
4793 ETH_ALEN);
4794
4795 err = ipw2100_hw_send_command(priv, &cmd);
4796
4797 IPW_DEBUG_INFO("exit\n");
4798 return err;
4799}
4800
Jiri Bencc4aee8c2005-08-25 20:04:43 -04004801static int ipw2100_set_port_type(struct ipw2100_priv *priv, u32 port_type,
James Ketrenos2c86c272005-03-23 17:32:29 -06004802 int batch_mode)
4803{
4804 struct host_command cmd = {
4805 .host_command = PORT_TYPE,
4806 .host_command_sequence = 0,
4807 .host_command_length = sizeof(u32)
4808 };
4809 int err;
4810
4811 switch (port_type) {
4812 case IW_MODE_INFRA:
4813 cmd.host_command_parameters[0] = IPW_BSS;
4814 break;
4815 case IW_MODE_ADHOC:
4816 cmd.host_command_parameters[0] = IPW_IBSS;
4817 break;
4818 }
4819
4820 IPW_DEBUG_HC("PORT_TYPE: %s\n",
4821 port_type == IPW_IBSS ? "Ad-Hoc" : "Managed");
4822
4823 if (!batch_mode) {
4824 err = ipw2100_disable_adapter(priv);
4825 if (err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004826 printk(KERN_ERR DRV_NAME
4827 ": %s: Could not disable adapter %d\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06004828 priv->net_dev->name, err);
4829 return err;
4830 }
4831 }
4832
4833 /* send cmd to firmware */
4834 err = ipw2100_hw_send_command(priv, &cmd);
4835
4836 if (!batch_mode)
4837 ipw2100_enable_adapter(priv);
4838
4839 return err;
4840}
4841
Jiri Bencc4aee8c2005-08-25 20:04:43 -04004842static int ipw2100_set_channel(struct ipw2100_priv *priv, u32 channel,
4843 int batch_mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06004844{
4845 struct host_command cmd = {
4846 .host_command = CHANNEL,
4847 .host_command_sequence = 0,
4848 .host_command_length = sizeof(u32)
4849 };
4850 int err;
4851
4852 cmd.host_command_parameters[0] = channel;
4853
4854 IPW_DEBUG_HC("CHANNEL: %d\n", channel);
4855
4856 /* If BSS then we don't support channel selection */
4857 if (priv->ieee->iw_mode == IW_MODE_INFRA)
4858 return 0;
4859
4860 if ((channel != 0) &&
4861 ((channel < REG_MIN_CHANNEL) || (channel > REG_MAX_CHANNEL)))
4862 return -EINVAL;
4863
4864 if (!batch_mode) {
4865 err = ipw2100_disable_adapter(priv);
4866 if (err)
4867 return err;
4868 }
4869
4870 err = ipw2100_hw_send_command(priv, &cmd);
4871 if (err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05004872 IPW_DEBUG_INFO("Failed to set channel to %d", channel);
James Ketrenos2c86c272005-03-23 17:32:29 -06004873 return err;
4874 }
4875
4876 if (channel)
4877 priv->config |= CFG_STATIC_CHANNEL;
4878 else
4879 priv->config &= ~CFG_STATIC_CHANNEL;
4880
4881 priv->channel = channel;
4882
4883 if (!batch_mode) {
4884 err = ipw2100_enable_adapter(priv);
4885 if (err)
4886 return err;
4887 }
4888
4889 return 0;
4890}
4891
Jiri Bencc4aee8c2005-08-25 20:04:43 -04004892static int ipw2100_system_config(struct ipw2100_priv *priv, int batch_mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06004893{
4894 struct host_command cmd = {
4895 .host_command = SYSTEM_CONFIG,
4896 .host_command_sequence = 0,
4897 .host_command_length = 12,
4898 };
4899 u32 ibss_mask, len = sizeof(u32);
4900 int err;
4901
4902 /* Set system configuration */
4903
4904 if (!batch_mode) {
4905 err = ipw2100_disable_adapter(priv);
4906 if (err)
4907 return err;
4908 }
4909
4910 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
4911 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_AUTO_START;
4912
4913 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_MASK |
James Ketrenosee8e3652005-09-14 09:47:29 -05004914 IPW_CFG_BSS_MASK | IPW_CFG_802_1x_ENABLE;
James Ketrenos2c86c272005-03-23 17:32:29 -06004915
4916 if (!(priv->config & CFG_LONG_PREAMBLE))
4917 cmd.host_command_parameters[0] |= IPW_CFG_PREAMBLE_AUTO;
4918
4919 err = ipw2100_get_ordinal(priv,
4920 IPW_ORD_EEPROM_IBSS_11B_CHANNELS,
James Ketrenosee8e3652005-09-14 09:47:29 -05004921 &ibss_mask, &len);
James Ketrenos2c86c272005-03-23 17:32:29 -06004922 if (err)
4923 ibss_mask = IPW_IBSS_11B_DEFAULT_MASK;
4924
4925 cmd.host_command_parameters[1] = REG_CHANNEL_MASK;
4926 cmd.host_command_parameters[2] = REG_CHANNEL_MASK & ibss_mask;
4927
4928 /* 11b only */
James Ketrenosee8e3652005-09-14 09:47:29 -05004929 /*cmd.host_command_parameters[0] |= DIVERSITY_ANTENNA_A; */
James Ketrenos2c86c272005-03-23 17:32:29 -06004930
4931 err = ipw2100_hw_send_command(priv, &cmd);
4932 if (err)
4933 return err;
4934
4935/* If IPv6 is configured in the kernel then we don't want to filter out all
4936 * of the multicast packets as IPv6 needs some. */
4937#if !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
4938 cmd.host_command = ADD_MULTICAST;
4939 cmd.host_command_sequence = 0;
4940 cmd.host_command_length = 0;
4941
4942 ipw2100_hw_send_command(priv, &cmd);
4943#endif
4944 if (!batch_mode) {
4945 err = ipw2100_enable_adapter(priv);
4946 if (err)
4947 return err;
4948 }
4949
4950 return 0;
4951}
4952
Jiri Bencc4aee8c2005-08-25 20:04:43 -04004953static int ipw2100_set_tx_rates(struct ipw2100_priv *priv, u32 rate,
4954 int batch_mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06004955{
4956 struct host_command cmd = {
4957 .host_command = BASIC_TX_RATES,
4958 .host_command_sequence = 0,
4959 .host_command_length = 4
4960 };
4961 int err;
4962
4963 cmd.host_command_parameters[0] = rate & TX_RATE_MASK;
4964
4965 if (!batch_mode) {
4966 err = ipw2100_disable_adapter(priv);
4967 if (err)
4968 return err;
4969 }
4970
4971 /* Set BASIC TX Rate first */
4972 ipw2100_hw_send_command(priv, &cmd);
4973
4974 /* Set TX Rate */
4975 cmd.host_command = TX_RATES;
4976 ipw2100_hw_send_command(priv, &cmd);
4977
4978 /* Set MSDU TX Rate */
4979 cmd.host_command = MSDU_TX_RATES;
4980 ipw2100_hw_send_command(priv, &cmd);
4981
4982 if (!batch_mode) {
4983 err = ipw2100_enable_adapter(priv);
4984 if (err)
4985 return err;
4986 }
4987
4988 priv->tx_rates = rate;
4989
4990 return 0;
4991}
4992
James Ketrenosee8e3652005-09-14 09:47:29 -05004993static int ipw2100_set_power_mode(struct ipw2100_priv *priv, int power_level)
James Ketrenos2c86c272005-03-23 17:32:29 -06004994{
4995 struct host_command cmd = {
4996 .host_command = POWER_MODE,
4997 .host_command_sequence = 0,
4998 .host_command_length = 4
4999 };
5000 int err;
5001
5002 cmd.host_command_parameters[0] = power_level;
5003
5004 err = ipw2100_hw_send_command(priv, &cmd);
5005 if (err)
5006 return err;
5007
5008 if (power_level == IPW_POWER_MODE_CAM)
5009 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
5010 else
5011 priv->power_mode = IPW_POWER_ENABLED | power_level;
5012
Robert P. J. Dayae800312007-01-31 02:39:40 -05005013#ifdef IPW2100_TX_POWER
James Ketrenosee8e3652005-09-14 09:47:29 -05005014 if (priv->port_type == IBSS && priv->adhoc_power != DFTL_IBSS_TX_POWER) {
James Ketrenos2c86c272005-03-23 17:32:29 -06005015 /* Set beacon interval */
5016 cmd.host_command = TX_POWER_INDEX;
James Ketrenosee8e3652005-09-14 09:47:29 -05005017 cmd.host_command_parameters[0] = (u32) priv->adhoc_power;
James Ketrenos2c86c272005-03-23 17:32:29 -06005018
5019 err = ipw2100_hw_send_command(priv, &cmd);
5020 if (err)
5021 return err;
5022 }
5023#endif
5024
5025 return 0;
5026}
5027
Jiri Bencc4aee8c2005-08-25 20:04:43 -04005028static int ipw2100_set_rts_threshold(struct ipw2100_priv *priv, u32 threshold)
James Ketrenos2c86c272005-03-23 17:32:29 -06005029{
5030 struct host_command cmd = {
5031 .host_command = RTS_THRESHOLD,
5032 .host_command_sequence = 0,
5033 .host_command_length = 4
5034 };
5035 int err;
5036
5037 if (threshold & RTS_DISABLED)
5038 cmd.host_command_parameters[0] = MAX_RTS_THRESHOLD;
5039 else
5040 cmd.host_command_parameters[0] = threshold & ~RTS_DISABLED;
5041
5042 err = ipw2100_hw_send_command(priv, &cmd);
5043 if (err)
5044 return err;
5045
5046 priv->rts_threshold = threshold;
5047
5048 return 0;
5049}
5050
5051#if 0
5052int ipw2100_set_fragmentation_threshold(struct ipw2100_priv *priv,
5053 u32 threshold, int batch_mode)
5054{
5055 struct host_command cmd = {
5056 .host_command = FRAG_THRESHOLD,
5057 .host_command_sequence = 0,
5058 .host_command_length = 4,
5059 .host_command_parameters[0] = 0,
5060 };
5061 int err;
5062
5063 if (!batch_mode) {
5064 err = ipw2100_disable_adapter(priv);
5065 if (err)
5066 return err;
5067 }
5068
5069 if (threshold == 0)
5070 threshold = DEFAULT_FRAG_THRESHOLD;
5071 else {
5072 threshold = max(threshold, MIN_FRAG_THRESHOLD);
5073 threshold = min(threshold, MAX_FRAG_THRESHOLD);
5074 }
5075
5076 cmd.host_command_parameters[0] = threshold;
5077
5078 IPW_DEBUG_HC("FRAG_THRESHOLD: %u\n", threshold);
5079
5080 err = ipw2100_hw_send_command(priv, &cmd);
5081
5082 if (!batch_mode)
5083 ipw2100_enable_adapter(priv);
5084
5085 if (!err)
5086 priv->frag_threshold = threshold;
5087
5088 return err;
5089}
5090#endif
5091
Jiri Bencc4aee8c2005-08-25 20:04:43 -04005092static int ipw2100_set_short_retry(struct ipw2100_priv *priv, u32 retry)
James Ketrenos2c86c272005-03-23 17:32:29 -06005093{
5094 struct host_command cmd = {
5095 .host_command = SHORT_RETRY_LIMIT,
5096 .host_command_sequence = 0,
5097 .host_command_length = 4
5098 };
5099 int err;
5100
5101 cmd.host_command_parameters[0] = retry;
5102
5103 err = ipw2100_hw_send_command(priv, &cmd);
5104 if (err)
5105 return err;
5106
5107 priv->short_retry_limit = retry;
5108
5109 return 0;
5110}
5111
Jiri Bencc4aee8c2005-08-25 20:04:43 -04005112static int ipw2100_set_long_retry(struct ipw2100_priv *priv, u32 retry)
James Ketrenos2c86c272005-03-23 17:32:29 -06005113{
5114 struct host_command cmd = {
5115 .host_command = LONG_RETRY_LIMIT,
5116 .host_command_sequence = 0,
5117 .host_command_length = 4
5118 };
5119 int err;
5120
5121 cmd.host_command_parameters[0] = retry;
5122
5123 err = ipw2100_hw_send_command(priv, &cmd);
5124 if (err)
5125 return err;
5126
5127 priv->long_retry_limit = retry;
5128
5129 return 0;
5130}
5131
James Ketrenosee8e3652005-09-14 09:47:29 -05005132static int ipw2100_set_mandatory_bssid(struct ipw2100_priv *priv, u8 * bssid,
Jiri Bencc4aee8c2005-08-25 20:04:43 -04005133 int batch_mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06005134{
5135 struct host_command cmd = {
5136 .host_command = MANDATORY_BSSID,
5137 .host_command_sequence = 0,
5138 .host_command_length = (bssid == NULL) ? 0 : ETH_ALEN
5139 };
5140 int err;
5141
Brice Goglin0f52bf92005-12-01 01:41:46 -08005142#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06005143 if (bssid != NULL)
Johannes Berge1749612008-10-27 15:59:26 -07005144 IPW_DEBUG_HC("MANDATORY_BSSID: %pM\n", bssid);
James Ketrenos2c86c272005-03-23 17:32:29 -06005145 else
5146 IPW_DEBUG_HC("MANDATORY_BSSID: <clear>\n");
5147#endif
5148 /* if BSSID is empty then we disable mandatory bssid mode */
5149 if (bssid != NULL)
James Ketrenos82328352005-08-24 22:33:31 -05005150 memcpy(cmd.host_command_parameters, bssid, ETH_ALEN);
James Ketrenos2c86c272005-03-23 17:32:29 -06005151
5152 if (!batch_mode) {
5153 err = ipw2100_disable_adapter(priv);
5154 if (err)
5155 return err;
5156 }
5157
5158 err = ipw2100_hw_send_command(priv, &cmd);
5159
5160 if (!batch_mode)
5161 ipw2100_enable_adapter(priv);
5162
5163 return err;
5164}
5165
James Ketrenos2c86c272005-03-23 17:32:29 -06005166static int ipw2100_disassociate_bssid(struct ipw2100_priv *priv)
5167{
5168 struct host_command cmd = {
5169 .host_command = DISASSOCIATION_BSSID,
5170 .host_command_sequence = 0,
5171 .host_command_length = ETH_ALEN
5172 };
5173 int err;
5174 int len;
5175
5176 IPW_DEBUG_HC("DISASSOCIATION_BSSID\n");
5177
5178 len = ETH_ALEN;
5179 /* The Firmware currently ignores the BSSID and just disassociates from
5180 * the currently associated AP -- but in the off chance that a future
5181 * firmware does use the BSSID provided here, we go ahead and try and
5182 * set it to the currently associated AP's BSSID */
5183 memcpy(cmd.host_command_parameters, priv->bssid, ETH_ALEN);
5184
5185 err = ipw2100_hw_send_command(priv, &cmd);
5186
5187 return err;
5188}
James Ketrenos2c86c272005-03-23 17:32:29 -06005189
5190static int ipw2100_set_wpa_ie(struct ipw2100_priv *,
5191 struct ipw2100_wpa_assoc_frame *, int)
James Ketrenosee8e3652005-09-14 09:47:29 -05005192 __attribute__ ((unused));
James Ketrenos2c86c272005-03-23 17:32:29 -06005193
5194static int ipw2100_set_wpa_ie(struct ipw2100_priv *priv,
5195 struct ipw2100_wpa_assoc_frame *wpa_frame,
5196 int batch_mode)
5197{
5198 struct host_command cmd = {
5199 .host_command = SET_WPA_IE,
5200 .host_command_sequence = 0,
5201 .host_command_length = sizeof(struct ipw2100_wpa_assoc_frame),
5202 };
5203 int err;
5204
5205 IPW_DEBUG_HC("SET_WPA_IE\n");
5206
5207 if (!batch_mode) {
5208 err = ipw2100_disable_adapter(priv);
5209 if (err)
5210 return err;
5211 }
5212
5213 memcpy(cmd.host_command_parameters, wpa_frame,
5214 sizeof(struct ipw2100_wpa_assoc_frame));
5215
5216 err = ipw2100_hw_send_command(priv, &cmd);
5217
5218 if (!batch_mode) {
5219 if (ipw2100_enable_adapter(priv))
5220 err = -EIO;
5221 }
5222
5223 return err;
5224}
5225
5226struct security_info_params {
5227 u32 allowed_ciphers;
5228 u16 version;
5229 u8 auth_mode;
5230 u8 replay_counters_number;
5231 u8 unicast_using_group;
5232} __attribute__ ((packed));
5233
Jiri Bencc4aee8c2005-08-25 20:04:43 -04005234static int ipw2100_set_security_information(struct ipw2100_priv *priv,
5235 int auth_mode,
5236 int security_level,
5237 int unicast_using_group,
5238 int batch_mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06005239{
5240 struct host_command cmd = {
5241 .host_command = SET_SECURITY_INFORMATION,
5242 .host_command_sequence = 0,
5243 .host_command_length = sizeof(struct security_info_params)
5244 };
5245 struct security_info_params *security =
James Ketrenosee8e3652005-09-14 09:47:29 -05005246 (struct security_info_params *)&cmd.host_command_parameters;
James Ketrenos2c86c272005-03-23 17:32:29 -06005247 int err;
5248 memset(security, 0, sizeof(*security));
5249
5250 /* If shared key AP authentication is turned on, then we need to
5251 * configure the firmware to try and use it.
5252 *
5253 * Actual data encryption/decryption is handled by the host. */
5254 security->auth_mode = auth_mode;
5255 security->unicast_using_group = unicast_using_group;
5256
5257 switch (security_level) {
5258 default:
5259 case SEC_LEVEL_0:
5260 security->allowed_ciphers = IPW_NONE_CIPHER;
5261 break;
5262 case SEC_LEVEL_1:
5263 security->allowed_ciphers = IPW_WEP40_CIPHER |
James Ketrenosee8e3652005-09-14 09:47:29 -05005264 IPW_WEP104_CIPHER;
James Ketrenos2c86c272005-03-23 17:32:29 -06005265 break;
5266 case SEC_LEVEL_2:
5267 security->allowed_ciphers = IPW_WEP40_CIPHER |
James Ketrenosee8e3652005-09-14 09:47:29 -05005268 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER;
James Ketrenos2c86c272005-03-23 17:32:29 -06005269 break;
5270 case SEC_LEVEL_2_CKIP:
5271 security->allowed_ciphers = IPW_WEP40_CIPHER |
James Ketrenosee8e3652005-09-14 09:47:29 -05005272 IPW_WEP104_CIPHER | IPW_CKIP_CIPHER;
James Ketrenos2c86c272005-03-23 17:32:29 -06005273 break;
5274 case SEC_LEVEL_3:
5275 security->allowed_ciphers = IPW_WEP40_CIPHER |
James Ketrenosee8e3652005-09-14 09:47:29 -05005276 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER | IPW_CCMP_CIPHER;
James Ketrenos2c86c272005-03-23 17:32:29 -06005277 break;
5278 }
5279
James Ketrenosee8e3652005-09-14 09:47:29 -05005280 IPW_DEBUG_HC
5281 ("SET_SECURITY_INFORMATION: auth:%d cipher:0x%02X (level %d)\n",
5282 security->auth_mode, security->allowed_ciphers, security_level);
James Ketrenos2c86c272005-03-23 17:32:29 -06005283
5284 security->replay_counters_number = 0;
5285
5286 if (!batch_mode) {
5287 err = ipw2100_disable_adapter(priv);
5288 if (err)
5289 return err;
5290 }
5291
5292 err = ipw2100_hw_send_command(priv, &cmd);
5293
5294 if (!batch_mode)
5295 ipw2100_enable_adapter(priv);
5296
5297 return err;
5298}
5299
James Ketrenosee8e3652005-09-14 09:47:29 -05005300static int ipw2100_set_tx_power(struct ipw2100_priv *priv, u32 tx_power)
James Ketrenos2c86c272005-03-23 17:32:29 -06005301{
5302 struct host_command cmd = {
5303 .host_command = TX_POWER_INDEX,
5304 .host_command_sequence = 0,
5305 .host_command_length = 4
5306 };
5307 int err = 0;
Zhu Yi3173ca02006-01-24 13:49:01 +08005308 u32 tmp = tx_power;
James Ketrenos2c86c272005-03-23 17:32:29 -06005309
Liu Hongf75459e2005-07-13 12:29:21 -05005310 if (tx_power != IPW_TX_POWER_DEFAULT)
Zhu Yi3173ca02006-01-24 13:49:01 +08005311 tmp = (tx_power - IPW_TX_POWER_MIN_DBM) * 16 /
5312 (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM);
Liu Hongf75459e2005-07-13 12:29:21 -05005313
Zhu Yi3173ca02006-01-24 13:49:01 +08005314 cmd.host_command_parameters[0] = tmp;
James Ketrenos2c86c272005-03-23 17:32:29 -06005315
5316 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
5317 err = ipw2100_hw_send_command(priv, &cmd);
5318 if (!err)
5319 priv->tx_power = tx_power;
5320
5321 return 0;
5322}
5323
Jiri Bencc4aee8c2005-08-25 20:04:43 -04005324static int ipw2100_set_ibss_beacon_interval(struct ipw2100_priv *priv,
5325 u32 interval, int batch_mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06005326{
5327 struct host_command cmd = {
5328 .host_command = BEACON_INTERVAL,
5329 .host_command_sequence = 0,
5330 .host_command_length = 4
5331 };
5332 int err;
5333
5334 cmd.host_command_parameters[0] = interval;
5335
5336 IPW_DEBUG_INFO("enter\n");
5337
5338 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5339 if (!batch_mode) {
5340 err = ipw2100_disable_adapter(priv);
5341 if (err)
5342 return err;
5343 }
5344
5345 ipw2100_hw_send_command(priv, &cmd);
5346
5347 if (!batch_mode) {
5348 err = ipw2100_enable_adapter(priv);
5349 if (err)
5350 return err;
5351 }
5352 }
5353
5354 IPW_DEBUG_INFO("exit\n");
5355
5356 return 0;
5357}
5358
Hannes Edera3d1fd22008-12-26 00:14:41 -08005359static void ipw2100_queues_initialize(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06005360{
5361 ipw2100_tx_initialize(priv);
5362 ipw2100_rx_initialize(priv);
5363 ipw2100_msg_initialize(priv);
5364}
5365
Hannes Edera3d1fd22008-12-26 00:14:41 -08005366static void ipw2100_queues_free(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06005367{
5368 ipw2100_tx_free(priv);
5369 ipw2100_rx_free(priv);
5370 ipw2100_msg_free(priv);
5371}
5372
Hannes Edera3d1fd22008-12-26 00:14:41 -08005373static int ipw2100_queues_allocate(struct ipw2100_priv *priv)
James Ketrenos2c86c272005-03-23 17:32:29 -06005374{
5375 if (ipw2100_tx_allocate(priv) ||
James Ketrenosee8e3652005-09-14 09:47:29 -05005376 ipw2100_rx_allocate(priv) || ipw2100_msg_allocate(priv))
James Ketrenos2c86c272005-03-23 17:32:29 -06005377 goto fail;
5378
5379 return 0;
5380
James Ketrenosee8e3652005-09-14 09:47:29 -05005381 fail:
James Ketrenos2c86c272005-03-23 17:32:29 -06005382 ipw2100_tx_free(priv);
5383 ipw2100_rx_free(priv);
5384 ipw2100_msg_free(priv);
5385 return -ENOMEM;
5386}
5387
5388#define IPW_PRIVACY_CAPABLE 0x0008
5389
5390static int ipw2100_set_wep_flags(struct ipw2100_priv *priv, u32 flags,
5391 int batch_mode)
5392{
5393 struct host_command cmd = {
5394 .host_command = WEP_FLAGS,
5395 .host_command_sequence = 0,
5396 .host_command_length = 4
5397 };
5398 int err;
5399
5400 cmd.host_command_parameters[0] = flags;
5401
5402 IPW_DEBUG_HC("WEP_FLAGS: flags = 0x%08X\n", flags);
5403
5404 if (!batch_mode) {
5405 err = ipw2100_disable_adapter(priv);
5406 if (err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05005407 printk(KERN_ERR DRV_NAME
5408 ": %s: Could not disable adapter %d\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06005409 priv->net_dev->name, err);
5410 return err;
5411 }
5412 }
5413
5414 /* send cmd to firmware */
5415 err = ipw2100_hw_send_command(priv, &cmd);
5416
5417 if (!batch_mode)
5418 ipw2100_enable_adapter(priv);
5419
5420 return err;
5421}
5422
5423struct ipw2100_wep_key {
5424 u8 idx;
5425 u8 len;
5426 u8 key[13];
5427};
5428
5429/* Macros to ease up priting WEP keys */
5430#define WEP_FMT_64 "%02X%02X%02X%02X-%02X"
5431#define WEP_FMT_128 "%02X%02X%02X%02X-%02X%02X%02X%02X-%02X%02X%02X"
5432#define WEP_STR_64(x) x[0],x[1],x[2],x[3],x[4]
5433#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]
5434
James Ketrenos2c86c272005-03-23 17:32:29 -06005435/**
5436 * Set a the wep key
5437 *
5438 * @priv: struct to work on
5439 * @idx: index of the key we want to set
5440 * @key: ptr to the key data to set
5441 * @len: length of the buffer at @key
5442 * @batch_mode: FIXME perform the operation in batch mode, not
5443 * disabling the device.
5444 *
5445 * @returns 0 if OK, < 0 errno code on error.
5446 *
5447 * Fill out a command structure with the new wep key, length an
5448 * index and send it down the wire.
5449 */
5450static int ipw2100_set_key(struct ipw2100_priv *priv,
5451 int idx, char *key, int len, int batch_mode)
5452{
5453 int keylen = len ? (len <= 5 ? 5 : 13) : 0;
5454 struct host_command cmd = {
5455 .host_command = WEP_KEY_INFO,
5456 .host_command_sequence = 0,
5457 .host_command_length = sizeof(struct ipw2100_wep_key),
5458 };
James Ketrenosee8e3652005-09-14 09:47:29 -05005459 struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
James Ketrenos2c86c272005-03-23 17:32:29 -06005460 int err;
5461
5462 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05005463 idx, keylen, len);
James Ketrenos2c86c272005-03-23 17:32:29 -06005464
5465 /* NOTE: We don't check cached values in case the firmware was reset
Adrian Bunk80f72282006-06-30 18:27:16 +02005466 * or some other problem is occurring. If the user is setting the key,
James Ketrenos2c86c272005-03-23 17:32:29 -06005467 * then we push the change */
5468
5469 wep_key->idx = idx;
5470 wep_key->len = keylen;
5471
5472 if (keylen) {
5473 memcpy(wep_key->key, key, len);
5474 memset(wep_key->key + len, 0, keylen - len);
5475 }
5476
5477 /* Will be optimized out on debug not being configured in */
5478 if (keylen == 0)
5479 IPW_DEBUG_WEP("%s: Clearing key %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05005480 priv->net_dev->name, wep_key->idx);
James Ketrenos2c86c272005-03-23 17:32:29 -06005481 else if (keylen == 5)
5482 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_64 "\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05005483 priv->net_dev->name, wep_key->idx, wep_key->len,
5484 WEP_STR_64(wep_key->key));
James Ketrenos2c86c272005-03-23 17:32:29 -06005485 else
5486 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_128
James Ketrenosee8e3652005-09-14 09:47:29 -05005487 "\n",
5488 priv->net_dev->name, wep_key->idx, wep_key->len,
5489 WEP_STR_128(wep_key->key));
James Ketrenos2c86c272005-03-23 17:32:29 -06005490
5491 if (!batch_mode) {
5492 err = ipw2100_disable_adapter(priv);
5493 /* FIXME: IPG: shouldn't this prink be in _disable_adapter()? */
5494 if (err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05005495 printk(KERN_ERR DRV_NAME
5496 ": %s: Could not disable adapter %d\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06005497 priv->net_dev->name, err);
5498 return err;
5499 }
5500 }
5501
5502 /* send cmd to firmware */
5503 err = ipw2100_hw_send_command(priv, &cmd);
5504
5505 if (!batch_mode) {
5506 int err2 = ipw2100_enable_adapter(priv);
5507 if (err == 0)
5508 err = err2;
5509 }
5510 return err;
5511}
5512
5513static int ipw2100_set_key_index(struct ipw2100_priv *priv,
5514 int idx, int batch_mode)
5515{
5516 struct host_command cmd = {
5517 .host_command = WEP_KEY_INDEX,
5518 .host_command_sequence = 0,
5519 .host_command_length = 4,
James Ketrenosee8e3652005-09-14 09:47:29 -05005520 .host_command_parameters = {idx},
James Ketrenos2c86c272005-03-23 17:32:29 -06005521 };
5522 int err;
5523
5524 IPW_DEBUG_HC("WEP_KEY_INDEX: index = %d\n", idx);
5525
5526 if (idx < 0 || idx > 3)
5527 return -EINVAL;
5528
5529 if (!batch_mode) {
5530 err = ipw2100_disable_adapter(priv);
5531 if (err) {
James Ketrenosee8e3652005-09-14 09:47:29 -05005532 printk(KERN_ERR DRV_NAME
5533 ": %s: Could not disable adapter %d\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06005534 priv->net_dev->name, err);
5535 return err;
5536 }
5537 }
5538
5539 /* send cmd to firmware */
5540 err = ipw2100_hw_send_command(priv, &cmd);
5541
5542 if (!batch_mode)
5543 ipw2100_enable_adapter(priv);
5544
5545 return err;
5546}
5547
James Ketrenosee8e3652005-09-14 09:47:29 -05005548static int ipw2100_configure_security(struct ipw2100_priv *priv, int batch_mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06005549{
5550 int i, err, auth_mode, sec_level, use_group;
5551
5552 if (!(priv->status & STATUS_RUNNING))
5553 return 0;
5554
5555 if (!batch_mode) {
5556 err = ipw2100_disable_adapter(priv);
5557 if (err)
5558 return err;
5559 }
5560
25b645b2005-07-12 15:45:30 -05005561 if (!priv->ieee->sec.enabled) {
James Ketrenosee8e3652005-09-14 09:47:29 -05005562 err =
5563 ipw2100_set_security_information(priv, IPW_AUTH_OPEN,
5564 SEC_LEVEL_0, 0, 1);
James Ketrenos2c86c272005-03-23 17:32:29 -06005565 } else {
5566 auth_mode = IPW_AUTH_OPEN;
Zhu Yicbbdd032006-01-24 13:48:53 +08005567 if (priv->ieee->sec.flags & SEC_AUTH_MODE) {
5568 if (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)
5569 auth_mode = IPW_AUTH_SHARED;
5570 else if (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP)
5571 auth_mode = IPW_AUTH_LEAP_CISCO_ID;
5572 }
James Ketrenos2c86c272005-03-23 17:32:29 -06005573
5574 sec_level = SEC_LEVEL_0;
25b645b2005-07-12 15:45:30 -05005575 if (priv->ieee->sec.flags & SEC_LEVEL)
5576 sec_level = priv->ieee->sec.level;
James Ketrenos2c86c272005-03-23 17:32:29 -06005577
5578 use_group = 0;
25b645b2005-07-12 15:45:30 -05005579 if (priv->ieee->sec.flags & SEC_UNICAST_GROUP)
5580 use_group = priv->ieee->sec.unicast_uses_group;
James Ketrenos2c86c272005-03-23 17:32:29 -06005581
James Ketrenosee8e3652005-09-14 09:47:29 -05005582 err =
5583 ipw2100_set_security_information(priv, auth_mode, sec_level,
5584 use_group, 1);
James Ketrenos2c86c272005-03-23 17:32:29 -06005585 }
5586
5587 if (err)
5588 goto exit;
5589
25b645b2005-07-12 15:45:30 -05005590 if (priv->ieee->sec.enabled) {
James Ketrenos2c86c272005-03-23 17:32:29 -06005591 for (i = 0; i < 4; i++) {
25b645b2005-07-12 15:45:30 -05005592 if (!(priv->ieee->sec.flags & (1 << i))) {
5593 memset(priv->ieee->sec.keys[i], 0, WEP_KEY_LEN);
5594 priv->ieee->sec.key_sizes[i] = 0;
James Ketrenos2c86c272005-03-23 17:32:29 -06005595 } else {
5596 err = ipw2100_set_key(priv, i,
25b645b2005-07-12 15:45:30 -05005597 priv->ieee->sec.keys[i],
5598 priv->ieee->sec.
5599 key_sizes[i], 1);
James Ketrenos2c86c272005-03-23 17:32:29 -06005600 if (err)
5601 goto exit;
5602 }
5603 }
5604
John W. Linville274bfb82008-10-29 11:35:05 -04005605 ipw2100_set_key_index(priv, priv->ieee->crypt_info.tx_keyidx, 1);
James Ketrenos2c86c272005-03-23 17:32:29 -06005606 }
5607
5608 /* Always enable privacy so the Host can filter WEP packets if
5609 * encrypted data is sent up */
James Ketrenosee8e3652005-09-14 09:47:29 -05005610 err =
5611 ipw2100_set_wep_flags(priv,
25b645b2005-07-12 15:45:30 -05005612 priv->ieee->sec.
5613 enabled ? IPW_PRIVACY_CAPABLE : 0, 1);
James Ketrenos2c86c272005-03-23 17:32:29 -06005614 if (err)
5615 goto exit;
5616
5617 priv->status &= ~STATUS_SECURITY_UPDATED;
5618
James Ketrenosee8e3652005-09-14 09:47:29 -05005619 exit:
James Ketrenos2c86c272005-03-23 17:32:29 -06005620 if (!batch_mode)
5621 ipw2100_enable_adapter(priv);
5622
5623 return err;
5624}
5625
David Howellsc4028952006-11-22 14:57:56 +00005626static void ipw2100_security_work(struct work_struct *work)
James Ketrenos2c86c272005-03-23 17:32:29 -06005627{
David Howellsc4028952006-11-22 14:57:56 +00005628 struct ipw2100_priv *priv =
5629 container_of(work, struct ipw2100_priv, security_work.work);
5630
James Ketrenos2c86c272005-03-23 17:32:29 -06005631 /* If we happen to have reconnected before we get a chance to
5632 * process this, then update the security settings--which causes
5633 * a disassociation to occur */
5634 if (!(priv->status & STATUS_ASSOCIATED) &&
5635 priv->status & STATUS_SECURITY_UPDATED)
5636 ipw2100_configure_security(priv, 0);
5637}
5638
5639static void shim__set_security(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005640 struct libipw_security *sec)
James Ketrenos2c86c272005-03-23 17:32:29 -06005641{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005642 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06005643 int i, force_update = 0;
5644
Ingo Molnar752e3772006-02-28 07:20:54 +08005645 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06005646 if (!(priv->status & STATUS_INITIALIZED))
5647 goto done;
5648
5649 for (i = 0; i < 4; i++) {
5650 if (sec->flags & (1 << i)) {
25b645b2005-07-12 15:45:30 -05005651 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos2c86c272005-03-23 17:32:29 -06005652 if (sec->key_sizes[i] == 0)
25b645b2005-07-12 15:45:30 -05005653 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos2c86c272005-03-23 17:32:29 -06005654 else
25b645b2005-07-12 15:45:30 -05005655 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos2c86c272005-03-23 17:32:29 -06005656 sec->key_sizes[i]);
Hong Liu054b08d2005-08-25 17:45:49 +08005657 if (sec->level == SEC_LEVEL_1) {
5658 priv->ieee->sec.flags |= (1 << i);
5659 priv->status |= STATUS_SECURITY_UPDATED;
5660 } else
5661 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos2c86c272005-03-23 17:32:29 -06005662 }
5663 }
5664
5665 if ((sec->flags & SEC_ACTIVE_KEY) &&
25b645b2005-07-12 15:45:30 -05005666 priv->ieee->sec.active_key != sec->active_key) {
James Ketrenos2c86c272005-03-23 17:32:29 -06005667 if (sec->active_key <= 3) {
25b645b2005-07-12 15:45:30 -05005668 priv->ieee->sec.active_key = sec->active_key;
5669 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
James Ketrenos2c86c272005-03-23 17:32:29 -06005670 } else
25b645b2005-07-12 15:45:30 -05005671 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos2c86c272005-03-23 17:32:29 -06005672
5673 priv->status |= STATUS_SECURITY_UPDATED;
5674 }
5675
5676 if ((sec->flags & SEC_AUTH_MODE) &&
25b645b2005-07-12 15:45:30 -05005677 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
5678 priv->ieee->sec.auth_mode = sec->auth_mode;
5679 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos2c86c272005-03-23 17:32:29 -06005680 priv->status |= STATUS_SECURITY_UPDATED;
5681 }
5682
25b645b2005-07-12 15:45:30 -05005683 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
5684 priv->ieee->sec.flags |= SEC_ENABLED;
5685 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos2c86c272005-03-23 17:32:29 -06005686 priv->status |= STATUS_SECURITY_UPDATED;
5687 force_update = 1;
5688 }
5689
25b645b2005-07-12 15:45:30 -05005690 if (sec->flags & SEC_ENCRYPT)
5691 priv->ieee->sec.encrypt = sec->encrypt;
5692
5693 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
5694 priv->ieee->sec.level = sec->level;
5695 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos2c86c272005-03-23 17:32:29 -06005696 priv->status |= STATUS_SECURITY_UPDATED;
5697 }
5698
5699 IPW_DEBUG_WEP("Security flags: %c %c%c%c%c %c%c%c%c\n",
25b645b2005-07-12 15:45:30 -05005700 priv->ieee->sec.flags & (1 << 8) ? '1' : '0',
5701 priv->ieee->sec.flags & (1 << 7) ? '1' : '0',
5702 priv->ieee->sec.flags & (1 << 6) ? '1' : '0',
5703 priv->ieee->sec.flags & (1 << 5) ? '1' : '0',
5704 priv->ieee->sec.flags & (1 << 4) ? '1' : '0',
5705 priv->ieee->sec.flags & (1 << 3) ? '1' : '0',
5706 priv->ieee->sec.flags & (1 << 2) ? '1' : '0',
5707 priv->ieee->sec.flags & (1 << 1) ? '1' : '0',
5708 priv->ieee->sec.flags & (1 << 0) ? '1' : '0');
James Ketrenos2c86c272005-03-23 17:32:29 -06005709
5710/* As a temporary work around to enable WPA until we figure out why
5711 * wpa_supplicant toggles the security capability of the driver, which
5712 * forces a disassocation with force_update...
5713 *
5714 * if (force_update || !(priv->status & STATUS_ASSOCIATED))*/
5715 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
5716 ipw2100_configure_security(priv, 0);
James Ketrenosee8e3652005-09-14 09:47:29 -05005717 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08005718 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06005719}
5720
5721static int ipw2100_adapter_setup(struct ipw2100_priv *priv)
5722{
5723 int err;
5724 int batch_mode = 1;
5725 u8 *bssid;
5726
5727 IPW_DEBUG_INFO("enter\n");
5728
5729 err = ipw2100_disable_adapter(priv);
5730 if (err)
5731 return err;
5732#ifdef CONFIG_IPW2100_MONITOR
5733 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
5734 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5735 if (err)
5736 return err;
5737
5738 IPW_DEBUG_INFO("exit\n");
5739
5740 return 0;
5741 }
James Ketrenosee8e3652005-09-14 09:47:29 -05005742#endif /* CONFIG_IPW2100_MONITOR */
James Ketrenos2c86c272005-03-23 17:32:29 -06005743
5744 err = ipw2100_read_mac_address(priv);
5745 if (err)
5746 return -EIO;
5747
5748 err = ipw2100_set_mac_address(priv, batch_mode);
5749 if (err)
5750 return err;
5751
5752 err = ipw2100_set_port_type(priv, priv->ieee->iw_mode, batch_mode);
5753 if (err)
5754 return err;
5755
5756 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5757 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5758 if (err)
5759 return err;
5760 }
5761
James Ketrenosee8e3652005-09-14 09:47:29 -05005762 err = ipw2100_system_config(priv, batch_mode);
James Ketrenos2c86c272005-03-23 17:32:29 -06005763 if (err)
5764 return err;
5765
5766 err = ipw2100_set_tx_rates(priv, priv->tx_rates, batch_mode);
5767 if (err)
5768 return err;
5769
5770 /* Default to power mode OFF */
5771 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
5772 if (err)
5773 return err;
5774
5775 err = ipw2100_set_rts_threshold(priv, priv->rts_threshold);
5776 if (err)
5777 return err;
5778
5779 if (priv->config & CFG_STATIC_BSSID)
5780 bssid = priv->bssid;
5781 else
5782 bssid = NULL;
5783 err = ipw2100_set_mandatory_bssid(priv, bssid, batch_mode);
5784 if (err)
5785 return err;
5786
5787 if (priv->config & CFG_STATIC_ESSID)
5788 err = ipw2100_set_essid(priv, priv->essid, priv->essid_len,
5789 batch_mode);
5790 else
5791 err = ipw2100_set_essid(priv, NULL, 0, batch_mode);
5792 if (err)
5793 return err;
5794
5795 err = ipw2100_configure_security(priv, batch_mode);
5796 if (err)
5797 return err;
5798
5799 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosee8e3652005-09-14 09:47:29 -05005800 err =
5801 ipw2100_set_ibss_beacon_interval(priv,
5802 priv->beacon_interval,
5803 batch_mode);
James Ketrenos2c86c272005-03-23 17:32:29 -06005804 if (err)
5805 return err;
5806
5807 err = ipw2100_set_tx_power(priv, priv->tx_power);
5808 if (err)
5809 return err;
5810 }
5811
5812 /*
James Ketrenosee8e3652005-09-14 09:47:29 -05005813 err = ipw2100_set_fragmentation_threshold(
5814 priv, priv->frag_threshold, batch_mode);
5815 if (err)
5816 return err;
5817 */
James Ketrenos2c86c272005-03-23 17:32:29 -06005818
5819 IPW_DEBUG_INFO("exit\n");
5820
5821 return 0;
5822}
5823
James Ketrenos2c86c272005-03-23 17:32:29 -06005824/*************************************************************************
5825 *
5826 * EXTERNALLY CALLED METHODS
5827 *
5828 *************************************************************************/
5829
5830/* This method is called by the network layer -- not to be confused with
5831 * ipw2100_set_mac_address() declared above called by this driver (and this
5832 * method as well) to talk to the firmware */
5833static int ipw2100_set_address(struct net_device *dev, void *p)
5834{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005835 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06005836 struct sockaddr *addr = p;
5837 int err = 0;
5838
5839 if (!is_valid_ether_addr(addr->sa_data))
5840 return -EADDRNOTAVAIL;
5841
Ingo Molnar752e3772006-02-28 07:20:54 +08005842 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06005843
5844 priv->config |= CFG_CUSTOM_MAC;
5845 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
5846
5847 err = ipw2100_set_mac_address(priv, 0);
5848 if (err)
5849 goto done;
5850
5851 priv->reset_backoff = 0;
Ingo Molnar752e3772006-02-28 07:20:54 +08005852 mutex_unlock(&priv->action_mutex);
David Howellsc4028952006-11-22 14:57:56 +00005853 ipw2100_reset_adapter(&priv->reset_work.work);
James Ketrenos2c86c272005-03-23 17:32:29 -06005854 return 0;
5855
James Ketrenosee8e3652005-09-14 09:47:29 -05005856 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08005857 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06005858 return err;
5859}
5860
5861static int ipw2100_open(struct net_device *dev)
5862{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005863 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06005864 unsigned long flags;
5865 IPW_DEBUG_INFO("dev->open\n");
5866
5867 spin_lock_irqsave(&priv->low_lock, flags);
Jiri Benc3ce329c2005-08-25 20:07:01 -04005868 if (priv->status & STATUS_ASSOCIATED) {
5869 netif_carrier_on(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06005870 netif_start_queue(dev);
Jiri Benc3ce329c2005-08-25 20:07:01 -04005871 }
James Ketrenos2c86c272005-03-23 17:32:29 -06005872 spin_unlock_irqrestore(&priv->low_lock, flags);
5873
5874 return 0;
5875}
5876
5877static int ipw2100_close(struct net_device *dev)
5878{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005879 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06005880 unsigned long flags;
5881 struct list_head *element;
5882 struct ipw2100_tx_packet *packet;
5883
5884 IPW_DEBUG_INFO("enter\n");
5885
5886 spin_lock_irqsave(&priv->low_lock, flags);
5887
5888 if (priv->status & STATUS_ASSOCIATED)
5889 netif_carrier_off(dev);
5890 netif_stop_queue(dev);
5891
5892 /* Flush the TX queue ... */
5893 while (!list_empty(&priv->tx_pend_list)) {
5894 element = priv->tx_pend_list.next;
James Ketrenosee8e3652005-09-14 09:47:29 -05005895 packet = list_entry(element, struct ipw2100_tx_packet, list);
James Ketrenos2c86c272005-03-23 17:32:29 -06005896
5897 list_del(element);
5898 DEC_STAT(&priv->tx_pend_stat);
5899
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005900 libipw_txb_free(packet->info.d_struct.txb);
James Ketrenos2c86c272005-03-23 17:32:29 -06005901 packet->info.d_struct.txb = NULL;
5902
5903 list_add_tail(element, &priv->tx_free_list);
5904 INC_STAT(&priv->tx_free_stat);
5905 }
5906 spin_unlock_irqrestore(&priv->low_lock, flags);
5907
5908 IPW_DEBUG_INFO("exit\n");
5909
5910 return 0;
5911}
5912
James Ketrenos2c86c272005-03-23 17:32:29 -06005913/*
5914 * TODO: Fix this function... its just wrong
5915 */
5916static void ipw2100_tx_timeout(struct net_device *dev)
5917{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005918 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06005919
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00005920 dev->stats.tx_errors++;
James Ketrenos2c86c272005-03-23 17:32:29 -06005921
5922#ifdef CONFIG_IPW2100_MONITOR
5923 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
5924 return;
5925#endif
5926
5927 IPW_DEBUG_INFO("%s: TX timed out. Scheduling firmware restart.\n",
5928 dev->name);
5929 schedule_reset(priv);
5930}
5931
James Ketrenosee8e3652005-09-14 09:47:29 -05005932static int ipw2100_wpa_enable(struct ipw2100_priv *priv, int value)
5933{
James Ketrenos82328352005-08-24 22:33:31 -05005934 /* This is called when wpa_supplicant loads and closes the driver
5935 * interface. */
5936 priv->ieee->wpa_enabled = value;
5937 return 0;
James Ketrenos2c86c272005-03-23 17:32:29 -06005938}
5939
James Ketrenosee8e3652005-09-14 09:47:29 -05005940static int ipw2100_wpa_set_auth_algs(struct ipw2100_priv *priv, int value)
5941{
James Ketrenos2c86c272005-03-23 17:32:29 -06005942
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005943 struct libipw_device *ieee = priv->ieee;
5944 struct libipw_security sec = {
James Ketrenos2c86c272005-03-23 17:32:29 -06005945 .flags = SEC_AUTH_MODE,
5946 };
5947 int ret = 0;
5948
James Ketrenos82328352005-08-24 22:33:31 -05005949 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenos2c86c272005-03-23 17:32:29 -06005950 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
5951 ieee->open_wep = 0;
James Ketrenos82328352005-08-24 22:33:31 -05005952 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenos2c86c272005-03-23 17:32:29 -06005953 sec.auth_mode = WLAN_AUTH_OPEN;
5954 ieee->open_wep = 1;
Zhu Yicbbdd032006-01-24 13:48:53 +08005955 } else if (value & IW_AUTH_ALG_LEAP) {
5956 sec.auth_mode = WLAN_AUTH_LEAP;
5957 ieee->open_wep = 1;
James Ketrenos82328352005-08-24 22:33:31 -05005958 } else
5959 return -EINVAL;
James Ketrenos2c86c272005-03-23 17:32:29 -06005960
5961 if (ieee->set_security)
5962 ieee->set_security(ieee->dev, &sec);
5963 else
5964 ret = -EOPNOTSUPP;
5965
5966 return ret;
5967}
5968
Adrian Bunk3c398b82006-01-21 01:36:36 +01005969static void ipw2100_wpa_assoc_frame(struct ipw2100_priv *priv,
5970 char *wpa_ie, int wpa_ie_len)
James Ketrenosee8e3652005-09-14 09:47:29 -05005971{
James Ketrenos2c86c272005-03-23 17:32:29 -06005972
5973 struct ipw2100_wpa_assoc_frame frame;
5974
5975 frame.fixed_ie_mask = 0;
5976
5977 /* copy WPA IE */
5978 memcpy(frame.var_ie, wpa_ie, wpa_ie_len);
5979 frame.var_ie_len = wpa_ie_len;
5980
5981 /* make sure WPA is enabled */
5982 ipw2100_wpa_enable(priv, 1);
5983 ipw2100_set_wpa_ie(priv, &frame, 0);
5984}
5985
James Ketrenos2c86c272005-03-23 17:32:29 -06005986static void ipw_ethtool_get_drvinfo(struct net_device *dev,
5987 struct ethtool_drvinfo *info)
5988{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005989 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06005990 char fw_ver[64], ucode_ver[64];
5991
5992 strcpy(info->driver, DRV_NAME);
5993 strcpy(info->version, DRV_VERSION);
5994
5995 ipw2100_get_fwversion(priv, fw_ver, sizeof(fw_ver));
5996 ipw2100_get_ucodeversion(priv, ucode_ver, sizeof(ucode_ver));
5997
5998 snprintf(info->fw_version, sizeof(info->fw_version), "%s:%d:%s",
5999 fw_ver, priv->eeprom_version, ucode_ver);
6000
6001 strcpy(info->bus_info, pci_name(priv->pci_dev));
6002}
6003
6004static u32 ipw2100_ethtool_get_link(struct net_device *dev)
6005{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006006 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenosee8e3652005-09-14 09:47:29 -05006007 return (priv->status & STATUS_ASSOCIATED) ? 1 : 0;
James Ketrenos2c86c272005-03-23 17:32:29 -06006008}
6009
Jeff Garzik7282d492006-09-13 14:30:00 -04006010static const struct ethtool_ops ipw2100_ethtool_ops = {
James Ketrenosee8e3652005-09-14 09:47:29 -05006011 .get_link = ipw2100_ethtool_get_link,
6012 .get_drvinfo = ipw_ethtool_get_drvinfo,
James Ketrenos2c86c272005-03-23 17:32:29 -06006013};
6014
David Howellsc4028952006-11-22 14:57:56 +00006015static void ipw2100_hang_check(struct work_struct *work)
James Ketrenos2c86c272005-03-23 17:32:29 -06006016{
David Howellsc4028952006-11-22 14:57:56 +00006017 struct ipw2100_priv *priv =
6018 container_of(work, struct ipw2100_priv, hang_check.work);
James Ketrenos2c86c272005-03-23 17:32:29 -06006019 unsigned long flags;
6020 u32 rtc = 0xa5a5a5a5;
6021 u32 len = sizeof(rtc);
6022 int restart = 0;
6023
6024 spin_lock_irqsave(&priv->low_lock, flags);
6025
6026 if (priv->fatal_error != 0) {
6027 /* If fatal_error is set then we need to restart */
6028 IPW_DEBUG_INFO("%s: Hardware fatal error detected.\n",
6029 priv->net_dev->name);
6030
6031 restart = 1;
6032 } else if (ipw2100_get_ordinal(priv, IPW_ORD_RTC_TIME, &rtc, &len) ||
6033 (rtc == priv->last_rtc)) {
6034 /* Check if firmware is hung */
6035 IPW_DEBUG_INFO("%s: Firmware RTC stalled.\n",
6036 priv->net_dev->name);
6037
6038 restart = 1;
6039 }
6040
6041 if (restart) {
6042 /* Kill timer */
6043 priv->stop_hang_check = 1;
6044 priv->hangs++;
6045
6046 /* Restart the NIC */
6047 schedule_reset(priv);
6048 }
6049
6050 priv->last_rtc = rtc;
6051
6052 if (!priv->stop_hang_check)
6053 queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2);
6054
6055 spin_unlock_irqrestore(&priv->low_lock, flags);
6056}
6057
David Howellsc4028952006-11-22 14:57:56 +00006058static void ipw2100_rf_kill(struct work_struct *work)
James Ketrenos2c86c272005-03-23 17:32:29 -06006059{
David Howellsc4028952006-11-22 14:57:56 +00006060 struct ipw2100_priv *priv =
6061 container_of(work, struct ipw2100_priv, rf_kill.work);
James Ketrenos2c86c272005-03-23 17:32:29 -06006062 unsigned long flags;
6063
6064 spin_lock_irqsave(&priv->low_lock, flags);
6065
6066 if (rf_kill_active(priv)) {
6067 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
6068 if (!priv->stop_rf_kill)
Stephen Hemmingera62056f2007-06-22 21:46:50 -07006069 queue_delayed_work(priv->workqueue, &priv->rf_kill,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05006070 round_jiffies_relative(HZ));
James Ketrenos2c86c272005-03-23 17:32:29 -06006071 goto exit_unlock;
6072 }
6073
6074 /* RF Kill is now disabled, so bring the device back up */
6075
6076 if (!(priv->status & STATUS_RF_KILL_MASK)) {
6077 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
6078 "device\n");
6079 schedule_reset(priv);
6080 } else
6081 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
6082 "enabled\n");
6083
James Ketrenosee8e3652005-09-14 09:47:29 -05006084 exit_unlock:
James Ketrenos2c86c272005-03-23 17:32:29 -06006085 spin_unlock_irqrestore(&priv->low_lock, flags);
6086}
6087
6088static void ipw2100_irq_tasklet(struct ipw2100_priv *priv);
6089
Stephen Hemminger3e47fce2009-03-20 19:36:40 +00006090static const struct net_device_ops ipw2100_netdev_ops = {
6091 .ndo_open = ipw2100_open,
6092 .ndo_stop = ipw2100_close,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006093 .ndo_start_xmit = libipw_xmit,
6094 .ndo_change_mtu = libipw_change_mtu,
Stephen Hemminger3e47fce2009-03-20 19:36:40 +00006095 .ndo_init = ipw2100_net_init,
6096 .ndo_tx_timeout = ipw2100_tx_timeout,
6097 .ndo_set_mac_address = ipw2100_set_address,
6098 .ndo_validate_addr = eth_validate_addr,
6099};
6100
Pavel Roskin27ae60f2010-03-12 00:01:22 -05006101/* Look into using netdev destructor to shutdown libipw? */
James Ketrenos2c86c272005-03-23 17:32:29 -06006102
James Ketrenosee8e3652005-09-14 09:47:29 -05006103static struct net_device *ipw2100_alloc_device(struct pci_dev *pci_dev,
6104 void __iomem * base_addr,
6105 unsigned long mem_start,
6106 unsigned long mem_len)
James Ketrenos2c86c272005-03-23 17:32:29 -06006107{
6108 struct ipw2100_priv *priv;
6109 struct net_device *dev;
6110
Pavel Roskin27ae60f2010-03-12 00:01:22 -05006111 dev = alloc_libipw(sizeof(struct ipw2100_priv), 0);
James Ketrenos2c86c272005-03-23 17:32:29 -06006112 if (!dev)
6113 return NULL;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006114 priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006115 priv->ieee = netdev_priv(dev);
6116 priv->pci_dev = pci_dev;
6117 priv->net_dev = dev;
6118
6119 priv->ieee->hard_start_xmit = ipw2100_tx;
6120 priv->ieee->set_security = shim__set_security;
6121
James Ketrenos82328352005-08-24 22:33:31 -05006122 priv->ieee->perfect_rssi = -20;
6123 priv->ieee->worst_rssi = -85;
6124
Stephen Hemminger3e47fce2009-03-20 19:36:40 +00006125 dev->netdev_ops = &ipw2100_netdev_ops;
James Ketrenos2c86c272005-03-23 17:32:29 -06006126 dev->ethtool_ops = &ipw2100_ethtool_ops;
James Ketrenos2c86c272005-03-23 17:32:29 -06006127 dev->wireless_handlers = &ipw2100_wx_handler_def;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006128 priv->wireless_data.libipw = priv->ieee;
James Ketrenoseaf8f532005-11-12 12:50:12 -06006129 dev->wireless_data = &priv->wireless_data;
James Ketrenosee8e3652005-09-14 09:47:29 -05006130 dev->watchdog_timeo = 3 * HZ;
James Ketrenos2c86c272005-03-23 17:32:29 -06006131 dev->irq = 0;
6132
6133 dev->base_addr = (unsigned long)base_addr;
6134 dev->mem_start = mem_start;
6135 dev->mem_end = dev->mem_start + mem_len - 1;
6136
6137 /* NOTE: We don't use the wireless_handlers hook
6138 * in dev as the system will start throwing WX requests
6139 * to us before we're actually initialized and it just
6140 * ends up causing problems. So, we just handle
6141 * the WX extensions through the ipw2100_ioctl interface */
6142
Jean Delvarec03983a2007-10-19 23:22:55 +02006143 /* memset() puts everything to 0, so we only have explicitly set
James Ketrenos2c86c272005-03-23 17:32:29 -06006144 * those values that need to be something else */
6145
6146 /* If power management is turned on, default to AUTO mode */
6147 priv->power_mode = IPW_POWER_AUTO;
6148
James Ketrenos82328352005-08-24 22:33:31 -05006149#ifdef CONFIG_IPW2100_MONITOR
6150 priv->config |= CFG_CRC_CHECK;
6151#endif
James Ketrenos2c86c272005-03-23 17:32:29 -06006152 priv->ieee->wpa_enabled = 0;
James Ketrenos2c86c272005-03-23 17:32:29 -06006153 priv->ieee->drop_unencrypted = 0;
6154 priv->ieee->privacy_invoked = 0;
6155 priv->ieee->ieee802_1x = 1;
James Ketrenos2c86c272005-03-23 17:32:29 -06006156
6157 /* Set module parameters */
Reinette Chatre21f8a732009-08-18 10:25:05 -07006158 switch (network_mode) {
James Ketrenos2c86c272005-03-23 17:32:29 -06006159 case 1:
6160 priv->ieee->iw_mode = IW_MODE_ADHOC;
6161 break;
6162#ifdef CONFIG_IPW2100_MONITOR
6163 case 2:
6164 priv->ieee->iw_mode = IW_MODE_MONITOR;
6165 break;
6166#endif
6167 default:
6168 case 0:
6169 priv->ieee->iw_mode = IW_MODE_INFRA;
6170 break;
6171 }
6172
6173 if (disable == 1)
6174 priv->status |= STATUS_RF_KILL_SW;
6175
6176 if (channel != 0 &&
James Ketrenosee8e3652005-09-14 09:47:29 -05006177 ((channel >= REG_MIN_CHANNEL) && (channel <= REG_MAX_CHANNEL))) {
James Ketrenos2c86c272005-03-23 17:32:29 -06006178 priv->config |= CFG_STATIC_CHANNEL;
6179 priv->channel = channel;
6180 }
6181
6182 if (associate)
6183 priv->config |= CFG_ASSOCIATE;
6184
6185 priv->beacon_interval = DEFAULT_BEACON_INTERVAL;
6186 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
6187 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
6188 priv->rts_threshold = DEFAULT_RTS_THRESHOLD | RTS_DISABLED;
6189 priv->frag_threshold = DEFAULT_FTS | FRAG_DISABLED;
6190 priv->tx_power = IPW_TX_POWER_DEFAULT;
6191 priv->tx_rates = DEFAULT_TX_RATES;
6192
6193 strcpy(priv->nick, "ipw2100");
6194
6195 spin_lock_init(&priv->low_lock);
Ingo Molnar752e3772006-02-28 07:20:54 +08006196 mutex_init(&priv->action_mutex);
6197 mutex_init(&priv->adapter_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006198
6199 init_waitqueue_head(&priv->wait_command_queue);
6200
6201 netif_carrier_off(dev);
6202
6203 INIT_LIST_HEAD(&priv->msg_free_list);
6204 INIT_LIST_HEAD(&priv->msg_pend_list);
6205 INIT_STAT(&priv->msg_free_stat);
6206 INIT_STAT(&priv->msg_pend_stat);
6207
6208 INIT_LIST_HEAD(&priv->tx_free_list);
6209 INIT_LIST_HEAD(&priv->tx_pend_list);
6210 INIT_STAT(&priv->tx_free_stat);
6211 INIT_STAT(&priv->tx_pend_stat);
6212
6213 INIT_LIST_HEAD(&priv->fw_pend_list);
6214 INIT_STAT(&priv->fw_pend_stat);
6215
James Ketrenos2c86c272005-03-23 17:32:29 -06006216 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos392d0f62005-09-07 18:39:03 -05006217
David Howellsc4028952006-11-22 14:57:56 +00006218 INIT_DELAYED_WORK(&priv->reset_work, ipw2100_reset_adapter);
6219 INIT_DELAYED_WORK(&priv->security_work, ipw2100_security_work);
6220 INIT_DELAYED_WORK(&priv->wx_event_work, ipw2100_wx_event_work);
6221 INIT_DELAYED_WORK(&priv->hang_check, ipw2100_hang_check);
6222 INIT_DELAYED_WORK(&priv->rf_kill, ipw2100_rf_kill);
Dan Williamsd20c6782007-10-10 12:28:07 -04006223 INIT_WORK(&priv->scan_event_now, ipw2100_scan_event_now);
6224 INIT_DELAYED_WORK(&priv->scan_event_later, ipw2100_scan_event_later);
James Ketrenos2c86c272005-03-23 17:32:29 -06006225
6226 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
6227 ipw2100_irq_tasklet, (unsigned long)priv);
6228
6229 /* NOTE: We do not start the deferred work for status checks yet */
6230 priv->stop_rf_kill = 1;
6231 priv->stop_hang_check = 1;
6232
6233 return dev;
6234}
6235
James Ketrenos2c86c272005-03-23 17:32:29 -06006236static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
6237 const struct pci_device_id *ent)
6238{
6239 unsigned long mem_start, mem_len, mem_flags;
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01006240 void __iomem *base_addr = NULL;
James Ketrenos2c86c272005-03-23 17:32:29 -06006241 struct net_device *dev = NULL;
6242 struct ipw2100_priv *priv = NULL;
6243 int err = 0;
6244 int registered = 0;
6245 u32 val;
6246
6247 IPW_DEBUG_INFO("enter\n");
6248
6249 mem_start = pci_resource_start(pci_dev, 0);
6250 mem_len = pci_resource_len(pci_dev, 0);
6251 mem_flags = pci_resource_flags(pci_dev, 0);
6252
6253 if ((mem_flags & IORESOURCE_MEM) != IORESOURCE_MEM) {
6254 IPW_DEBUG_INFO("weird - resource type is not memory\n");
6255 err = -ENODEV;
6256 goto fail;
6257 }
6258
6259 base_addr = ioremap_nocache(mem_start, mem_len);
6260 if (!base_addr) {
6261 printk(KERN_WARNING DRV_NAME
6262 "Error calling ioremap_nocache.\n");
6263 err = -EIO;
6264 goto fail;
6265 }
6266
6267 /* allocate and initialize our net_device */
6268 dev = ipw2100_alloc_device(pci_dev, base_addr, mem_start, mem_len);
6269 if (!dev) {
6270 printk(KERN_WARNING DRV_NAME
6271 "Error calling ipw2100_alloc_device.\n");
6272 err = -ENOMEM;
6273 goto fail;
6274 }
6275
6276 /* set up PCI mappings for device */
6277 err = pci_enable_device(pci_dev);
6278 if (err) {
6279 printk(KERN_WARNING DRV_NAME
6280 "Error calling pci_enable_device.\n");
6281 return err;
6282 }
6283
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006284 priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006285
6286 pci_set_master(pci_dev);
6287 pci_set_drvdata(pci_dev, priv);
6288
Yang Hongyang284901a2009-04-06 19:01:15 -07006289 err = pci_set_dma_mask(pci_dev, DMA_BIT_MASK(32));
James Ketrenos2c86c272005-03-23 17:32:29 -06006290 if (err) {
6291 printk(KERN_WARNING DRV_NAME
6292 "Error calling pci_set_dma_mask.\n");
6293 pci_disable_device(pci_dev);
6294 return err;
6295 }
6296
6297 err = pci_request_regions(pci_dev, DRV_NAME);
6298 if (err) {
6299 printk(KERN_WARNING DRV_NAME
6300 "Error calling pci_request_regions.\n");
6301 pci_disable_device(pci_dev);
6302 return err;
6303 }
6304
James Ketrenosee8e3652005-09-14 09:47:29 -05006305 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos2c86c272005-03-23 17:32:29 -06006306 * PCI Tx retries from interfering with C3 CPU state */
6307 pci_read_config_dword(pci_dev, 0x40, &val);
6308 if ((val & 0x0000ff00) != 0)
6309 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6310
Pavel Machek8724a112005-06-20 14:28:43 -07006311 pci_set_power_state(pci_dev, PCI_D0);
James Ketrenos2c86c272005-03-23 17:32:29 -06006312
6313 if (!ipw2100_hw_is_adapter_in_system(dev)) {
6314 printk(KERN_WARNING DRV_NAME
6315 "Device not found via register read.\n");
6316 err = -ENODEV;
6317 goto fail;
6318 }
6319
6320 SET_NETDEV_DEV(dev, &pci_dev->dev);
6321
6322 /* Force interrupts to be shut off on the device */
6323 priv->status |= STATUS_INT_ENABLED;
6324 ipw2100_disable_interrupts(priv);
6325
6326 /* Allocate and initialize the Tx/Rx queues and lists */
6327 if (ipw2100_queues_allocate(priv)) {
6328 printk(KERN_WARNING DRV_NAME
Zhu Yi90c009a2006-12-05 14:41:32 +08006329 "Error calling ipw2100_queues_allocate.\n");
James Ketrenos2c86c272005-03-23 17:32:29 -06006330 err = -ENOMEM;
6331 goto fail;
6332 }
6333 ipw2100_queues_initialize(priv);
6334
6335 err = request_irq(pci_dev->irq,
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07006336 ipw2100_interrupt, IRQF_SHARED, dev->name, priv);
James Ketrenos2c86c272005-03-23 17:32:29 -06006337 if (err) {
6338 printk(KERN_WARNING DRV_NAME
James Ketrenosee8e3652005-09-14 09:47:29 -05006339 "Error calling request_irq: %d.\n", pci_dev->irq);
James Ketrenos2c86c272005-03-23 17:32:29 -06006340 goto fail;
6341 }
6342 dev->irq = pci_dev->irq;
6343
6344 IPW_DEBUG_INFO("Attempting to register device...\n");
6345
James Ketrenos2c86c272005-03-23 17:32:29 -06006346 printk(KERN_INFO DRV_NAME
6347 ": Detected Intel PRO/Wireless 2100 Network Connection\n");
6348
6349 /* Bring up the interface. Pre 0.46, after we registered the
6350 * network device we would call ipw2100_up. This introduced a race
6351 * condition with newer hotplug configurations (network was coming
6352 * up and making calls before the device was initialized).
6353 *
6354 * If we called ipw2100_up before we registered the device, then the
6355 * device name wasn't registered. So, we instead use the net_dev->init
6356 * member to call a function that then just turns and calls ipw2100_up.
6357 * net_dev->init is called after name allocation but before the
6358 * notifier chain is called */
James Ketrenos2c86c272005-03-23 17:32:29 -06006359 err = register_netdev(dev);
6360 if (err) {
6361 printk(KERN_WARNING DRV_NAME
6362 "Error calling register_netdev.\n");
Zhu Yiefbd8092006-08-21 11:38:52 +08006363 goto fail;
James Ketrenos2c86c272005-03-23 17:32:29 -06006364 }
Zhu Yiefbd8092006-08-21 11:38:52 +08006365
6366 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006367 registered = 1;
6368
6369 IPW_DEBUG_INFO("%s: Bound to %s\n", dev->name, pci_name(pci_dev));
6370
6371 /* perform this after register_netdev so that dev->name is set */
Jeff Garzikde897882006-10-01 07:31:09 -04006372 err = sysfs_create_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6373 if (err)
6374 goto fail_unlock;
James Ketrenos2c86c272005-03-23 17:32:29 -06006375
6376 /* If the RF Kill switch is disabled, go ahead and complete the
6377 * startup sequence */
6378 if (!(priv->status & STATUS_RF_KILL_MASK)) {
6379 /* Enable the adapter - sends HOST_COMPLETE */
6380 if (ipw2100_enable_adapter(priv)) {
6381 printk(KERN_WARNING DRV_NAME
6382 ": %s: failed in call to enable adapter.\n",
6383 priv->net_dev->name);
6384 ipw2100_hw_stop_adapter(priv);
6385 err = -EIO;
6386 goto fail_unlock;
6387 }
6388
6389 /* Start a scan . . . */
6390 ipw2100_set_scan_options(priv);
6391 ipw2100_start_scan(priv);
6392 }
6393
6394 IPW_DEBUG_INFO("exit\n");
6395
6396 priv->status |= STATUS_INITIALIZED;
6397
Ingo Molnar752e3772006-02-28 07:20:54 +08006398 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006399
6400 return 0;
6401
James Ketrenosee8e3652005-09-14 09:47:29 -05006402 fail_unlock:
Ingo Molnar752e3772006-02-28 07:20:54 +08006403 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006404
James Ketrenosee8e3652005-09-14 09:47:29 -05006405 fail:
James Ketrenos2c86c272005-03-23 17:32:29 -06006406 if (dev) {
John W. Linville143d40f2009-11-06 12:58:20 -05006407 if (registered)
James Ketrenos2c86c272005-03-23 17:32:29 -06006408 unregister_netdev(dev);
6409
6410 ipw2100_hw_stop_adapter(priv);
6411
6412 ipw2100_disable_interrupts(priv);
6413
6414 if (dev->irq)
6415 free_irq(dev->irq, priv);
6416
6417 ipw2100_kill_workqueue(priv);
6418
6419 /* These are safe to call even if they weren't allocated */
6420 ipw2100_queues_free(priv);
James Ketrenosee8e3652005-09-14 09:47:29 -05006421 sysfs_remove_group(&pci_dev->dev.kobj,
6422 &ipw2100_attribute_group);
James Ketrenos2c86c272005-03-23 17:32:29 -06006423
Pavel Roskin27ae60f2010-03-12 00:01:22 -05006424 free_libipw(dev, 0);
James Ketrenos2c86c272005-03-23 17:32:29 -06006425 pci_set_drvdata(pci_dev, NULL);
6426 }
6427
6428 if (base_addr)
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01006429 iounmap(base_addr);
James Ketrenos2c86c272005-03-23 17:32:29 -06006430
6431 pci_release_regions(pci_dev);
6432 pci_disable_device(pci_dev);
6433
6434 return err;
6435}
6436
6437static void __devexit ipw2100_pci_remove_one(struct pci_dev *pci_dev)
6438{
6439 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6440 struct net_device *dev;
6441
6442 if (priv) {
Ingo Molnar752e3772006-02-28 07:20:54 +08006443 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006444
6445 priv->status &= ~STATUS_INITIALIZED;
6446
6447 dev = priv->net_dev;
James Ketrenosee8e3652005-09-14 09:47:29 -05006448 sysfs_remove_group(&pci_dev->dev.kobj,
6449 &ipw2100_attribute_group);
James Ketrenos2c86c272005-03-23 17:32:29 -06006450
6451#ifdef CONFIG_PM
6452 if (ipw2100_firmware.version)
6453 ipw2100_release_firmware(priv, &ipw2100_firmware);
6454#endif
6455 /* Take down the hardware */
6456 ipw2100_down(priv);
6457
Ingo Molnar752e3772006-02-28 07:20:54 +08006458 /* Release the mutex so that the network subsystem can
James Ketrenos2c86c272005-03-23 17:32:29 -06006459 * complete any needed calls into the driver... */
Ingo Molnar752e3772006-02-28 07:20:54 +08006460 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006461
6462 /* Unregister the device first - this results in close()
6463 * being called if the device is open. If we free storage
6464 * first, then close() will crash. */
6465 unregister_netdev(dev);
6466
6467 /* ipw2100_down will ensure that there is no more pending work
6468 * in the workqueue's, so we can safely remove them now. */
6469 ipw2100_kill_workqueue(priv);
6470
6471 ipw2100_queues_free(priv);
6472
6473 /* Free potential debugging firmware snapshot */
6474 ipw2100_snapshot_free(priv);
6475
6476 if (dev->irq)
6477 free_irq(dev->irq, priv);
6478
6479 if (dev->base_addr)
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01006480 iounmap((void __iomem *)dev->base_addr);
James Ketrenos2c86c272005-03-23 17:32:29 -06006481
Pavel Roskin27ae60f2010-03-12 00:01:22 -05006482 /* wiphy_unregister needs to be here, before free_libipw */
Matthew Garrettc26409a2009-11-11 14:36:30 -05006483 wiphy_unregister(priv->ieee->wdev.wiphy);
6484 kfree(priv->ieee->bg_band.channels);
Pavel Roskin27ae60f2010-03-12 00:01:22 -05006485 free_libipw(dev, 0);
James Ketrenos2c86c272005-03-23 17:32:29 -06006486 }
6487
6488 pci_release_regions(pci_dev);
6489 pci_disable_device(pci_dev);
6490
6491 IPW_DEBUG_INFO("exit\n");
6492}
6493
James Ketrenos2c86c272005-03-23 17:32:29 -06006494#ifdef CONFIG_PM
James Ketrenos2c86c272005-03-23 17:32:29 -06006495static int ipw2100_suspend(struct pci_dev *pci_dev, pm_message_t state)
James Ketrenos2c86c272005-03-23 17:32:29 -06006496{
6497 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6498 struct net_device *dev = priv->net_dev;
6499
James Ketrenosee8e3652005-09-14 09:47:29 -05006500 IPW_DEBUG_INFO("%s: Going into suspend...\n", dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06006501
Ingo Molnar752e3772006-02-28 07:20:54 +08006502 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006503 if (priv->status & STATUS_INITIALIZED) {
6504 /* Take down the device; powers it off, etc. */
6505 ipw2100_down(priv);
6506 }
6507
6508 /* Remove the PRESENT state of the device */
6509 netif_device_detach(dev);
6510
James Ketrenos2c86c272005-03-23 17:32:29 -06006511 pci_save_state(pci_dev);
James Ketrenosee8e3652005-09-14 09:47:29 -05006512 pci_disable_device(pci_dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006513 pci_set_power_state(pci_dev, PCI_D3hot);
James Ketrenos2c86c272005-03-23 17:32:29 -06006514
Dan Williamsc3d72b92009-02-11 13:26:06 -05006515 priv->suspend_at = get_seconds();
6516
Ingo Molnar752e3772006-02-28 07:20:54 +08006517 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006518
6519 return 0;
6520}
6521
6522static int ipw2100_resume(struct pci_dev *pci_dev)
6523{
6524 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6525 struct net_device *dev = priv->net_dev;
John W. Linville02e0e5e2006-11-07 20:53:48 -05006526 int err;
James Ketrenos2c86c272005-03-23 17:32:29 -06006527 u32 val;
6528
6529 if (IPW2100_PM_DISABLED)
6530 return 0;
6531
Ingo Molnar752e3772006-02-28 07:20:54 +08006532 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006533
James Ketrenosee8e3652005-09-14 09:47:29 -05006534 IPW_DEBUG_INFO("%s: Coming out of suspend...\n", dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06006535
James Ketrenos2c86c272005-03-23 17:32:29 -06006536 pci_set_power_state(pci_dev, PCI_D0);
John W. Linville02e0e5e2006-11-07 20:53:48 -05006537 err = pci_enable_device(pci_dev);
6538 if (err) {
6539 printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
6540 dev->name);
Julia Lawall80c42af2008-07-21 09:58:11 +02006541 mutex_unlock(&priv->action_mutex);
John W. Linville02e0e5e2006-11-07 20:53:48 -05006542 return err;
6543 }
James Ketrenos2c86c272005-03-23 17:32:29 -06006544 pci_restore_state(pci_dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006545
6546 /*
6547 * Suspend/Resume resets the PCI configuration space, so we have to
6548 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
6549 * from interfering with C3 CPU state. pci_restore_state won't help
6550 * here since it only restores the first 64 bytes pci config header.
6551 */
6552 pci_read_config_dword(pci_dev, 0x40, &val);
6553 if ((val & 0x0000ff00) != 0)
6554 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6555
6556 /* Set the device back into the PRESENT state; this will also wake
6557 * the queue of needed */
6558 netif_device_attach(dev);
6559
Dan Williamsc3d72b92009-02-11 13:26:06 -05006560 priv->suspend_time = get_seconds() - priv->suspend_at;
6561
James Ketrenosee8e3652005-09-14 09:47:29 -05006562 /* Bring the device back up */
6563 if (!(priv->status & STATUS_RF_KILL_SW))
6564 ipw2100_up(priv, 0);
James Ketrenos2c86c272005-03-23 17:32:29 -06006565
Ingo Molnar752e3772006-02-28 07:20:54 +08006566 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006567
6568 return 0;
6569}
6570#endif
6571
Zhu Yi52ce3e9a72009-12-02 14:24:37 +08006572static void ipw2100_shutdown(struct pci_dev *pci_dev)
6573{
6574 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6575
6576 /* Take down the device; powers it off, etc. */
6577 ipw2100_down(priv);
6578
6579 pci_disable_device(pci_dev);
6580}
6581
James Ketrenos2c86c272005-03-23 17:32:29 -06006582#define IPW2100_DEV_ID(x) { PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, x }
6583
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006584static DEFINE_PCI_DEVICE_TABLE(ipw2100_pci_id_table) = {
James Ketrenosee8e3652005-09-14 09:47:29 -05006585 IPW2100_DEV_ID(0x2520), /* IN 2100A mPCI 3A */
6586 IPW2100_DEV_ID(0x2521), /* IN 2100A mPCI 3B */
6587 IPW2100_DEV_ID(0x2524), /* IN 2100A mPCI 3B */
6588 IPW2100_DEV_ID(0x2525), /* IN 2100A mPCI 3B */
6589 IPW2100_DEV_ID(0x2526), /* IN 2100A mPCI Gen A3 */
6590 IPW2100_DEV_ID(0x2522), /* IN 2100 mPCI 3B */
6591 IPW2100_DEV_ID(0x2523), /* IN 2100 mPCI 3A */
6592 IPW2100_DEV_ID(0x2527), /* IN 2100 mPCI 3B */
6593 IPW2100_DEV_ID(0x2528), /* IN 2100 mPCI 3B */
6594 IPW2100_DEV_ID(0x2529), /* IN 2100 mPCI 3B */
6595 IPW2100_DEV_ID(0x252B), /* IN 2100 mPCI 3A */
6596 IPW2100_DEV_ID(0x252C), /* IN 2100 mPCI 3A */
6597 IPW2100_DEV_ID(0x252D), /* IN 2100 mPCI 3A */
James Ketrenos2c86c272005-03-23 17:32:29 -06006598
James Ketrenosee8e3652005-09-14 09:47:29 -05006599 IPW2100_DEV_ID(0x2550), /* IB 2100A mPCI 3B */
6600 IPW2100_DEV_ID(0x2551), /* IB 2100 mPCI 3B */
6601 IPW2100_DEV_ID(0x2553), /* IB 2100 mPCI 3B */
6602 IPW2100_DEV_ID(0x2554), /* IB 2100 mPCI 3B */
6603 IPW2100_DEV_ID(0x2555), /* IB 2100 mPCI 3B */
James Ketrenos2c86c272005-03-23 17:32:29 -06006604
James Ketrenosee8e3652005-09-14 09:47:29 -05006605 IPW2100_DEV_ID(0x2560), /* DE 2100A mPCI 3A */
6606 IPW2100_DEV_ID(0x2562), /* DE 2100A mPCI 3A */
6607 IPW2100_DEV_ID(0x2563), /* DE 2100A mPCI 3A */
6608 IPW2100_DEV_ID(0x2561), /* DE 2100 mPCI 3A */
6609 IPW2100_DEV_ID(0x2565), /* DE 2100 mPCI 3A */
6610 IPW2100_DEV_ID(0x2566), /* DE 2100 mPCI 3A */
6611 IPW2100_DEV_ID(0x2567), /* DE 2100 mPCI 3A */
James Ketrenos2c86c272005-03-23 17:32:29 -06006612
James Ketrenosee8e3652005-09-14 09:47:29 -05006613 IPW2100_DEV_ID(0x2570), /* GA 2100 mPCI 3B */
James Ketrenos2c86c272005-03-23 17:32:29 -06006614
James Ketrenosee8e3652005-09-14 09:47:29 -05006615 IPW2100_DEV_ID(0x2580), /* TO 2100A mPCI 3B */
6616 IPW2100_DEV_ID(0x2582), /* TO 2100A mPCI 3B */
6617 IPW2100_DEV_ID(0x2583), /* TO 2100A mPCI 3B */
6618 IPW2100_DEV_ID(0x2581), /* TO 2100 mPCI 3B */
6619 IPW2100_DEV_ID(0x2585), /* TO 2100 mPCI 3B */
6620 IPW2100_DEV_ID(0x2586), /* TO 2100 mPCI 3B */
6621 IPW2100_DEV_ID(0x2587), /* TO 2100 mPCI 3B */
James Ketrenos2c86c272005-03-23 17:32:29 -06006622
James Ketrenosee8e3652005-09-14 09:47:29 -05006623 IPW2100_DEV_ID(0x2590), /* SO 2100A mPCI 3B */
6624 IPW2100_DEV_ID(0x2592), /* SO 2100A mPCI 3B */
6625 IPW2100_DEV_ID(0x2591), /* SO 2100 mPCI 3B */
6626 IPW2100_DEV_ID(0x2593), /* SO 2100 mPCI 3B */
6627 IPW2100_DEV_ID(0x2596), /* SO 2100 mPCI 3B */
6628 IPW2100_DEV_ID(0x2598), /* SO 2100 mPCI 3B */
James Ketrenos2c86c272005-03-23 17:32:29 -06006629
James Ketrenosee8e3652005-09-14 09:47:29 -05006630 IPW2100_DEV_ID(0x25A0), /* HP 2100 mPCI 3B */
James Ketrenos2c86c272005-03-23 17:32:29 -06006631 {0,},
6632};
6633
6634MODULE_DEVICE_TABLE(pci, ipw2100_pci_id_table);
6635
6636static struct pci_driver ipw2100_pci_driver = {
6637 .name = DRV_NAME,
6638 .id_table = ipw2100_pci_id_table,
6639 .probe = ipw2100_pci_init_one,
6640 .remove = __devexit_p(ipw2100_pci_remove_one),
6641#ifdef CONFIG_PM
6642 .suspend = ipw2100_suspend,
6643 .resume = ipw2100_resume,
6644#endif
Zhu Yi52ce3e9a72009-12-02 14:24:37 +08006645 .shutdown = ipw2100_shutdown,
James Ketrenos2c86c272005-03-23 17:32:29 -06006646};
6647
James Ketrenos2c86c272005-03-23 17:32:29 -06006648/**
6649 * Initialize the ipw2100 driver/module
6650 *
6651 * @returns 0 if ok, < 0 errno node con error.
6652 *
6653 * Note: we cannot init the /proc stuff until the PCI driver is there,
6654 * or we risk an unlikely race condition on someone accessing
6655 * uninitialized data in the PCI dev struct through /proc.
6656 */
6657static int __init ipw2100_init(void)
6658{
6659 int ret;
6660
6661 printk(KERN_INFO DRV_NAME ": %s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
6662 printk(KERN_INFO DRV_NAME ": %s\n", DRV_COPYRIGHT);
6663
Jeff Garzik29917622006-08-19 17:48:59 -04006664 ret = pci_register_driver(&ipw2100_pci_driver);
Jeff Garzikde897882006-10-01 07:31:09 -04006665 if (ret)
6666 goto out;
James Ketrenos2c86c272005-03-23 17:32:29 -06006667
Mark Grossed771342010-05-06 01:59:26 +02006668 ipw2100_pm_qos_req = pm_qos_add_request(PM_QOS_CPU_DMA_LATENCY,
Mark Grossf011e2e2008-02-04 22:30:09 -08006669 PM_QOS_DEFAULT_VALUE);
Brice Goglin0f52bf92005-12-01 01:41:46 -08006670#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06006671 ipw2100_debug_level = debug;
Jeff Garzikde897882006-10-01 07:31:09 -04006672 ret = driver_create_file(&ipw2100_pci_driver.driver,
6673 &driver_attr_debug_level);
James Ketrenos2c86c272005-03-23 17:32:29 -06006674#endif
6675
Jeff Garzikde897882006-10-01 07:31:09 -04006676out:
James Ketrenos2c86c272005-03-23 17:32:29 -06006677 return ret;
6678}
6679
James Ketrenos2c86c272005-03-23 17:32:29 -06006680/**
6681 * Cleanup ipw2100 driver registration
6682 */
6683static void __exit ipw2100_exit(void)
6684{
6685 /* FIXME: IPG: check that we have no instances of the devices open */
Brice Goglin0f52bf92005-12-01 01:41:46 -08006686#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06006687 driver_remove_file(&ipw2100_pci_driver.driver,
6688 &driver_attr_debug_level);
6689#endif
6690 pci_unregister_driver(&ipw2100_pci_driver);
Mark Grossed771342010-05-06 01:59:26 +02006691 pm_qos_remove_request(ipw2100_pm_qos_req);
James Ketrenos2c86c272005-03-23 17:32:29 -06006692}
6693
6694module_init(ipw2100_init);
6695module_exit(ipw2100_exit);
6696
James Ketrenos2c86c272005-03-23 17:32:29 -06006697static int ipw2100_wx_get_name(struct net_device *dev,
6698 struct iw_request_info *info,
6699 union iwreq_data *wrqu, char *extra)
6700{
6701 /*
6702 * This can be called at any time. No action lock required
6703 */
6704
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006705 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006706 if (!(priv->status & STATUS_ASSOCIATED))
6707 strcpy(wrqu->name, "unassociated");
6708 else
6709 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
6710
6711 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
6712 return 0;
6713}
6714
James Ketrenos2c86c272005-03-23 17:32:29 -06006715static int ipw2100_wx_set_freq(struct net_device *dev,
6716 struct iw_request_info *info,
6717 union iwreq_data *wrqu, char *extra)
6718{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006719 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006720 struct iw_freq *fwrq = &wrqu->freq;
6721 int err = 0;
6722
6723 if (priv->ieee->iw_mode == IW_MODE_INFRA)
6724 return -EOPNOTSUPP;
6725
Ingo Molnar752e3772006-02-28 07:20:54 +08006726 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006727 if (!(priv->status & STATUS_INITIALIZED)) {
6728 err = -EIO;
6729 goto done;
6730 }
6731
6732 /* if setting by freq convert to channel */
6733 if (fwrq->e == 1) {
James Ketrenosee8e3652005-09-14 09:47:29 -05006734 if ((fwrq->m >= (int)2.412e8 && fwrq->m <= (int)2.487e8)) {
James Ketrenos2c86c272005-03-23 17:32:29 -06006735 int f = fwrq->m / 100000;
6736 int c = 0;
6737
6738 while ((c < REG_MAX_CHANNEL) &&
6739 (f != ipw2100_frequencies[c]))
6740 c++;
6741
6742 /* hack to fall through */
6743 fwrq->e = 0;
6744 fwrq->m = c + 1;
6745 }
6746 }
6747
James Ketrenos82328352005-08-24 22:33:31 -05006748 if (fwrq->e > 0 || fwrq->m > 1000) {
6749 err = -EOPNOTSUPP;
6750 goto done;
6751 } else { /* Set the channel */
Frans Pop9fd1ea42010-03-24 19:46:31 +01006752 IPW_DEBUG_WX("SET Freq/Channel -> %d\n", fwrq->m);
James Ketrenos2c86c272005-03-23 17:32:29 -06006753 err = ipw2100_set_channel(priv, fwrq->m, 0);
6754 }
6755
James Ketrenosee8e3652005-09-14 09:47:29 -05006756 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08006757 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006758 return err;
6759}
6760
James Ketrenos2c86c272005-03-23 17:32:29 -06006761static int ipw2100_wx_get_freq(struct net_device *dev,
6762 struct iw_request_info *info,
6763 union iwreq_data *wrqu, char *extra)
6764{
6765 /*
6766 * This can be called at any time. No action lock required
6767 */
6768
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006769 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006770
6771 wrqu->freq.e = 0;
6772
6773 /* If we are associated, trying to associate, or have a statically
6774 * configured CHANNEL then return that; otherwise return ANY */
6775 if (priv->config & CFG_STATIC_CHANNEL ||
6776 priv->status & STATUS_ASSOCIATED)
6777 wrqu->freq.m = priv->channel;
6778 else
6779 wrqu->freq.m = 0;
6780
Frans Pop9fd1ea42010-03-24 19:46:31 +01006781 IPW_DEBUG_WX("GET Freq/Channel -> %d\n", priv->channel);
James Ketrenos2c86c272005-03-23 17:32:29 -06006782 return 0;
6783
6784}
6785
6786static int ipw2100_wx_set_mode(struct net_device *dev,
6787 struct iw_request_info *info,
6788 union iwreq_data *wrqu, char *extra)
6789{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006790 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006791 int err = 0;
6792
Frans Pop9fd1ea42010-03-24 19:46:31 +01006793 IPW_DEBUG_WX("SET Mode -> %d\n", wrqu->mode);
James Ketrenos2c86c272005-03-23 17:32:29 -06006794
6795 if (wrqu->mode == priv->ieee->iw_mode)
6796 return 0;
6797
Ingo Molnar752e3772006-02-28 07:20:54 +08006798 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06006799 if (!(priv->status & STATUS_INITIALIZED)) {
6800 err = -EIO;
6801 goto done;
6802 }
6803
6804 switch (wrqu->mode) {
6805#ifdef CONFIG_IPW2100_MONITOR
6806 case IW_MODE_MONITOR:
6807 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
6808 break;
James Ketrenosee8e3652005-09-14 09:47:29 -05006809#endif /* CONFIG_IPW2100_MONITOR */
James Ketrenos2c86c272005-03-23 17:32:29 -06006810 case IW_MODE_ADHOC:
6811 err = ipw2100_switch_mode(priv, IW_MODE_ADHOC);
6812 break;
6813 case IW_MODE_INFRA:
6814 case IW_MODE_AUTO:
6815 default:
6816 err = ipw2100_switch_mode(priv, IW_MODE_INFRA);
6817 break;
6818 }
6819
James Ketrenosee8e3652005-09-14 09:47:29 -05006820 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08006821 mutex_unlock(&priv->action_mutex);
James Ketrenosee8e3652005-09-14 09:47:29 -05006822 return err;
James Ketrenos2c86c272005-03-23 17:32:29 -06006823}
6824
6825static int ipw2100_wx_get_mode(struct net_device *dev,
6826 struct iw_request_info *info,
6827 union iwreq_data *wrqu, char *extra)
6828{
6829 /*
6830 * This can be called at any time. No action lock required
6831 */
6832
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006833 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006834
6835 wrqu->mode = priv->ieee->iw_mode;
6836 IPW_DEBUG_WX("GET Mode -> %d\n", wrqu->mode);
6837
6838 return 0;
6839}
6840
James Ketrenos2c86c272005-03-23 17:32:29 -06006841#define POWER_MODES 5
6842
6843/* Values are in microsecond */
Jiri Bencc4aee8c2005-08-25 20:04:43 -04006844static const s32 timeout_duration[POWER_MODES] = {
James Ketrenos2c86c272005-03-23 17:32:29 -06006845 350000,
6846 250000,
6847 75000,
6848 37000,
6849 25000,
6850};
6851
Jiri Bencc4aee8c2005-08-25 20:04:43 -04006852static const s32 period_duration[POWER_MODES] = {
James Ketrenos2c86c272005-03-23 17:32:29 -06006853 400000,
6854 700000,
6855 1000000,
6856 1000000,
6857 1000000
6858};
6859
6860static int ipw2100_wx_get_range(struct net_device *dev,
6861 struct iw_request_info *info,
6862 union iwreq_data *wrqu, char *extra)
6863{
6864 /*
6865 * This can be called at any time. No action lock required
6866 */
6867
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006868 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006869 struct iw_range *range = (struct iw_range *)extra;
6870 u16 val;
6871 int i, level;
6872
6873 wrqu->data.length = sizeof(*range);
6874 memset(range, 0, sizeof(*range));
6875
6876 /* Let's try to keep this struct in the same order as in
6877 * linux/include/wireless.h
6878 */
6879
6880 /* TODO: See what values we can set, and remove the ones we can't
6881 * set, or fill them with some default data.
6882 */
6883
6884 /* ~5 Mb/s real (802.11b) */
6885 range->throughput = 5 * 1000 * 1000;
6886
James Ketrenosee8e3652005-09-14 09:47:29 -05006887// range->sensitivity; /* signal level threshold range */
James Ketrenos2c86c272005-03-23 17:32:29 -06006888
6889 range->max_qual.qual = 100;
6890 /* TODO: Find real max RSSI and stick here */
6891 range->max_qual.level = 0;
6892 range->max_qual.noise = 0;
James Ketrenosee8e3652005-09-14 09:47:29 -05006893 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos2c86c272005-03-23 17:32:29 -06006894
James Ketrenosee8e3652005-09-14 09:47:29 -05006895 range->avg_qual.qual = 70; /* > 8% missed beacons is 'bad' */
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006896 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
James Ketrenos2c86c272005-03-23 17:32:29 -06006897 range->avg_qual.level = 20 + IPW2100_RSSI_TO_DBM;
6898 range->avg_qual.noise = 0;
James Ketrenosee8e3652005-09-14 09:47:29 -05006899 range->avg_qual.updated = 7; /* Updated all three */
James Ketrenos2c86c272005-03-23 17:32:29 -06006900
6901 range->num_bitrates = RATE_COUNT;
6902
6903 for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++) {
6904 range->bitrate[i] = ipw2100_rates_11b[i];
6905 }
6906
6907 range->min_rts = MIN_RTS_THRESHOLD;
6908 range->max_rts = MAX_RTS_THRESHOLD;
6909 range->min_frag = MIN_FRAG_THRESHOLD;
6910 range->max_frag = MAX_FRAG_THRESHOLD;
6911
6912 range->min_pmp = period_duration[0]; /* Minimal PM period */
James Ketrenosee8e3652005-09-14 09:47:29 -05006913 range->max_pmp = period_duration[POWER_MODES - 1]; /* Maximal PM period */
6914 range->min_pmt = timeout_duration[POWER_MODES - 1]; /* Minimal PM timeout */
6915 range->max_pmt = timeout_duration[0]; /* Maximal PM timeout */
James Ketrenos2c86c272005-03-23 17:32:29 -06006916
James Ketrenosee8e3652005-09-14 09:47:29 -05006917 /* How to decode max/min PM period */
James Ketrenos2c86c272005-03-23 17:32:29 -06006918 range->pmp_flags = IW_POWER_PERIOD;
James Ketrenosee8e3652005-09-14 09:47:29 -05006919 /* How to decode max/min PM period */
James Ketrenos2c86c272005-03-23 17:32:29 -06006920 range->pmt_flags = IW_POWER_TIMEOUT;
6921 /* What PM options are supported */
6922 range->pm_capa = IW_POWER_TIMEOUT | IW_POWER_PERIOD;
6923
6924 range->encoding_size[0] = 5;
James Ketrenosee8e3652005-09-14 09:47:29 -05006925 range->encoding_size[1] = 13; /* Different token sizes */
6926 range->num_encoding_sizes = 2; /* Number of entry in the list */
6927 range->max_encoding_tokens = WEP_KEYS; /* Max number of tokens */
6928// range->encoding_login_index; /* token index for login token */
James Ketrenos2c86c272005-03-23 17:32:29 -06006929
6930 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6931 range->txpower_capa = IW_TXPOW_DBM;
6932 range->num_txpower = IW_MAX_TXPOWER;
James Ketrenosee8e3652005-09-14 09:47:29 -05006933 for (i = 0, level = (IPW_TX_POWER_MAX_DBM * 16);
6934 i < IW_MAX_TXPOWER;
6935 i++, level -=
6936 ((IPW_TX_POWER_MAX_DBM -
6937 IPW_TX_POWER_MIN_DBM) * 16) / (IW_MAX_TXPOWER - 1))
James Ketrenos2c86c272005-03-23 17:32:29 -06006938 range->txpower[i] = level / 16;
6939 } else {
6940 range->txpower_capa = 0;
6941 range->num_txpower = 0;
6942 }
6943
James Ketrenos2c86c272005-03-23 17:32:29 -06006944 /* Set the Wireless Extension versions */
6945 range->we_version_compiled = WIRELESS_EXT;
Dan Williams166c3432006-01-09 11:04:31 -05006946 range->we_version_source = 18;
James Ketrenos2c86c272005-03-23 17:32:29 -06006947
James Ketrenosee8e3652005-09-14 09:47:29 -05006948// range->retry_capa; /* What retry options are supported */
6949// range->retry_flags; /* How to decode max/min retry limit */
6950// range->r_time_flags; /* How to decode max/min retry life */
6951// range->min_retry; /* Minimal number of retries */
6952// range->max_retry; /* Maximal number of retries */
6953// range->min_r_time; /* Minimal retry lifetime */
6954// range->max_r_time; /* Maximal retry lifetime */
James Ketrenos2c86c272005-03-23 17:32:29 -06006955
James Ketrenosee8e3652005-09-14 09:47:29 -05006956 range->num_channels = FREQ_COUNT;
James Ketrenos2c86c272005-03-23 17:32:29 -06006957
6958 val = 0;
6959 for (i = 0; i < FREQ_COUNT; i++) {
6960 // TODO: Include only legal frequencies for some countries
James Ketrenosee8e3652005-09-14 09:47:29 -05006961// if (local->channel_mask & (1 << i)) {
6962 range->freq[val].i = i + 1;
6963 range->freq[val].m = ipw2100_frequencies[i] * 100000;
6964 range->freq[val].e = 1;
6965 val++;
6966// }
James Ketrenos2c86c272005-03-23 17:32:29 -06006967 if (val == IW_MAX_FREQUENCIES)
James Ketrenosee8e3652005-09-14 09:47:29 -05006968 break;
James Ketrenos2c86c272005-03-23 17:32:29 -06006969 }
6970 range->num_frequency = val;
6971
James Ketrenoseaf8f532005-11-12 12:50:12 -06006972 /* Event capability (kernel + driver) */
6973 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
6974 IW_EVENT_CAPA_MASK(SIOCGIWAP));
6975 range->event_capa[1] = IW_EVENT_CAPA_K_1;
6976
Dan Williams166c3432006-01-09 11:04:31 -05006977 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
6978 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
6979
James Ketrenos2c86c272005-03-23 17:32:29 -06006980 IPW_DEBUG_WX("GET Range\n");
6981
6982 return 0;
6983}
6984
6985static int ipw2100_wx_set_wap(struct net_device *dev,
6986 struct iw_request_info *info,
6987 union iwreq_data *wrqu, char *extra)
6988{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006989 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06006990 int err = 0;
6991
6992 static const unsigned char any[] = {
6993 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
6994 };
6995 static const unsigned char off[] = {
6996 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
6997 };
6998
6999 // sanity checks
7000 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
7001 return -EINVAL;
7002
Ingo Molnar752e3772006-02-28 07:20:54 +08007003 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007004 if (!(priv->status & STATUS_INITIALIZED)) {
7005 err = -EIO;
7006 goto done;
7007 }
7008
7009 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
7010 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
7011 /* we disable mandatory BSSID association */
7012 IPW_DEBUG_WX("exit - disable mandatory BSSID\n");
7013 priv->config &= ~CFG_STATIC_BSSID;
7014 err = ipw2100_set_mandatory_bssid(priv, NULL, 0);
7015 goto done;
7016 }
7017
7018 priv->config |= CFG_STATIC_BSSID;
7019 memcpy(priv->mandatory_bssid_mac, wrqu->ap_addr.sa_data, ETH_ALEN);
7020
7021 err = ipw2100_set_mandatory_bssid(priv, wrqu->ap_addr.sa_data, 0);
7022
Johannes Berge1749612008-10-27 15:59:26 -07007023 IPW_DEBUG_WX("SET BSSID -> %pM\n", wrqu->ap_addr.sa_data);
James Ketrenos2c86c272005-03-23 17:32:29 -06007024
James Ketrenosee8e3652005-09-14 09:47:29 -05007025 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007026 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007027 return err;
7028}
7029
7030static int ipw2100_wx_get_wap(struct net_device *dev,
7031 struct iw_request_info *info,
7032 union iwreq_data *wrqu, char *extra)
7033{
7034 /*
7035 * This can be called at any time. No action lock required
7036 */
7037
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007038 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007039
7040 /* If we are associated, trying to associate, or have a statically
7041 * configured BSSID then return that; otherwise return ANY */
James Ketrenosee8e3652005-09-14 09:47:29 -05007042 if (priv->config & CFG_STATIC_BSSID || priv->status & STATUS_ASSOCIATED) {
James Ketrenos2c86c272005-03-23 17:32:29 -06007043 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenos82328352005-08-24 22:33:31 -05007044 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos2c86c272005-03-23 17:32:29 -06007045 } else
7046 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
7047
Johannes Berge1749612008-10-27 15:59:26 -07007048 IPW_DEBUG_WX("Getting WAP BSSID: %pM\n", wrqu->ap_addr.sa_data);
James Ketrenos2c86c272005-03-23 17:32:29 -06007049 return 0;
7050}
7051
7052static int ipw2100_wx_set_essid(struct net_device *dev,
7053 struct iw_request_info *info,
7054 union iwreq_data *wrqu, char *extra)
7055{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007056 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenosee8e3652005-09-14 09:47:29 -05007057 char *essid = ""; /* ANY */
James Ketrenos2c86c272005-03-23 17:32:29 -06007058 int length = 0;
7059 int err = 0;
John W. Linville9387b7c2008-09-30 20:59:05 -04007060 DECLARE_SSID_BUF(ssid);
James Ketrenos2c86c272005-03-23 17:32:29 -06007061
Ingo Molnar752e3772006-02-28 07:20:54 +08007062 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007063 if (!(priv->status & STATUS_INITIALIZED)) {
7064 err = -EIO;
7065 goto done;
7066 }
7067
7068 if (wrqu->essid.flags && wrqu->essid.length) {
Jean Tourrilhes5b63bae2006-08-29 18:00:48 -07007069 length = wrqu->essid.length;
James Ketrenos2c86c272005-03-23 17:32:29 -06007070 essid = extra;
7071 }
7072
7073 if (length == 0) {
7074 IPW_DEBUG_WX("Setting ESSID to ANY\n");
7075 priv->config &= ~CFG_STATIC_ESSID;
7076 err = ipw2100_set_essid(priv, NULL, 0, 0);
7077 goto done;
7078 }
7079
7080 length = min(length, IW_ESSID_MAX_SIZE);
7081
7082 priv->config |= CFG_STATIC_ESSID;
7083
7084 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
7085 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
7086 err = 0;
7087 goto done;
7088 }
7089
John W. Linville9387b7c2008-09-30 20:59:05 -04007090 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n",
7091 print_ssid(ssid, essid, length), length);
James Ketrenos2c86c272005-03-23 17:32:29 -06007092
7093 priv->essid_len = length;
7094 memcpy(priv->essid, essid, priv->essid_len);
7095
7096 err = ipw2100_set_essid(priv, essid, length, 0);
7097
James Ketrenosee8e3652005-09-14 09:47:29 -05007098 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007099 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007100 return err;
7101}
7102
7103static int ipw2100_wx_get_essid(struct net_device *dev,
7104 struct iw_request_info *info,
7105 union iwreq_data *wrqu, char *extra)
7106{
7107 /*
7108 * This can be called at any time. No action lock required
7109 */
7110
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007111 struct ipw2100_priv *priv = libipw_priv(dev);
John W. Linville9387b7c2008-09-30 20:59:05 -04007112 DECLARE_SSID_BUF(ssid);
James Ketrenos2c86c272005-03-23 17:32:29 -06007113
7114 /* If we are associated, trying to associate, or have a statically
7115 * configured ESSID then return that; otherwise return ANY */
James Ketrenosee8e3652005-09-14 09:47:29 -05007116 if (priv->config & CFG_STATIC_ESSID || priv->status & STATUS_ASSOCIATED) {
James Ketrenos2c86c272005-03-23 17:32:29 -06007117 IPW_DEBUG_WX("Getting essid: '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04007118 print_ssid(ssid, priv->essid, priv->essid_len));
James Ketrenos2c86c272005-03-23 17:32:29 -06007119 memcpy(extra, priv->essid, priv->essid_len);
7120 wrqu->essid.length = priv->essid_len;
James Ketrenosee8e3652005-09-14 09:47:29 -05007121 wrqu->essid.flags = 1; /* active */
James Ketrenos2c86c272005-03-23 17:32:29 -06007122 } else {
7123 IPW_DEBUG_WX("Getting essid: ANY\n");
7124 wrqu->essid.length = 0;
James Ketrenosee8e3652005-09-14 09:47:29 -05007125 wrqu->essid.flags = 0; /* active */
James Ketrenos2c86c272005-03-23 17:32:29 -06007126 }
7127
7128 return 0;
7129}
7130
7131static int ipw2100_wx_set_nick(struct net_device *dev,
7132 struct iw_request_info *info,
7133 union iwreq_data *wrqu, char *extra)
7134{
7135 /*
7136 * This can be called at any time. No action lock required
7137 */
7138
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007139 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007140
7141 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
7142 return -E2BIG;
7143
James Ketrenosee8e3652005-09-14 09:47:29 -05007144 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos2c86c272005-03-23 17:32:29 -06007145 memset(priv->nick, 0, sizeof(priv->nick));
James Ketrenosee8e3652005-09-14 09:47:29 -05007146 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos2c86c272005-03-23 17:32:29 -06007147
Frans Pop9fd1ea42010-03-24 19:46:31 +01007148 IPW_DEBUG_WX("SET Nickname -> %s\n", priv->nick);
James Ketrenos2c86c272005-03-23 17:32:29 -06007149
7150 return 0;
7151}
7152
7153static int ipw2100_wx_get_nick(struct net_device *dev,
7154 struct iw_request_info *info,
7155 union iwreq_data *wrqu, char *extra)
7156{
7157 /*
7158 * This can be called at any time. No action lock required
7159 */
7160
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007161 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007162
Jean Tourrilhes5b63bae2006-08-29 18:00:48 -07007163 wrqu->data.length = strlen(priv->nick);
James Ketrenos2c86c272005-03-23 17:32:29 -06007164 memcpy(extra, priv->nick, wrqu->data.length);
James Ketrenosee8e3652005-09-14 09:47:29 -05007165 wrqu->data.flags = 1; /* active */
James Ketrenos2c86c272005-03-23 17:32:29 -06007166
Frans Pop9fd1ea42010-03-24 19:46:31 +01007167 IPW_DEBUG_WX("GET Nickname -> %s\n", extra);
James Ketrenos2c86c272005-03-23 17:32:29 -06007168
7169 return 0;
7170}
7171
7172static int ipw2100_wx_set_rate(struct net_device *dev,
7173 struct iw_request_info *info,
7174 union iwreq_data *wrqu, char *extra)
7175{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007176 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007177 u32 target_rate = wrqu->bitrate.value;
7178 u32 rate;
7179 int err = 0;
7180
Ingo Molnar752e3772006-02-28 07:20:54 +08007181 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007182 if (!(priv->status & STATUS_INITIALIZED)) {
7183 err = -EIO;
7184 goto done;
7185 }
7186
7187 rate = 0;
7188
7189 if (target_rate == 1000000 ||
7190 (!wrqu->bitrate.fixed && target_rate > 1000000))
7191 rate |= TX_RATE_1_MBIT;
7192 if (target_rate == 2000000 ||
7193 (!wrqu->bitrate.fixed && target_rate > 2000000))
7194 rate |= TX_RATE_2_MBIT;
7195 if (target_rate == 5500000 ||
7196 (!wrqu->bitrate.fixed && target_rate > 5500000))
7197 rate |= TX_RATE_5_5_MBIT;
7198 if (target_rate == 11000000 ||
7199 (!wrqu->bitrate.fixed && target_rate > 11000000))
7200 rate |= TX_RATE_11_MBIT;
7201 if (rate == 0)
7202 rate = DEFAULT_TX_RATES;
7203
7204 err = ipw2100_set_tx_rates(priv, rate, 0);
7205
Frans Pop9fd1ea42010-03-24 19:46:31 +01007206 IPW_DEBUG_WX("SET Rate -> %04X\n", rate);
James Ketrenosee8e3652005-09-14 09:47:29 -05007207 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007208 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007209 return err;
7210}
7211
James Ketrenos2c86c272005-03-23 17:32:29 -06007212static int ipw2100_wx_get_rate(struct net_device *dev,
7213 struct iw_request_info *info,
7214 union iwreq_data *wrqu, char *extra)
7215{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007216 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007217 int val;
Hannes Ederb9da9e92009-02-14 11:50:26 +00007218 unsigned int len = sizeof(val);
James Ketrenos2c86c272005-03-23 17:32:29 -06007219 int err = 0;
7220
7221 if (!(priv->status & STATUS_ENABLED) ||
7222 priv->status & STATUS_RF_KILL_MASK ||
7223 !(priv->status & STATUS_ASSOCIATED)) {
7224 wrqu->bitrate.value = 0;
7225 return 0;
7226 }
7227
Ingo Molnar752e3772006-02-28 07:20:54 +08007228 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007229 if (!(priv->status & STATUS_INITIALIZED)) {
7230 err = -EIO;
7231 goto done;
7232 }
7233
7234 err = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &val, &len);
7235 if (err) {
7236 IPW_DEBUG_WX("failed querying ordinals.\n");
Julia Lawall80c42af2008-07-21 09:58:11 +02007237 goto done;
James Ketrenos2c86c272005-03-23 17:32:29 -06007238 }
7239
7240 switch (val & TX_RATE_MASK) {
7241 case TX_RATE_1_MBIT:
7242 wrqu->bitrate.value = 1000000;
7243 break;
7244 case TX_RATE_2_MBIT:
7245 wrqu->bitrate.value = 2000000;
7246 break;
7247 case TX_RATE_5_5_MBIT:
7248 wrqu->bitrate.value = 5500000;
7249 break;
7250 case TX_RATE_11_MBIT:
7251 wrqu->bitrate.value = 11000000;
7252 break;
7253 default:
7254 wrqu->bitrate.value = 0;
7255 }
7256
Frans Pop9fd1ea42010-03-24 19:46:31 +01007257 IPW_DEBUG_WX("GET Rate -> %d\n", wrqu->bitrate.value);
James Ketrenos2c86c272005-03-23 17:32:29 -06007258
James Ketrenosee8e3652005-09-14 09:47:29 -05007259 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007260 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007261 return err;
7262}
7263
7264static int ipw2100_wx_set_rts(struct net_device *dev,
7265 struct iw_request_info *info,
7266 union iwreq_data *wrqu, char *extra)
7267{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007268 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007269 int value, err;
7270
7271 /* Auto RTS not yet supported */
7272 if (wrqu->rts.fixed == 0)
7273 return -EINVAL;
7274
Ingo Molnar752e3772006-02-28 07:20:54 +08007275 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007276 if (!(priv->status & STATUS_INITIALIZED)) {
7277 err = -EIO;
7278 goto done;
7279 }
7280
7281 if (wrqu->rts.disabled)
7282 value = priv->rts_threshold | RTS_DISABLED;
7283 else {
James Ketrenosee8e3652005-09-14 09:47:29 -05007284 if (wrqu->rts.value < 1 || wrqu->rts.value > 2304) {
James Ketrenos2c86c272005-03-23 17:32:29 -06007285 err = -EINVAL;
7286 goto done;
7287 }
7288 value = wrqu->rts.value;
7289 }
7290
7291 err = ipw2100_set_rts_threshold(priv, value);
7292
Frans Pop9fd1ea42010-03-24 19:46:31 +01007293 IPW_DEBUG_WX("SET RTS Threshold -> 0x%08X\n", value);
James Ketrenosee8e3652005-09-14 09:47:29 -05007294 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007295 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007296 return err;
7297}
7298
7299static int ipw2100_wx_get_rts(struct net_device *dev,
7300 struct iw_request_info *info,
7301 union iwreq_data *wrqu, char *extra)
7302{
7303 /*
7304 * This can be called at any time. No action lock required
7305 */
7306
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007307 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007308
7309 wrqu->rts.value = priv->rts_threshold & ~RTS_DISABLED;
James Ketrenosee8e3652005-09-14 09:47:29 -05007310 wrqu->rts.fixed = 1; /* no auto select */
James Ketrenos2c86c272005-03-23 17:32:29 -06007311
7312 /* If RTS is set to the default value, then it is disabled */
7313 wrqu->rts.disabled = (priv->rts_threshold & RTS_DISABLED) ? 1 : 0;
7314
Frans Pop9fd1ea42010-03-24 19:46:31 +01007315 IPW_DEBUG_WX("GET RTS Threshold -> 0x%08X\n", wrqu->rts.value);
James Ketrenos2c86c272005-03-23 17:32:29 -06007316
7317 return 0;
7318}
7319
7320static int ipw2100_wx_set_txpow(struct net_device *dev,
7321 struct iw_request_info *info,
7322 union iwreq_data *wrqu, char *extra)
7323{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007324 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007325 int err = 0, value;
Zhu Yib6e4da72006-01-24 13:49:32 +08007326
7327 if (ipw_radio_kill_sw(priv, wrqu->txpower.disabled))
7328 return -EINPROGRESS;
James Ketrenos2c86c272005-03-23 17:32:29 -06007329
7330 if (priv->ieee->iw_mode != IW_MODE_ADHOC)
Zhu Yib6e4da72006-01-24 13:49:32 +08007331 return 0;
7332
7333 if ((wrqu->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
James Ketrenos2c86c272005-03-23 17:32:29 -06007334 return -EINVAL;
7335
Zhu Yib6e4da72006-01-24 13:49:32 +08007336 if (wrqu->txpower.fixed == 0)
James Ketrenos2c86c272005-03-23 17:32:29 -06007337 value = IPW_TX_POWER_DEFAULT;
7338 else {
7339 if (wrqu->txpower.value < IPW_TX_POWER_MIN_DBM ||
7340 wrqu->txpower.value > IPW_TX_POWER_MAX_DBM)
7341 return -EINVAL;
7342
Liu Hongf75459e2005-07-13 12:29:21 -05007343 value = wrqu->txpower.value;
James Ketrenos2c86c272005-03-23 17:32:29 -06007344 }
7345
Ingo Molnar752e3772006-02-28 07:20:54 +08007346 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007347 if (!(priv->status & STATUS_INITIALIZED)) {
7348 err = -EIO;
7349 goto done;
7350 }
7351
7352 err = ipw2100_set_tx_power(priv, value);
7353
Frans Pop9fd1ea42010-03-24 19:46:31 +01007354 IPW_DEBUG_WX("SET TX Power -> %d\n", value);
James Ketrenos2c86c272005-03-23 17:32:29 -06007355
James Ketrenosee8e3652005-09-14 09:47:29 -05007356 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007357 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007358 return err;
7359}
7360
7361static int ipw2100_wx_get_txpow(struct net_device *dev,
7362 struct iw_request_info *info,
7363 union iwreq_data *wrqu, char *extra)
7364{
7365 /*
7366 * This can be called at any time. No action lock required
7367 */
7368
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007369 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007370
Zhu Yib6e4da72006-01-24 13:49:32 +08007371 wrqu->txpower.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
James Ketrenos2c86c272005-03-23 17:32:29 -06007372
7373 if (priv->tx_power == IPW_TX_POWER_DEFAULT) {
Zhu Yib6e4da72006-01-24 13:49:32 +08007374 wrqu->txpower.fixed = 0;
7375 wrqu->txpower.value = IPW_TX_POWER_MAX_DBM;
James Ketrenos2c86c272005-03-23 17:32:29 -06007376 } else {
Zhu Yib6e4da72006-01-24 13:49:32 +08007377 wrqu->txpower.fixed = 1;
7378 wrqu->txpower.value = priv->tx_power;
James Ketrenos2c86c272005-03-23 17:32:29 -06007379 }
7380
Zhu Yib6e4da72006-01-24 13:49:32 +08007381 wrqu->txpower.flags = IW_TXPOW_DBM;
James Ketrenos2c86c272005-03-23 17:32:29 -06007382
Frans Pop9fd1ea42010-03-24 19:46:31 +01007383 IPW_DEBUG_WX("GET TX Power -> %d\n", wrqu->txpower.value);
James Ketrenos2c86c272005-03-23 17:32:29 -06007384
7385 return 0;
7386}
7387
7388static int ipw2100_wx_set_frag(struct net_device *dev,
7389 struct iw_request_info *info,
7390 union iwreq_data *wrqu, char *extra)
7391{
7392 /*
7393 * This can be called at any time. No action lock required
7394 */
7395
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007396 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007397
7398 if (!wrqu->frag.fixed)
7399 return -EINVAL;
7400
7401 if (wrqu->frag.disabled) {
7402 priv->frag_threshold |= FRAG_DISABLED;
7403 priv->ieee->fts = DEFAULT_FTS;
7404 } else {
7405 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
7406 wrqu->frag.value > MAX_FRAG_THRESHOLD)
7407 return -EINVAL;
7408
7409 priv->ieee->fts = wrqu->frag.value & ~0x1;
7410 priv->frag_threshold = priv->ieee->fts;
7411 }
7412
Frans Pop9fd1ea42010-03-24 19:46:31 +01007413 IPW_DEBUG_WX("SET Frag Threshold -> %d\n", priv->ieee->fts);
James Ketrenos2c86c272005-03-23 17:32:29 -06007414
7415 return 0;
7416}
7417
7418static int ipw2100_wx_get_frag(struct net_device *dev,
7419 struct iw_request_info *info,
7420 union iwreq_data *wrqu, char *extra)
7421{
7422 /*
7423 * This can be called at any time. No action lock required
7424 */
7425
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007426 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007427 wrqu->frag.value = priv->frag_threshold & ~FRAG_DISABLED;
7428 wrqu->frag.fixed = 0; /* no auto select */
7429 wrqu->frag.disabled = (priv->frag_threshold & FRAG_DISABLED) ? 1 : 0;
7430
Frans Pop9fd1ea42010-03-24 19:46:31 +01007431 IPW_DEBUG_WX("GET Frag Threshold -> %d\n", wrqu->frag.value);
James Ketrenos2c86c272005-03-23 17:32:29 -06007432
7433 return 0;
7434}
7435
7436static int ipw2100_wx_set_retry(struct net_device *dev,
7437 struct iw_request_info *info,
7438 union iwreq_data *wrqu, char *extra)
7439{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007440 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007441 int err = 0;
7442
James Ketrenosee8e3652005-09-14 09:47:29 -05007443 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
James Ketrenos2c86c272005-03-23 17:32:29 -06007444 return -EINVAL;
7445
7446 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
7447 return 0;
7448
Ingo Molnar752e3772006-02-28 07:20:54 +08007449 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007450 if (!(priv->status & STATUS_INITIALIZED)) {
7451 err = -EIO;
7452 goto done;
7453 }
7454
Jean Tourrilhes5b63bae2006-08-29 18:00:48 -07007455 if (wrqu->retry.flags & IW_RETRY_SHORT) {
James Ketrenos2c86c272005-03-23 17:32:29 -06007456 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
Frans Pop9fd1ea42010-03-24 19:46:31 +01007457 IPW_DEBUG_WX("SET Short 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
Jean Tourrilhes5b63bae2006-08-29 18:00:48 -07007462 if (wrqu->retry.flags & IW_RETRY_LONG) {
James Ketrenos2c86c272005-03-23 17:32:29 -06007463 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
Frans Pop9fd1ea42010-03-24 19:46:31 +01007464 IPW_DEBUG_WX("SET Long Retry Limit -> %d\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05007465 wrqu->retry.value);
James Ketrenos2c86c272005-03-23 17:32:29 -06007466 goto done;
7467 }
7468
7469 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7470 if (!err)
7471 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7472
Frans Pop9fd1ea42010-03-24 19:46:31 +01007473 IPW_DEBUG_WX("SET Both Retry Limits -> %d\n", wrqu->retry.value);
James Ketrenos2c86c272005-03-23 17:32:29 -06007474
James Ketrenosee8e3652005-09-14 09:47:29 -05007475 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007476 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007477 return err;
7478}
7479
7480static int ipw2100_wx_get_retry(struct net_device *dev,
7481 struct iw_request_info *info,
7482 union iwreq_data *wrqu, char *extra)
7483{
7484 /*
7485 * This can be called at any time. No action lock required
7486 */
7487
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007488 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007489
James Ketrenosee8e3652005-09-14 09:47:29 -05007490 wrqu->retry.disabled = 0; /* can't be disabled */
James Ketrenos2c86c272005-03-23 17:32:29 -06007491
James Ketrenosee8e3652005-09-14 09:47:29 -05007492 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME)
James Ketrenos2c86c272005-03-23 17:32:29 -06007493 return -EINVAL;
7494
Jean Tourrilhes5b63bae2006-08-29 18:00:48 -07007495 if (wrqu->retry.flags & IW_RETRY_LONG) {
7496 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
James Ketrenos2c86c272005-03-23 17:32:29 -06007497 wrqu->retry.value = priv->long_retry_limit;
7498 } else {
7499 wrqu->retry.flags =
7500 (priv->short_retry_limit !=
7501 priv->long_retry_limit) ?
Jean Tourrilhes5b63bae2006-08-29 18:00:48 -07007502 IW_RETRY_LIMIT | IW_RETRY_SHORT : IW_RETRY_LIMIT;
James Ketrenos2c86c272005-03-23 17:32:29 -06007503
7504 wrqu->retry.value = priv->short_retry_limit;
7505 }
7506
Frans Pop9fd1ea42010-03-24 19:46:31 +01007507 IPW_DEBUG_WX("GET Retry -> %d\n", wrqu->retry.value);
James Ketrenos2c86c272005-03-23 17:32:29 -06007508
7509 return 0;
7510}
7511
7512static int ipw2100_wx_set_scan(struct net_device *dev,
7513 struct iw_request_info *info,
7514 union iwreq_data *wrqu, char *extra)
7515{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007516 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007517 int err = 0;
7518
Ingo Molnar752e3772006-02-28 07:20:54 +08007519 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007520 if (!(priv->status & STATUS_INITIALIZED)) {
7521 err = -EIO;
7522 goto done;
7523 }
7524
7525 IPW_DEBUG_WX("Initiating scan...\n");
Dan Williamsd20c6782007-10-10 12:28:07 -04007526
7527 priv->user_requested_scan = 1;
James Ketrenosee8e3652005-09-14 09:47:29 -05007528 if (ipw2100_set_scan_options(priv) || ipw2100_start_scan(priv)) {
James Ketrenos2c86c272005-03-23 17:32:29 -06007529 IPW_DEBUG_WX("Start scan failed.\n");
7530
7531 /* TODO: Mark a scan as pending so when hardware initialized
7532 * a scan starts */
7533 }
7534
James Ketrenosee8e3652005-09-14 09:47:29 -05007535 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007536 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007537 return err;
7538}
7539
7540static int ipw2100_wx_get_scan(struct net_device *dev,
7541 struct iw_request_info *info,
7542 union iwreq_data *wrqu, char *extra)
7543{
7544 /*
7545 * This can be called at any time. No action lock required
7546 */
7547
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007548 struct ipw2100_priv *priv = libipw_priv(dev);
7549 return libipw_wx_get_scan(priv->ieee, info, wrqu, extra);
James Ketrenos2c86c272005-03-23 17:32:29 -06007550}
7551
James Ketrenos2c86c272005-03-23 17:32:29 -06007552/*
7553 * Implementation based on code in hostap-driver v0.1.3 hostap_ioctl.c
7554 */
7555static int ipw2100_wx_set_encode(struct net_device *dev,
7556 struct iw_request_info *info,
7557 union iwreq_data *wrqu, char *key)
7558{
7559 /*
7560 * No check of STATUS_INITIALIZED required
7561 */
7562
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007563 struct ipw2100_priv *priv = libipw_priv(dev);
7564 return libipw_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenos2c86c272005-03-23 17:32:29 -06007565}
7566
7567static int ipw2100_wx_get_encode(struct net_device *dev,
7568 struct iw_request_info *info,
7569 union iwreq_data *wrqu, char *key)
7570{
7571 /*
7572 * This can be called at any time. No action lock required
7573 */
7574
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007575 struct ipw2100_priv *priv = libipw_priv(dev);
7576 return libipw_wx_get_encode(priv->ieee, info, wrqu, key);
James Ketrenos2c86c272005-03-23 17:32:29 -06007577}
7578
7579static int ipw2100_wx_set_power(struct net_device *dev,
James Ketrenosee8e3652005-09-14 09:47:29 -05007580 struct iw_request_info *info,
7581 union iwreq_data *wrqu, char *extra)
James Ketrenos2c86c272005-03-23 17:32:29 -06007582{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007583 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007584 int err = 0;
7585
Ingo Molnar752e3772006-02-28 07:20:54 +08007586 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007587 if (!(priv->status & STATUS_INITIALIZED)) {
7588 err = -EIO;
7589 goto done;
7590 }
7591
7592 if (wrqu->power.disabled) {
7593 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
7594 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
7595 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
7596 goto done;
7597 }
7598
7599 switch (wrqu->power.flags & IW_POWER_MODE) {
James Ketrenosee8e3652005-09-14 09:47:29 -05007600 case IW_POWER_ON: /* If not specified */
7601 case IW_POWER_MODE: /* If set all mask */
Jean Delvarec03983a2007-10-19 23:22:55 +02007602 case IW_POWER_ALL_R: /* If explicitly state all */
James Ketrenos2c86c272005-03-23 17:32:29 -06007603 break;
James Ketrenosee8e3652005-09-14 09:47:29 -05007604 default: /* Otherwise we don't support it */
James Ketrenos2c86c272005-03-23 17:32:29 -06007605 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
7606 wrqu->power.flags);
7607 err = -EOPNOTSUPP;
7608 goto done;
7609 }
7610
7611 /* If the user hasn't specified a power management mode yet, default
7612 * to BATTERY */
7613 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
7614 err = ipw2100_set_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
7615
James Ketrenosee8e3652005-09-14 09:47:29 -05007616 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
James Ketrenos2c86c272005-03-23 17:32:29 -06007617
James Ketrenosee8e3652005-09-14 09:47:29 -05007618 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007619 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007620 return err;
7621
7622}
7623
7624static int ipw2100_wx_get_power(struct net_device *dev,
James Ketrenosee8e3652005-09-14 09:47:29 -05007625 struct iw_request_info *info,
7626 union iwreq_data *wrqu, char *extra)
James Ketrenos2c86c272005-03-23 17:32:29 -06007627{
7628 /*
7629 * This can be called at any time. No action lock required
7630 */
7631
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007632 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007633
James Ketrenos82328352005-08-24 22:33:31 -05007634 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos2c86c272005-03-23 17:32:29 -06007635 wrqu->power.disabled = 1;
James Ketrenos82328352005-08-24 22:33:31 -05007636 else {
James Ketrenos2c86c272005-03-23 17:32:29 -06007637 wrqu->power.disabled = 0;
7638 wrqu->power.flags = 0;
7639 }
7640
7641 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
7642
7643 return 0;
7644}
7645
James Ketrenos82328352005-08-24 22:33:31 -05007646/*
7647 * WE-18 WPA support
7648 */
7649
7650/* SIOCSIWGENIE */
7651static int ipw2100_wx_set_genie(struct net_device *dev,
7652 struct iw_request_info *info,
7653 union iwreq_data *wrqu, char *extra)
7654{
7655
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007656 struct ipw2100_priv *priv = libipw_priv(dev);
7657 struct libipw_device *ieee = priv->ieee;
James Ketrenos82328352005-08-24 22:33:31 -05007658 u8 *buf;
7659
7660 if (!ieee->wpa_enabled)
7661 return -EOPNOTSUPP;
7662
7663 if (wrqu->data.length > MAX_WPA_IE_LEN ||
7664 (wrqu->data.length && extra == NULL))
7665 return -EINVAL;
7666
7667 if (wrqu->data.length) {
Eric Sesterhennc3a9392e2006-10-23 22:20:15 +02007668 buf = kmemdup(extra, wrqu->data.length, GFP_KERNEL);
James Ketrenos82328352005-08-24 22:33:31 -05007669 if (buf == NULL)
7670 return -ENOMEM;
7671
James Ketrenos82328352005-08-24 22:33:31 -05007672 kfree(ieee->wpa_ie);
7673 ieee->wpa_ie = buf;
7674 ieee->wpa_ie_len = wrqu->data.length;
7675 } else {
7676 kfree(ieee->wpa_ie);
7677 ieee->wpa_ie = NULL;
7678 ieee->wpa_ie_len = 0;
7679 }
7680
7681 ipw2100_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
7682
7683 return 0;
7684}
7685
7686/* SIOCGIWGENIE */
7687static int ipw2100_wx_get_genie(struct net_device *dev,
7688 struct iw_request_info *info,
7689 union iwreq_data *wrqu, char *extra)
7690{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007691 struct ipw2100_priv *priv = libipw_priv(dev);
7692 struct libipw_device *ieee = priv->ieee;
James Ketrenos82328352005-08-24 22:33:31 -05007693
7694 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
7695 wrqu->data.length = 0;
7696 return 0;
7697 }
7698
7699 if (wrqu->data.length < ieee->wpa_ie_len)
7700 return -E2BIG;
7701
7702 wrqu->data.length = ieee->wpa_ie_len;
7703 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
7704
7705 return 0;
7706}
7707
7708/* SIOCSIWAUTH */
7709static int ipw2100_wx_set_auth(struct net_device *dev,
7710 struct iw_request_info *info,
7711 union iwreq_data *wrqu, char *extra)
7712{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007713 struct ipw2100_priv *priv = libipw_priv(dev);
7714 struct libipw_device *ieee = priv->ieee;
James Ketrenos82328352005-08-24 22:33:31 -05007715 struct iw_param *param = &wrqu->param;
John W. Linville274bfb82008-10-29 11:35:05 -04007716 struct lib80211_crypt_data *crypt;
James Ketrenos82328352005-08-24 22:33:31 -05007717 unsigned long flags;
7718 int ret = 0;
7719
7720 switch (param->flags & IW_AUTH_INDEX) {
7721 case IW_AUTH_WPA_VERSION:
7722 case IW_AUTH_CIPHER_PAIRWISE:
7723 case IW_AUTH_CIPHER_GROUP:
7724 case IW_AUTH_KEY_MGMT:
7725 /*
7726 * ipw2200 does not use these parameters
7727 */
7728 break;
7729
7730 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04007731 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00007732 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenos82328352005-08-24 22:33:31 -05007733 break;
James Ketrenos82328352005-08-24 22:33:31 -05007734
7735 flags = crypt->ops->get_flags(crypt->priv);
7736
7737 if (param->value)
7738 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
7739 else
7740 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
7741
7742 crypt->ops->set_flags(flags, crypt->priv);
7743
7744 break;
7745
7746 case IW_AUTH_DROP_UNENCRYPTED:{
7747 /* HACK:
7748 *
7749 * wpa_supplicant calls set_wpa_enabled when the driver
7750 * is loaded and unloaded, regardless of if WPA is being
7751 * used. No other calls are made which can be used to
7752 * determine if encryption will be used or not prior to
7753 * association being expected. If encryption is not being
7754 * used, drop_unencrypted is set to false, else true -- we
7755 * can use this to determine if the CAP_PRIVACY_ON bit should
7756 * be set.
7757 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007758 struct libipw_security sec = {
James Ketrenos82328352005-08-24 22:33:31 -05007759 .flags = SEC_ENABLED,
7760 .enabled = param->value,
7761 };
7762 priv->ieee->drop_unencrypted = param->value;
7763 /* We only change SEC_LEVEL for open mode. Others
7764 * are set by ipw_wpa_set_encryption.
7765 */
7766 if (!param->value) {
7767 sec.flags |= SEC_LEVEL;
7768 sec.level = SEC_LEVEL_0;
7769 } else {
7770 sec.flags |= SEC_LEVEL;
7771 sec.level = SEC_LEVEL_1;
7772 }
7773 if (priv->ieee->set_security)
7774 priv->ieee->set_security(priv->ieee->dev, &sec);
7775 break;
7776 }
7777
7778 case IW_AUTH_80211_AUTH_ALG:
7779 ret = ipw2100_wpa_set_auth_algs(priv, param->value);
7780 break;
7781
7782 case IW_AUTH_WPA_ENABLED:
7783 ret = ipw2100_wpa_enable(priv, param->value);
7784 break;
7785
7786 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
7787 ieee->ieee802_1x = param->value;
7788 break;
7789
7790 //case IW_AUTH_ROAMING_CONTROL:
7791 case IW_AUTH_PRIVACY_INVOKED:
7792 ieee->privacy_invoked = param->value;
7793 break;
7794
7795 default:
7796 return -EOPNOTSUPP;
7797 }
7798 return ret;
7799}
7800
7801/* SIOCGIWAUTH */
7802static int ipw2100_wx_get_auth(struct net_device *dev,
7803 struct iw_request_info *info,
7804 union iwreq_data *wrqu, char *extra)
7805{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007806 struct ipw2100_priv *priv = libipw_priv(dev);
7807 struct libipw_device *ieee = priv->ieee;
John W. Linville274bfb82008-10-29 11:35:05 -04007808 struct lib80211_crypt_data *crypt;
James Ketrenos82328352005-08-24 22:33:31 -05007809 struct iw_param *param = &wrqu->param;
7810 int ret = 0;
7811
7812 switch (param->flags & IW_AUTH_INDEX) {
7813 case IW_AUTH_WPA_VERSION:
7814 case IW_AUTH_CIPHER_PAIRWISE:
7815 case IW_AUTH_CIPHER_GROUP:
7816 case IW_AUTH_KEY_MGMT:
7817 /*
7818 * wpa_supplicant will control these internally
7819 */
7820 ret = -EOPNOTSUPP;
7821 break;
7822
7823 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04007824 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos82328352005-08-24 22:33:31 -05007825 if (!crypt || !crypt->ops->get_flags) {
7826 IPW_DEBUG_WARNING("Can't get TKIP countermeasures: "
7827 "crypt not set!\n");
7828 break;
7829 }
7830
7831 param->value = (crypt->ops->get_flags(crypt->priv) &
7832 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
7833
7834 break;
7835
7836 case IW_AUTH_DROP_UNENCRYPTED:
7837 param->value = ieee->drop_unencrypted;
7838 break;
7839
7840 case IW_AUTH_80211_AUTH_ALG:
25b645b2005-07-12 15:45:30 -05007841 param->value = priv->ieee->sec.auth_mode;
James Ketrenos82328352005-08-24 22:33:31 -05007842 break;
7843
7844 case IW_AUTH_WPA_ENABLED:
7845 param->value = ieee->wpa_enabled;
7846 break;
7847
7848 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
7849 param->value = ieee->ieee802_1x;
7850 break;
7851
7852 case IW_AUTH_ROAMING_CONTROL:
7853 case IW_AUTH_PRIVACY_INVOKED:
7854 param->value = ieee->privacy_invoked;
7855 break;
7856
7857 default:
7858 return -EOPNOTSUPP;
7859 }
7860 return 0;
7861}
7862
7863/* SIOCSIWENCODEEXT */
7864static int ipw2100_wx_set_encodeext(struct net_device *dev,
7865 struct iw_request_info *info,
7866 union iwreq_data *wrqu, char *extra)
7867{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007868 struct ipw2100_priv *priv = libipw_priv(dev);
7869 return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenos82328352005-08-24 22:33:31 -05007870}
7871
7872/* SIOCGIWENCODEEXT */
7873static int ipw2100_wx_get_encodeext(struct net_device *dev,
7874 struct iw_request_info *info,
7875 union iwreq_data *wrqu, char *extra)
7876{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007877 struct ipw2100_priv *priv = libipw_priv(dev);
7878 return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenos82328352005-08-24 22:33:31 -05007879}
7880
7881/* SIOCSIWMLME */
7882static int ipw2100_wx_set_mlme(struct net_device *dev,
7883 struct iw_request_info *info,
7884 union iwreq_data *wrqu, char *extra)
7885{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007886 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos82328352005-08-24 22:33:31 -05007887 struct iw_mlme *mlme = (struct iw_mlme *)extra;
Al Viro1edd3a52007-12-21 00:15:18 -05007888 __le16 reason;
James Ketrenos82328352005-08-24 22:33:31 -05007889
7890 reason = cpu_to_le16(mlme->reason_code);
7891
7892 switch (mlme->cmd) {
7893 case IW_MLME_DEAUTH:
7894 // silently ignore
7895 break;
7896
7897 case IW_MLME_DISASSOC:
7898 ipw2100_disassociate_bssid(priv);
7899 break;
7900
7901 default:
7902 return -EOPNOTSUPP;
7903 }
7904 return 0;
7905}
James Ketrenos2c86c272005-03-23 17:32:29 -06007906
7907/*
7908 *
7909 * IWPRIV handlers
7910 *
7911 */
7912#ifdef CONFIG_IPW2100_MONITOR
7913static int ipw2100_wx_set_promisc(struct net_device *dev,
7914 struct iw_request_info *info,
7915 union iwreq_data *wrqu, char *extra)
7916{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007917 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007918 int *parms = (int *)extra;
7919 int enable = (parms[0] > 0);
7920 int err = 0;
7921
Ingo Molnar752e3772006-02-28 07:20:54 +08007922 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007923 if (!(priv->status & STATUS_INITIALIZED)) {
7924 err = -EIO;
7925 goto done;
7926 }
7927
7928 if (enable) {
7929 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7930 err = ipw2100_set_channel(priv, parms[1], 0);
7931 goto done;
7932 }
7933 priv->channel = parms[1];
7934 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
7935 } else {
7936 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
7937 err = ipw2100_switch_mode(priv, priv->last_mode);
7938 }
James Ketrenosee8e3652005-09-14 09:47:29 -05007939 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007940 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007941 return err;
7942}
7943
7944static int ipw2100_wx_reset(struct net_device *dev,
7945 struct iw_request_info *info,
7946 union iwreq_data *wrqu, char *extra)
7947{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007948 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007949 if (priv->status & STATUS_INITIALIZED)
7950 schedule_reset(priv);
7951 return 0;
7952}
7953
7954#endif
7955
7956static int ipw2100_wx_set_powermode(struct net_device *dev,
7957 struct iw_request_info *info,
7958 union iwreq_data *wrqu, char *extra)
7959{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007960 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007961 int err = 0, mode = *(int *)extra;
7962
Ingo Molnar752e3772006-02-28 07:20:54 +08007963 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007964 if (!(priv->status & STATUS_INITIALIZED)) {
7965 err = -EIO;
7966 goto done;
7967 }
7968
Zhu Yi9f3b2412007-07-12 16:09:24 +08007969 if ((mode < 0) || (mode > POWER_MODES))
James Ketrenos2c86c272005-03-23 17:32:29 -06007970 mode = IPW_POWER_AUTO;
7971
Zhu Yi9f3b2412007-07-12 16:09:24 +08007972 if (IPW_POWER_LEVEL(priv->power_mode) != mode)
James Ketrenos2c86c272005-03-23 17:32:29 -06007973 err = ipw2100_set_power_mode(priv, mode);
James Ketrenosee8e3652005-09-14 09:47:29 -05007974 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08007975 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06007976 return err;
7977}
7978
7979#define MAX_POWER_STRING 80
7980static int ipw2100_wx_get_powermode(struct net_device *dev,
7981 struct iw_request_info *info,
7982 union iwreq_data *wrqu, char *extra)
7983{
7984 /*
7985 * This can be called at any time. No action lock required
7986 */
7987
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007988 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06007989 int level = IPW_POWER_LEVEL(priv->power_mode);
7990 s32 timeout, period;
7991
7992 if (!(priv->power_mode & IPW_POWER_ENABLED)) {
7993 snprintf(extra, MAX_POWER_STRING,
7994 "Power save level: %d (Off)", level);
7995 } else {
7996 switch (level) {
7997 case IPW_POWER_MODE_CAM:
7998 snprintf(extra, MAX_POWER_STRING,
7999 "Power save level: %d (None)", level);
8000 break;
8001 case IPW_POWER_AUTO:
James Ketrenosee8e3652005-09-14 09:47:29 -05008002 snprintf(extra, MAX_POWER_STRING,
Zhu Yi9f3b2412007-07-12 16:09:24 +08008003 "Power save level: %d (Auto)", level);
James Ketrenos2c86c272005-03-23 17:32:29 -06008004 break;
8005 default:
8006 timeout = timeout_duration[level - 1] / 1000;
8007 period = period_duration[level - 1] / 1000;
8008 snprintf(extra, MAX_POWER_STRING,
8009 "Power save level: %d "
8010 "(Timeout %dms, Period %dms)",
8011 level, timeout, period);
8012 }
8013 }
8014
8015 wrqu->data.length = strlen(extra) + 1;
8016
8017 return 0;
8018}
8019
James Ketrenos2c86c272005-03-23 17:32:29 -06008020static int ipw2100_wx_set_preamble(struct net_device *dev,
8021 struct iw_request_info *info,
8022 union iwreq_data *wrqu, char *extra)
8023{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008024 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06008025 int err, mode = *(int *)extra;
8026
Ingo Molnar752e3772006-02-28 07:20:54 +08008027 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06008028 if (!(priv->status & STATUS_INITIALIZED)) {
8029 err = -EIO;
8030 goto done;
8031 }
8032
8033 if (mode == 1)
8034 priv->config |= CFG_LONG_PREAMBLE;
8035 else if (mode == 0)
8036 priv->config &= ~CFG_LONG_PREAMBLE;
8037 else {
8038 err = -EINVAL;
8039 goto done;
8040 }
8041
8042 err = ipw2100_system_config(priv, 0);
8043
James Ketrenosee8e3652005-09-14 09:47:29 -05008044 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08008045 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06008046 return err;
8047}
8048
8049static int ipw2100_wx_get_preamble(struct net_device *dev,
James Ketrenosee8e3652005-09-14 09:47:29 -05008050 struct iw_request_info *info,
8051 union iwreq_data *wrqu, char *extra)
James Ketrenos2c86c272005-03-23 17:32:29 -06008052{
8053 /*
8054 * This can be called at any time. No action lock required
8055 */
8056
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008057 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06008058
8059 if (priv->config & CFG_LONG_PREAMBLE)
8060 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
8061 else
8062 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
8063
8064 return 0;
8065}
8066
James Ketrenos82328352005-08-24 22:33:31 -05008067#ifdef CONFIG_IPW2100_MONITOR
8068static int ipw2100_wx_set_crc_check(struct net_device *dev,
8069 struct iw_request_info *info,
8070 union iwreq_data *wrqu, char *extra)
James Ketrenos2c86c272005-03-23 17:32:29 -06008071{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008072 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos82328352005-08-24 22:33:31 -05008073 int err, mode = *(int *)extra;
8074
Ingo Molnar752e3772006-02-28 07:20:54 +08008075 mutex_lock(&priv->action_mutex);
James Ketrenos82328352005-08-24 22:33:31 -05008076 if (!(priv->status & STATUS_INITIALIZED)) {
8077 err = -EIO;
8078 goto done;
8079 }
8080
8081 if (mode == 1)
8082 priv->config |= CFG_CRC_CHECK;
8083 else if (mode == 0)
8084 priv->config &= ~CFG_CRC_CHECK;
8085 else {
8086 err = -EINVAL;
8087 goto done;
8088 }
8089 err = 0;
8090
8091 done:
Ingo Molnar752e3772006-02-28 07:20:54 +08008092 mutex_unlock(&priv->action_mutex);
James Ketrenos82328352005-08-24 22:33:31 -05008093 return err;
8094}
8095
8096static int ipw2100_wx_get_crc_check(struct net_device *dev,
8097 struct iw_request_info *info,
8098 union iwreq_data *wrqu, char *extra)
8099{
8100 /*
8101 * This can be called at any time. No action lock required
8102 */
8103
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008104 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos82328352005-08-24 22:33:31 -05008105
8106 if (priv->config & CFG_CRC_CHECK)
8107 snprintf(wrqu->name, IFNAMSIZ, "CRC checked (1)");
8108 else
8109 snprintf(wrqu->name, IFNAMSIZ, "CRC ignored (0)");
8110
8111 return 0;
8112}
8113#endif /* CONFIG_IPW2100_MONITOR */
8114
James Ketrenosee8e3652005-09-14 09:47:29 -05008115static iw_handler ipw2100_wx_handlers[] = {
8116 NULL, /* SIOCSIWCOMMIT */
8117 ipw2100_wx_get_name, /* SIOCGIWNAME */
8118 NULL, /* SIOCSIWNWID */
8119 NULL, /* SIOCGIWNWID */
8120 ipw2100_wx_set_freq, /* SIOCSIWFREQ */
8121 ipw2100_wx_get_freq, /* SIOCGIWFREQ */
8122 ipw2100_wx_set_mode, /* SIOCSIWMODE */
8123 ipw2100_wx_get_mode, /* SIOCGIWMODE */
8124 NULL, /* SIOCSIWSENS */
8125 NULL, /* SIOCGIWSENS */
8126 NULL, /* SIOCSIWRANGE */
8127 ipw2100_wx_get_range, /* SIOCGIWRANGE */
8128 NULL, /* SIOCSIWPRIV */
8129 NULL, /* SIOCGIWPRIV */
8130 NULL, /* SIOCSIWSTATS */
8131 NULL, /* SIOCGIWSTATS */
8132 NULL, /* SIOCSIWSPY */
8133 NULL, /* SIOCGIWSPY */
8134 NULL, /* SIOCGIWTHRSPY */
8135 NULL, /* SIOCWIWTHRSPY */
8136 ipw2100_wx_set_wap, /* SIOCSIWAP */
8137 ipw2100_wx_get_wap, /* SIOCGIWAP */
James Ketrenos82328352005-08-24 22:33:31 -05008138 ipw2100_wx_set_mlme, /* SIOCSIWMLME */
James Ketrenosee8e3652005-09-14 09:47:29 -05008139 NULL, /* SIOCGIWAPLIST -- deprecated */
8140 ipw2100_wx_set_scan, /* SIOCSIWSCAN */
8141 ipw2100_wx_get_scan, /* SIOCGIWSCAN */
8142 ipw2100_wx_set_essid, /* SIOCSIWESSID */
8143 ipw2100_wx_get_essid, /* SIOCGIWESSID */
8144 ipw2100_wx_set_nick, /* SIOCSIWNICKN */
8145 ipw2100_wx_get_nick, /* SIOCGIWNICKN */
8146 NULL, /* -- hole -- */
8147 NULL, /* -- hole -- */
8148 ipw2100_wx_set_rate, /* SIOCSIWRATE */
8149 ipw2100_wx_get_rate, /* SIOCGIWRATE */
8150 ipw2100_wx_set_rts, /* SIOCSIWRTS */
8151 ipw2100_wx_get_rts, /* SIOCGIWRTS */
8152 ipw2100_wx_set_frag, /* SIOCSIWFRAG */
8153 ipw2100_wx_get_frag, /* SIOCGIWFRAG */
8154 ipw2100_wx_set_txpow, /* SIOCSIWTXPOW */
8155 ipw2100_wx_get_txpow, /* SIOCGIWTXPOW */
8156 ipw2100_wx_set_retry, /* SIOCSIWRETRY */
8157 ipw2100_wx_get_retry, /* SIOCGIWRETRY */
8158 ipw2100_wx_set_encode, /* SIOCSIWENCODE */
8159 ipw2100_wx_get_encode, /* SIOCGIWENCODE */
8160 ipw2100_wx_set_power, /* SIOCSIWPOWER */
8161 ipw2100_wx_get_power, /* SIOCGIWPOWER */
James Ketrenos82328352005-08-24 22:33:31 -05008162 NULL, /* -- hole -- */
8163 NULL, /* -- hole -- */
8164 ipw2100_wx_set_genie, /* SIOCSIWGENIE */
8165 ipw2100_wx_get_genie, /* SIOCGIWGENIE */
8166 ipw2100_wx_set_auth, /* SIOCSIWAUTH */
8167 ipw2100_wx_get_auth, /* SIOCGIWAUTH */
8168 ipw2100_wx_set_encodeext, /* SIOCSIWENCODEEXT */
8169 ipw2100_wx_get_encodeext, /* SIOCGIWENCODEEXT */
8170 NULL, /* SIOCSIWPMKSA */
James Ketrenos2c86c272005-03-23 17:32:29 -06008171};
8172
8173#define IPW2100_PRIV_SET_MONITOR SIOCIWFIRSTPRIV
8174#define IPW2100_PRIV_RESET SIOCIWFIRSTPRIV+1
8175#define IPW2100_PRIV_SET_POWER SIOCIWFIRSTPRIV+2
8176#define IPW2100_PRIV_GET_POWER SIOCIWFIRSTPRIV+3
8177#define IPW2100_PRIV_SET_LONGPREAMBLE SIOCIWFIRSTPRIV+4
8178#define IPW2100_PRIV_GET_LONGPREAMBLE SIOCIWFIRSTPRIV+5
James Ketrenos82328352005-08-24 22:33:31 -05008179#define IPW2100_PRIV_SET_CRC_CHECK SIOCIWFIRSTPRIV+6
8180#define IPW2100_PRIV_GET_CRC_CHECK SIOCIWFIRSTPRIV+7
James Ketrenos2c86c272005-03-23 17:32:29 -06008181
8182static const struct iw_priv_args ipw2100_private_args[] = {
8183
8184#ifdef CONFIG_IPW2100_MONITOR
8185 {
James Ketrenosee8e3652005-09-14 09:47:29 -05008186 IPW2100_PRIV_SET_MONITOR,
8187 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
James Ketrenos2c86c272005-03-23 17:32:29 -06008188 {
James Ketrenosee8e3652005-09-14 09:47:29 -05008189 IPW2100_PRIV_RESET,
8190 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
8191#endif /* CONFIG_IPW2100_MONITOR */
James Ketrenos2c86c272005-03-23 17:32:29 -06008192
8193 {
James Ketrenosee8e3652005-09-14 09:47:29 -05008194 IPW2100_PRIV_SET_POWER,
8195 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_power"},
James Ketrenos2c86c272005-03-23 17:32:29 -06008196 {
James Ketrenosee8e3652005-09-14 09:47:29 -05008197 IPW2100_PRIV_GET_POWER,
8198 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_POWER_STRING,
8199 "get_power"},
James Ketrenos2c86c272005-03-23 17:32:29 -06008200 {
James Ketrenosee8e3652005-09-14 09:47:29 -05008201 IPW2100_PRIV_SET_LONGPREAMBLE,
8202 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_preamble"},
James Ketrenos2c86c272005-03-23 17:32:29 -06008203 {
James Ketrenosee8e3652005-09-14 09:47:29 -05008204 IPW2100_PRIV_GET_LONGPREAMBLE,
8205 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_preamble"},
James Ketrenos82328352005-08-24 22:33:31 -05008206#ifdef CONFIG_IPW2100_MONITOR
8207 {
8208 IPW2100_PRIV_SET_CRC_CHECK,
8209 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_crc_check"},
8210 {
8211 IPW2100_PRIV_GET_CRC_CHECK,
8212 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_crc_check"},
8213#endif /* CONFIG_IPW2100_MONITOR */
James Ketrenos2c86c272005-03-23 17:32:29 -06008214};
8215
8216static iw_handler ipw2100_private_handler[] = {
8217#ifdef CONFIG_IPW2100_MONITOR
8218 ipw2100_wx_set_promisc,
8219 ipw2100_wx_reset,
James Ketrenosee8e3652005-09-14 09:47:29 -05008220#else /* CONFIG_IPW2100_MONITOR */
James Ketrenos2c86c272005-03-23 17:32:29 -06008221 NULL,
8222 NULL,
James Ketrenosee8e3652005-09-14 09:47:29 -05008223#endif /* CONFIG_IPW2100_MONITOR */
James Ketrenos2c86c272005-03-23 17:32:29 -06008224 ipw2100_wx_set_powermode,
8225 ipw2100_wx_get_powermode,
8226 ipw2100_wx_set_preamble,
8227 ipw2100_wx_get_preamble,
James Ketrenos82328352005-08-24 22:33:31 -05008228#ifdef CONFIG_IPW2100_MONITOR
8229 ipw2100_wx_set_crc_check,
8230 ipw2100_wx_get_crc_check,
8231#else /* CONFIG_IPW2100_MONITOR */
8232 NULL,
8233 NULL,
8234#endif /* CONFIG_IPW2100_MONITOR */
James Ketrenos2c86c272005-03-23 17:32:29 -06008235};
8236
James Ketrenos2c86c272005-03-23 17:32:29 -06008237/*
8238 * Get wireless statistics.
8239 * Called by /proc/net/wireless
8240 * Also called by SIOCGIWSTATS
8241 */
James Ketrenosee8e3652005-09-14 09:47:29 -05008242static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device *dev)
James Ketrenos2c86c272005-03-23 17:32:29 -06008243{
8244 enum {
8245 POOR = 30,
8246 FAIR = 60,
8247 GOOD = 80,
8248 VERY_GOOD = 90,
8249 EXCELLENT = 95,
8250 PERFECT = 100
8251 };
8252 int rssi_qual;
8253 int tx_qual;
8254 int beacon_qual;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008255 int quality;
James Ketrenos2c86c272005-03-23 17:32:29 -06008256
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008257 struct ipw2100_priv *priv = libipw_priv(dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06008258 struct iw_statistics *wstats;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008259 u32 rssi, tx_retries, missed_beacons, tx_failures;
James Ketrenos2c86c272005-03-23 17:32:29 -06008260 u32 ord_len = sizeof(u32);
8261
8262 if (!priv)
James Ketrenosee8e3652005-09-14 09:47:29 -05008263 return (struct iw_statistics *)NULL;
James Ketrenos2c86c272005-03-23 17:32:29 -06008264
8265 wstats = &priv->wstats;
8266
8267 /* if hw is disabled, then ipw2100_get_ordinal() can't be called.
8268 * ipw2100_wx_wireless_stats seems to be called before fw is
8269 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
8270 * and associated; if not associcated, the values are all meaningless
8271 * anyway, so set them all to NULL and INVALID */
8272 if (!(priv->status & STATUS_ASSOCIATED)) {
8273 wstats->miss.beacon = 0;
8274 wstats->discard.retries = 0;
8275 wstats->qual.qual = 0;
8276 wstats->qual.level = 0;
8277 wstats->qual.noise = 0;
8278 wstats->qual.updated = 7;
8279 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
James Ketrenosee8e3652005-09-14 09:47:29 -05008280 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos2c86c272005-03-23 17:32:29 -06008281 return wstats;
8282 }
8283
8284 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_MISSED_BCNS,
8285 &missed_beacons, &ord_len))
8286 goto fail_get_ordinal;
8287
James Ketrenosee8e3652005-09-14 09:47:29 -05008288 /* If we don't have a connection the quality and level is 0 */
James Ketrenos2c86c272005-03-23 17:32:29 -06008289 if (!(priv->status & STATUS_ASSOCIATED)) {
8290 wstats->qual.qual = 0;
8291 wstats->qual.level = 0;
8292 } else {
8293 if (ipw2100_get_ordinal(priv, IPW_ORD_RSSI_AVG_CURR,
8294 &rssi, &ord_len))
8295 goto fail_get_ordinal;
8296 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8297 if (rssi < 10)
8298 rssi_qual = rssi * POOR / 10;
8299 else if (rssi < 15)
8300 rssi_qual = (rssi - 10) * (FAIR - POOR) / 5 + POOR;
8301 else if (rssi < 20)
8302 rssi_qual = (rssi - 15) * (GOOD - FAIR) / 5 + FAIR;
8303 else if (rssi < 30)
8304 rssi_qual = (rssi - 20) * (VERY_GOOD - GOOD) /
James Ketrenosee8e3652005-09-14 09:47:29 -05008305 10 + GOOD;
James Ketrenos2c86c272005-03-23 17:32:29 -06008306 else
8307 rssi_qual = (rssi - 30) * (PERFECT - VERY_GOOD) /
James Ketrenosee8e3652005-09-14 09:47:29 -05008308 10 + VERY_GOOD;
James Ketrenos2c86c272005-03-23 17:32:29 -06008309
8310 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_RETRIES,
8311 &tx_retries, &ord_len))
8312 goto fail_get_ordinal;
8313
8314 if (tx_retries > 75)
8315 tx_qual = (90 - tx_retries) * POOR / 15;
8316 else if (tx_retries > 70)
8317 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
8318 else if (tx_retries > 65)
8319 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
8320 else if (tx_retries > 50)
8321 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
James Ketrenosee8e3652005-09-14 09:47:29 -05008322 15 + GOOD;
James Ketrenos2c86c272005-03-23 17:32:29 -06008323 else
8324 tx_qual = (50 - tx_retries) *
James Ketrenosee8e3652005-09-14 09:47:29 -05008325 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
James Ketrenos2c86c272005-03-23 17:32:29 -06008326
8327 if (missed_beacons > 50)
8328 beacon_qual = (60 - missed_beacons) * POOR / 10;
8329 else if (missed_beacons > 40)
8330 beacon_qual = (50 - missed_beacons) * (FAIR - POOR) /
James Ketrenosee8e3652005-09-14 09:47:29 -05008331 10 + POOR;
James Ketrenos2c86c272005-03-23 17:32:29 -06008332 else if (missed_beacons > 32)
8333 beacon_qual = (40 - missed_beacons) * (GOOD - FAIR) /
James Ketrenosee8e3652005-09-14 09:47:29 -05008334 18 + FAIR;
James Ketrenos2c86c272005-03-23 17:32:29 -06008335 else if (missed_beacons > 20)
8336 beacon_qual = (32 - missed_beacons) *
James Ketrenosee8e3652005-09-14 09:47:29 -05008337 (VERY_GOOD - GOOD) / 20 + GOOD;
James Ketrenos2c86c272005-03-23 17:32:29 -06008338 else
8339 beacon_qual = (20 - missed_beacons) *
James Ketrenosee8e3652005-09-14 09:47:29 -05008340 (PERFECT - VERY_GOOD) / 20 + VERY_GOOD;
James Ketrenos2c86c272005-03-23 17:32:29 -06008341
Reinette Chatre21f8a732009-08-18 10:25:05 -07008342 quality = min(tx_qual, rssi_qual);
8343 quality = min(beacon_qual, quality);
James Ketrenos2c86c272005-03-23 17:32:29 -06008344
Brice Goglin0f52bf92005-12-01 01:41:46 -08008345#ifdef CONFIG_IPW2100_DEBUG
James Ketrenos2c86c272005-03-23 17:32:29 -06008346 if (beacon_qual == quality)
8347 IPW_DEBUG_WX("Quality clamped by Missed Beacons\n");
8348 else if (tx_qual == quality)
8349 IPW_DEBUG_WX("Quality clamped by Tx Retries\n");
8350 else if (quality != 100)
8351 IPW_DEBUG_WX("Quality clamped by Signal Strength\n");
8352 else
8353 IPW_DEBUG_WX("Quality not clamped.\n");
8354#endif
8355
8356 wstats->qual.qual = quality;
8357 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8358 }
8359
8360 wstats->qual.noise = 0;
8361 wstats->qual.updated = 7;
8362 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
8363
James Ketrenosee8e3652005-09-14 09:47:29 -05008364 /* FIXME: this is percent and not a # */
James Ketrenos2c86c272005-03-23 17:32:29 -06008365 wstats->miss.beacon = missed_beacons;
8366
8367 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURES,
8368 &tx_failures, &ord_len))
8369 goto fail_get_ordinal;
8370 wstats->discard.retries = tx_failures;
8371
8372 return wstats;
8373
James Ketrenosee8e3652005-09-14 09:47:29 -05008374 fail_get_ordinal:
James Ketrenos2c86c272005-03-23 17:32:29 -06008375 IPW_DEBUG_WX("failed querying ordinals.\n");
8376
James Ketrenosee8e3652005-09-14 09:47:29 -05008377 return (struct iw_statistics *)NULL;
James Ketrenos2c86c272005-03-23 17:32:29 -06008378}
8379
James Ketrenoseaf8f532005-11-12 12:50:12 -06008380static struct iw_handler_def ipw2100_wx_handler_def = {
8381 .standard = ipw2100_wx_handlers,
Denis Chengff8ac602007-09-02 18:30:18 +08008382 .num_standard = ARRAY_SIZE(ipw2100_wx_handlers),
8383 .num_private = ARRAY_SIZE(ipw2100_private_handler),
8384 .num_private_args = ARRAY_SIZE(ipw2100_private_args),
James Ketrenoseaf8f532005-11-12 12:50:12 -06008385 .private = (iw_handler *) ipw2100_private_handler,
8386 .private_args = (struct iw_priv_args *)ipw2100_private_args,
8387 .get_wireless_stats = ipw2100_wx_wireless_stats,
8388};
8389
David Howellsc4028952006-11-22 14:57:56 +00008390static void ipw2100_wx_event_work(struct work_struct *work)
James Ketrenos2c86c272005-03-23 17:32:29 -06008391{
David Howellsc4028952006-11-22 14:57:56 +00008392 struct ipw2100_priv *priv =
8393 container_of(work, struct ipw2100_priv, wx_event_work.work);
James Ketrenos2c86c272005-03-23 17:32:29 -06008394 union iwreq_data wrqu;
Hannes Ederb9da9e92009-02-14 11:50:26 +00008395 unsigned int len = ETH_ALEN;
James Ketrenos2c86c272005-03-23 17:32:29 -06008396
8397 if (priv->status & STATUS_STOPPING)
8398 return;
8399
Ingo Molnar752e3772006-02-28 07:20:54 +08008400 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06008401
8402 IPW_DEBUG_WX("enter\n");
8403
Ingo Molnar752e3772006-02-28 07:20:54 +08008404 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06008405
8406 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
8407
8408 /* Fetch BSSID from the hardware */
8409 if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) ||
8410 priv->status & STATUS_RF_KILL_MASK ||
8411 ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
James Ketrenosee8e3652005-09-14 09:47:29 -05008412 &priv->bssid, &len)) {
James Ketrenos2c86c272005-03-23 17:32:29 -06008413 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
8414 } else {
8415 /* We now have the BSSID, so can finish setting to the full
8416 * associated state */
8417 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos82328352005-08-24 22:33:31 -05008418 memcpy(priv->ieee->bssid, priv->bssid, ETH_ALEN);
James Ketrenos2c86c272005-03-23 17:32:29 -06008419 priv->status &= ~STATUS_ASSOCIATING;
8420 priv->status |= STATUS_ASSOCIATED;
8421 netif_carrier_on(priv->net_dev);
James Ketrenos82328352005-08-24 22:33:31 -05008422 netif_wake_queue(priv->net_dev);
James Ketrenos2c86c272005-03-23 17:32:29 -06008423 }
8424
8425 if (!(priv->status & STATUS_ASSOCIATED)) {
8426 IPW_DEBUG_WX("Configuring ESSID\n");
Ingo Molnar752e3772006-02-28 07:20:54 +08008427 mutex_lock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06008428 /* This is a disassociation event, so kick the firmware to
8429 * look for another AP */
8430 if (priv->config & CFG_STATIC_ESSID)
James Ketrenosee8e3652005-09-14 09:47:29 -05008431 ipw2100_set_essid(priv, priv->essid, priv->essid_len,
8432 0);
James Ketrenos2c86c272005-03-23 17:32:29 -06008433 else
8434 ipw2100_set_essid(priv, NULL, 0, 0);
Ingo Molnar752e3772006-02-28 07:20:54 +08008435 mutex_unlock(&priv->action_mutex);
James Ketrenos2c86c272005-03-23 17:32:29 -06008436 }
8437
8438 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
8439}
8440
8441#define IPW2100_FW_MAJOR_VERSION 1
8442#define IPW2100_FW_MINOR_VERSION 3
8443
8444#define IPW2100_FW_MINOR(x) ((x & 0xff) >> 8)
8445#define IPW2100_FW_MAJOR(x) (x & 0xff)
8446
8447#define IPW2100_FW_VERSION ((IPW2100_FW_MINOR_VERSION << 8) | \
8448 IPW2100_FW_MAJOR_VERSION)
8449
8450#define IPW2100_FW_PREFIX "ipw2100-" __stringify(IPW2100_FW_MAJOR_VERSION) \
8451"." __stringify(IPW2100_FW_MINOR_VERSION)
8452
8453#define IPW2100_FW_NAME(x) IPW2100_FW_PREFIX "" x ".fw"
8454
James Ketrenos2c86c272005-03-23 17:32:29 -06008455/*
8456
8457BINARY FIRMWARE HEADER FORMAT
8458
8459offset length desc
84600 2 version
84612 2 mode == 0:BSS,1:IBSS,2:MONITOR
84624 4 fw_len
84638 4 uc_len
8464C fw_len firmware data
846512 + fw_len uc_len microcode data
8466
8467*/
8468
8469struct ipw2100_fw_header {
8470 short version;
8471 short mode;
8472 unsigned int fw_size;
8473 unsigned int uc_size;
8474} __attribute__ ((packed));
8475
James Ketrenos2c86c272005-03-23 17:32:29 -06008476static int ipw2100_mod_firmware_load(struct ipw2100_fw *fw)
8477{
8478 struct ipw2100_fw_header *h =
James Ketrenosee8e3652005-09-14 09:47:29 -05008479 (struct ipw2100_fw_header *)fw->fw_entry->data;
James Ketrenos2c86c272005-03-23 17:32:29 -06008480
8481 if (IPW2100_FW_MAJOR(h->version) != IPW2100_FW_MAJOR_VERSION) {
Jiri Benc797b4f72005-08-25 20:03:27 -04008482 printk(KERN_WARNING DRV_NAME ": Firmware image not compatible "
James Ketrenos2c86c272005-03-23 17:32:29 -06008483 "(detected version id of %u). "
8484 "See Documentation/networking/README.ipw2100\n",
8485 h->version);
8486 return 1;
8487 }
8488
8489 fw->version = h->version;
8490 fw->fw.data = fw->fw_entry->data + sizeof(struct ipw2100_fw_header);
8491 fw->fw.size = h->fw_size;
8492 fw->uc.data = fw->fw.data + h->fw_size;
8493 fw->uc.size = h->uc_size;
8494
8495 return 0;
8496}
8497
Jiri Bencc4aee8c2005-08-25 20:04:43 -04008498static int ipw2100_get_firmware(struct ipw2100_priv *priv,
8499 struct ipw2100_fw *fw)
James Ketrenos2c86c272005-03-23 17:32:29 -06008500{
8501 char *fw_name;
8502 int rc;
8503
8504 IPW_DEBUG_INFO("%s: Using hotplug firmware load.\n",
James Ketrenosee8e3652005-09-14 09:47:29 -05008505 priv->net_dev->name);
James Ketrenos2c86c272005-03-23 17:32:29 -06008506
8507 switch (priv->ieee->iw_mode) {
8508 case IW_MODE_ADHOC:
8509 fw_name = IPW2100_FW_NAME("-i");
8510 break;
8511#ifdef CONFIG_IPW2100_MONITOR
8512 case IW_MODE_MONITOR:
8513 fw_name = IPW2100_FW_NAME("-p");
8514 break;
8515#endif
8516 case IW_MODE_INFRA:
8517 default:
8518 fw_name = IPW2100_FW_NAME("");
8519 break;
8520 }
8521
8522 rc = request_firmware(&fw->fw_entry, fw_name, &priv->pci_dev->dev);
8523
8524 if (rc < 0) {
Jiri Benc797b4f72005-08-25 20:03:27 -04008525 printk(KERN_ERR DRV_NAME ": "
James Ketrenos2c86c272005-03-23 17:32:29 -06008526 "%s: Firmware '%s' not available or load failed.\n",
8527 priv->net_dev->name, fw_name);
8528 return rc;
8529 }
Jiri Bencaaa4d302005-06-07 14:58:41 +02008530 IPW_DEBUG_INFO("firmware data %p size %zd\n", fw->fw_entry->data,
James Ketrenosee8e3652005-09-14 09:47:29 -05008531 fw->fw_entry->size);
James Ketrenos2c86c272005-03-23 17:32:29 -06008532
8533 ipw2100_mod_firmware_load(fw);
8534
8535 return 0;
8536}
8537
Ben Hutchingsa278ea32009-11-07 21:58:47 +00008538MODULE_FIRMWARE(IPW2100_FW_NAME("-i"));
8539#ifdef CONFIG_IPW2100_MONITOR
8540MODULE_FIRMWARE(IPW2100_FW_NAME("-p"));
8541#endif
8542MODULE_FIRMWARE(IPW2100_FW_NAME(""));
8543
Jiri Bencc4aee8c2005-08-25 20:04:43 -04008544static void ipw2100_release_firmware(struct ipw2100_priv *priv,
8545 struct ipw2100_fw *fw)
James Ketrenos2c86c272005-03-23 17:32:29 -06008546{
8547 fw->version = 0;
8548 if (fw->fw_entry)
8549 release_firmware(fw->fw_entry);
8550 fw->fw_entry = NULL;
8551}
8552
Jiri Bencc4aee8c2005-08-25 20:04:43 -04008553static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf,
8554 size_t max)
James Ketrenos2c86c272005-03-23 17:32:29 -06008555{
8556 char ver[MAX_FW_VERSION_LEN];
8557 u32 len = MAX_FW_VERSION_LEN;
8558 u32 tmp;
8559 int i;
8560 /* firmware version is an ascii string (max len of 14) */
James Ketrenosee8e3652005-09-14 09:47:29 -05008561 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_FW_VER_NUM, ver, &len))
James Ketrenos2c86c272005-03-23 17:32:29 -06008562 return -EIO;
8563 tmp = max;
8564 if (len >= max)
8565 len = max - 1;
8566 for (i = 0; i < len; i++)
8567 buf[i] = ver[i];
8568 buf[i] = '\0';
8569 return tmp;
8570}
8571
Jiri Bencc4aee8c2005-08-25 20:04:43 -04008572static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf,
8573 size_t max)
James Ketrenos2c86c272005-03-23 17:32:29 -06008574{
8575 u32 ver;
8576 u32 len = sizeof(ver);
8577 /* microcode version is a 32 bit integer */
James Ketrenosee8e3652005-09-14 09:47:29 -05008578 if (ipw2100_get_ordinal(priv, IPW_ORD_UCODE_VERSION, &ver, &len))
James Ketrenos2c86c272005-03-23 17:32:29 -06008579 return -EIO;
8580 return snprintf(buf, max, "%08X", ver);
8581}
8582
8583/*
8584 * On exit, the firmware will have been freed from the fw list
8585 */
James Ketrenosee8e3652005-09-14 09:47:29 -05008586static int ipw2100_fw_download(struct ipw2100_priv *priv, struct ipw2100_fw *fw)
James Ketrenos2c86c272005-03-23 17:32:29 -06008587{
8588 /* firmware is constructed of N contiguous entries, each entry is
8589 * structured as:
8590 *
8591 * offset sie desc
8592 * 0 4 address to write to
8593 * 4 2 length of data run
James Ketrenosee8e3652005-09-14 09:47:29 -05008594 * 6 length data
James Ketrenos2c86c272005-03-23 17:32:29 -06008595 */
8596 unsigned int addr;
8597 unsigned short len;
8598
8599 const unsigned char *firmware_data = fw->fw.data;
8600 unsigned int firmware_data_left = fw->fw.size;
8601
8602 while (firmware_data_left > 0) {
James Ketrenosee8e3652005-09-14 09:47:29 -05008603 addr = *(u32 *) (firmware_data);
8604 firmware_data += 4;
James Ketrenos2c86c272005-03-23 17:32:29 -06008605 firmware_data_left -= 4;
8606
James Ketrenosee8e3652005-09-14 09:47:29 -05008607 len = *(u16 *) (firmware_data);
8608 firmware_data += 2;
James Ketrenos2c86c272005-03-23 17:32:29 -06008609 firmware_data_left -= 2;
8610
8611 if (len > 32) {
Jiri Benc797b4f72005-08-25 20:03:27 -04008612 printk(KERN_ERR DRV_NAME ": "
James Ketrenos2c86c272005-03-23 17:32:29 -06008613 "Invalid firmware run-length of %d bytes\n",
8614 len);
8615 return -EINVAL;
8616 }
8617
8618 write_nic_memory(priv->net_dev, addr, len, firmware_data);
James Ketrenosee8e3652005-09-14 09:47:29 -05008619 firmware_data += len;
James Ketrenos2c86c272005-03-23 17:32:29 -06008620 firmware_data_left -= len;
8621 }
8622
8623 return 0;
8624}
8625
8626struct symbol_alive_response {
8627 u8 cmd_id;
8628 u8 seq_num;
8629 u8 ucode_rev;
8630 u8 eeprom_valid;
8631 u16 valid_flags;
8632 u8 IEEE_addr[6];
8633 u16 flags;
8634 u16 pcb_rev;
8635 u16 clock_settle_time; // 1us LSB
8636 u16 powerup_settle_time; // 1us LSB
8637 u16 hop_settle_time; // 1us LSB
8638 u8 date[3]; // month, day, year
8639 u8 time[2]; // hours, minutes
8640 u8 ucode_valid;
8641};
8642
Jiri Bencc4aee8c2005-08-25 20:04:43 -04008643static int ipw2100_ucode_download(struct ipw2100_priv *priv,
8644 struct ipw2100_fw *fw)
James Ketrenos2c86c272005-03-23 17:32:29 -06008645{
8646 struct net_device *dev = priv->net_dev;
8647 const unsigned char *microcode_data = fw->uc.data;
8648 unsigned int microcode_data_left = fw->uc.size;
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008649 void __iomem *reg = (void __iomem *)dev->base_addr;
James Ketrenos2c86c272005-03-23 17:32:29 -06008650
8651 struct symbol_alive_response response;
8652 int i, j;
8653 u8 data;
8654
8655 /* Symbol control */
8656 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008657 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008658 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008659 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008660
8661 /* HW config */
8662 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008663 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008664 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008665 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008666
8667 /* EN_CS_ACCESS bit to reset control store pointer */
8668 write_nic_byte(dev, 0x210000, 0x40);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008669 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008670 write_nic_byte(dev, 0x210000, 0x0);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008671 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008672 write_nic_byte(dev, 0x210000, 0x40);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008673 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008674
8675 /* copy microcode from buffer into Symbol */
8676
8677 while (microcode_data_left > 0) {
8678 write_nic_byte(dev, 0x210010, *microcode_data++);
8679 write_nic_byte(dev, 0x210010, *microcode_data++);
8680 microcode_data_left -= 2;
8681 }
8682
8683 /* EN_CS_ACCESS bit to reset the control store pointer */
8684 write_nic_byte(dev, 0x210000, 0x0);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008685 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008686
8687 /* Enable System (Reg 0)
8688 * first enable causes garbage in RX FIFO */
8689 write_nic_byte(dev, 0x210000, 0x0);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008690 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008691 write_nic_byte(dev, 0x210000, 0x80);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008692 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008693
8694 /* Reset External Baseband Reg */
8695 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008696 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008697 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008698 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008699
8700 /* HW Config (Reg 5) */
8701 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
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, 0x210014, 0x72); // fifo width =16
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008704 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008705
8706 /* Enable System (Reg 0)
8707 * second enable should be OK */
8708 write_nic_byte(dev, 0x210000, 0x00); // clear enable system
viro@ftp.linux.org.uk2be041a2005-09-05 03:26:08 +01008709 readl(reg);
James Ketrenos2c86c272005-03-23 17:32:29 -06008710 write_nic_byte(dev, 0x210000, 0x80); // set enable system
8711
8712 /* check Symbol is enabled - upped this from 5 as it wasn't always
8713 * catching the update */
8714 for (i = 0; i < 10; i++) {
8715 udelay(10);
8716
8717 /* check Dino is enabled bit */
8718 read_nic_byte(dev, 0x210000, &data);
8719 if (data & 0x1)
8720 break;
8721 }
8722
8723 if (i == 10) {
Jiri Benc797b4f72005-08-25 20:03:27 -04008724 printk(KERN_ERR DRV_NAME ": %s: Error initializing Symbol\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06008725 dev->name);
8726 return -EIO;
8727 }
8728
8729 /* Get Symbol alive response */
8730 for (i = 0; i < 30; i++) {
8731 /* Read alive response structure */
8732 for (j = 0;
James Ketrenosee8e3652005-09-14 09:47:29 -05008733 j < (sizeof(struct symbol_alive_response) >> 1); j++)
8734 read_nic_word(dev, 0x210004, ((u16 *) & response) + j);
James Ketrenos2c86c272005-03-23 17:32:29 -06008735
James Ketrenosee8e3652005-09-14 09:47:29 -05008736 if ((response.cmd_id == 1) && (response.ucode_valid == 0x1))
James Ketrenos2c86c272005-03-23 17:32:29 -06008737 break;
8738 udelay(10);
8739 }
8740
8741 if (i == 30) {
James Ketrenosee8e3652005-09-14 09:47:29 -05008742 printk(KERN_ERR DRV_NAME
8743 ": %s: No response from Symbol - hw not alive\n",
James Ketrenos2c86c272005-03-23 17:32:29 -06008744 dev->name);
James Ketrenosee8e3652005-09-14 09:47:29 -05008745 printk_buf(IPW_DL_ERROR, (u8 *) & response, sizeof(response));
James Ketrenos2c86c272005-03-23 17:32:29 -06008746 return -EIO;
8747 }
8748
8749 return 0;
8750}