| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | /******************************************************************************
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Copyright(c) 2003 - 2005 Intel Corporation. All rights reserved. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   This program is free software; you can redistribute it and/or modify it | 
					
						
							|  |  |  |   under the terms of version 2 of the GNU General Public License as | 
					
						
							|  |  |  |   published by the Free Software Foundation. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   This program is distributed in the hope that it will be useful, but WITHOUT | 
					
						
							|  |  |  |   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 
					
						
							|  |  |  |   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for | 
					
						
							|  |  |  |   more details. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   You should have received a copy of the GNU General Public License along with | 
					
						
							|  |  |  |   this program; if not, write to the Free Software Foundation, Inc., 59 | 
					
						
							|  |  |  |   Temple Place - Suite 330, Boston, MA  02111-1307, USA. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   The full GNU General Public License is included in this distribution in the | 
					
						
							|  |  |  |   file called LICENSE. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Contact Information: | 
					
						
							|  |  |  |   James P. Ketrenos <ipw2100-admin@linux.intel.com> | 
					
						
							|  |  |  |   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Portions of this file are based on the sample_* files provided by Wireless | 
					
						
							|  |  |  |   Extensions 0.26 package and copyright (c) 1997-2003 Jean Tourrilhes | 
					
						
							|  |  |  |   <jt@hpl.hp.com> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Portions of this file are based on the Host AP project, | 
					
						
							|  |  |  |   Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen | 
					
						
							|  |  |  |     <jkmaline@cc.hut.fi> | 
					
						
							|  |  |  |   Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Portions of ipw2100_mod_firmware_load, ipw2100_do_mod_firmware_load, and | 
					
						
							|  |  |  |   ipw2100_fw_load are loosely based on drivers/sound/sound_firmware.c | 
					
						
							|  |  |  |   available in the 2.4.25 kernel sources, and are copyright (c) Alan Cox | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ******************************************************************************/ | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  Initial driver on which this is based was developed by Janusz Gorycki, | 
					
						
							|  |  |  |  Maciej Urbaniak, and Maciej Sosnowski. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  Promiscuous mode support added by Jacek Wysoczynski and Maciej Urbaniak. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Theory of Operation | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Tx - Commands and Data | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Firmware and host share a circular queue of Transmit Buffer Descriptors (TBDs) | 
					
						
							|  |  |  | Each TBD contains a pointer to the physical (dma_addr_t) address of data being | 
					
						
							|  |  |  | sent to the firmware as well as the length of the data. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The host writes to the TBD queue at the WRITE index.  The WRITE index points | 
					
						
							|  |  |  | to the _next_ packet to be written and is advanced when after the TBD has been | 
					
						
							|  |  |  | filled. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The firmware pulls from the TBD queue at the READ index.  The READ index points | 
					
						
							|  |  |  | to the currently being read entry, and is advanced once the firmware is | 
					
						
							|  |  |  | done with a packet. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | When data is sent to the firmware, the first TBD is used to indicate to the | 
					
						
							|  |  |  | firmware if a Command or Data is being sent.  If it is Command, all of the | 
					
						
							|  |  |  | command information is contained within the physical address referred to by the | 
					
						
							|  |  |  | TBD.  If it is Data, the first TBD indicates the type of data packet, number | 
					
						
							|  |  |  | of fragments, etc.  The next TBD then referrs to the actual packet location. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The Tx flow cycle is as follows: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 1) ipw2100_tx() is called by kernel with SKB to transmit | 
					
						
							|  |  |  | 2) Packet is move from the tx_free_list and appended to the transmit pending | 
					
						
							|  |  |  |    list (tx_pend_list) | 
					
						
							|  |  |  | 3) work is scheduled to move pending packets into the shared circular queue. | 
					
						
							|  |  |  | 4) when placing packet in the circular queue, the incoming SKB is DMA mapped | 
					
						
							|  |  |  |    to a physical address.  That address is entered into a TBD.  Two TBDs are | 
					
						
							|  |  |  |    filled out.  The first indicating a data packet, the second referring to the | 
					
						
							|  |  |  |    actual payload data. | 
					
						
							|  |  |  | 5) the packet is removed from tx_pend_list and placed on the end of the | 
					
						
							|  |  |  |    firmware pending list (fw_pend_list) | 
					
						
							|  |  |  | 6) firmware is notified that the WRITE index has | 
					
						
							|  |  |  | 7) Once the firmware has processed the TBD, INTA is triggered. | 
					
						
							|  |  |  | 8) For each Tx interrupt received from the firmware, the READ index is checked | 
					
						
							|  |  |  |    to see which TBDs are done being processed. | 
					
						
							|  |  |  | 9) For each TBD that has been processed, the ISR pulls the oldest packet | 
					
						
							|  |  |  |    from the fw_pend_list. | 
					
						
							|  |  |  | 10)The packet structure contained in the fw_pend_list is then used | 
					
						
							|  |  |  |    to unmap the DMA address and to free the SKB originally passed to the driver | 
					
						
							|  |  |  |    from the kernel. | 
					
						
							|  |  |  | 11)The packet structure is placed onto the tx_free_list | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The above steps are the same for commands, only the msg_free_list/msg_pend_list | 
					
						
							|  |  |  | are used instead of tx_free_list/tx_pend_list | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ... | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Critical Sections / Locking : | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | There are two locks utilized.  The first is the low level lock (priv->low_lock) | 
					
						
							|  |  |  | that protects the following: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | - Access to the Tx/Rx queue lists via priv->low_lock. The lists are as follows: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   tx_free_list : Holds pre-allocated Tx buffers. | 
					
						
							|  |  |  |     TAIL modified in __ipw2100_tx_process() | 
					
						
							|  |  |  |     HEAD modified in ipw2100_tx() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   tx_pend_list : Holds used Tx buffers waiting to go into the TBD ring | 
					
						
							|  |  |  |     TAIL modified ipw2100_tx() | 
					
						
							| 
									
										
										
										
											2005-08-25 20:02:10 -04:00
										 |  |  |     HEAD modified by ipw2100_tx_send_data() | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |   msg_free_list : Holds pre-allocated Msg (Command) buffers | 
					
						
							|  |  |  |     TAIL modified in __ipw2100_tx_process() | 
					
						
							|  |  |  |     HEAD modified in ipw2100_hw_send_command() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   msg_pend_list : Holds used Msg buffers waiting to go into the TBD ring | 
					
						
							|  |  |  |     TAIL modified in ipw2100_hw_send_command() | 
					
						
							| 
									
										
										
										
											2005-08-25 20:02:10 -04:00
										 |  |  |     HEAD modified in ipw2100_tx_send_commands() | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |   The flow of data on the TX side is as follows: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   MSG_FREE_LIST + COMMAND => MSG_PEND_LIST => TBD => MSG_FREE_LIST | 
					
						
							|  |  |  |   TX_FREE_LIST + DATA => TX_PEND_LIST => TBD => TX_FREE_LIST | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   The methods that work on the TBD ring are protected via priv->low_lock. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | - The internal data state of the device itself | 
					
						
							|  |  |  | - Access to the firmware read/write indexes for the BD queues | 
					
						
							|  |  |  |   and associated logic | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | All external entry functions are locked with the priv->action_lock to ensure | 
					
						
							|  |  |  | that only one external action is invoked at a time. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/compiler.h>
 | 
					
						
							|  |  |  | #include <linux/config.h>
 | 
					
						
							|  |  |  | #include <linux/errno.h>
 | 
					
						
							|  |  |  | #include <linux/if_arp.h>
 | 
					
						
							|  |  |  | #include <linux/in6.h>
 | 
					
						
							|  |  |  | #include <linux/in.h>
 | 
					
						
							|  |  |  | #include <linux/ip.h>
 | 
					
						
							|  |  |  | #include <linux/kernel.h>
 | 
					
						
							|  |  |  | #include <linux/kmod.h>
 | 
					
						
							|  |  |  | #include <linux/module.h>
 | 
					
						
							|  |  |  | #include <linux/netdevice.h>
 | 
					
						
							|  |  |  | #include <linux/ethtool.h>
 | 
					
						
							|  |  |  | #include <linux/pci.h>
 | 
					
						
							| 
									
										
										
										
											2005-06-20 14:28:40 -07:00
										 |  |  | #include <linux/dma-mapping.h>
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | #include <linux/proc_fs.h>
 | 
					
						
							|  |  |  | #include <linux/skbuff.h>
 | 
					
						
							|  |  |  | #include <asm/uaccess.h>
 | 
					
						
							|  |  |  | #include <asm/io.h>
 | 
					
						
							|  |  |  | #define __KERNEL_SYSCALLS__
 | 
					
						
							|  |  |  | #include <linux/fs.h>
 | 
					
						
							|  |  |  | #include <linux/mm.h>
 | 
					
						
							|  |  |  | #include <linux/slab.h>
 | 
					
						
							|  |  |  | #include <linux/unistd.h>
 | 
					
						
							|  |  |  | #include <linux/stringify.h>
 | 
					
						
							|  |  |  | #include <linux/tcp.h>
 | 
					
						
							|  |  |  | #include <linux/types.h>
 | 
					
						
							|  |  |  | #include <linux/version.h>
 | 
					
						
							|  |  |  | #include <linux/time.h>
 | 
					
						
							|  |  |  | #include <linux/firmware.h>
 | 
					
						
							|  |  |  | #include <linux/acpi.h>
 | 
					
						
							|  |  |  | #include <linux/ctype.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ipw2100.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-15 00:42:42 -05:00
										 |  |  | #define IPW2100_VERSION "1.1.3"
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define DRV_NAME	"ipw2100"
 | 
					
						
							|  |  |  | #define DRV_VERSION	IPW2100_VERSION
 | 
					
						
							|  |  |  | #define DRV_DESCRIPTION	"Intel(R) PRO/Wireless 2100 Network Driver"
 | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | #define DRV_COPYRIGHT	"Copyright(c) 2003-2005 Intel Corporation"
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Debugging stuff */ | 
					
						
							| 
									
										
										
										
											2005-12-01 01:41:46 -08:00
										 |  |  | #ifdef CONFIG_IPW2100_DEBUG
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | #define CONFIG_IPW2100_RX_DEBUG	/* Reception debugging */
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MODULE_DESCRIPTION(DRV_DESCRIPTION); | 
					
						
							|  |  |  | MODULE_VERSION(DRV_VERSION); | 
					
						
							|  |  |  | MODULE_AUTHOR(DRV_COPYRIGHT); | 
					
						
							|  |  |  | MODULE_LICENSE("GPL"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int debug = 0; | 
					
						
							|  |  |  | static int mode = 0; | 
					
						
							|  |  |  | static int channel = 0; | 
					
						
							|  |  |  | static int associate = 1; | 
					
						
							|  |  |  | static int disable = 0; | 
					
						
							|  |  |  | #ifdef CONFIG_PM
 | 
					
						
							|  |  |  | static struct ipw2100_fw ipw2100_firmware; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/moduleparam.h>
 | 
					
						
							|  |  |  | module_param(debug, int, 0444); | 
					
						
							|  |  |  | module_param(mode, int, 0444); | 
					
						
							|  |  |  | module_param(channel, int, 0444); | 
					
						
							|  |  |  | module_param(associate, int, 0444); | 
					
						
							|  |  |  | module_param(disable, int, 0444); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MODULE_PARM_DESC(debug, "debug level"); | 
					
						
							|  |  |  | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)"); | 
					
						
							|  |  |  | MODULE_PARM_DESC(channel, "channel"); | 
					
						
							|  |  |  | MODULE_PARM_DESC(associate, "auto associate when scanning (default on)"); | 
					
						
							|  |  |  | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static u32 ipw2100_debug_level = IPW_DL_NONE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-01 01:41:46 -08:00
										 |  |  | #ifdef CONFIG_IPW2100_DEBUG
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | #define IPW_DEBUG(level, message...) \
 | 
					
						
							|  |  |  | do { \ | 
					
						
							|  |  |  | 	if (ipw2100_debug_level & (level)) { \ | 
					
						
							|  |  |  | 		printk(KERN_DEBUG "ipw2100: %c %s ", \ | 
					
						
							|  |  |  |                        in_interrupt() ? 'I' : 'U',  __FUNCTION__); \ | 
					
						
							|  |  |  | 		printk(message); \ | 
					
						
							|  |  |  | 	} \ | 
					
						
							|  |  |  | } while (0) | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #define IPW_DEBUG(level, message...) do {} while (0)
 | 
					
						
							| 
									
										
										
										
											2005-12-01 01:41:46 -08:00
										 |  |  | #endif				/* CONFIG_IPW2100_DEBUG */
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-01 01:41:46 -08:00
										 |  |  | #ifdef CONFIG_IPW2100_DEBUG
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | static const char *command_types[] = { | 
					
						
							|  |  |  | 	"undefined", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	"unused",		/* HOST_ATTENTION */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	"HOST_COMPLETE", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	"unused",		/* SLEEP */ | 
					
						
							|  |  |  | 	"unused",		/* HOST_POWER_DOWN */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	"unused", | 
					
						
							|  |  |  | 	"SYSTEM_CONFIG", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	"unused",		/* SET_IMR */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	"SSID", | 
					
						
							|  |  |  | 	"MANDATORY_BSSID", | 
					
						
							|  |  |  | 	"AUTHENTICATION_TYPE", | 
					
						
							|  |  |  | 	"ADAPTER_ADDRESS", | 
					
						
							|  |  |  | 	"PORT_TYPE", | 
					
						
							|  |  |  | 	"INTERNATIONAL_MODE", | 
					
						
							|  |  |  | 	"CHANNEL", | 
					
						
							|  |  |  | 	"RTS_THRESHOLD", | 
					
						
							|  |  |  | 	"FRAG_THRESHOLD", | 
					
						
							|  |  |  | 	"POWER_MODE", | 
					
						
							|  |  |  | 	"TX_RATES", | 
					
						
							|  |  |  | 	"BASIC_TX_RATES", | 
					
						
							|  |  |  | 	"WEP_KEY_INFO", | 
					
						
							|  |  |  | 	"unused", | 
					
						
							|  |  |  | 	"unused", | 
					
						
							|  |  |  | 	"unused", | 
					
						
							|  |  |  | 	"unused", | 
					
						
							|  |  |  | 	"WEP_KEY_INDEX", | 
					
						
							|  |  |  | 	"WEP_FLAGS", | 
					
						
							|  |  |  | 	"ADD_MULTICAST", | 
					
						
							|  |  |  | 	"CLEAR_ALL_MULTICAST", | 
					
						
							|  |  |  | 	"BEACON_INTERVAL", | 
					
						
							|  |  |  | 	"ATIM_WINDOW", | 
					
						
							|  |  |  | 	"CLEAR_STATISTICS", | 
					
						
							|  |  |  | 	"undefined", | 
					
						
							|  |  |  | 	"undefined", | 
					
						
							|  |  |  | 	"undefined", | 
					
						
							|  |  |  | 	"undefined", | 
					
						
							|  |  |  | 	"TX_POWER_INDEX", | 
					
						
							|  |  |  | 	"undefined", | 
					
						
							|  |  |  | 	"undefined", | 
					
						
							|  |  |  | 	"undefined", | 
					
						
							|  |  |  | 	"undefined", | 
					
						
							|  |  |  | 	"undefined", | 
					
						
							|  |  |  | 	"undefined", | 
					
						
							|  |  |  | 	"BROADCAST_SCAN", | 
					
						
							|  |  |  | 	"CARD_DISABLE", | 
					
						
							|  |  |  | 	"PREFERRED_BSSID", | 
					
						
							|  |  |  | 	"SET_SCAN_OPTIONS", | 
					
						
							|  |  |  | 	"SCAN_DWELL_TIME", | 
					
						
							|  |  |  | 	"SWEEP_TABLE", | 
					
						
							|  |  |  | 	"AP_OR_STATION_TABLE", | 
					
						
							|  |  |  | 	"GROUP_ORDINALS", | 
					
						
							|  |  |  | 	"SHORT_RETRY_LIMIT", | 
					
						
							|  |  |  | 	"LONG_RETRY_LIMIT", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	"unused",		/* SAVE_CALIBRATION */ | 
					
						
							|  |  |  | 	"unused",		/* RESTORE_CALIBRATION */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	"undefined", | 
					
						
							|  |  |  | 	"undefined", | 
					
						
							|  |  |  | 	"undefined", | 
					
						
							|  |  |  | 	"HOST_PRE_POWER_DOWN", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	"unused",		/* HOST_INTERRUPT_COALESCING */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	"undefined", | 
					
						
							|  |  |  | 	"CARD_DISABLE_PHY_OFF", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	"MSDU_TX_RATES" "undefined", | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	"undefined", | 
					
						
							|  |  |  | 	"SET_STATION_STAT_BITS", | 
					
						
							|  |  |  | 	"CLEAR_STATIONS_STAT_BITS", | 
					
						
							|  |  |  | 	"LEAP_ROGUE_MODE", | 
					
						
							|  |  |  | 	"SET_SECURITY_INFORMATION", | 
					
						
							|  |  |  | 	"DISASSOCIATION_BSSID", | 
					
						
							|  |  |  | 	"SET_WPA_ASS_IE" | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Pre-decl until we get the code solid and then we can clean it up */ | 
					
						
							| 
									
										
										
										
											2005-08-25 20:02:10 -04:00
										 |  |  | static void ipw2100_tx_send_commands(struct ipw2100_priv *priv); | 
					
						
							|  |  |  | static void ipw2100_tx_send_data(struct ipw2100_priv *priv); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | static int ipw2100_adapter_setup(struct ipw2100_priv *priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ipw2100_queues_initialize(struct ipw2100_priv *priv); | 
					
						
							|  |  |  | static void ipw2100_queues_free(struct ipw2100_priv *priv); | 
					
						
							|  |  |  | static int ipw2100_queues_allocate(struct ipw2100_priv *priv); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static int ipw2100_fw_download(struct ipw2100_priv *priv, | 
					
						
							|  |  |  | 			       struct ipw2100_fw *fw); | 
					
						
							|  |  |  | static int ipw2100_get_firmware(struct ipw2100_priv *priv, | 
					
						
							|  |  |  | 				struct ipw2100_fw *fw); | 
					
						
							|  |  |  | static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf, | 
					
						
							|  |  |  | 				 size_t max); | 
					
						
							|  |  |  | static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf, | 
					
						
							|  |  |  | 				    size_t max); | 
					
						
							|  |  |  | static void ipw2100_release_firmware(struct ipw2100_priv *priv, | 
					
						
							|  |  |  | 				     struct ipw2100_fw *fw); | 
					
						
							|  |  |  | static int ipw2100_ucode_download(struct ipw2100_priv *priv, | 
					
						
							|  |  |  | 				  struct ipw2100_fw *fw); | 
					
						
							|  |  |  | static void ipw2100_wx_event_work(struct ipw2100_priv *priv); | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device *dev); | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static struct iw_handler_def ipw2100_wx_handler_def; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static inline void read_register(struct net_device *dev, u32 reg, u32 * val) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	*val = readl((void __iomem *)(dev->base_addr + reg)); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	IPW_DEBUG_IO("r: 0x%08X => 0x%08X\n", reg, *val); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void write_register(struct net_device *dev, u32 reg, u32 val) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	writel(val, (void __iomem *)(dev->base_addr + reg)); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	IPW_DEBUG_IO("w: 0x%08X <= 0x%08X\n", reg, val); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static inline void read_register_word(struct net_device *dev, u32 reg, | 
					
						
							|  |  |  | 				      u16 * val) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	*val = readw((void __iomem *)(dev->base_addr + reg)); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	IPW_DEBUG_IO("r: 0x%08X => %04X\n", reg, *val); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static inline void read_register_byte(struct net_device *dev, u32 reg, u8 * val) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	*val = readb((void __iomem *)(dev->base_addr + reg)); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	IPW_DEBUG_IO("r: 0x%08X => %02X\n", reg, *val); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void write_register_word(struct net_device *dev, u32 reg, u16 val) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	writew(val, (void __iomem *)(dev->base_addr + reg)); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	IPW_DEBUG_IO("w: 0x%08X <= %04X\n", reg, val); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void write_register_byte(struct net_device *dev, u32 reg, u8 val) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	writeb(val, (void __iomem *)(dev->base_addr + reg)); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	IPW_DEBUG_IO("w: 0x%08X =< %02X\n", reg, val); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static inline void read_nic_dword(struct net_device *dev, u32 addr, u32 * val) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | 
					
						
							|  |  |  | 		       addr & IPW_REG_INDIRECT_ADDR_MASK); | 
					
						
							|  |  |  | 	read_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void write_nic_dword(struct net_device *dev, u32 addr, u32 val) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | 
					
						
							|  |  |  | 		       addr & IPW_REG_INDIRECT_ADDR_MASK); | 
					
						
							|  |  |  | 	write_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static inline void read_nic_word(struct net_device *dev, u32 addr, u16 * val) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | 
					
						
							|  |  |  | 		       addr & IPW_REG_INDIRECT_ADDR_MASK); | 
					
						
							|  |  |  | 	read_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void write_nic_word(struct net_device *dev, u32 addr, u16 val) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | 
					
						
							|  |  |  | 		       addr & IPW_REG_INDIRECT_ADDR_MASK); | 
					
						
							|  |  |  | 	write_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static inline void read_nic_byte(struct net_device *dev, u32 addr, u8 * val) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | 
					
						
							|  |  |  | 		       addr & IPW_REG_INDIRECT_ADDR_MASK); | 
					
						
							|  |  |  | 	read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void write_nic_byte(struct net_device *dev, u32 addr, u8 val) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | 
					
						
							|  |  |  | 		       addr & IPW_REG_INDIRECT_ADDR_MASK); | 
					
						
							|  |  |  | 	write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void write_nic_auto_inc_address(struct net_device *dev, u32 addr) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS, | 
					
						
							|  |  |  | 		       addr & IPW_REG_INDIRECT_ADDR_MASK); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void write_nic_dword_auto_inc(struct net_device *dev, u32 val) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	write_register(dev, IPW_REG_AUTOINCREMENT_DATA, val); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-14 13:20:43 -08:00
										 |  |  | static void write_nic_memory(struct net_device *dev, u32 addr, u32 len, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 				    const u8 * buf) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	u32 aligned_addr; | 
					
						
							|  |  |  | 	u32 aligned_len; | 
					
						
							|  |  |  | 	u32 dif_len; | 
					
						
							|  |  |  | 	u32 i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* read first nibble byte by byte */ | 
					
						
							|  |  |  | 	aligned_addr = addr & (~0x3); | 
					
						
							|  |  |  | 	dif_len = addr - aligned_addr; | 
					
						
							|  |  |  | 	if (dif_len) { | 
					
						
							|  |  |  | 		/* Start reading at aligned_addr + dif_len */ | 
					
						
							|  |  |  | 		write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | 
					
						
							|  |  |  | 			       aligned_addr); | 
					
						
							|  |  |  | 		for (i = dif_len; i < 4; i++, buf++) | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			write_register_byte(dev, | 
					
						
							|  |  |  | 					    IPW_REG_INDIRECT_ACCESS_DATA + i, | 
					
						
							|  |  |  | 					    *buf); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		len -= dif_len; | 
					
						
							|  |  |  | 		aligned_addr += 4; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* read DWs through autoincrement registers */ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS, aligned_addr); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	aligned_len = len & (~0x3); | 
					
						
							|  |  |  | 	for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4) | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		write_register(dev, IPW_REG_AUTOINCREMENT_DATA, *(u32 *) buf); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* copy the last nibble */ | 
					
						
							|  |  |  | 	dif_len = len - aligned_len; | 
					
						
							|  |  |  | 	write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr); | 
					
						
							|  |  |  | 	for (i = 0; i < dif_len; i++, buf++) | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA + i, | 
					
						
							|  |  |  | 				    *buf); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-14 13:20:43 -08:00
										 |  |  | static void read_nic_memory(struct net_device *dev, u32 addr, u32 len, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 				   u8 * buf) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	u32 aligned_addr; | 
					
						
							|  |  |  | 	u32 aligned_len; | 
					
						
							|  |  |  | 	u32 dif_len; | 
					
						
							|  |  |  | 	u32 i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* read first nibble byte by byte */ | 
					
						
							|  |  |  | 	aligned_addr = addr & (~0x3); | 
					
						
							|  |  |  | 	dif_len = addr - aligned_addr; | 
					
						
							|  |  |  | 	if (dif_len) { | 
					
						
							|  |  |  | 		/* Start reading at aligned_addr + dif_len */ | 
					
						
							|  |  |  | 		write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | 
					
						
							|  |  |  | 			       aligned_addr); | 
					
						
							|  |  |  | 		for (i = dif_len; i < 4; i++, buf++) | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			read_register_byte(dev, | 
					
						
							|  |  |  | 					   IPW_REG_INDIRECT_ACCESS_DATA + i, | 
					
						
							|  |  |  | 					   buf); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		len -= dif_len; | 
					
						
							|  |  |  | 		aligned_addr += 4; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* read DWs through autoincrement registers */ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS, aligned_addr); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	aligned_len = len & (~0x3); | 
					
						
							|  |  |  | 	for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4) | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		read_register(dev, IPW_REG_AUTOINCREMENT_DATA, (u32 *) buf); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* copy the last nibble */ | 
					
						
							|  |  |  | 	dif_len = len - aligned_len; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	for (i = 0; i < dif_len; i++, buf++) | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA + i, buf); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline int ipw2100_hw_is_adapter_in_system(struct net_device *dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return (dev->base_addr && | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		(readl | 
					
						
							|  |  |  | 		 ((void __iomem *)(dev->base_addr + | 
					
						
							|  |  |  | 				   IPW_REG_DOA_DEBUG_AREA_START)) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		 == IPW_DATA_DOA_DEBUG_VALUE)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static int ipw2100_get_ordinal(struct ipw2100_priv *priv, u32 ord, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			       void *val, u32 * len) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_ordinals *ordinals = &priv->ordinals; | 
					
						
							|  |  |  | 	u32 addr; | 
					
						
							|  |  |  | 	u32 field_info; | 
					
						
							|  |  |  | 	u16 field_len; | 
					
						
							|  |  |  | 	u16 field_count; | 
					
						
							|  |  |  | 	u32 total_length; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ordinals->table1_addr == 0) { | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 		printk(KERN_WARNING DRV_NAME ": attempt to use fw ordinals " | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		       "before they have been loaded.\n"); | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) { | 
					
						
							|  |  |  | 		if (*len < IPW_ORD_TAB_1_ENTRY_SIZE) { | 
					
						
							|  |  |  | 			*len = IPW_ORD_TAB_1_ENTRY_SIZE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 			printk(KERN_WARNING DRV_NAME | 
					
						
							| 
									
										
										
										
											2005-06-07 14:58:41 +02:00
										 |  |  | 			       ": ordinal buffer length too small, need %zd\n", | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			       IPW_ORD_TAB_1_ENTRY_SIZE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			return -EINVAL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		read_nic_dword(priv->net_dev, | 
					
						
							|  |  |  | 			       ordinals->table1_addr + (ord << 2), &addr); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		read_nic_dword(priv->net_dev, addr, val); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		*len = IPW_ORD_TAB_1_ENTRY_SIZE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (IS_ORDINAL_TABLE_TWO(ordinals, ord)) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ord -= IPW_START_ORD_TAB_2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* get the address of statistic */ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		read_nic_dword(priv->net_dev, | 
					
						
							|  |  |  | 			       ordinals->table2_addr + (ord << 3), &addr); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* get the second DW of statistics ;
 | 
					
						
							|  |  |  | 		 * two 16-bit words - first is length, second is count */ | 
					
						
							|  |  |  | 		read_nic_dword(priv->net_dev, | 
					
						
							|  |  |  | 			       ordinals->table2_addr + (ord << 3) + sizeof(u32), | 
					
						
							|  |  |  | 			       &field_info); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* get each entry length */ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		field_len = *((u16 *) & field_info); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* get number of entries */ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		field_count = *(((u16 *) & field_info) + 1); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* abort if no enought memory */ | 
					
						
							|  |  |  | 		total_length = field_len * field_count; | 
					
						
							|  |  |  | 		if (total_length > *len) { | 
					
						
							|  |  |  | 			*len = total_length; | 
					
						
							|  |  |  | 			return -EINVAL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		*len = total_length; | 
					
						
							|  |  |  | 		if (!total_length) | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* read the ordinal data from the SRAM */ | 
					
						
							|  |  |  | 		read_nic_memory(priv->net_dev, addr, total_length, val); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 	printk(KERN_WARNING DRV_NAME ": ordinal %d neither in table 1 nor " | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	       "in table 2\n", ord); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return -EINVAL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static int ipw2100_set_ordinal(struct ipw2100_priv *priv, u32 ord, u32 * val, | 
					
						
							|  |  |  | 			       u32 * len) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_ordinals *ordinals = &priv->ordinals; | 
					
						
							|  |  |  | 	u32 addr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) { | 
					
						
							|  |  |  | 		if (*len != IPW_ORD_TAB_1_ENTRY_SIZE) { | 
					
						
							|  |  |  | 			*len = IPW_ORD_TAB_1_ENTRY_SIZE; | 
					
						
							|  |  |  | 			IPW_DEBUG_INFO("wrong size\n"); | 
					
						
							|  |  |  | 			return -EINVAL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		read_nic_dword(priv->net_dev, | 
					
						
							|  |  |  | 			       ordinals->table1_addr + (ord << 2), &addr); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		write_nic_dword(priv->net_dev, addr, *val); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		*len = IPW_ORD_TAB_1_ENTRY_SIZE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("wrong table\n"); | 
					
						
							|  |  |  | 	if (IS_ORDINAL_TABLE_TWO(ordinals, ord)) | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return -EINVAL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char *snprint_line(char *buf, size_t count, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			  const u8 * data, u32 len, u32 ofs) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	int out, i, j, l; | 
					
						
							|  |  |  | 	char c; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out = snprintf(buf, count, "%08X", ofs); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (l = 0, i = 0; i < 2; i++) { | 
					
						
							|  |  |  | 		out += snprintf(buf + out, count - out, " "); | 
					
						
							|  |  |  | 		for (j = 0; j < 8 && l < len; j++, l++) | 
					
						
							|  |  |  | 			out += snprintf(buf + out, count - out, "%02X ", | 
					
						
							|  |  |  | 					data[(i * 8 + j)]); | 
					
						
							|  |  |  | 		for (; j < 8; j++) | 
					
						
							|  |  |  | 			out += snprintf(buf + out, count - out, "   "); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out += snprintf(buf + out, count - out, " "); | 
					
						
							|  |  |  | 	for (l = 0, i = 0; i < 2; i++) { | 
					
						
							|  |  |  | 		out += snprintf(buf + out, count - out, " "); | 
					
						
							|  |  |  | 		for (j = 0; j < 8 && l < len; j++, l++) { | 
					
						
							|  |  |  | 			c = data[(i * 8 + j)]; | 
					
						
							|  |  |  | 			if (!isascii(c) || !isprint(c)) | 
					
						
							|  |  |  | 				c = '.'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			out += snprintf(buf + out, count - out, "%c", c); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (; j < 8; j++) | 
					
						
							|  |  |  | 			out += snprintf(buf + out, count - out, " "); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return buf; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static void printk_buf(int level, const u8 * data, u32 len) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	char line[81]; | 
					
						
							|  |  |  | 	u32 ofs = 0; | 
					
						
							|  |  |  | 	if (!(ipw2100_debug_level & level)) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (len) { | 
					
						
							|  |  |  | 		printk(KERN_DEBUG "%s\n", | 
					
						
							|  |  |  | 		       snprint_line(line, sizeof(line), &data[ofs], | 
					
						
							|  |  |  | 				    min(len, 16U), ofs)); | 
					
						
							|  |  |  | 		ofs += 16; | 
					
						
							|  |  |  | 		len -= min(len, 16U); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define MAX_RESET_BACKOFF 10
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-14 13:20:43 -08:00
										 |  |  | static void schedule_reset(struct ipw2100_priv *priv) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	unsigned long now = get_seconds(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* If we haven't received a reset request within the backoff period,
 | 
					
						
							|  |  |  | 	 * then we can reset the backoff interval so this reset occurs | 
					
						
							|  |  |  | 	 * immediately */ | 
					
						
							|  |  |  | 	if (priv->reset_backoff && | 
					
						
							|  |  |  | 	    (now - priv->last_reset > priv->reset_backoff)) | 
					
						
							|  |  |  | 		priv->reset_backoff = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->last_reset = get_seconds(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_RESET_PENDING)) { | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("%s: Scheduling firmware restart (%ds).\n", | 
					
						
							|  |  |  | 			       priv->net_dev->name, priv->reset_backoff); | 
					
						
							|  |  |  | 		netif_carrier_off(priv->net_dev); | 
					
						
							|  |  |  | 		netif_stop_queue(priv->net_dev); | 
					
						
							|  |  |  | 		priv->status |= STATUS_RESET_PENDING; | 
					
						
							|  |  |  | 		if (priv->reset_backoff) | 
					
						
							|  |  |  | 			queue_delayed_work(priv->workqueue, &priv->reset_work, | 
					
						
							|  |  |  | 					   priv->reset_backoff * HZ); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			queue_work(priv->workqueue, &priv->reset_work); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (priv->reset_backoff < MAX_RESET_BACKOFF) | 
					
						
							|  |  |  | 			priv->reset_backoff++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		wake_up_interruptible(&priv->wait_command_queue); | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("%s: Firmware restart already in progress.\n", | 
					
						
							|  |  |  | 			       priv->net_dev->name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define HOST_COMPLETE_TIMEOUT (2 * HZ)
 | 
					
						
							|  |  |  | static int ipw2100_hw_send_command(struct ipw2100_priv *priv, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 				   struct host_command *cmd) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct list_head *element; | 
					
						
							|  |  |  | 	struct ipw2100_tx_packet *packet; | 
					
						
							|  |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 	int err = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n", | 
					
						
							|  |  |  | 		     command_types[cmd->host_command], cmd->host_command, | 
					
						
							|  |  |  | 		     cmd->host_command_length); | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	printk_buf(IPW_DL_HC, (u8 *) cmd->host_command_parameters, | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		   cmd->host_command_length); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&priv->low_lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->fatal_error) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		IPW_DEBUG_INFO | 
					
						
							|  |  |  | 		    ("Attempt to send command while hardware in fatal error condition.\n"); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		err = -EIO; | 
					
						
							|  |  |  | 		goto fail_unlock; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_RUNNING)) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		IPW_DEBUG_INFO | 
					
						
							|  |  |  | 		    ("Attempt to send command while hardware is not running.\n"); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		err = -EIO; | 
					
						
							|  |  |  | 		goto fail_unlock; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->status & STATUS_CMD_ACTIVE) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		IPW_DEBUG_INFO | 
					
						
							|  |  |  | 		    ("Attempt to send command while another command is pending.\n"); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		err = -EBUSY; | 
					
						
							|  |  |  | 		goto fail_unlock; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (list_empty(&priv->msg_free_list)) { | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("no available msg buffers\n"); | 
					
						
							|  |  |  | 		goto fail_unlock; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->status |= STATUS_CMD_ACTIVE; | 
					
						
							|  |  |  | 	priv->messages_sent++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	element = priv->msg_free_list.next; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	packet = list_entry(element, struct ipw2100_tx_packet, list); | 
					
						
							|  |  |  | 	packet->jiffy_start = jiffies; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* initialize the firmware command packet */ | 
					
						
							|  |  |  | 	packet->info.c_struct.cmd->host_command_reg = cmd->host_command; | 
					
						
							|  |  |  | 	packet->info.c_struct.cmd->host_command_reg1 = cmd->host_command1; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	packet->info.c_struct.cmd->host_command_len_reg = | 
					
						
							|  |  |  | 	    cmd->host_command_length; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	packet->info.c_struct.cmd->sequence = cmd->host_command_sequence; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	memcpy(packet->info.c_struct.cmd->host_command_params_reg, | 
					
						
							|  |  |  | 	       cmd->host_command_parameters, | 
					
						
							|  |  |  | 	       sizeof(packet->info.c_struct.cmd->host_command_params_reg)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	list_del(element); | 
					
						
							|  |  |  | 	DEC_STAT(&priv->msg_free_stat); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	list_add_tail(element, &priv->msg_pend_list); | 
					
						
							|  |  |  | 	INC_STAT(&priv->msg_pend_stat); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:02:10 -04:00
										 |  |  | 	ipw2100_tx_send_commands(priv); | 
					
						
							|  |  |  | 	ipw2100_tx_send_data(priv); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&priv->low_lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * We must wait for this command to complete before another | 
					
						
							|  |  |  | 	 * command can be sent...  but if we wait more than 3 seconds | 
					
						
							|  |  |  | 	 * then there is a problem. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	err = | 
					
						
							|  |  |  | 	    wait_event_interruptible_timeout(priv->wait_command_queue, | 
					
						
							|  |  |  | 					     !(priv-> | 
					
						
							|  |  |  | 					       status & STATUS_CMD_ACTIVE), | 
					
						
							|  |  |  | 					     HOST_COMPLETE_TIMEOUT); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (err == 0) { | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("Command completion failed out after %dms.\n", | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 			       1000 * (HOST_COMPLETE_TIMEOUT / HZ)); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		priv->fatal_error = IPW2100_ERR_MSG_TIMEOUT; | 
					
						
							|  |  |  | 		priv->status &= ~STATUS_CMD_ACTIVE; | 
					
						
							|  |  |  | 		schedule_reset(priv); | 
					
						
							|  |  |  | 		return -EIO; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->fatal_error) { | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 		printk(KERN_WARNING DRV_NAME ": %s: firmware fatal error\n", | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		       priv->net_dev->name); | 
					
						
							|  |  |  | 		return -EIO; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* !!!!! HACK TEST !!!!!
 | 
					
						
							|  |  |  | 	 * When lots of debug trace statements are enabled, the driver | 
					
						
							|  |  |  | 	 * doesn't seem to have as many firmware restart cycles... | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * As a test, we're sticking in a 1/100s delay here */ | 
					
						
							| 
									
										
										
										
											2005-09-11 02:09:55 -07:00
										 |  |  | 	schedule_timeout_uninterruptible(msecs_to_jiffies(10)); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       fail_unlock: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	spin_unlock_irqrestore(&priv->low_lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Verify the values and data access of the hardware | 
					
						
							|  |  |  |  * No locks needed or used.  No functions called. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static int ipw2100_verify(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u32 data1, data2; | 
					
						
							|  |  |  | 	u32 address; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	u32 val1 = 0x76543210; | 
					
						
							|  |  |  | 	u32 val2 = 0xFEDCBA98; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Domain 0 check - all values should be DOA_DEBUG */ | 
					
						
							|  |  |  | 	for (address = IPW_REG_DOA_DEBUG_AREA_START; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	     address < IPW_REG_DOA_DEBUG_AREA_END; address += sizeof(u32)) { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		read_register(priv->net_dev, address, &data1); | 
					
						
							|  |  |  | 		if (data1 != IPW_DATA_DOA_DEBUG_VALUE) | 
					
						
							|  |  |  | 			return -EIO; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Domain 1 check - use arbitrary read/write compare  */ | 
					
						
							|  |  |  | 	for (address = 0; address < 5; address++) { | 
					
						
							|  |  |  | 		/* The memory area is not used now */ | 
					
						
							|  |  |  | 		write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32, | 
					
						
							|  |  |  | 			       val1); | 
					
						
							|  |  |  | 		write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36, | 
					
						
							|  |  |  | 			       val2); | 
					
						
							|  |  |  | 		read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32, | 
					
						
							|  |  |  | 			      &data1); | 
					
						
							|  |  |  | 		read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36, | 
					
						
							|  |  |  | 			      &data2); | 
					
						
							|  |  |  | 		if (val1 == data1 && val2 == data2) | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return -EIO; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Loop until the CARD_DISABLED bit is the same value as the | 
					
						
							|  |  |  |  * supplied parameter | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * TODO: See if it would be more efficient to do a wait/wake | 
					
						
							|  |  |  |  *       cycle and have the completion event trigger the wakeup | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #define IPW_CARD_DISABLE_COMPLETE_WAIT		    100	// 100 milli
 | 
					
						
							|  |  |  | static int ipw2100_wait_for_card_state(struct ipw2100_priv *priv, int state) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	u32 card_state; | 
					
						
							|  |  |  | 	u32 len = sizeof(card_state); | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i <= IPW_CARD_DISABLE_COMPLETE_WAIT * 1000; i += 50) { | 
					
						
							|  |  |  | 		err = ipw2100_get_ordinal(priv, IPW_ORD_CARD_DISABLED, | 
					
						
							|  |  |  | 					  &card_state, &len); | 
					
						
							|  |  |  | 		if (err) { | 
					
						
							|  |  |  | 			IPW_DEBUG_INFO("Query of CARD_DISABLED ordinal " | 
					
						
							|  |  |  | 				       "failed.\n"); | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* We'll break out if either the HW state says it is
 | 
					
						
							|  |  |  | 		 * in the state we want, or if HOST_COMPLETE command | 
					
						
							|  |  |  | 		 * finishes */ | 
					
						
							|  |  |  | 		if ((card_state == state) || | 
					
						
							|  |  |  | 		    ((priv->status & STATUS_ENABLED) ? | 
					
						
							|  |  |  | 		     IPW_HW_STATE_ENABLED : IPW_HW_STATE_DISABLED) == state) { | 
					
						
							|  |  |  | 			if (state == IPW_HW_STATE_ENABLED) | 
					
						
							|  |  |  | 				priv->status |= STATUS_ENABLED; | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				priv->status &= ~STATUS_ENABLED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		udelay(50); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("ipw2100_wait_for_card_state to %s state timed out\n", | 
					
						
							|  |  |  | 		       state ? "DISABLED" : "ENABLED"); | 
					
						
							|  |  |  | 	return -EIO; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*********************************************************************
 | 
					
						
							|  |  |  |     Procedure   :   sw_reset_and_clock | 
					
						
							|  |  |  |     Purpose     :   Asserts s/w reset, asserts clock initialization | 
					
						
							|  |  |  |                     and waits for clock stabilization | 
					
						
							|  |  |  |  ********************************************************************/ | 
					
						
							|  |  |  | static int sw_reset_and_clock(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	u32 r; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// assert s/w reset
 | 
					
						
							|  |  |  | 	write_register(priv->net_dev, IPW_REG_RESET_REG, | 
					
						
							|  |  |  | 		       IPW_AUX_HOST_RESET_REG_SW_RESET); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// wait for clock stabilization
 | 
					
						
							|  |  |  | 	for (i = 0; i < 1000; i++) { | 
					
						
							|  |  |  | 		udelay(IPW_WAIT_RESET_ARC_COMPLETE_DELAY); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// check clock ready bit
 | 
					
						
							|  |  |  | 		read_register(priv->net_dev, IPW_REG_RESET_REG, &r); | 
					
						
							|  |  |  | 		if (r & IPW_AUX_HOST_RESET_REG_PRINCETON_RESET) | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (i == 1000) | 
					
						
							|  |  |  | 		return -EIO;	// TODO: better error value
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* set "initialization complete" bit to move adapter to
 | 
					
						
							|  |  |  | 	 * D0 state */ | 
					
						
							|  |  |  | 	write_register(priv->net_dev, IPW_REG_GP_CNTRL, | 
					
						
							|  |  |  | 		       IPW_AUX_HOST_GP_CNTRL_BIT_INIT_DONE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* wait for clock stabilization */ | 
					
						
							|  |  |  | 	for (i = 0; i < 10000; i++) { | 
					
						
							|  |  |  | 		udelay(IPW_WAIT_CLOCK_STABILIZATION_DELAY * 4); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* check clock ready bit */ | 
					
						
							|  |  |  | 		read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r); | 
					
						
							|  |  |  | 		if (r & IPW_AUX_HOST_GP_CNTRL_BIT_CLOCK_READY) | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (i == 10000) | 
					
						
							|  |  |  | 		return -EIO;	/* TODO: better error value */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* set D0 standby bit */ | 
					
						
							|  |  |  | 	read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r); | 
					
						
							|  |  |  | 	write_register(priv->net_dev, IPW_REG_GP_CNTRL, | 
					
						
							|  |  |  | 		       r | IPW_AUX_HOST_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*********************************************************************
 | 
					
						
							| 
									
										
										
										
											2005-06-20 14:28:43 -07:00
										 |  |  |     Procedure   :   ipw2100_download_firmware | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  |     Purpose     :   Initiaze adapter after power on. | 
					
						
							|  |  |  |                     The sequence is: | 
					
						
							|  |  |  |                     1. assert s/w reset first! | 
					
						
							|  |  |  |                     2. awake clocks & wait for clock stabilization | 
					
						
							|  |  |  |                     3. hold ARC (don't ask me why...) | 
					
						
							|  |  |  |                     4. load Dino ucode and reset/clock init again | 
					
						
							|  |  |  |                     5. zero-out shared mem | 
					
						
							|  |  |  |                     6. download f/w | 
					
						
							|  |  |  |  *******************************************************************/ | 
					
						
							|  |  |  | static int ipw2100_download_firmware(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u32 address; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef CONFIG_PM
 | 
					
						
							|  |  |  | 	/* Fetch the firmware and microcode */ | 
					
						
							|  |  |  | 	struct ipw2100_fw ipw2100_firmware; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->fatal_error) { | 
					
						
							|  |  |  | 		IPW_DEBUG_ERROR("%s: ipw2100_download_firmware called after " | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 				"fatal error %d.  Interface must be brought down.\n", | 
					
						
							|  |  |  | 				priv->net_dev->name, priv->fatal_error); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #ifdef CONFIG_PM
 | 
					
						
							|  |  |  | 	if (!ipw2100_firmware.version) { | 
					
						
							|  |  |  | 		err = ipw2100_get_firmware(priv, &ipw2100_firmware); | 
					
						
							|  |  |  | 		if (err) { | 
					
						
							|  |  |  | 			IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 					priv->net_dev->name, err); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			priv->fatal_error = IPW2100_ERR_FW_LOAD; | 
					
						
							|  |  |  | 			goto fail; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 	err = ipw2100_get_firmware(priv, &ipw2100_firmware); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							|  |  |  | 		IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 				priv->net_dev->name, err); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		priv->fatal_error = IPW2100_ERR_FW_LOAD; | 
					
						
							|  |  |  | 		goto fail; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	priv->firmware_version = ipw2100_firmware.version; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* s/w reset and clock stabilization */ | 
					
						
							|  |  |  | 	err = sw_reset_and_clock(priv); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							|  |  |  | 		IPW_DEBUG_ERROR("%s: sw_reset_and_clock failed: %d\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 				priv->net_dev->name, err); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		goto fail; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_verify(priv); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							|  |  |  | 		IPW_DEBUG_ERROR("%s: ipw2100_verify failed: %d\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 				priv->net_dev->name, err); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		goto fail; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Hold ARC */ | 
					
						
							|  |  |  | 	write_nic_dword(priv->net_dev, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			IPW_INTERNAL_REGISTER_HALT_AND_RESET, 0x80000000); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* allow ARC to run */ | 
					
						
							|  |  |  | 	write_register(priv->net_dev, IPW_REG_RESET_REG, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* load microcode */ | 
					
						
							|  |  |  | 	err = ipw2100_ucode_download(priv, &ipw2100_firmware); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 		printk(KERN_ERR DRV_NAME ": %s: Error loading microcode: %d\n", | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		       priv->net_dev->name, err); | 
					
						
							|  |  |  | 		goto fail; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* release ARC */ | 
					
						
							|  |  |  | 	write_nic_dword(priv->net_dev, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			IPW_INTERNAL_REGISTER_HALT_AND_RESET, 0x00000000); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* s/w reset and clock stabilization (again!!!) */ | 
					
						
							|  |  |  | 	err = sw_reset_and_clock(priv); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		printk(KERN_ERR DRV_NAME | 
					
						
							|  |  |  | 		       ": %s: sw_reset_and_clock failed: %d\n", | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		       priv->net_dev->name, err); | 
					
						
							|  |  |  | 		goto fail; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* load f/w */ | 
					
						
							|  |  |  | 	err = ipw2100_fw_download(priv, &ipw2100_firmware); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							|  |  |  | 		IPW_DEBUG_ERROR("%s: Error loading firmware: %d\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 				priv->net_dev->name, err); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		goto fail; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #ifndef CONFIG_PM
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * When the .resume method of the driver is called, the other | 
					
						
							|  |  |  | 	 * part of the system, i.e. the ide driver could still stay in | 
					
						
							|  |  |  | 	 * the suspend stage. This prevents us from loading the firmware | 
					
						
							|  |  |  | 	 * from the disk.  --YZ | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* free any storage allocated for firmware image */ | 
					
						
							|  |  |  | 	ipw2100_release_firmware(priv, &ipw2100_firmware); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* zero out Domain 1 area indirectly (Si requirement) */ | 
					
						
							|  |  |  | 	for (address = IPW_HOST_FW_SHARED_AREA0; | 
					
						
							|  |  |  | 	     address < IPW_HOST_FW_SHARED_AREA0_END; address += 4) | 
					
						
							|  |  |  | 		write_nic_dword(priv->net_dev, address, 0); | 
					
						
							|  |  |  | 	for (address = IPW_HOST_FW_SHARED_AREA1; | 
					
						
							|  |  |  | 	     address < IPW_HOST_FW_SHARED_AREA1_END; address += 4) | 
					
						
							|  |  |  | 		write_nic_dword(priv->net_dev, address, 0); | 
					
						
							|  |  |  | 	for (address = IPW_HOST_FW_SHARED_AREA2; | 
					
						
							|  |  |  | 	     address < IPW_HOST_FW_SHARED_AREA2_END; address += 4) | 
					
						
							|  |  |  | 		write_nic_dword(priv->net_dev, address, 0); | 
					
						
							|  |  |  | 	for (address = IPW_HOST_FW_SHARED_AREA3; | 
					
						
							|  |  |  | 	     address < IPW_HOST_FW_SHARED_AREA3_END; address += 4) | 
					
						
							|  |  |  | 		write_nic_dword(priv->net_dev, address, 0); | 
					
						
							|  |  |  | 	for (address = IPW_HOST_FW_INTERRUPT_AREA; | 
					
						
							|  |  |  | 	     address < IPW_HOST_FW_INTERRUPT_AREA_END; address += 4) | 
					
						
							|  |  |  | 		write_nic_dword(priv->net_dev, address, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       fail: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	ipw2100_release_firmware(priv, &ipw2100_firmware); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void ipw2100_enable_interrupts(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (priv->status & STATUS_INT_ENABLED) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	priv->status |= STATUS_INT_ENABLED; | 
					
						
							|  |  |  | 	write_register(priv->net_dev, IPW_REG_INTA_MASK, IPW_INTERRUPT_MASK); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void ipw2100_disable_interrupts(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_INT_ENABLED)) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	priv->status &= ~STATUS_INT_ENABLED; | 
					
						
							|  |  |  | 	write_register(priv->net_dev, IPW_REG_INTA_MASK, 0x0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ipw2100_initialize_ordinals(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_ordinals *ord = &priv->ordinals; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("enter\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_1, | 
					
						
							|  |  |  | 		      &ord->table1_addr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_2, | 
					
						
							|  |  |  | 		      &ord->table2_addr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	read_nic_dword(priv->net_dev, ord->table1_addr, &ord->table1_size); | 
					
						
							|  |  |  | 	read_nic_dword(priv->net_dev, ord->table2_addr, &ord->table2_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ord->table2_size &= 0x0000FFFF; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("table 1 size: %d\n", ord->table1_size); | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("table 2 size: %d\n", ord->table2_size); | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("exit\n"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void ipw2100_hw_set_gpio(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u32 reg = 0; | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Set GPIO 3 writable by FW; GPIO 1 writable | 
					
						
							|  |  |  | 	 * by driver and enable clock | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	reg = (IPW_BIT_GPIO_GPIO3_MASK | IPW_BIT_GPIO_GPIO1_ENABLE | | 
					
						
							|  |  |  | 	       IPW_BIT_GPIO_LED_OFF); | 
					
						
							|  |  |  | 	write_register(priv->net_dev, IPW_REG_GPIO, reg); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-14 13:20:43 -08:00
										 |  |  | static int rf_kill_active(struct ipw2100_priv *priv) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | #define MAX_RF_KILL_CHECKS 5
 | 
					
						
							|  |  |  | #define RF_KILL_CHECK_DELAY 40
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	unsigned short value = 0; | 
					
						
							|  |  |  | 	u32 reg = 0; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(priv->hw_features & HW_FEATURE_RFKILL)) { | 
					
						
							|  |  |  | 		priv->status &= ~STATUS_RF_KILL_HW; | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < MAX_RF_KILL_CHECKS; i++) { | 
					
						
							|  |  |  | 		udelay(RF_KILL_CHECK_DELAY); | 
					
						
							|  |  |  | 		read_register(priv->net_dev, IPW_REG_GPIO, ®); | 
					
						
							|  |  |  | 		value = (value << 1) | ((reg & IPW_BIT_GPIO_RF_KILL) ? 0 : 1); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (value == 0) | 
					
						
							|  |  |  | 		priv->status |= STATUS_RF_KILL_HW; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		priv->status &= ~STATUS_RF_KILL_HW; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return (value == 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_get_hw_features(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u32 addr, len; | 
					
						
							|  |  |  | 	u32 val; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * EEPROM_SRAM_DB_START_ADDRESS using ordinal in ordinal table 1 | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	len = sizeof(addr); | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	if (ipw2100_get_ordinal | 
					
						
							|  |  |  | 	    (priv, IPW_ORD_EEPROM_SRAM_DB_BLOCK_START_ADDRESS, &addr, &len)) { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			       __LINE__); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		return -EIO; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("EEPROM address: %08X\n", addr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * EEPROM version is the byte at offset 0xfd in firmware | 
					
						
							|  |  |  | 	 * We read 4 bytes, then shift out the byte we actually want */ | 
					
						
							|  |  |  | 	read_nic_dword(priv->net_dev, addr + 0xFC, &val); | 
					
						
							|  |  |  | 	priv->eeprom_version = (val >> 24) & 0xFF; | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("EEPROM version: %d\n", priv->eeprom_version); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	/*
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	 *  HW RF Kill enable is bit 0 in byte at offset 0x21 in firmware | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 *  notice that the EEPROM bit is reverse polarity, i.e. | 
					
						
							|  |  |  | 	 *     bit = 0  signifies HW RF kill switch is supported | 
					
						
							|  |  |  | 	 *     bit = 1  signifies HW RF kill switch is NOT supported | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	read_nic_dword(priv->net_dev, addr + 0x20, &val); | 
					
						
							|  |  |  | 	if (!((val >> 24) & 0x01)) | 
					
						
							|  |  |  | 		priv->hw_features |= HW_FEATURE_RFKILL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("HW RF Kill: %ssupported.\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		       (priv->hw_features & HW_FEATURE_RFKILL) ? "" : "not "); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Start firmware execution after power on and intialization | 
					
						
							|  |  |  |  * The sequence is: | 
					
						
							|  |  |  |  *  1. Release ARC | 
					
						
							|  |  |  |  *  2. Wait for f/w initialization completes; | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static int ipw2100_start_adapter(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	u32 inta, inta_mask, gpio; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("enter\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->status & STATUS_RUNNING) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Initialize the hw - drive adapter to DO state by setting | 
					
						
							|  |  |  | 	 * init_done bit. Wait for clk_ready bit and Download | 
					
						
							|  |  |  | 	 * fw & dino ucode | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (ipw2100_download_firmware(priv)) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		printk(KERN_ERR DRV_NAME | 
					
						
							|  |  |  | 		       ": %s: Failed to power on the adapter.\n", | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		       priv->net_dev->name); | 
					
						
							|  |  |  | 		return -EIO; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Clear the Tx, Rx and Msg queues and the r/w indexes
 | 
					
						
							|  |  |  | 	 * in the firmware RBD and TBD ring queue */ | 
					
						
							|  |  |  | 	ipw2100_queues_initialize(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ipw2100_hw_set_gpio(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* TODO -- Look at disabling interrupts here to make sure none
 | 
					
						
							|  |  |  | 	 * get fired during FW initialization */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Release ARC - clear reset bit */ | 
					
						
							|  |  |  | 	write_register(priv->net_dev, IPW_REG_RESET_REG, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* wait for f/w intialization complete */ | 
					
						
							|  |  |  | 	IPW_DEBUG_FW("Waiting for f/w initialization to complete...\n"); | 
					
						
							|  |  |  | 	i = 5000; | 
					
						
							|  |  |  | 	do { | 
					
						
							| 
									
										
										
										
											2005-09-11 02:09:55 -07:00
										 |  |  | 		schedule_timeout_uninterruptible(msecs_to_jiffies(40)); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		/* Todo... wait for sync command ... */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		read_register(priv->net_dev, IPW_REG_INTA, &inta); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* check "init done" bit */ | 
					
						
							|  |  |  | 		if (inta & IPW2100_INTA_FW_INIT_DONE) { | 
					
						
							|  |  |  | 			/* reset "init done" bit */ | 
					
						
							|  |  |  | 			write_register(priv->net_dev, IPW_REG_INTA, | 
					
						
							|  |  |  | 				       IPW2100_INTA_FW_INIT_DONE); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* check error conditions : we check these after the firmware
 | 
					
						
							|  |  |  | 		 * check so that if there is an error, the interrupt handler | 
					
						
							|  |  |  | 		 * will see it and the adapter will be reset */ | 
					
						
							|  |  |  | 		if (inta & | 
					
						
							|  |  |  | 		    (IPW2100_INTA_FATAL_ERROR | IPW2100_INTA_PARITY_ERROR)) { | 
					
						
							|  |  |  | 			/* clear error conditions */ | 
					
						
							|  |  |  | 			write_register(priv->net_dev, IPW_REG_INTA, | 
					
						
							|  |  |  | 				       IPW2100_INTA_FATAL_ERROR | | 
					
						
							|  |  |  | 				       IPW2100_INTA_PARITY_ERROR); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} while (i--); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Clear out any pending INTAs since we aren't supposed to have
 | 
					
						
							|  |  |  | 	 * interrupts enabled at this point... */ | 
					
						
							|  |  |  | 	read_register(priv->net_dev, IPW_REG_INTA, &inta); | 
					
						
							|  |  |  | 	read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask); | 
					
						
							|  |  |  | 	inta &= IPW_INTERRUPT_MASK; | 
					
						
							|  |  |  | 	/* Clear out any pending interrupts */ | 
					
						
							|  |  |  | 	if (inta & inta_mask) | 
					
						
							|  |  |  | 		write_register(priv->net_dev, IPW_REG_INTA, inta); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_FW("f/w initialization complete: %s\n", | 
					
						
							|  |  |  | 		     i ? "SUCCESS" : "FAILED"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!i) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		printk(KERN_WARNING DRV_NAME | 
					
						
							|  |  |  | 		       ": %s: Firmware did not initialize.\n", | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		       priv->net_dev->name); | 
					
						
							|  |  |  | 		return -EIO; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* allow firmware to write to GPIO1 & GPIO3 */ | 
					
						
							|  |  |  | 	read_register(priv->net_dev, IPW_REG_GPIO, &gpio); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gpio |= (IPW_BIT_GPIO_GPIO1_MASK | IPW_BIT_GPIO_GPIO3_MASK); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	write_register(priv->net_dev, IPW_REG_GPIO, gpio); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Ready to receive commands */ | 
					
						
							|  |  |  | 	priv->status |= STATUS_RUNNING; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* The adapter has been reset; we are not associated */ | 
					
						
							|  |  |  | 	priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("exit\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void ipw2100_reset_fatalerror(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!priv->fatal_error) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->fatal_errors[priv->fatal_index++] = priv->fatal_error; | 
					
						
							|  |  |  | 	priv->fatal_index %= IPW2100_ERROR_QUEUE; | 
					
						
							|  |  |  | 	priv->fatal_error = 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* NOTE: Our interrupt is disabled when this method is called */ | 
					
						
							|  |  |  | static int ipw2100_power_cycle_adapter(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u32 reg; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("Power cycling the hardware.\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ipw2100_hw_set_gpio(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Step 1. Stop Master Assert */ | 
					
						
							|  |  |  | 	write_register(priv->net_dev, IPW_REG_RESET_REG, | 
					
						
							|  |  |  | 		       IPW_AUX_HOST_RESET_REG_STOP_MASTER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Step 2. Wait for stop Master Assert
 | 
					
						
							|  |  |  | 	 *         (not more then 50us, otherwise ret error */ | 
					
						
							|  |  |  | 	i = 5; | 
					
						
							|  |  |  | 	do { | 
					
						
							|  |  |  | 		udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY); | 
					
						
							|  |  |  | 		read_register(priv->net_dev, IPW_REG_RESET_REG, ®); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED) | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	} while (i--); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	priv->status &= ~STATUS_RESET_PENDING; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!i) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		IPW_DEBUG_INFO | 
					
						
							|  |  |  | 		    ("exit - waited too long for master assert stop\n"); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		return -EIO; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	write_register(priv->net_dev, IPW_REG_RESET_REG, | 
					
						
							|  |  |  | 		       IPW_AUX_HOST_RESET_REG_SW_RESET); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Reset any fatal_error conditions */ | 
					
						
							|  |  |  | 	ipw2100_reset_fatalerror(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* At this point, the adapter is now stopped and disabled */ | 
					
						
							|  |  |  | 	priv->status &= ~(STATUS_RUNNING | STATUS_ASSOCIATING | | 
					
						
							|  |  |  | 			  STATUS_ASSOCIATED | STATUS_ENABLED); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Send the CARD_DISABLE_PHY_OFF comamnd to the card to disable it | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * After disabling, if the card was associated, a STATUS_ASSN_LOST will be sent. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * STATUS_CARD_DISABLE_NOTIFICATION will be sent regardless of | 
					
						
							|  |  |  |  * if STATUS_ASSN_LOST is sent. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static int ipw2100_hw_phy_off(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define HW_PHY_OFF_LOOP_DELAY (HZ / 5000)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = CARD_DISABLE_PHY_OFF, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = 0, | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int err, i; | 
					
						
							|  |  |  | 	u32 val1, val2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_HC("CARD_DISABLE_PHY_OFF\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Turn off the radio */ | 
					
						
							|  |  |  | 	err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < 2500; i++) { | 
					
						
							|  |  |  | 		read_nic_dword(priv->net_dev, IPW2100_CONTROL_REG, &val1); | 
					
						
							|  |  |  | 		read_nic_dword(priv->net_dev, IPW2100_COMMAND, &val2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ((val1 & IPW2100_CONTROL_PHY_OFF) && | 
					
						
							|  |  |  | 		    (val2 & IPW2100_COMMAND_PHY_OFF)) | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-11 02:09:55 -07:00
										 |  |  | 		schedule_timeout_uninterruptible(HW_PHY_OFF_LOOP_DELAY); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return -EIO; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_enable_adapter(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = HOST_COMPLETE, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = 0 | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int err = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_HC("HOST_COMPLETE\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->status & STATUS_ENABLED) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->adapter_sem); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (rf_kill_active(priv)) { | 
					
						
							|  |  |  | 		IPW_DEBUG_HC("Command aborted due to RF kill active.\n"); | 
					
						
							|  |  |  | 		goto fail_up; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("Failed to send HOST_COMPLETE command\n"); | 
					
						
							|  |  |  | 		goto fail_up; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_ENABLED); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		IPW_DEBUG_INFO("%s: card not responding to init command.\n", | 
					
						
							|  |  |  | 			       priv->net_dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		goto fail_up; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->stop_hang_check) { | 
					
						
							|  |  |  | 		priv->stop_hang_check = 0; | 
					
						
							|  |  |  | 		queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       fail_up: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	up(&priv->adapter_sem); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_hw_stop_adapter(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-09-11 02:09:55 -07:00
										 |  |  | #define HW_POWER_DOWN_DELAY (msecs_to_jiffies(100))
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = HOST_PRE_POWER_DOWN, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = 0, | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int err, i; | 
					
						
							|  |  |  | 	u32 reg; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_RUNNING)) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->status |= STATUS_STOPPING; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* We can only shut down the card if the firmware is operational.  So,
 | 
					
						
							|  |  |  | 	 * if we haven't reset since a fatal_error, then we can not send the | 
					
						
							|  |  |  | 	 * shutdown commands. */ | 
					
						
							|  |  |  | 	if (!priv->fatal_error) { | 
					
						
							|  |  |  | 		/* First, make sure the adapter is enabled so that the PHY_OFF
 | 
					
						
							|  |  |  | 		 * command can shut it down */ | 
					
						
							|  |  |  | 		ipw2100_enable_adapter(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		err = ipw2100_hw_phy_off(priv); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			printk(KERN_WARNING DRV_NAME | 
					
						
							|  |  |  | 			       ": Error disabling radio %d\n", err); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * If in D0-standby mode going directly to D3 may cause a | 
					
						
							|  |  |  | 		 * PCI bus violation.  Therefore we must change out of the D0 | 
					
						
							|  |  |  | 		 * state. | 
					
						
							|  |  |  | 		 * | 
					
						
							|  |  |  | 		 * Sending the PREPARE_FOR_POWER_DOWN will restrict the | 
					
						
							|  |  |  | 		 * hardware from going into standby mode and will transition | 
					
						
							|  |  |  | 		 * out of D0-standy if it is already in that state. | 
					
						
							|  |  |  | 		 * | 
					
						
							|  |  |  | 		 * STATUS_PREPARE_POWER_DOWN_COMPLETE will be sent by the | 
					
						
							|  |  |  | 		 * driver upon completion.  Once received, the driver can | 
					
						
							|  |  |  | 		 * proceed to the D3 state. | 
					
						
							|  |  |  | 		 * | 
					
						
							|  |  |  | 		 * Prepare for power down command to fw.  This command would | 
					
						
							|  |  |  | 		 * take HW out of D0-standby and prepare it for D3 state. | 
					
						
							|  |  |  | 		 * | 
					
						
							|  |  |  | 		 * Currently FW does not support event notification for this | 
					
						
							|  |  |  | 		 * event. Therefore, skip waiting for it.  Just wait a fixed | 
					
						
							|  |  |  | 		 * 100ms | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		IPW_DEBUG_HC("HOST_PRE_POWER_DOWN\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 			printk(KERN_WARNING DRV_NAME ": " | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			       "%s: Power down command failed: Error %d\n", | 
					
						
							|  |  |  | 			       priv->net_dev->name, err); | 
					
						
							| 
									
										
										
										
											2005-09-11 02:09:55 -07:00
										 |  |  | 		else | 
					
						
							|  |  |  | 			schedule_timeout_uninterruptible(HW_POWER_DOWN_DELAY); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->status &= ~STATUS_ENABLED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Set GPIO 3 writable by FW; GPIO 1 writable | 
					
						
							|  |  |  | 	 * by driver and enable clock | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	ipw2100_hw_set_gpio(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Power down adapter.  Sequence: | 
					
						
							|  |  |  | 	 * 1. Stop master assert (RESET_REG[9]=1) | 
					
						
							|  |  |  | 	 * 2. Wait for stop master (RESET_REG[8]==1) | 
					
						
							|  |  |  | 	 * 3. S/w reset assert (RESET_REG[7] = 1) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Stop master assert */ | 
					
						
							|  |  |  | 	write_register(priv->net_dev, IPW_REG_RESET_REG, | 
					
						
							|  |  |  | 		       IPW_AUX_HOST_RESET_REG_STOP_MASTER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* wait stop master not more than 50 usec.
 | 
					
						
							|  |  |  | 	 * Otherwise return error. */ | 
					
						
							|  |  |  | 	for (i = 5; i > 0; i--) { | 
					
						
							|  |  |  | 		udelay(10); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Check master stop bit */ | 
					
						
							|  |  |  | 		read_register(priv->net_dev, IPW_REG_RESET_REG, ®); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED) | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (i == 0) | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 		printk(KERN_WARNING DRV_NAME | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		       ": %s: Could now power down adapter.\n", | 
					
						
							|  |  |  | 		       priv->net_dev->name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* assert s/w reset */ | 
					
						
							|  |  |  | 	write_register(priv->net_dev, IPW_REG_RESET_REG, | 
					
						
							|  |  |  | 		       IPW_AUX_HOST_RESET_REG_SW_RESET); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->status &= ~(STATUS_RUNNING | STATUS_STOPPING); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_disable_adapter(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = CARD_DISABLE, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = 0 | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int err = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_HC("CARD_DISABLE\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_ENABLED)) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Make sure we clear the associated state */ | 
					
						
							|  |  |  | 	priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!priv->stop_hang_check) { | 
					
						
							|  |  |  | 		priv->stop_hang_check = 1; | 
					
						
							|  |  |  | 		cancel_delayed_work(&priv->hang_check); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->adapter_sem); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		printk(KERN_WARNING DRV_NAME | 
					
						
							|  |  |  | 		       ": exit - failed to send CARD_DISABLE command\n"); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		goto fail_up; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_DISABLED); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		printk(KERN_WARNING DRV_NAME | 
					
						
							|  |  |  | 		       ": exit - card failed to change to DISABLED\n"); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		goto fail_up; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("TODO: implement scan state machine\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       fail_up: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	up(&priv->adapter_sem); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static int ipw2100_set_scan_options(struct ipw2100_priv *priv) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = SET_SCAN_OPTIONS, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = 8 | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("enter\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_SCAN("setting scan options\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cmd.host_command_parameters[0] = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(priv->config & CFG_ASSOCIATE)) | 
					
						
							|  |  |  | 		cmd.host_command_parameters[0] |= IPW_SCAN_NOASSOCIATE; | 
					
						
							| 
									
										
										
										
											2005-07-12 15:45:30 -05:00
										 |  |  | 	if ((priv->ieee->sec.flags & SEC_ENABLED) && priv->ieee->sec.enabled) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		cmd.host_command_parameters[0] |= IPW_SCAN_MIXED_CELL; | 
					
						
							|  |  |  | 	if (priv->config & CFG_PASSIVE_SCAN) | 
					
						
							|  |  |  | 		cmd.host_command_parameters[0] |= IPW_SCAN_PASSIVE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cmd.host_command_parameters[1] = priv->channel_mask; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_HC("SET_SCAN_OPTIONS 0x%04X\n", | 
					
						
							|  |  |  | 		     cmd.host_command_parameters[0]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static int ipw2100_start_scan(struct ipw2100_priv *priv) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = BROADCAST_SCAN, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = 4 | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_HC("START_SCAN\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cmd.host_command_parameters[0] = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* No scanning if in monitor mode */ | 
					
						
							|  |  |  | 	if (priv->ieee->iw_mode == IW_MODE_MONITOR) | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->status & STATUS_SCANNING) { | 
					
						
							|  |  |  | 		IPW_DEBUG_SCAN("Scan requested while already in scan...\n"); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("enter\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Not clearing here; doing so makes iwlist always return nothing...
 | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * We should modify the table logic to use aging tables vs. clearing | 
					
						
							|  |  |  | 	 * the table on each scan start. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	IPW_DEBUG_SCAN("starting scan\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->status |= STATUS_SCANNING; | 
					
						
							|  |  |  | 	err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		priv->status &= ~STATUS_SCANNING; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("exit\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_up(struct ipw2100_priv *priv, int deferred) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 	int rc = 0; | 
					
						
							|  |  |  | 	u32 lock; | 
					
						
							|  |  |  | 	u32 ord_len = sizeof(lock); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Quite if manually disabled. */ | 
					
						
							|  |  |  | 	if (priv->status & STATUS_RF_KILL_SW) { | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("%s: Radio is disabled by Manual Disable " | 
					
						
							|  |  |  | 			       "switch\n", priv->net_dev->name); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* If the interrupt is enabled, turn it off... */ | 
					
						
							|  |  |  | 	spin_lock_irqsave(&priv->low_lock, flags); | 
					
						
							|  |  |  | 	ipw2100_disable_interrupts(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Reset any fatal_error conditions */ | 
					
						
							|  |  |  | 	ipw2100_reset_fatalerror(priv); | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&priv->low_lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->status & STATUS_POWERED || | 
					
						
							|  |  |  | 	    (priv->status & STATUS_RESET_PENDING)) { | 
					
						
							|  |  |  | 		/* Power cycle the card ... */ | 
					
						
							|  |  |  | 		if (ipw2100_power_cycle_adapter(priv)) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			printk(KERN_WARNING DRV_NAME | 
					
						
							|  |  |  | 			       ": %s: Could not cycle adapter.\n", | 
					
						
							|  |  |  | 			       priv->net_dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			rc = 1; | 
					
						
							|  |  |  | 			goto exit; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | 		priv->status |= STATUS_POWERED; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-20 14:28:43 -07:00
										 |  |  | 	/* Load the firmware, start the clocks, etc. */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	if (ipw2100_start_adapter(priv)) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		printk(KERN_ERR DRV_NAME | 
					
						
							|  |  |  | 		       ": %s: Failed to start the firmware.\n", | 
					
						
							|  |  |  | 		       priv->net_dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		rc = 1; | 
					
						
							|  |  |  | 		goto exit; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ipw2100_initialize_ordinals(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Determine capabilities of this particular HW configuration */ | 
					
						
							|  |  |  | 	if (ipw2100_get_hw_features(priv)) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		printk(KERN_ERR DRV_NAME | 
					
						
							|  |  |  | 		       ": %s: Failed to determine HW features.\n", | 
					
						
							|  |  |  | 		       priv->net_dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		rc = 1; | 
					
						
							|  |  |  | 		goto exit; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	lock = LOCK_NONE; | 
					
						
							|  |  |  | 	if (ipw2100_set_ordinal(priv, IPW_ORD_PERS_DB_LOCK, &lock, &ord_len)) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		printk(KERN_ERR DRV_NAME | 
					
						
							|  |  |  | 		       ": %s: Failed to clear ordinal lock.\n", | 
					
						
							|  |  |  | 		       priv->net_dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		rc = 1; | 
					
						
							|  |  |  | 		goto exit; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->status &= ~STATUS_SCANNING; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (rf_kill_active(priv)) { | 
					
						
							|  |  |  | 		printk(KERN_INFO "%s: Radio is disabled by RF switch.\n", | 
					
						
							|  |  |  | 		       priv->net_dev->name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (priv->stop_rf_kill) { | 
					
						
							|  |  |  | 			priv->stop_rf_kill = 0; | 
					
						
							|  |  |  | 			queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		deferred = 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Turn on the interrupt so that commands can be processed */ | 
					
						
							|  |  |  | 	ipw2100_enable_interrupts(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Send all of the commands that must be sent prior to
 | 
					
						
							|  |  |  | 	 * HOST_COMPLETE */ | 
					
						
							|  |  |  | 	if (ipw2100_adapter_setup(priv)) { | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 		printk(KERN_ERR DRV_NAME ": %s: Failed to start the card.\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		       priv->net_dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		rc = 1; | 
					
						
							|  |  |  | 		goto exit; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!deferred) { | 
					
						
							|  |  |  | 		/* Enable the adapter - sends HOST_COMPLETE */ | 
					
						
							|  |  |  | 		if (ipw2100_enable_adapter(priv)) { | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 			printk(KERN_ERR DRV_NAME ": " | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			       "%s: failed in call to enable adapter.\n", | 
					
						
							|  |  |  | 			       priv->net_dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			ipw2100_hw_stop_adapter(priv); | 
					
						
							|  |  |  | 			rc = 1; | 
					
						
							|  |  |  | 			goto exit; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Start a scan . . . */ | 
					
						
							|  |  |  | 		ipw2100_set_scan_options(priv); | 
					
						
							|  |  |  | 		ipw2100_start_scan(priv); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       exit: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	return rc; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Called by register_netdev() */ | 
					
						
							|  |  |  | static int ipw2100_net_init(struct net_device *dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	return ipw2100_up(priv, 1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ipw2100_down(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 	union iwreq_data wrqu = { | 
					
						
							|  |  |  | 		.ap_addr = { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			    .sa_family = ARPHRD_ETHER} | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 	int associated = priv->status & STATUS_ASSOCIATED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Kill the RF switch timer */ | 
					
						
							|  |  |  | 	if (!priv->stop_rf_kill) { | 
					
						
							|  |  |  | 		priv->stop_rf_kill = 1; | 
					
						
							|  |  |  | 		cancel_delayed_work(&priv->rf_kill); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Kill the firmare hang check timer */ | 
					
						
							|  |  |  | 	if (!priv->stop_hang_check) { | 
					
						
							|  |  |  | 		priv->stop_hang_check = 1; | 
					
						
							|  |  |  | 		cancel_delayed_work(&priv->hang_check); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Kill any pending resets */ | 
					
						
							|  |  |  | 	if (priv->status & STATUS_RESET_PENDING) | 
					
						
							|  |  |  | 		cancel_delayed_work(&priv->reset_work); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Make sure the interrupt is on so that FW commands will be
 | 
					
						
							|  |  |  | 	 * processed correctly */ | 
					
						
							|  |  |  | 	spin_lock_irqsave(&priv->low_lock, flags); | 
					
						
							|  |  |  | 	ipw2100_enable_interrupts(priv); | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&priv->low_lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ipw2100_hw_stop_adapter(priv)) | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 		printk(KERN_ERR DRV_NAME ": %s: Error stopping adapter.\n", | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		       priv->net_dev->name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Do not disable the interrupt until _after_ we disable
 | 
					
						
							|  |  |  | 	 * the adaptor.  Otherwise the CARD_DISABLE command will never | 
					
						
							|  |  |  | 	 * be ack'd by the firmware */ | 
					
						
							|  |  |  | 	spin_lock_irqsave(&priv->low_lock, flags); | 
					
						
							|  |  |  | 	ipw2100_disable_interrupts(priv); | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&priv->low_lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef ACPI_CSTATE_LIMIT_DEFINED
 | 
					
						
							|  |  |  | 	if (priv->config & CFG_C3_DISABLED) { | 
					
						
							| 
									
										
										
										
											2005-07-04 14:06:00 +08:00
										 |  |  | 		IPW_DEBUG_INFO(": Resetting C3 transitions.\n"); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		acpi_set_cstate_limit(priv->cstate_limit); | 
					
						
							|  |  |  | 		priv->config &= ~CFG_C3_DISABLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* We have to signal any supplicant if we are disassociating */ | 
					
						
							|  |  |  | 	if (associated) | 
					
						
							|  |  |  | 		wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); | 
					
						
							|  |  |  | 	netif_carrier_off(priv->net_dev); | 
					
						
							|  |  |  | 	netif_stop_queue(priv->net_dev); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static void ipw2100_reset_adapter(struct ipw2100_priv *priv) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 	union iwreq_data wrqu = { | 
					
						
							|  |  |  | 		.ap_addr = { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			    .sa_family = ARPHRD_ETHER} | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 	int associated = priv->status & STATUS_ASSOCIATED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&priv->low_lock, flags); | 
					
						
							| 
									
										
										
										
											2005-07-04 14:06:00 +08:00
										 |  |  | 	IPW_DEBUG_INFO(": %s: Restarting adapter.\n", priv->net_dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	priv->resets++; | 
					
						
							|  |  |  | 	priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); | 
					
						
							|  |  |  | 	priv->status |= STATUS_SECURITY_UPDATED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Force a power cycle even if interface hasn't been opened
 | 
					
						
							|  |  |  | 	 * yet */ | 
					
						
							|  |  |  | 	cancel_delayed_work(&priv->reset_work); | 
					
						
							|  |  |  | 	priv->status |= STATUS_RESET_PENDING; | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&priv->low_lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->action_sem); | 
					
						
							|  |  |  | 	/* stop timed checks so that they don't interfere with reset */ | 
					
						
							|  |  |  | 	priv->stop_hang_check = 1; | 
					
						
							|  |  |  | 	cancel_delayed_work(&priv->hang_check); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* We have to signal any supplicant if we are disassociating */ | 
					
						
							|  |  |  | 	if (associated) | 
					
						
							|  |  |  | 		wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ipw2100_up(priv, 0); | 
					
						
							|  |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void isr_indicate_associated(struct ipw2100_priv *priv, u32 status) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define MAC_ASSOCIATION_READ_DELAY (HZ)
 | 
					
						
							|  |  |  | 	int ret, len, essid_len; | 
					
						
							|  |  |  | 	char essid[IW_ESSID_MAX_SIZE]; | 
					
						
							|  |  |  | 	u32 txrate; | 
					
						
							|  |  |  | 	u32 chan; | 
					
						
							|  |  |  | 	char *txratename; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	u8 bssid[ETH_ALEN]; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * TBD: BSSID is usually 00:00:00:00:00:00 here and not | 
					
						
							|  |  |  | 	 *      an actual MAC of the AP. Seems like FW sets this | 
					
						
							|  |  |  | 	 *      address too late. Read it later and expose through | 
					
						
							|  |  |  | 	 *      /proc or schedule a later task to query and update | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	essid_len = IW_ESSID_MAX_SIZE; | 
					
						
							|  |  |  | 	ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID, | 
					
						
							|  |  |  | 				  essid, &essid_len); | 
					
						
							|  |  |  | 	if (ret) { | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			       __LINE__); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	len = sizeof(u32); | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	ret = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &txrate, &len); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	if (ret) { | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			       __LINE__); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	len = sizeof(u32); | 
					
						
							|  |  |  | 	ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &len); | 
					
						
							|  |  |  | 	if (ret) { | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			       __LINE__); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	len = ETH_ALEN; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID, &bssid, &len); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	if (ret) { | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			       __LINE__); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	memcpy(priv->ieee->bssid, bssid, ETH_ALEN); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (txrate) { | 
					
						
							|  |  |  | 	case TX_RATE_1_MBIT: | 
					
						
							|  |  |  | 		txratename = "1Mbps"; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case TX_RATE_2_MBIT: | 
					
						
							|  |  |  | 		txratename = "2Mbsp"; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case TX_RATE_5_5_MBIT: | 
					
						
							|  |  |  | 		txratename = "5.5Mbps"; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case TX_RATE_11_MBIT: | 
					
						
							|  |  |  | 		txratename = "11Mbps"; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("Unknown rate: %d\n", txrate); | 
					
						
							|  |  |  | 		txratename = "unknown rate"; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("%s: Associated with '%s' at %s, channel %d (BSSID=" | 
					
						
							|  |  |  | 		       MAC_FMT ")\n", | 
					
						
							|  |  |  | 		       priv->net_dev->name, escape_essid(essid, essid_len), | 
					
						
							|  |  |  | 		       txratename, chan, MAC_ARG(bssid)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* now we copy read ssid into dev */ | 
					
						
							|  |  |  | 	if (!(priv->config & CFG_STATIC_ESSID)) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		priv->essid_len = min((u8) essid_len, (u8) IW_ESSID_MAX_SIZE); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		memcpy(priv->essid, essid, priv->essid_len); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	priv->channel = chan; | 
					
						
							|  |  |  | 	memcpy(priv->bssid, bssid, ETH_ALEN); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->status |= STATUS_ASSOCIATING; | 
					
						
							|  |  |  | 	priv->connect_start = get_seconds(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	queue_delayed_work(priv->workqueue, &priv->wx_event_work, HZ / 10); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid, | 
					
						
							|  |  |  | 			     int length, int batch_mode) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	int ssid_len = min(length, IW_ESSID_MAX_SIZE); | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = SSID, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = ssid_len | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_HC("SSID: '%s'\n", escape_essid(essid, ssid_len)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ssid_len) | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 		memcpy(cmd.host_command_parameters, essid, ssid_len); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) { | 
					
						
							|  |  |  | 		err = ipw2100_disable_adapter(priv); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Bug in FW currently doesn't honor bit 0 in SET_SCAN_OPTIONS to
 | 
					
						
							|  |  |  | 	 * disable auto association -- so we cheat by setting a bogus SSID */ | 
					
						
							|  |  |  | 	if (!ssid_len && !(priv->config & CFG_ASSOCIATE)) { | 
					
						
							|  |  |  | 		int i; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		u8 *bogus = (u8 *) cmd.host_command_parameters; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		for (i = 0; i < IW_ESSID_MAX_SIZE; i++) | 
					
						
							|  |  |  | 			bogus[i] = 0x18 + i; | 
					
						
							|  |  |  | 		cmd.host_command_length = IW_ESSID_MAX_SIZE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* NOTE:  We always send the SSID command even if the provided ESSID is
 | 
					
						
							|  |  |  | 	 * the same as what we currently think is set. */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 	if (!err) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		memset(priv->essid + ssid_len, 0, IW_ESSID_MAX_SIZE - ssid_len); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		memcpy(priv->essid, essid, ssid_len); | 
					
						
							|  |  |  | 		priv->essid_len = ssid_len; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) { | 
					
						
							|  |  |  | 		if (ipw2100_enable_adapter(priv)) | 
					
						
							|  |  |  | 			err = -EIO; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void isr_indicate_association_lost(struct ipw2100_priv *priv, u32 status) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC, | 
					
						
							|  |  |  | 		  "disassociated: '%s' " MAC_FMT " \n", | 
					
						
							|  |  |  | 		  escape_essid(priv->essid, priv->essid_len), | 
					
						
							|  |  |  | 		  MAC_ARG(priv->bssid)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->status & STATUS_STOPPING) { | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("Card is stopping itself, discard ASSN_LOST.\n"); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	memset(priv->bssid, 0, ETH_ALEN); | 
					
						
							|  |  |  | 	memset(priv->ieee->bssid, 0, ETH_ALEN); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	netif_carrier_off(priv->net_dev); | 
					
						
							|  |  |  | 	netif_stop_queue(priv->net_dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_RUNNING)) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->status & STATUS_SECURITY_UPDATED) | 
					
						
							|  |  |  | 		queue_work(priv->workqueue, &priv->security_work); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	queue_work(priv->workqueue, &priv->wx_event_work); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void isr_indicate_rf_kill(struct ipw2100_priv *priv, u32 status) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("%s: RF Kill state changed to radio OFF.\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		       priv->net_dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* RF_KILL is now enabled (else we wouldn't be here) */ | 
					
						
							|  |  |  | 	priv->status |= STATUS_RF_KILL_HW; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef ACPI_CSTATE_LIMIT_DEFINED
 | 
					
						
							|  |  |  | 	if (priv->config & CFG_C3_DISABLED) { | 
					
						
							| 
									
										
										
										
											2005-07-04 14:06:00 +08:00
										 |  |  | 		IPW_DEBUG_INFO(": Resetting C3 transitions.\n"); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		acpi_set_cstate_limit(priv->cstate_limit); | 
					
						
							|  |  |  | 		priv->config &= ~CFG_C3_DISABLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Make sure the RF Kill check timer is running */ | 
					
						
							|  |  |  | 	priv->stop_rf_kill = 0; | 
					
						
							|  |  |  | 	cancel_delayed_work(&priv->rf_kill); | 
					
						
							|  |  |  | 	queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void isr_scan_complete(struct ipw2100_priv *priv, u32 status) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	IPW_DEBUG_SCAN("scan complete\n"); | 
					
						
							|  |  |  | 	/* Age the scan results... */ | 
					
						
							|  |  |  | 	priv->ieee->scans++; | 
					
						
							|  |  |  | 	priv->status &= ~STATUS_SCANNING; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-01 01:41:46 -08:00
										 |  |  | #ifdef CONFIG_IPW2100_DEBUG
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | #define IPW2100_HANDLER(v, f) { v, f, # v }
 | 
					
						
							|  |  |  | struct ipw2100_status_indicator { | 
					
						
							|  |  |  | 	int status; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	void (*cb) (struct ipw2100_priv * priv, u32 status); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	char *name; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #define IPW2100_HANDLER(v, f) { v, f }
 | 
					
						
							|  |  |  | struct ipw2100_status_indicator { | 
					
						
							|  |  |  | 	int status; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	void (*cb) (struct ipw2100_priv * priv, u32 status); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2005-12-01 01:41:46 -08:00
										 |  |  | #endif				/* CONFIG_IPW2100_DEBUG */
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void isr_indicate_scanning(struct ipw2100_priv *priv, u32 status) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	IPW_DEBUG_SCAN("Scanning...\n"); | 
					
						
							|  |  |  | 	priv->status |= STATUS_SCANNING; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static const struct ipw2100_status_indicator status_handlers[] = { | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	IPW2100_HANDLER(IPW_STATE_INITIALIZED, NULL), | 
					
						
							|  |  |  | 	IPW2100_HANDLER(IPW_STATE_COUNTRY_FOUND, NULL), | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	IPW2100_HANDLER(IPW_STATE_ASSOCIATED, isr_indicate_associated), | 
					
						
							|  |  |  | 	IPW2100_HANDLER(IPW_STATE_ASSN_LOST, isr_indicate_association_lost), | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	IPW2100_HANDLER(IPW_STATE_ASSN_CHANGED, NULL), | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	IPW2100_HANDLER(IPW_STATE_SCAN_COMPLETE, isr_scan_complete), | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	IPW2100_HANDLER(IPW_STATE_ENTERED_PSP, NULL), | 
					
						
							|  |  |  | 	IPW2100_HANDLER(IPW_STATE_LEFT_PSP, NULL), | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	IPW2100_HANDLER(IPW_STATE_RF_KILL, isr_indicate_rf_kill), | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	IPW2100_HANDLER(IPW_STATE_DISABLED, NULL), | 
					
						
							|  |  |  | 	IPW2100_HANDLER(IPW_STATE_POWER_DOWN, NULL), | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	IPW2100_HANDLER(IPW_STATE_SCANNING, isr_indicate_scanning), | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	IPW2100_HANDLER(-1, NULL) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void isr_status_change(struct ipw2100_priv *priv, int status) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (status == IPW_STATE_SCANNING && | 
					
						
							|  |  |  | 	    priv->status & STATUS_ASSOCIATED && | 
					
						
							|  |  |  | 	    !(priv->status & STATUS_SCANNING)) { | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("Scan detected while associated, with " | 
					
						
							|  |  |  | 			       "no scan request.  Restarting firmware.\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Wake up any sleeping jobs */ | 
					
						
							|  |  |  | 		schedule_reset(priv); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; status_handlers[i].status != -1; i++) { | 
					
						
							|  |  |  | 		if (status == status_handlers[i].status) { | 
					
						
							|  |  |  | 			IPW_DEBUG_NOTIF("Status change: %s\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 					status_handlers[i].name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			if (status_handlers[i].cb) | 
					
						
							|  |  |  | 				status_handlers[i].cb(priv, status); | 
					
						
							|  |  |  | 			priv->wstats.status = status; | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_NOTIF("unknown status received: %04x\n", status); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static void isr_rx_complete_command(struct ipw2100_priv *priv, | 
					
						
							|  |  |  | 				    struct ipw2100_cmd_header *cmd) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-12-01 01:41:46 -08:00
										 |  |  | #ifdef CONFIG_IPW2100_DEBUG
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	if (cmd->host_command_reg < ARRAY_SIZE(command_types)) { | 
					
						
							|  |  |  | 		IPW_DEBUG_HC("Command completed '%s (%d)'\n", | 
					
						
							|  |  |  | 			     command_types[cmd->host_command_reg], | 
					
						
							|  |  |  | 			     cmd->host_command_reg); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	if (cmd->host_command_reg == HOST_COMPLETE) | 
					
						
							|  |  |  | 		priv->status |= STATUS_ENABLED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (cmd->host_command_reg == CARD_DISABLE) | 
					
						
							|  |  |  | 		priv->status &= ~STATUS_ENABLED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->status &= ~STATUS_CMD_ACTIVE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wake_up_interruptible(&priv->wait_command_queue); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-01 01:41:46 -08:00
										 |  |  | #ifdef CONFIG_IPW2100_DEBUG
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static const char *frame_types[] = { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	"COMMAND_STATUS_VAL", | 
					
						
							|  |  |  | 	"STATUS_CHANGE_VAL", | 
					
						
							|  |  |  | 	"P80211_DATA_VAL", | 
					
						
							|  |  |  | 	"P8023_DATA_VAL", | 
					
						
							|  |  |  | 	"HOST_NOTIFICATION_VAL" | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-14 13:20:43 -08:00
										 |  |  | static int ipw2100_alloc_skb(struct ipw2100_priv *priv, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 				    struct ipw2100_rx_packet *packet) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	packet->skb = dev_alloc_skb(sizeof(struct ipw2100_rx)); | 
					
						
							|  |  |  | 	if (!packet->skb) | 
					
						
							|  |  |  | 		return -ENOMEM; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	packet->rxp = (struct ipw2100_rx *)packet->skb->data; | 
					
						
							|  |  |  | 	packet->dma_addr = pci_map_single(priv->pci_dev, packet->skb->data, | 
					
						
							|  |  |  | 					  sizeof(struct ipw2100_rx), | 
					
						
							|  |  |  | 					  PCI_DMA_FROMDEVICE); | 
					
						
							|  |  |  | 	/* NOTE: pci_map_single does not return an error code, and 0 is a valid
 | 
					
						
							|  |  |  | 	 *       dma_addr */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define SEARCH_ERROR   0xffffffff
 | 
					
						
							|  |  |  | #define SEARCH_FAIL    0xfffffffe
 | 
					
						
							|  |  |  | #define SEARCH_SUCCESS 0xfffffff0
 | 
					
						
							|  |  |  | #define SEARCH_DISCARD 0
 | 
					
						
							|  |  |  | #define SEARCH_SNAPSHOT 1
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define SNAPSHOT_ADDR(ofs) (priv->snapshot[((ofs) >> 12) & 0xff] + ((ofs) & 0xfff))
 | 
					
						
							| 
									
										
										
										
											2006-01-24 13:49:26 +08:00
										 |  |  | static void ipw2100_snapshot_free(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	if (!priv->snapshot[0]) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	for (i = 0; i < 0x30; i++) | 
					
						
							|  |  |  | 		kfree(priv->snapshot[i]); | 
					
						
							|  |  |  | 	priv->snapshot[0] = NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef CONFIG_IPW2100_DEBUG_C3
 | 
					
						
							| 
									
										
										
										
											2006-01-14 13:20:43 -08:00
										 |  |  | static int ipw2100_snapshot_alloc(struct ipw2100_priv *priv) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	if (priv->snapshot[0]) | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	for (i = 0; i < 0x30; i++) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		priv->snapshot[i] = (u8 *) kmalloc(0x1000, GFP_ATOMIC); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		if (!priv->snapshot[i]) { | 
					
						
							|  |  |  | 			IPW_DEBUG_INFO("%s: Error allocating snapshot " | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 				       "buffer %d\n", priv->net_dev->name, i); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			while (i > 0) | 
					
						
							|  |  |  | 				kfree(priv->snapshot[--i]); | 
					
						
							|  |  |  | 			priv->snapshot[0] = NULL; | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-14 13:20:43 -08:00
										 |  |  | static u32 ipw2100_match_buf(struct ipw2100_priv *priv, u8 * in_buf, | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 				    size_t len, int mode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u32 i, j; | 
					
						
							|  |  |  | 	u32 tmp; | 
					
						
							|  |  |  | 	u8 *s, *d; | 
					
						
							|  |  |  | 	u32 ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	s = in_buf; | 
					
						
							|  |  |  | 	if (mode == SEARCH_SNAPSHOT) { | 
					
						
							|  |  |  | 		if (!ipw2100_snapshot_alloc(priv)) | 
					
						
							|  |  |  | 			mode = SEARCH_DISCARD; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (ret = SEARCH_FAIL, i = 0; i < 0x30000; i += 4) { | 
					
						
							|  |  |  | 		read_nic_dword(priv->net_dev, i, &tmp); | 
					
						
							|  |  |  | 		if (mode == SEARCH_SNAPSHOT) | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			*(u32 *) SNAPSHOT_ADDR(i) = tmp; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		if (ret == SEARCH_FAIL) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			d = (u8 *) & tmp; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			for (j = 0; j < 4; j++) { | 
					
						
							|  |  |  | 				if (*s != *d) { | 
					
						
							|  |  |  | 					s = in_buf; | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				s++; | 
					
						
							|  |  |  | 				d++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if ((s - in_buf) == len) | 
					
						
							|  |  |  | 					ret = (i + j) - len + 1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else if (mode == SEARCH_DISCARD) | 
					
						
							|  |  |  | 			return ret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2006-01-24 13:49:26 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 0) Disconnect the SKB from the firmware (just unmap) | 
					
						
							|  |  |  |  * 1) Pack the ETH header into the SKB | 
					
						
							|  |  |  |  * 2) Pass the SKB to the network stack | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * When packet is provided by the firmware, it contains the following: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * .  ieee80211_hdr | 
					
						
							|  |  |  |  * .  ieee80211_snap_hdr | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The size of the constructed ethernet | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #ifdef CONFIG_IPW2100_RX_DEBUG
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static u8 packet_data[IPW_RX_NIC_BUFFER_LENGTH]; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-14 13:20:43 -08:00
										 |  |  | static void ipw2100_corruption_detected(struct ipw2100_priv *priv, int i) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-12-01 01:41:46 -08:00
										 |  |  | #ifdef CONFIG_IPW2100_DEBUG_C3
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	struct ipw2100_status *status = &priv->status_queue.drv[i]; | 
					
						
							|  |  |  | 	u32 match, reg; | 
					
						
							|  |  |  | 	int j; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #ifdef ACPI_CSTATE_LIMIT_DEFINED
 | 
					
						
							|  |  |  | 	int limit; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-04 14:06:00 +08:00
										 |  |  | 	IPW_DEBUG_INFO(": PCI latency error detected at 0x%04zX.\n", | 
					
						
							|  |  |  | 		       i * sizeof(struct ipw2100_status)); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef ACPI_CSTATE_LIMIT_DEFINED
 | 
					
						
							| 
									
										
										
										
											2005-07-04 14:06:00 +08:00
										 |  |  | 	IPW_DEBUG_INFO(": Disabling C3 transitions.\n"); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	limit = acpi_get_cstate_limit(); | 
					
						
							|  |  |  | 	if (limit > 2) { | 
					
						
							|  |  |  | 		priv->cstate_limit = limit; | 
					
						
							|  |  |  | 		acpi_set_cstate_limit(2); | 
					
						
							|  |  |  | 		priv->config |= CFG_C3_DISABLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-01 01:41:46 -08:00
										 |  |  | #ifdef CONFIG_IPW2100_DEBUG_C3
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	/* Halt the fimrware so we can get a good image */ | 
					
						
							|  |  |  | 	write_register(priv->net_dev, IPW_REG_RESET_REG, | 
					
						
							|  |  |  | 		       IPW_AUX_HOST_RESET_REG_STOP_MASTER); | 
					
						
							|  |  |  | 	j = 5; | 
					
						
							|  |  |  | 	do { | 
					
						
							|  |  |  | 		udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY); | 
					
						
							|  |  |  | 		read_register(priv->net_dev, IPW_REG_RESET_REG, ®); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED) | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	} while (j--); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	match = ipw2100_match_buf(priv, (u8 *) status, | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 				  sizeof(struct ipw2100_status), | 
					
						
							|  |  |  | 				  SEARCH_SNAPSHOT); | 
					
						
							|  |  |  | 	if (match < SEARCH_SUCCESS) | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("%s: DMA status match in Firmware at " | 
					
						
							|  |  |  | 			       "offset 0x%06X, length %d:\n", | 
					
						
							|  |  |  | 			       priv->net_dev->name, match, | 
					
						
							|  |  |  | 			       sizeof(struct ipw2100_status)); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("%s: No DMA status match in " | 
					
						
							|  |  |  | 			       "Firmware.\n", priv->net_dev->name); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	printk_buf((u8 *) priv->status_queue.drv, | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		   sizeof(struct ipw2100_status) * RX_QUEUE_LENGTH); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->fatal_error = IPW2100_ERR_C3_CORRUPTION; | 
					
						
							|  |  |  | 	priv->ieee->stats.rx_errors++; | 
					
						
							|  |  |  | 	schedule_reset(priv); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-14 13:20:43 -08:00
										 |  |  | static void isr_rx(struct ipw2100_priv *priv, int i, | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			  struct ieee80211_rx_stats *stats) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_status *status = &priv->status_queue.drv[i]; | 
					
						
							|  |  |  | 	struct ipw2100_rx_packet *packet = &priv->rx_buffers[i]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_RX("Handler...\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (unlikely(status->frame_size > skb_tailroom(packet->skb))) { | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!" | 
					
						
							|  |  |  | 			       "  Dropping.\n", | 
					
						
							|  |  |  | 			       priv->net_dev->name, | 
					
						
							|  |  |  | 			       status->frame_size, skb_tailroom(packet->skb)); | 
					
						
							|  |  |  | 		priv->ieee->stats.rx_errors++; | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (unlikely(!netif_running(priv->net_dev))) { | 
					
						
							|  |  |  | 		priv->ieee->stats.rx_errors++; | 
					
						
							|  |  |  | 		priv->wstats.discard.misc++; | 
					
						
							|  |  |  | 		IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | #ifdef CONFIG_IPW2100_MONITOR
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	if (unlikely(priv->ieee->iw_mode == IW_MODE_MONITOR && | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 		     priv->config & CFG_CRC_CHECK && | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		     status->flags & IPW_STATUS_FLAG_CRC_ERROR)) { | 
					
						
							|  |  |  | 		IPW_DEBUG_RX("CRC error in packet.  Dropping.\n"); | 
					
						
							|  |  |  | 		priv->ieee->stats.rx_errors++; | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (unlikely(priv->ieee->iw_mode != IW_MODE_MONITOR && | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		     !(priv->status & STATUS_ASSOCIATED))) { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		IPW_DEBUG_DROP("Dropping packet while not associated.\n"); | 
					
						
							|  |  |  | 		priv->wstats.discard.misc++; | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pci_unmap_single(priv->pci_dev, | 
					
						
							|  |  |  | 			 packet->dma_addr, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			 sizeof(struct ipw2100_rx), PCI_DMA_FROMDEVICE); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	skb_put(packet->skb, status->frame_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef CONFIG_IPW2100_RX_DEBUG
 | 
					
						
							|  |  |  | 	/* Make a copy of the frame so we can dump it to the logs if
 | 
					
						
							|  |  |  | 	 * ieee80211_rx fails */ | 
					
						
							|  |  |  | 	memcpy(packet_data, packet->skb->data, | 
					
						
							| 
									
										
										
										
											2005-06-07 14:58:41 +02:00
										 |  |  | 	       min_t(u32, status->frame_size, IPW_RX_NIC_BUFFER_LENGTH)); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!ieee80211_rx(priv->ieee, packet->skb, stats)) { | 
					
						
							|  |  |  | #ifdef CONFIG_IPW2100_RX_DEBUG
 | 
					
						
							|  |  |  | 		IPW_DEBUG_DROP("%s: Non consumed packet:\n", | 
					
						
							|  |  |  | 			       priv->net_dev->name); | 
					
						
							|  |  |  | 		printk_buf(IPW_DL_DROP, packet_data, status->frame_size); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 		priv->ieee->stats.rx_errors++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* ieee80211_rx failed, so it didn't free the SKB */ | 
					
						
							|  |  |  | 		dev_kfree_skb_any(packet->skb); | 
					
						
							|  |  |  | 		packet->skb = NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* We need to allocate a new SKB and attach it to the RDB. */ | 
					
						
							|  |  |  | 	if (unlikely(ipw2100_alloc_skb(priv, packet))) { | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 		printk(KERN_WARNING DRV_NAME ": " | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		       "%s: Unable to allocate SKB onto RBD ring - disabling " | 
					
						
							|  |  |  | 		       "adapter.\n", priv->net_dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		/* TODO: schedule adapter shutdown */ | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("TODO: Shutdown adapter...\n"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Update the RDB entry */ | 
					
						
							|  |  |  | 	priv->rx_queue.drv[i].host_addr = packet->dma_addr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-14 13:20:43 -08:00
										 |  |  | static int ipw2100_corruption_check(struct ipw2100_priv *priv, int i) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_status *status = &priv->status_queue.drv[i]; | 
					
						
							|  |  |  | 	struct ipw2100_rx *u = priv->rx_buffers[i].rxp; | 
					
						
							|  |  |  | 	u16 frame_type = status->status_fields & STATUS_TYPE_MASK; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (frame_type) { | 
					
						
							|  |  |  | 	case COMMAND_STATUS_VAL: | 
					
						
							|  |  |  | 		return (status->frame_size != sizeof(u->rx_data.command)); | 
					
						
							|  |  |  | 	case STATUS_CHANGE_VAL: | 
					
						
							|  |  |  | 		return (status->frame_size != sizeof(u->rx_data.status)); | 
					
						
							|  |  |  | 	case HOST_NOTIFICATION_VAL: | 
					
						
							|  |  |  | 		return (status->frame_size < sizeof(u->rx_data.notification)); | 
					
						
							|  |  |  | 	case P80211_DATA_VAL: | 
					
						
							|  |  |  | 	case P8023_DATA_VAL: | 
					
						
							|  |  |  | #ifdef CONFIG_IPW2100_MONITOR
 | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 		switch (WLAN_FC_GET_TYPE(u->rx_data.header.frame_ctl)) { | 
					
						
							|  |  |  | 		case IEEE80211_FTYPE_MGMT: | 
					
						
							|  |  |  | 		case IEEE80211_FTYPE_CTL: | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		case IEEE80211_FTYPE_DATA: | 
					
						
							|  |  |  | 			return (status->frame_size > | 
					
						
							|  |  |  | 				IPW_MAX_802_11_PAYLOAD_LENGTH); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * ipw2100 interrupts are disabled at this point, and the ISR | 
					
						
							|  |  |  |  * is the only code that calls this method.  So, we do not need | 
					
						
							|  |  |  |  * to play with any locks. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * RX Queue works as follows: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Read index - firmware places packet in entry identified by the | 
					
						
							|  |  |  |  *              Read index and advances Read index.  In this manner, | 
					
						
							|  |  |  |  *              Read index will always point to the next packet to | 
					
						
							|  |  |  |  *              be filled--but not yet valid. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Write index - driver fills this entry with an unused RBD entry. | 
					
						
							|  |  |  |  *               This entry has not filled by the firmware yet. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * In between the W and R indexes are the RBDs that have been received | 
					
						
							|  |  |  |  * but not yet processed. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The process of handling packets will start at WRITE + 1 and advance | 
					
						
							|  |  |  |  * until it reaches the READ index. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The WRITE index is cached in the variable 'priv->rx_queue.next'. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2006-01-14 13:20:43 -08:00
										 |  |  | static void __ipw2100_rx_process(struct ipw2100_priv *priv) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_bd_queue *rxq = &priv->rx_queue; | 
					
						
							|  |  |  | 	struct ipw2100_status_queue *sq = &priv->status_queue; | 
					
						
							|  |  |  | 	struct ipw2100_rx_packet *packet; | 
					
						
							|  |  |  | 	u16 frame_type; | 
					
						
							|  |  |  | 	u32 r, w, i, s; | 
					
						
							|  |  |  | 	struct ipw2100_rx *u; | 
					
						
							|  |  |  | 	struct ieee80211_rx_stats stats = { | 
					
						
							|  |  |  | 		.mac_time = jiffies, | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_READ_INDEX, &r); | 
					
						
							|  |  |  | 	read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, &w); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (r >= rxq->entries) { | 
					
						
							|  |  |  | 		IPW_DEBUG_RX("exit - bad read index\n"); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	i = (rxq->next + 1) % rxq->entries; | 
					
						
							|  |  |  | 	s = i; | 
					
						
							|  |  |  | 	while (i != r) { | 
					
						
							|  |  |  | 		/* IPW_DEBUG_RX("r = %d : w = %d : processing = %d\n",
 | 
					
						
							|  |  |  | 		   r, rxq->next, i); */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		packet = &priv->rx_buffers[i]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Sync the DMA for the STATUS buffer so CPU is sure to get
 | 
					
						
							|  |  |  | 		 * the correct values */ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		pci_dma_sync_single_for_cpu(priv->pci_dev, | 
					
						
							|  |  |  | 					    sq->nic + | 
					
						
							|  |  |  | 					    sizeof(struct ipw2100_status) * i, | 
					
						
							|  |  |  | 					    sizeof(struct ipw2100_status), | 
					
						
							|  |  |  | 					    PCI_DMA_FROMDEVICE); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* Sync the DMA for the RX buffer so CPU is sure to get
 | 
					
						
							|  |  |  | 		 * the correct values */ | 
					
						
							|  |  |  | 		pci_dma_sync_single_for_cpu(priv->pci_dev, packet->dma_addr, | 
					
						
							|  |  |  | 					    sizeof(struct ipw2100_rx), | 
					
						
							|  |  |  | 					    PCI_DMA_FROMDEVICE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (unlikely(ipw2100_corruption_check(priv, i))) { | 
					
						
							|  |  |  | 			ipw2100_corruption_detected(priv, i); | 
					
						
							|  |  |  | 			goto increment; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		u = packet->rxp; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		frame_type = sq->drv[i].status_fields & STATUS_TYPE_MASK; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		stats.rssi = sq->drv[i].rssi + IPW2100_RSSI_TO_DBM; | 
					
						
							|  |  |  | 		stats.len = sq->drv[i].frame_size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		stats.mask = 0; | 
					
						
							|  |  |  | 		if (stats.rssi != 0) | 
					
						
							|  |  |  | 			stats.mask |= IEEE80211_STATMASK_RSSI; | 
					
						
							|  |  |  | 		stats.freq = IEEE80211_24GHZ_BAND; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		IPW_DEBUG_RX("%s: '%s' frame type received (%d).\n", | 
					
						
							|  |  |  | 			     priv->net_dev->name, frame_types[frame_type], | 
					
						
							|  |  |  | 			     stats.len); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		switch (frame_type) { | 
					
						
							|  |  |  | 		case COMMAND_STATUS_VAL: | 
					
						
							|  |  |  | 			/* Reset Rx watchdog */ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			isr_rx_complete_command(priv, &u->rx_data.command); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		case STATUS_CHANGE_VAL: | 
					
						
							|  |  |  | 			isr_status_change(priv, u->rx_data.status); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		case P80211_DATA_VAL: | 
					
						
							|  |  |  | 		case P8023_DATA_VAL: | 
					
						
							|  |  |  | #ifdef CONFIG_IPW2100_MONITOR
 | 
					
						
							|  |  |  | 			if (priv->ieee->iw_mode == IW_MODE_MONITOR) { | 
					
						
							|  |  |  | 				isr_rx(priv, i, &stats); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 			if (stats.len < sizeof(u->rx_data.header)) | 
					
						
							|  |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			switch (WLAN_FC_GET_TYPE(u->rx_data.header.frame_ctl)) { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			case IEEE80211_FTYPE_MGMT: | 
					
						
							|  |  |  | 				ieee80211_rx_mgt(priv->ieee, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 						 &u->rx_data.header, &stats); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			case IEEE80211_FTYPE_CTL: | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			case IEEE80211_FTYPE_DATA: | 
					
						
							|  |  |  | 				isr_rx(priv, i, &stats); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	      increment: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		/* clear status field associated with this RBD */ | 
					
						
							|  |  |  | 		rxq->drv[i].status.info.field = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		i = (i + 1) % rxq->entries; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (i != s) { | 
					
						
							|  |  |  | 		/* backtrack one entry, wrapping to end if at 0 */ | 
					
						
							|  |  |  | 		rxq->next = (i ? i : rxq->entries) - 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		write_register(priv->net_dev, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			       IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, rxq->next); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * __ipw2100_tx_process | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This routine will determine whether the next packet on | 
					
						
							|  |  |  |  * the fw_pend_list has been processed by the firmware yet. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * If not, then it does nothing and returns. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * If so, then it removes the item from the fw_pend_list, frees | 
					
						
							|  |  |  |  * any associated storage, and places the item back on the | 
					
						
							|  |  |  |  * free list of its source (either msg_free_list or tx_free_list) | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * TX Queue works as follows: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Read index - points to the next TBD that the firmware will | 
					
						
							|  |  |  |  *              process.  The firmware will read the data, and once | 
					
						
							|  |  |  |  *              done processing, it will advance the Read index. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Write index - driver fills this entry with an constructed TBD | 
					
						
							|  |  |  |  *               entry.  The Write index is not advanced until the | 
					
						
							|  |  |  |  *               packet has been configured. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * In between the W and R indexes are the TBDs that have NOT been | 
					
						
							|  |  |  |  * processed.  Lagging behind the R index are packets that have | 
					
						
							|  |  |  |  * been processed but have not been freed by the driver. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * In order to free old storage, an internal index will be maintained | 
					
						
							|  |  |  |  * that points to the next packet to be freed.  When all used | 
					
						
							|  |  |  |  * packets have been freed, the oldest index will be the same as the | 
					
						
							|  |  |  |  * firmware's read index. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The OLDEST index is cached in the variable 'priv->tx_queue.oldest' | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Because the TBD structure can not contain arbitrary data, the | 
					
						
							|  |  |  |  * driver must keep an internal queue of cached allocations such that | 
					
						
							|  |  |  |  * it can put that data back into the tx_free_list and msg_free_list | 
					
						
							|  |  |  |  * for use by future command and data packets. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2006-01-14 13:20:43 -08:00
										 |  |  | static int __ipw2100_tx_process(struct ipw2100_priv *priv) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_bd_queue *txq = &priv->tx_queue; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	struct ipw2100_bd *tbd; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	struct list_head *element; | 
					
						
							|  |  |  | 	struct ipw2100_tx_packet *packet; | 
					
						
							|  |  |  | 	int descriptors_used; | 
					
						
							|  |  |  | 	int e, i; | 
					
						
							|  |  |  | 	u32 r, w, frag_num = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (list_empty(&priv->fw_pend_list)) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	element = priv->fw_pend_list.next; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	packet = list_entry(element, struct ipw2100_tx_packet, list); | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	tbd = &txq->drv[packet->index]; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Determine how many TBD entries must be finished... */ | 
					
						
							|  |  |  | 	switch (packet->type) { | 
					
						
							|  |  |  | 	case COMMAND: | 
					
						
							|  |  |  | 		/* COMMAND uses only one slot; don't advance */ | 
					
						
							|  |  |  | 		descriptors_used = 1; | 
					
						
							|  |  |  | 		e = txq->oldest; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case DATA: | 
					
						
							|  |  |  | 		/* DATA uses two slots; advance and loop position. */ | 
					
						
							|  |  |  | 		descriptors_used = tbd->num_fragments; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		frag_num = tbd->num_fragments - 1; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		e = txq->oldest + frag_num; | 
					
						
							|  |  |  | 		e %= txq->entries; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 		printk(KERN_WARNING DRV_NAME ": %s: Bad fw_pend_list entry!\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		       priv->net_dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* if the last TBD is not done by NIC yet, then packet is
 | 
					
						
							|  |  |  | 	 * not ready to be released. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX, | 
					
						
							|  |  |  | 		      &r); | 
					
						
							|  |  |  | 	read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX, | 
					
						
							|  |  |  | 		      &w); | 
					
						
							|  |  |  | 	if (w != txq->next) | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 		printk(KERN_WARNING DRV_NAME ": %s: write index mismatch\n", | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		       priv->net_dev->name); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	/*
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	 * txq->next is the index of the last packet written txq->oldest is | 
					
						
							|  |  |  | 	 * the index of the r is the index of the next packet to be read by | 
					
						
							|  |  |  | 	 * firmware | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Quick graphic to help you visualize the following | 
					
						
							|  |  |  | 	 * if / else statement | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * ===>|                     s---->|=============== | 
					
						
							|  |  |  | 	 *                               e>| | 
					
						
							|  |  |  | 	 * | a | b | c | d | e | f | g | h | i | j | k | l | 
					
						
							|  |  |  | 	 *       r---->| | 
					
						
							|  |  |  | 	 *               w | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * w - updated by driver | 
					
						
							|  |  |  | 	 * r - updated by firmware | 
					
						
							|  |  |  | 	 * s - start of oldest BD entry (txq->oldest) | 
					
						
							|  |  |  | 	 * e - end of oldest BD entry | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (!((r <= w && (e < r || e >= w)) || (e < r && e >= w))) { | 
					
						
							|  |  |  | 		IPW_DEBUG_TX("exit - no processed packets ready to release.\n"); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	list_del(element); | 
					
						
							|  |  |  | 	DEC_STAT(&priv->fw_pend_stat); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-01 01:41:46 -08:00
										 |  |  | #ifdef CONFIG_IPW2100_DEBUG
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		int i = txq->oldest; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		IPW_DEBUG_TX("TX%d V=%p P=%04X T=%04X L=%d\n", i, | 
					
						
							|  |  |  | 			     &txq->drv[i], | 
					
						
							|  |  |  | 			     (u32) (txq->nic + i * sizeof(struct ipw2100_bd)), | 
					
						
							|  |  |  | 			     txq->drv[i].host_addr, txq->drv[i].buf_length); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (packet->type == DATA) { | 
					
						
							|  |  |  | 			i = (i + 1) % txq->entries; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			IPW_DEBUG_TX("TX%d V=%p P=%04X T=%04X L=%d\n", i, | 
					
						
							|  |  |  | 				     &txq->drv[i], | 
					
						
							|  |  |  | 				     (u32) (txq->nic + i * | 
					
						
							|  |  |  | 					    sizeof(struct ipw2100_bd)), | 
					
						
							|  |  |  | 				     (u32) txq->drv[i].host_addr, | 
					
						
							|  |  |  | 				     txq->drv[i].buf_length); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (packet->type) { | 
					
						
							|  |  |  | 	case DATA: | 
					
						
							|  |  |  | 		if (txq->drv[txq->oldest].status.info.fields.txType != 0) | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 			printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch.  " | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			       "Expecting DATA TBD but pulled " | 
					
						
							|  |  |  | 			       "something else: ids %d=%d.\n", | 
					
						
							|  |  |  | 			       priv->net_dev->name, txq->oldest, packet->index); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* DATA packet; we have to unmap and free the SKB */ | 
					
						
							|  |  |  | 		for (i = 0; i < frag_num; i++) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			tbd = &txq->drv[(packet->index + 1 + i) % txq->entries]; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			IPW_DEBUG_TX("TX%d P=%08x L=%d\n", | 
					
						
							|  |  |  | 				     (packet->index + 1 + i) % txq->entries, | 
					
						
							|  |  |  | 				     tbd->host_addr, tbd->buf_length); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			pci_unmap_single(priv->pci_dev, | 
					
						
							|  |  |  | 					 tbd->host_addr, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 					 tbd->buf_length, PCI_DMA_TODEVICE); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ieee80211_txb_free(packet->info.d_struct.txb); | 
					
						
							|  |  |  | 		packet->info.d_struct.txb = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		list_add_tail(element, &priv->tx_free_list); | 
					
						
							|  |  |  | 		INC_STAT(&priv->tx_free_stat); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* We have a free slot in the Tx queue, so wake up the
 | 
					
						
							|  |  |  | 		 * transmit layer if it is stopped. */ | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 		if (priv->status & STATUS_ASSOCIATED) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			netif_wake_queue(priv->net_dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* A packet was processed by the hardware, so update the
 | 
					
						
							|  |  |  | 		 * watchdog */ | 
					
						
							|  |  |  | 		priv->net_dev->trans_start = jiffies; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case COMMAND: | 
					
						
							|  |  |  | 		if (txq->drv[txq->oldest].status.info.fields.txType != 1) | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 			printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch.  " | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			       "Expecting COMMAND TBD but pulled " | 
					
						
							|  |  |  | 			       "something else: ids %d=%d.\n", | 
					
						
							|  |  |  | 			       priv->net_dev->name, txq->oldest, packet->index); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-01 01:41:46 -08:00
										 |  |  | #ifdef CONFIG_IPW2100_DEBUG
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		if (packet->info.c_struct.cmd->host_command_reg < | 
					
						
							|  |  |  | 		    sizeof(command_types) / sizeof(*command_types)) | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			IPW_DEBUG_TX("Command '%s (%d)' processed: %d.\n", | 
					
						
							|  |  |  | 				     command_types[packet->info.c_struct.cmd-> | 
					
						
							|  |  |  | 						   host_command_reg], | 
					
						
							|  |  |  | 				     packet->info.c_struct.cmd-> | 
					
						
							|  |  |  | 				     host_command_reg, | 
					
						
							|  |  |  | 				     packet->info.c_struct.cmd->cmd_status_reg); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		list_add_tail(element, &priv->msg_free_list); | 
					
						
							|  |  |  | 		INC_STAT(&priv->msg_free_stat); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* advance oldest used TBD pointer to start of next entry */ | 
					
						
							|  |  |  | 	txq->oldest = (e + 1) % txq->entries; | 
					
						
							|  |  |  | 	/* increase available TBDs number */ | 
					
						
							|  |  |  | 	txq->available += descriptors_used; | 
					
						
							|  |  |  | 	SET_STAT(&priv->txq_stat, txq->available); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_TX("packet latency (send to process)  %ld jiffies\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		     jiffies - packet->jiffy_start); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return (!list_empty(&priv->fw_pend_list)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void __ipw2100_tx_complete(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	while (__ipw2100_tx_process(priv) && i < 200) | 
					
						
							|  |  |  | 		i++; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (i == 200) { | 
					
						
							| 
									
										
										
										
											2005-08-25 20:02:10 -04:00
										 |  |  | 		printk(KERN_WARNING DRV_NAME ": " | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		       "%s: Driver is running slow (%d iters).\n", | 
					
						
							|  |  |  | 		       priv->net_dev->name, i); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:02:10 -04:00
										 |  |  | static void ipw2100_tx_send_commands(struct ipw2100_priv *priv) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct list_head *element; | 
					
						
							|  |  |  | 	struct ipw2100_tx_packet *packet; | 
					
						
							|  |  |  | 	struct ipw2100_bd_queue *txq = &priv->tx_queue; | 
					
						
							|  |  |  | 	struct ipw2100_bd *tbd; | 
					
						
							|  |  |  | 	int next = txq->next; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (!list_empty(&priv->msg_pend_list)) { | 
					
						
							|  |  |  | 		/* if there isn't enough space in TBD queue, then
 | 
					
						
							|  |  |  | 		 * don't stuff a new one in. | 
					
						
							|  |  |  | 		 * NOTE: 3 are needed as a command will take one, | 
					
						
							|  |  |  | 		 *       and there is a minimum of 2 that must be | 
					
						
							|  |  |  | 		 *       maintained between the r and w indexes | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		if (txq->available <= 3) { | 
					
						
							|  |  |  | 			IPW_DEBUG_TX("no room in tx_queue\n"); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		element = priv->msg_pend_list.next; | 
					
						
							|  |  |  | 		list_del(element); | 
					
						
							|  |  |  | 		DEC_STAT(&priv->msg_pend_stat); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		packet = list_entry(element, struct ipw2100_tx_packet, list); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		IPW_DEBUG_TX("using TBD at virt=%p, phys=%p\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			     &txq->drv[txq->next], | 
					
						
							|  |  |  | 			     (void *)(txq->nic + txq->next * | 
					
						
							|  |  |  | 				      sizeof(struct ipw2100_bd))); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		packet->index = txq->next; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		tbd = &txq->drv[txq->next]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* initialize TBD */ | 
					
						
							|  |  |  | 		tbd->host_addr = packet->info.c_struct.cmd_phys; | 
					
						
							|  |  |  | 		tbd->buf_length = sizeof(struct ipw2100_cmd_header); | 
					
						
							|  |  |  | 		/* not marking number of fragments causes problems
 | 
					
						
							|  |  |  | 		 * with f/w debug version */ | 
					
						
							|  |  |  | 		tbd->num_fragments = 1; | 
					
						
							|  |  |  | 		tbd->status.info.field = | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		    IPW_BD_STATUS_TX_FRAME_COMMAND | | 
					
						
							|  |  |  | 		    IPW_BD_STATUS_TX_INTERRUPT_ENABLE; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* update TBD queue counters */ | 
					
						
							|  |  |  | 		txq->next++; | 
					
						
							|  |  |  | 		txq->next %= txq->entries; | 
					
						
							|  |  |  | 		txq->available--; | 
					
						
							|  |  |  | 		DEC_STAT(&priv->txq_stat); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		list_add_tail(element, &priv->fw_pend_list); | 
					
						
							|  |  |  | 		INC_STAT(&priv->fw_pend_stat); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (txq->next != next) { | 
					
						
							|  |  |  | 		/* kick off the DMA by notifying firmware the
 | 
					
						
							|  |  |  | 		 * write index has moved; make sure TBD stores are sync'd */ | 
					
						
							|  |  |  | 		wmb(); | 
					
						
							|  |  |  | 		write_register(priv->net_dev, | 
					
						
							|  |  |  | 			       IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX, | 
					
						
							|  |  |  | 			       txq->next); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:02:10 -04:00
										 |  |  |  * ipw2100_tx_send_data | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2005-08-25 20:02:10 -04:00
										 |  |  | static void ipw2100_tx_send_data(struct ipw2100_priv *priv) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct list_head *element; | 
					
						
							|  |  |  | 	struct ipw2100_tx_packet *packet; | 
					
						
							|  |  |  | 	struct ipw2100_bd_queue *txq = &priv->tx_queue; | 
					
						
							|  |  |  | 	struct ipw2100_bd *tbd; | 
					
						
							|  |  |  | 	int next = txq->next; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	int i = 0; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	struct ipw2100_data_header *ipw_hdr; | 
					
						
							| 
									
										
										
										
											2005-09-21 12:23:25 -05:00
										 |  |  | 	struct ieee80211_hdr_3addr *hdr; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	while (!list_empty(&priv->tx_pend_list)) { | 
					
						
							|  |  |  | 		/* if there isn't enough space in TBD queue, then
 | 
					
						
							|  |  |  | 		 * don't stuff a new one in. | 
					
						
							|  |  |  | 		 * NOTE: 4 are needed as a data will take two, | 
					
						
							|  |  |  | 		 *       and there is a minimum of 2 that must be | 
					
						
							|  |  |  | 		 *       maintained between the r and w indexes | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		element = priv->tx_pend_list.next; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		packet = list_entry(element, struct ipw2100_tx_packet, list); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (unlikely(1 + packet->info.d_struct.txb->nr_frags > | 
					
						
							|  |  |  | 			     IPW_MAX_BDS)) { | 
					
						
							|  |  |  | 			/* TODO: Support merging buffers if more than
 | 
					
						
							|  |  |  | 			 * IPW_MAX_BDS are used */ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			IPW_DEBUG_INFO("%s: Maximum BD theshold exceeded.  " | 
					
						
							|  |  |  | 				       "Increase fragmentation level.\n", | 
					
						
							|  |  |  | 				       priv->net_dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		if (txq->available <= 3 + packet->info.d_struct.txb->nr_frags) { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			IPW_DEBUG_TX("no room in tx_queue\n"); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		list_del(element); | 
					
						
							|  |  |  | 		DEC_STAT(&priv->tx_pend_stat); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		tbd = &txq->drv[txq->next]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		packet->index = txq->next; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ipw_hdr = packet->info.d_struct.data; | 
					
						
							| 
									
										
										
										
											2005-09-21 12:23:25 -05:00
										 |  |  | 		hdr = (struct ieee80211_hdr_3addr *)packet->info.d_struct.txb-> | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		    fragments[0]->data; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (priv->ieee->iw_mode == IW_MODE_INFRA) { | 
					
						
							|  |  |  | 			/* To DS: Addr1 = BSSID, Addr2 = SA,
 | 
					
						
							|  |  |  | 			   Addr3 = DA */ | 
					
						
							|  |  |  | 			memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN); | 
					
						
							|  |  |  | 			memcpy(ipw_hdr->dst_addr, hdr->addr3, ETH_ALEN); | 
					
						
							|  |  |  | 		} else if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | 
					
						
							|  |  |  | 			/* not From/To DS: Addr1 = DA, Addr2 = SA,
 | 
					
						
							|  |  |  | 			   Addr3 = BSSID */ | 
					
						
							|  |  |  | 			memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN); | 
					
						
							|  |  |  | 			memcpy(ipw_hdr->dst_addr, hdr->addr1, ETH_ALEN); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ipw_hdr->host_command_reg = SEND; | 
					
						
							|  |  |  | 		ipw_hdr->host_command_reg1 = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* For now we only support host based encryption */ | 
					
						
							|  |  |  | 		ipw_hdr->needs_encryption = 0; | 
					
						
							|  |  |  | 		ipw_hdr->encrypted = packet->info.d_struct.txb->encrypted; | 
					
						
							|  |  |  | 		if (packet->info.d_struct.txb->nr_frags > 1) | 
					
						
							|  |  |  | 			ipw_hdr->fragment_size = | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			    packet->info.d_struct.txb->frag_size - | 
					
						
							|  |  |  | 			    IEEE80211_3ADDR_LEN; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		else | 
					
						
							|  |  |  | 			ipw_hdr->fragment_size = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		tbd->host_addr = packet->info.d_struct.data_phys; | 
					
						
							|  |  |  | 		tbd->buf_length = sizeof(struct ipw2100_data_header); | 
					
						
							|  |  |  | 		tbd->num_fragments = 1 + packet->info.d_struct.txb->nr_frags; | 
					
						
							|  |  |  | 		tbd->status.info.field = | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		    IPW_BD_STATUS_TX_FRAME_802_3 | | 
					
						
							|  |  |  | 		    IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		txq->next++; | 
					
						
							|  |  |  | 		txq->next %= txq->entries; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		IPW_DEBUG_TX("data header tbd TX%d P=%08x L=%d\n", | 
					
						
							|  |  |  | 			     packet->index, tbd->host_addr, tbd->buf_length); | 
					
						
							| 
									
										
										
										
											2005-12-01 01:41:46 -08:00
										 |  |  | #ifdef CONFIG_IPW2100_DEBUG
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		if (packet->info.d_struct.txb->nr_frags > 1) | 
					
						
							|  |  |  | 			IPW_DEBUG_FRAG("fragment Tx: %d frames\n", | 
					
						
							|  |  |  | 				       packet->info.d_struct.txb->nr_frags); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		for (i = 0; i < packet->info.d_struct.txb->nr_frags; i++) { | 
					
						
							|  |  |  | 			tbd = &txq->drv[txq->next]; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			if (i == packet->info.d_struct.txb->nr_frags - 1) | 
					
						
							|  |  |  | 				tbd->status.info.field = | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 				    IPW_BD_STATUS_TX_FRAME_802_3 | | 
					
						
							|  |  |  | 				    IPW_BD_STATUS_TX_INTERRUPT_ENABLE; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			else | 
					
						
							|  |  |  | 				tbd->status.info.field = | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 				    IPW_BD_STATUS_TX_FRAME_802_3 | | 
					
						
							|  |  |  | 				    IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			tbd->buf_length = packet->info.d_struct.txb-> | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			    fragments[i]->len - IEEE80211_3ADDR_LEN; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			tbd->host_addr = pci_map_single(priv->pci_dev, | 
					
						
							|  |  |  | 							packet->info.d_struct. | 
					
						
							|  |  |  | 							txb->fragments[i]-> | 
					
						
							|  |  |  | 							data + | 
					
						
							|  |  |  | 							IEEE80211_3ADDR_LEN, | 
					
						
							|  |  |  | 							tbd->buf_length, | 
					
						
							|  |  |  | 							PCI_DMA_TODEVICE); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			IPW_DEBUG_TX("data frag tbd TX%d P=%08x L=%d\n", | 
					
						
							|  |  |  | 				     txq->next, tbd->host_addr, | 
					
						
							|  |  |  | 				     tbd->buf_length); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			pci_dma_sync_single_for_device(priv->pci_dev, | 
					
						
							|  |  |  | 						       tbd->host_addr, | 
					
						
							|  |  |  | 						       tbd->buf_length, | 
					
						
							|  |  |  | 						       PCI_DMA_TODEVICE); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			txq->next++; | 
					
						
							|  |  |  | 			txq->next %= txq->entries; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		txq->available -= 1 + packet->info.d_struct.txb->nr_frags; | 
					
						
							|  |  |  | 		SET_STAT(&priv->txq_stat, txq->available); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		list_add_tail(element, &priv->fw_pend_list); | 
					
						
							|  |  |  | 		INC_STAT(&priv->fw_pend_stat); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (txq->next != next) { | 
					
						
							|  |  |  | 		/* kick off the DMA by notifying firmware the
 | 
					
						
							|  |  |  | 		 * write index has moved; make sure TBD stores are sync'd */ | 
					
						
							|  |  |  | 		write_register(priv->net_dev, | 
					
						
							|  |  |  | 			       IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX, | 
					
						
							|  |  |  | 			       txq->next); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	return; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ipw2100_irq_tasklet(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct net_device *dev = priv->net_dev; | 
					
						
							|  |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 	u32 inta, tmp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&priv->low_lock, flags); | 
					
						
							|  |  |  | 	ipw2100_disable_interrupts(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	read_register(dev, IPW_REG_INTA, &inta); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_ISR("enter - INTA: 0x%08lX\n", | 
					
						
							|  |  |  | 		      (unsigned long)inta & IPW_INTERRUPT_MASK); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->in_isr++; | 
					
						
							|  |  |  | 	priv->interrupts++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* We do not loop and keep polling for more interrupts as this
 | 
					
						
							|  |  |  | 	 * is frowned upon and doesn't play nicely with other potentially | 
					
						
							|  |  |  | 	 * chained IRQs */ | 
					
						
							|  |  |  | 	IPW_DEBUG_ISR("INTA: 0x%08lX\n", | 
					
						
							|  |  |  | 		      (unsigned long)inta & IPW_INTERRUPT_MASK); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (inta & IPW2100_INTA_FATAL_ERROR) { | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 		printk(KERN_WARNING DRV_NAME | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		       ": Fatal interrupt. Scheduling firmware restart.\n"); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		priv->inta_other++; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		write_register(dev, IPW_REG_INTA, IPW2100_INTA_FATAL_ERROR); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		read_nic_dword(dev, IPW_NIC_FATAL_ERROR, &priv->fatal_error); | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("%s: Fatal error value: 0x%08X\n", | 
					
						
							|  |  |  | 			       priv->net_dev->name, priv->fatal_error); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		read_nic_dword(dev, IPW_ERROR_ADDR(priv->fatal_error), &tmp); | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("%s: Fatal error address value: 0x%08X\n", | 
					
						
							|  |  |  | 			       priv->net_dev->name, tmp); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Wake up any sleeping jobs */ | 
					
						
							|  |  |  | 		schedule_reset(priv); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (inta & IPW2100_INTA_PARITY_ERROR) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		printk(KERN_ERR DRV_NAME | 
					
						
							|  |  |  | 		       ": ***** PARITY ERROR INTERRUPT !!!! \n"); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		priv->inta_other++; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		write_register(dev, IPW_REG_INTA, IPW2100_INTA_PARITY_ERROR); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (inta & IPW2100_INTA_RX_TRANSFER) { | 
					
						
							|  |  |  | 		IPW_DEBUG_ISR("RX interrupt\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		priv->rx_interrupts++; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		write_register(dev, IPW_REG_INTA, IPW2100_INTA_RX_TRANSFER); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		__ipw2100_rx_process(priv); | 
					
						
							|  |  |  | 		__ipw2100_tx_complete(priv); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (inta & IPW2100_INTA_TX_TRANSFER) { | 
					
						
							|  |  |  | 		IPW_DEBUG_ISR("TX interrupt\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		priv->tx_interrupts++; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		write_register(dev, IPW_REG_INTA, IPW2100_INTA_TX_TRANSFER); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		__ipw2100_tx_complete(priv); | 
					
						
							| 
									
										
										
										
											2005-08-25 20:02:10 -04:00
										 |  |  | 		ipw2100_tx_send_commands(priv); | 
					
						
							|  |  |  | 		ipw2100_tx_send_data(priv); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (inta & IPW2100_INTA_TX_COMPLETE) { | 
					
						
							|  |  |  | 		IPW_DEBUG_ISR("TX complete\n"); | 
					
						
							|  |  |  | 		priv->inta_other++; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		write_register(dev, IPW_REG_INTA, IPW2100_INTA_TX_COMPLETE); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		__ipw2100_tx_complete(priv); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (inta & IPW2100_INTA_EVENT_INTERRUPT) { | 
					
						
							|  |  |  | 		/* ipw2100_handle_event(dev); */ | 
					
						
							|  |  |  | 		priv->inta_other++; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		write_register(dev, IPW_REG_INTA, IPW2100_INTA_EVENT_INTERRUPT); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (inta & IPW2100_INTA_FW_INIT_DONE) { | 
					
						
							|  |  |  | 		IPW_DEBUG_ISR("FW init done interrupt\n"); | 
					
						
							|  |  |  | 		priv->inta_other++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		read_register(dev, IPW_REG_INTA, &tmp); | 
					
						
							|  |  |  | 		if (tmp & (IPW2100_INTA_FATAL_ERROR | | 
					
						
							|  |  |  | 			   IPW2100_INTA_PARITY_ERROR)) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			write_register(dev, IPW_REG_INTA, | 
					
						
							|  |  |  | 				       IPW2100_INTA_FATAL_ERROR | | 
					
						
							|  |  |  | 				       IPW2100_INTA_PARITY_ERROR); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		write_register(dev, IPW_REG_INTA, IPW2100_INTA_FW_INIT_DONE); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (inta & IPW2100_INTA_STATUS_CHANGE) { | 
					
						
							|  |  |  | 		IPW_DEBUG_ISR("Status change interrupt\n"); | 
					
						
							|  |  |  | 		priv->inta_other++; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		write_register(dev, IPW_REG_INTA, IPW2100_INTA_STATUS_CHANGE); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (inta & IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE) { | 
					
						
							|  |  |  | 		IPW_DEBUG_ISR("slave host mode interrupt\n"); | 
					
						
							|  |  |  | 		priv->inta_other++; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		write_register(dev, IPW_REG_INTA, | 
					
						
							|  |  |  | 			       IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->in_isr--; | 
					
						
							|  |  |  | 	ipw2100_enable_interrupts(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&priv->low_lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_ISR("exit\n"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static irqreturn_t ipw2100_interrupt(int irq, void *data, struct pt_regs *regs) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = data; | 
					
						
							|  |  |  | 	u32 inta, inta_mask; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!data) | 
					
						
							|  |  |  | 		return IRQ_NONE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	spin_lock(&priv->low_lock); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* We check to see if we should be ignoring interrupts before
 | 
					
						
							|  |  |  | 	 * we touch the hardware.  During ucode load if we try and handle | 
					
						
							|  |  |  | 	 * an interrupt we can cause keyboard problems as well as cause | 
					
						
							|  |  |  | 	 * the ucode to fail to initialize */ | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_INT_ENABLED)) { | 
					
						
							|  |  |  | 		/* Shared IRQ */ | 
					
						
							|  |  |  | 		goto none; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask); | 
					
						
							|  |  |  | 	read_register(priv->net_dev, IPW_REG_INTA, &inta); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (inta == 0xFFFFFFFF) { | 
					
						
							|  |  |  | 		/* Hardware disappeared */ | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 		printk(KERN_WARNING DRV_NAME ": IRQ INTA == 0xFFFFFFFF\n"); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		goto none; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	inta &= IPW_INTERRUPT_MASK; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(inta & inta_mask)) { | 
					
						
							|  |  |  | 		/* Shared interrupt */ | 
					
						
							|  |  |  | 		goto none; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* We disable the hardware interrupt here just to prevent unneeded
 | 
					
						
							|  |  |  | 	 * calls to be made.  We disable this again within the actual | 
					
						
							|  |  |  | 	 * work tasklet, so if another part of the code re-enables the | 
					
						
							|  |  |  | 	 * interrupt, that is fine */ | 
					
						
							|  |  |  | 	ipw2100_disable_interrupts(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tasklet_schedule(&priv->irq_tasklet); | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	spin_unlock(&priv->low_lock); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return IRQ_HANDLED; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       none: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	spin_unlock(&priv->low_lock); | 
					
						
							|  |  |  | 	return IRQ_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-21 12:23:37 -05:00
										 |  |  | static int ipw2100_tx(struct ieee80211_txb *txb, struct net_device *dev, | 
					
						
							|  |  |  | 		      int pri) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	struct list_head *element; | 
					
						
							|  |  |  | 	struct ipw2100_tx_packet *packet; | 
					
						
							|  |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&priv->low_lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_ASSOCIATED)) { | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("Can not transmit when not connected.\n"); | 
					
						
							|  |  |  | 		priv->ieee->stats.tx_carrier_errors++; | 
					
						
							|  |  |  | 		netif_stop_queue(dev); | 
					
						
							|  |  |  | 		goto fail_unlock; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (list_empty(&priv->tx_free_list)) | 
					
						
							|  |  |  | 		goto fail_unlock; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	element = priv->tx_free_list.next; | 
					
						
							|  |  |  | 	packet = list_entry(element, struct ipw2100_tx_packet, list); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	packet->info.d_struct.txb = txb; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	IPW_DEBUG_TX("Sending fragment (%d bytes):\n", txb->fragments[0]->len); | 
					
						
							|  |  |  | 	printk_buf(IPW_DL_TX, txb->fragments[0]->data, txb->fragments[0]->len); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	packet->jiffy_start = jiffies; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	list_del(element); | 
					
						
							|  |  |  | 	DEC_STAT(&priv->tx_free_stat); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	list_add_tail(element, &priv->tx_pend_list); | 
					
						
							|  |  |  | 	INC_STAT(&priv->tx_pend_stat); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:02:10 -04:00
										 |  |  | 	ipw2100_tx_send_data(priv); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&priv->low_lock, flags); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       fail_unlock: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	netif_stop_queue(dev); | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&priv->low_lock, flags); | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_msg_allocate(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i, j, err = -EINVAL; | 
					
						
							|  |  |  | 	void *v; | 
					
						
							|  |  |  | 	dma_addr_t p; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	priv->msg_buffers = | 
					
						
							|  |  |  | 	    (struct ipw2100_tx_packet *)kmalloc(IPW_COMMAND_POOL_SIZE * | 
					
						
							|  |  |  | 						sizeof(struct | 
					
						
							|  |  |  | 						       ipw2100_tx_packet), | 
					
						
							|  |  |  | 						GFP_KERNEL); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	if (!priv->msg_buffers) { | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 		printk(KERN_ERR DRV_NAME ": %s: PCI alloc failed for msg " | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		       "buffers.\n", priv->net_dev->name); | 
					
						
							|  |  |  | 		return -ENOMEM; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		v = pci_alloc_consistent(priv->pci_dev, | 
					
						
							|  |  |  | 					 sizeof(struct ipw2100_cmd_header), &p); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		if (!v) { | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 			printk(KERN_ERR DRV_NAME ": " | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			       "%s: PCI alloc failed for msg " | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			       "buffers.\n", priv->net_dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			err = -ENOMEM; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		memset(v, 0, sizeof(struct ipw2100_cmd_header)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		priv->msg_buffers[i].type = COMMAND; | 
					
						
							|  |  |  | 		priv->msg_buffers[i].info.c_struct.cmd = | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		    (struct ipw2100_cmd_header *)v; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		priv->msg_buffers[i].info.c_struct.cmd_phys = p; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (i == IPW_COMMAND_POOL_SIZE) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (j = 0; j < i; j++) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		pci_free_consistent(priv->pci_dev, | 
					
						
							|  |  |  | 				    sizeof(struct ipw2100_cmd_header), | 
					
						
							|  |  |  | 				    priv->msg_buffers[j].info.c_struct.cmd, | 
					
						
							|  |  |  | 				    priv->msg_buffers[j].info.c_struct. | 
					
						
							|  |  |  | 				    cmd_phys); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	kfree(priv->msg_buffers); | 
					
						
							|  |  |  | 	priv->msg_buffers = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_msg_initialize(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	INIT_LIST_HEAD(&priv->msg_free_list); | 
					
						
							|  |  |  | 	INIT_LIST_HEAD(&priv->msg_pend_list); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) | 
					
						
							|  |  |  | 		list_add_tail(&priv->msg_buffers[i].list, &priv->msg_free_list); | 
					
						
							|  |  |  | 	SET_STAT(&priv->msg_free_stat, i); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ipw2100_msg_free(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!priv->msg_buffers) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) { | 
					
						
							|  |  |  | 		pci_free_consistent(priv->pci_dev, | 
					
						
							|  |  |  | 				    sizeof(struct ipw2100_cmd_header), | 
					
						
							|  |  |  | 				    priv->msg_buffers[i].info.c_struct.cmd, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 				    priv->msg_buffers[i].info.c_struct. | 
					
						
							|  |  |  | 				    cmd_phys); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	kfree(priv->msg_buffers); | 
					
						
							|  |  |  | 	priv->msg_buffers = NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-20 14:30:35 -07:00
										 |  |  | static ssize_t show_pci(struct device *d, struct device_attribute *attr, | 
					
						
							|  |  |  | 			char *buf) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct pci_dev *pci_dev = container_of(d, struct pci_dev, dev); | 
					
						
							|  |  |  | 	char *out = buf; | 
					
						
							|  |  |  | 	int i, j; | 
					
						
							|  |  |  | 	u32 val; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < 16; i++) { | 
					
						
							|  |  |  | 		out += sprintf(out, "[%08X] ", i * 16); | 
					
						
							|  |  |  | 		for (j = 0; j < 16; j += 4) { | 
					
						
							|  |  |  | 			pci_read_config_dword(pci_dev, i * 16 + j, &val); | 
					
						
							|  |  |  | 			out += sprintf(out, "%08X ", val); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		out += sprintf(out, "\n"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return out - buf; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | static DEVICE_ATTR(pci, S_IRUGO, show_pci, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-20 14:30:35 -07:00
										 |  |  | static ssize_t show_cfg(struct device *d, struct device_attribute *attr, | 
					
						
							|  |  |  | 			char *buf) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-06-20 14:30:35 -07:00
										 |  |  | 	struct ipw2100_priv *p = d->driver_data; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	return sprintf(buf, "0x%08x\n", (int)p->config); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-20 14:30:35 -07:00
										 |  |  | static ssize_t show_status(struct device *d, struct device_attribute *attr, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			   char *buf) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-06-20 14:30:35 -07:00
										 |  |  | 	struct ipw2100_priv *p = d->driver_data; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	return sprintf(buf, "0x%08x\n", (int)p->status); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-20 14:30:35 -07:00
										 |  |  | static ssize_t show_capability(struct device *d, struct device_attribute *attr, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			       char *buf) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-06-20 14:30:35 -07:00
										 |  |  | 	struct ipw2100_priv *p = d->driver_data; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	return sprintf(buf, "0x%08x\n", (int)p->capability); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static DEVICE_ATTR(capability, S_IRUGO, show_capability, NULL); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define IPW2100_REG(x) { IPW_ ##x, #x }
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static const struct { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	u32 addr; | 
					
						
							|  |  |  | 	const char *name; | 
					
						
							|  |  |  | } hw_data[] = { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | IPW2100_REG(REG_GP_CNTRL), | 
					
						
							|  |  |  | 	    IPW2100_REG(REG_GPIO), | 
					
						
							|  |  |  | 	    IPW2100_REG(REG_INTA), | 
					
						
							|  |  |  | 	    IPW2100_REG(REG_INTA_MASK), IPW2100_REG(REG_RESET_REG),}; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | #define IPW2100_NIC(x, s) { x, #x, s }
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static const struct { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	u32 addr; | 
					
						
							|  |  |  | 	const char *name; | 
					
						
							|  |  |  | 	size_t size; | 
					
						
							|  |  |  | } nic_data[] = { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | IPW2100_NIC(IPW2100_CONTROL_REG, 2), | 
					
						
							|  |  |  | 	    IPW2100_NIC(0x210014, 1), IPW2100_NIC(0x210000, 1),}; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | #define IPW2100_ORD(x, d) { IPW_ORD_ ##x, #x, d }
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static const struct { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	u8 index; | 
					
						
							|  |  |  | 	const char *name; | 
					
						
							|  |  |  | 	const char *desc; | 
					
						
							|  |  |  | } ord_data[] = { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | IPW2100_ORD(STAT_TX_HOST_REQUESTS, "requested Host Tx's (MSDU)"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_HOST_COMPLETE, | 
					
						
							|  |  |  | 				"successful Host Tx's (MSDU)"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_DIR_DATA, | 
					
						
							|  |  |  | 				"successful Directed Tx's (MSDU)"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_DIR_DATA1, | 
					
						
							|  |  |  | 				"successful Directed Tx's (MSDU) @ 1MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_DIR_DATA2, | 
					
						
							|  |  |  | 				"successful Directed Tx's (MSDU) @ 2MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_DIR_DATA5_5, | 
					
						
							|  |  |  | 				"successful Directed Tx's (MSDU) @ 5_5MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_DIR_DATA11, | 
					
						
							|  |  |  | 				"successful Directed Tx's (MSDU) @ 11MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_NODIR_DATA1, | 
					
						
							|  |  |  | 				"successful Non_Directed Tx's (MSDU) @ 1MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_NODIR_DATA2, | 
					
						
							|  |  |  | 				"successful Non_Directed Tx's (MSDU) @ 2MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_NODIR_DATA5_5, | 
					
						
							|  |  |  | 				"successful Non_Directed Tx's (MSDU) @ 5.5MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_NODIR_DATA11, | 
					
						
							|  |  |  | 				"successful Non_Directed Tx's (MSDU) @ 11MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_NULL_DATA, "successful NULL data Tx's"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_RTS, "successful Tx RTS"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_CTS, "successful Tx CTS"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_ACK, "successful Tx ACK"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_ASSN, "successful Association Tx's"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_ASSN_RESP, | 
					
						
							|  |  |  | 				"successful Association response Tx's"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_REASSN, | 
					
						
							|  |  |  | 				"successful Reassociation Tx's"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_REASSN_RESP, | 
					
						
							|  |  |  | 				"successful Reassociation response Tx's"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_PROBE, | 
					
						
							|  |  |  | 				"probes successfully transmitted"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_PROBE_RESP, | 
					
						
							|  |  |  | 				"probe responses successfully transmitted"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_BEACON, "tx beacon"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_ATIM, "Tx ATIM"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_DISASSN, | 
					
						
							|  |  |  | 				"successful Disassociation TX"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_AUTH, "successful Authentication Tx"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_DEAUTH, | 
					
						
							|  |  |  | 				"successful Deauthentication TX"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_TOTAL_BYTES, | 
					
						
							|  |  |  | 				"Total successful Tx data bytes"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_RETRIES, "Tx retries"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_RETRY1, "Tx retries at 1MBPS"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_RETRY2, "Tx retries at 2MBPS"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_RETRY5_5, "Tx retries at 5.5MBPS"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_RETRY11, "Tx retries at 11MBPS"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_FAILURES, "Tx Failures"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_MAX_TRIES_IN_HOP, | 
					
						
							|  |  |  | 				"times max tries in a hop failed"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_DISASSN_FAIL, | 
					
						
							|  |  |  | 				"times disassociation failed"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_ERR_CTS, "missed/bad CTS frames"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_TX_ERR_ACK, "tx err due to acks"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_HOST, "packets passed to host"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_DIR_DATA, "directed packets"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_DIR_DATA1, "directed packets at 1MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_DIR_DATA2, "directed packets at 2MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_DIR_DATA5_5, | 
					
						
							|  |  |  | 				"directed packets at 5.5MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_DIR_DATA11, "directed packets at 11MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_NODIR_DATA, "nondirected packets"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_NODIR_DATA1, | 
					
						
							|  |  |  | 				"nondirected packets at 1MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_NODIR_DATA2, | 
					
						
							|  |  |  | 				"nondirected packets at 2MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_NODIR_DATA5_5, | 
					
						
							|  |  |  | 				"nondirected packets at 5.5MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_NODIR_DATA11, | 
					
						
							|  |  |  | 				"nondirected packets at 11MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_NULL_DATA, "null data rx's"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_RTS, "Rx RTS"), IPW2100_ORD(STAT_RX_CTS, | 
					
						
							|  |  |  | 								    "Rx CTS"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_ACK, "Rx ACK"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_CFEND, "Rx CF End"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_CFEND_ACK, "Rx CF End + CF Ack"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_ASSN, "Association Rx's"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_ASSN_RESP, "Association response Rx's"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_REASSN, "Reassociation Rx's"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_REASSN_RESP, | 
					
						
							|  |  |  | 				"Reassociation response Rx's"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_PROBE, "probe Rx's"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_PROBE_RESP, "probe response Rx's"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_BEACON, "Rx beacon"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_ATIM, "Rx ATIM"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_DISASSN, "disassociation Rx"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_AUTH, "authentication Rx"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_DEAUTH, "deauthentication Rx"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_TOTAL_BYTES, | 
					
						
							|  |  |  | 				"Total rx data bytes received"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_ERR_CRC, "packets with Rx CRC error"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_ERR_CRC1, "Rx CRC errors at 1MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_ERR_CRC2, "Rx CRC errors at 2MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_ERR_CRC5_5, "Rx CRC errors at 5.5MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_ERR_CRC11, "Rx CRC errors at 11MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_DUPLICATE1, | 
					
						
							|  |  |  | 				"duplicate rx packets at 1MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_DUPLICATE2, | 
					
						
							|  |  |  | 				"duplicate rx packets at 2MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_DUPLICATE5_5, | 
					
						
							|  |  |  | 				"duplicate rx packets at 5.5MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_DUPLICATE11, | 
					
						
							|  |  |  | 				"duplicate rx packets at 11MB"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_DUPLICATE, "duplicate rx packets"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(PERS_DB_LOCK, "locking fw permanent  db"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(PERS_DB_SIZE, "size of fw permanent  db"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(PERS_DB_ADDR, "address of fw permanent  db"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_INVALID_PROTOCOL, | 
					
						
							|  |  |  | 				"rx frames with invalid protocol"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(SYS_BOOT_TIME, "Boot time"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_NO_BUFFER, | 
					
						
							|  |  |  | 				"rx frames rejected due to no buffer"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_MISSING_FRAG, | 
					
						
							|  |  |  | 				"rx frames dropped due to missing fragment"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_ORPHAN_FRAG, | 
					
						
							|  |  |  | 				"rx frames dropped due to non-sequential fragment"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_ORPHAN_FRAME, | 
					
						
							|  |  |  | 				"rx frames dropped due to unmatched 1st frame"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_FRAG_AGEOUT, | 
					
						
							|  |  |  | 				"rx frames dropped due to uncompleted frame"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_RX_ICV_ERRORS, | 
					
						
							|  |  |  | 				"ICV errors during decryption"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_PSP_SUSPENSION, "times adapter suspended"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_PSP_BCN_TIMEOUT, "beacon timeout"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_PSP_POLL_TIMEOUT, | 
					
						
							|  |  |  | 				"poll response timeouts"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_PSP_NONDIR_TIMEOUT, | 
					
						
							|  |  |  | 				"timeouts waiting for last {broad,multi}cast pkt"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_PSP_RX_DTIMS, "PSP DTIMs received"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_PSP_RX_TIMS, "PSP TIMs received"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_PSP_STATION_ID, "PSP Station ID"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(LAST_ASSN_TIME, "RTC time of last association"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_PERCENT_MISSED_BCNS, | 
					
						
							|  |  |  | 				"current calculation of % missed beacons"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_PERCENT_RETRIES, | 
					
						
							|  |  |  | 				"current calculation of % missed tx retries"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(ASSOCIATED_AP_PTR, | 
					
						
							|  |  |  | 				"0 if not associated, else pointer to AP table entry"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(AVAILABLE_AP_CNT, | 
					
						
							|  |  |  | 				"AP's decsribed in the AP table"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(AP_LIST_PTR, "Ptr to list of available APs"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_AP_ASSNS, "associations"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_ASSN_FAIL, "association failures"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_ASSN_RESP_FAIL, | 
					
						
							|  |  |  | 				"failures due to response fail"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_FULL_SCANS, "full scans"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(CARD_DISABLED, "Card Disabled"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_ROAM_INHIBIT, | 
					
						
							|  |  |  | 				"times roaming was inhibited due to activity"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(RSSI_AT_ASSN, | 
					
						
							|  |  |  | 				"RSSI of associated AP at time of association"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_ASSN_CAUSE1, | 
					
						
							|  |  |  | 				"reassociation: no probe response or TX on hop"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_ASSN_CAUSE2, | 
					
						
							|  |  |  | 				"reassociation: poor tx/rx quality"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_ASSN_CAUSE3, | 
					
						
							|  |  |  | 				"reassociation: tx/rx quality (excessive AP load"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_ASSN_CAUSE4, | 
					
						
							|  |  |  | 				"reassociation: AP RSSI level"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_ASSN_CAUSE5, | 
					
						
							|  |  |  | 				"reassociations due to load leveling"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_AUTH_FAIL, "times authentication failed"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STAT_AUTH_RESP_FAIL, | 
					
						
							|  |  |  | 				"times authentication response failed"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(STATION_TABLE_CNT, | 
					
						
							|  |  |  | 				"entries in association table"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(RSSI_AVG_CURR, "Current avg RSSI"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(POWER_MGMT_MODE, "Power mode - 0=CAM, 1=PSP"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(COUNTRY_CODE, | 
					
						
							|  |  |  | 				"IEEE country code as recv'd from beacon"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(COUNTRY_CHANNELS, | 
					
						
							|  |  |  | 				"channels suported by country"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(RESET_CNT, "adapter resets (warm)"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(BEACON_INTERVAL, "Beacon interval"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(ANTENNA_DIVERSITY, | 
					
						
							|  |  |  | 				"TRUE if antenna diversity is disabled"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(DTIM_PERIOD, "beacon intervals between DTIMs"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(OUR_FREQ, | 
					
						
							|  |  |  | 				"current radio freq lower digits - channel ID"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(RTC_TIME, "current RTC time"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(PORT_TYPE, "operating mode"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(CURRENT_TX_RATE, "current tx rate"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(SUPPORTED_RATES, "supported tx rates"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(ATIM_WINDOW, "current ATIM Window"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(BASIC_RATES, "basic tx rates"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(NIC_HIGHEST_RATE, "NIC highest tx rate"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(AP_HIGHEST_RATE, "AP highest tx rate"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(CAPABILITIES, | 
					
						
							|  |  |  | 				"Management frame capability field"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(AUTH_TYPE, "Type of authentication"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(RADIO_TYPE, "Adapter card platform type"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(RTS_THRESHOLD, | 
					
						
							|  |  |  | 				"Min packet length for RTS handshaking"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(INT_MODE, "International mode"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(FRAGMENTATION_THRESHOLD, | 
					
						
							|  |  |  | 				"protocol frag threshold"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_START_ADDRESS, | 
					
						
							|  |  |  | 				"EEPROM offset in SRAM"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_SIZE, | 
					
						
							|  |  |  | 				"EEPROM size in SRAM"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(EEPROM_SKU_CAPABILITY, "EEPROM SKU Capability"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(EEPROM_IBSS_11B_CHANNELS, | 
					
						
							|  |  |  | 				"EEPROM IBSS 11b channel set"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(MAC_VERSION, "MAC Version"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(MAC_REVISION, "MAC Revision"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(RADIO_VERSION, "Radio Version"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(NIC_MANF_DATE_TIME, "MANF Date/Time STAMP"), | 
					
						
							|  |  |  | 	    IPW2100_ORD(UCODE_VERSION, "Ucode Version"),}; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-20 14:30:35 -07:00
										 |  |  | static ssize_t show_registers(struct device *d, struct device_attribute *attr, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			      char *buf) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = dev_get_drvdata(d); | 
					
						
							|  |  |  | 	struct net_device *dev = priv->net_dev; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	char *out = buf; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	u32 val = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out += sprintf(out, "%30s [Address ] : Hex\n", "Register"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < (sizeof(hw_data) / sizeof(*hw_data)); i++) { | 
					
						
							|  |  |  | 		read_register(dev, hw_data[i].addr, &val); | 
					
						
							|  |  |  | 		out += sprintf(out, "%30s [%08X] : %08X\n", | 
					
						
							|  |  |  | 			       hw_data[i].name, hw_data[i].addr, val); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return out - buf; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-20 14:30:35 -07:00
										 |  |  | static ssize_t show_hardware(struct device *d, struct device_attribute *attr, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			     char *buf) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = dev_get_drvdata(d); | 
					
						
							|  |  |  | 	struct net_device *dev = priv->net_dev; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	char *out = buf; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out += sprintf(out, "%30s [Address ] : Hex\n", "NIC entry"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < (sizeof(nic_data) / sizeof(*nic_data)); i++) { | 
					
						
							|  |  |  | 		u8 tmp8; | 
					
						
							|  |  |  | 		u16 tmp16; | 
					
						
							|  |  |  | 		u32 tmp32; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		switch (nic_data[i].size) { | 
					
						
							|  |  |  | 		case 1: | 
					
						
							|  |  |  | 			read_nic_byte(dev, nic_data[i].addr, &tmp8); | 
					
						
							|  |  |  | 			out += sprintf(out, "%30s [%08X] : %02X\n", | 
					
						
							|  |  |  | 				       nic_data[i].name, nic_data[i].addr, | 
					
						
							|  |  |  | 				       tmp8); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 2: | 
					
						
							|  |  |  | 			read_nic_word(dev, nic_data[i].addr, &tmp16); | 
					
						
							|  |  |  | 			out += sprintf(out, "%30s [%08X] : %04X\n", | 
					
						
							|  |  |  | 				       nic_data[i].name, nic_data[i].addr, | 
					
						
							|  |  |  | 				       tmp16); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 4: | 
					
						
							|  |  |  | 			read_nic_dword(dev, nic_data[i].addr, &tmp32); | 
					
						
							|  |  |  | 			out += sprintf(out, "%30s [%08X] : %08X\n", | 
					
						
							|  |  |  | 				       nic_data[i].name, nic_data[i].addr, | 
					
						
							|  |  |  | 				       tmp32); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return out - buf; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static DEVICE_ATTR(hardware, S_IRUGO, show_hardware, NULL); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-20 14:30:35 -07:00
										 |  |  | static ssize_t show_memory(struct device *d, struct device_attribute *attr, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			   char *buf) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = dev_get_drvdata(d); | 
					
						
							|  |  |  | 	struct net_device *dev = priv->net_dev; | 
					
						
							|  |  |  | 	static unsigned long loop = 0; | 
					
						
							|  |  |  | 	int len = 0; | 
					
						
							|  |  |  | 	u32 buffer[4]; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	char line[81]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (loop >= 0x30000) | 
					
						
							|  |  |  | 		loop = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* sysfs provides us PAGE_SIZE buffer */ | 
					
						
							|  |  |  | 	while (len < PAGE_SIZE - 128 && loop < 0x30000) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		if (priv->snapshot[0]) | 
					
						
							|  |  |  | 			for (i = 0; i < 4; i++) | 
					
						
							|  |  |  | 				buffer[i] = | 
					
						
							|  |  |  | 				    *(u32 *) SNAPSHOT_ADDR(loop + i * 4); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			for (i = 0; i < 4; i++) | 
					
						
							|  |  |  | 				read_nic_dword(dev, loop + i * 4, &buffer[i]); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (priv->dump_raw) | 
					
						
							|  |  |  | 			len += sprintf(buf + len, | 
					
						
							|  |  |  | 				       "%c%c%c%c" | 
					
						
							|  |  |  | 				       "%c%c%c%c" | 
					
						
							|  |  |  | 				       "%c%c%c%c" | 
					
						
							|  |  |  | 				       "%c%c%c%c", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 				       ((u8 *) buffer)[0x0], | 
					
						
							|  |  |  | 				       ((u8 *) buffer)[0x1], | 
					
						
							|  |  |  | 				       ((u8 *) buffer)[0x2], | 
					
						
							|  |  |  | 				       ((u8 *) buffer)[0x3], | 
					
						
							|  |  |  | 				       ((u8 *) buffer)[0x4], | 
					
						
							|  |  |  | 				       ((u8 *) buffer)[0x5], | 
					
						
							|  |  |  | 				       ((u8 *) buffer)[0x6], | 
					
						
							|  |  |  | 				       ((u8 *) buffer)[0x7], | 
					
						
							|  |  |  | 				       ((u8 *) buffer)[0x8], | 
					
						
							|  |  |  | 				       ((u8 *) buffer)[0x9], | 
					
						
							|  |  |  | 				       ((u8 *) buffer)[0xa], | 
					
						
							|  |  |  | 				       ((u8 *) buffer)[0xb], | 
					
						
							|  |  |  | 				       ((u8 *) buffer)[0xc], | 
					
						
							|  |  |  | 				       ((u8 *) buffer)[0xd], | 
					
						
							|  |  |  | 				       ((u8 *) buffer)[0xe], | 
					
						
							|  |  |  | 				       ((u8 *) buffer)[0xf]); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		else | 
					
						
							|  |  |  | 			len += sprintf(buf + len, "%s\n", | 
					
						
							|  |  |  | 				       snprint_line(line, sizeof(line), | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 						    (u8 *) buffer, 16, loop)); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		loop += 16; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return len; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-20 14:30:35 -07:00
										 |  |  | static ssize_t store_memory(struct device *d, struct device_attribute *attr, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			    const char *buf, size_t count) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = dev_get_drvdata(d); | 
					
						
							|  |  |  | 	struct net_device *dev = priv->net_dev; | 
					
						
							|  |  |  | 	const char *p = buf; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-09 00:49:38 -05:00
										 |  |  | 	(void) dev; /* kill unused-var warning for debug-only code */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	if (count < 1) | 
					
						
							|  |  |  | 		return count; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (p[0] == '1' || | 
					
						
							|  |  |  | 	    (count >= 2 && tolower(p[0]) == 'o' && tolower(p[1]) == 'n')) { | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("%s: Setting memory dump to RAW mode.\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			       dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		priv->dump_raw = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	} else if (p[0] == '0' || (count >= 2 && tolower(p[0]) == 'o' && | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 				   tolower(p[1]) == 'f')) { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		IPW_DEBUG_INFO("%s: Setting memory dump to HEX mode.\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			       dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		priv->dump_raw = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	} else if (tolower(p[0]) == 'r') { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		IPW_DEBUG_INFO("%s: Resetting firmware snapshot.\n", dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		ipw2100_snapshot_free(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("%s: Usage: 0|on = HEX, 1|off = RAW, " | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			       "reset = clear memory snapshot\n", dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return count; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static DEVICE_ATTR(memory, S_IWUSR | S_IRUGO, show_memory, store_memory); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-20 14:30:35 -07:00
										 |  |  | static ssize_t show_ordinals(struct device *d, struct device_attribute *attr, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			     char *buf) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = dev_get_drvdata(d); | 
					
						
							|  |  |  | 	u32 val = 0; | 
					
						
							|  |  |  | 	int len = 0; | 
					
						
							|  |  |  | 	u32 val_len; | 
					
						
							|  |  |  | 	static int loop = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 	if (priv->status & STATUS_RF_KILL_MASK) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	if (loop >= sizeof(ord_data) / sizeof(*ord_data)) | 
					
						
							|  |  |  | 		loop = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* sysfs provides us PAGE_SIZE buffer */ | 
					
						
							|  |  |  | 	while (len < PAGE_SIZE - 128 && | 
					
						
							|  |  |  | 	       loop < (sizeof(ord_data) / sizeof(*ord_data))) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		val_len = sizeof(u32); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (ipw2100_get_ordinal(priv, ord_data[loop].index, &val, | 
					
						
							|  |  |  | 					&val_len)) | 
					
						
							|  |  |  | 			len += sprintf(buf + len, "[0x%02X] = ERROR    %s\n", | 
					
						
							|  |  |  | 				       ord_data[loop].index, | 
					
						
							|  |  |  | 				       ord_data[loop].desc); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			len += sprintf(buf + len, "[0x%02X] = 0x%08X %s\n", | 
					
						
							|  |  |  | 				       ord_data[loop].index, val, | 
					
						
							|  |  |  | 				       ord_data[loop].desc); | 
					
						
							|  |  |  | 		loop++; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return len; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static DEVICE_ATTR(ordinals, S_IRUGO, show_ordinals, NULL); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-20 14:30:35 -07:00
										 |  |  | static ssize_t show_stats(struct device *d, struct device_attribute *attr, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			  char *buf) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = dev_get_drvdata(d); | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	char *out = buf; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	out += sprintf(out, "interrupts: %d {tx: %d, rx: %d, other: %d}\n", | 
					
						
							|  |  |  | 		       priv->interrupts, priv->tx_interrupts, | 
					
						
							|  |  |  | 		       priv->rx_interrupts, priv->inta_other); | 
					
						
							|  |  |  | 	out += sprintf(out, "firmware resets: %d\n", priv->resets); | 
					
						
							|  |  |  | 	out += sprintf(out, "firmware hangs: %d\n", priv->hangs); | 
					
						
							| 
									
										
										
										
											2005-12-01 01:41:46 -08:00
										 |  |  | #ifdef CONFIG_IPW2100_DEBUG
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	out += sprintf(out, "packet mismatch image: %s\n", | 
					
						
							|  |  |  | 		       priv->snapshot[0] ? "YES" : "NO"); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return out - buf; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static int ipw2100_switch_mode(struct ipw2100_priv *priv, u32 mode) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (mode == priv->ieee->iw_mode) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_disable_adapter(priv); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 		printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n", | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		       priv->net_dev->name, err); | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (mode) { | 
					
						
							|  |  |  | 	case IW_MODE_INFRA: | 
					
						
							|  |  |  | 		priv->net_dev->type = ARPHRD_ETHER; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IW_MODE_ADHOC: | 
					
						
							|  |  |  | 		priv->net_dev->type = ARPHRD_ETHER; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | #ifdef CONFIG_IPW2100_MONITOR
 | 
					
						
							|  |  |  | 	case IW_MODE_MONITOR: | 
					
						
							|  |  |  | 		priv->last_mode = priv->ieee->iw_mode; | 
					
						
							|  |  |  | 		priv->net_dev->type = ARPHRD_IEEE80211; | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | #endif				/* CONFIG_IPW2100_MONITOR */
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->ieee->iw_mode = mode; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef CONFIG_PM
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	/* Indicate ipw2100_download_firmware download firmware
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	 * from disk instead of memory. */ | 
					
						
							|  |  |  | 	ipw2100_firmware.version = 0; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	printk(KERN_INFO "%s: Reseting on mode change.\n", priv->net_dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	priv->reset_backoff = 0; | 
					
						
							|  |  |  | 	schedule_reset(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-20 14:30:35 -07:00
										 |  |  | static ssize_t show_internals(struct device *d, struct device_attribute *attr, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			      char *buf) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = dev_get_drvdata(d); | 
					
						
							|  |  |  | 	int len = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | #define DUMP_VAR(x,y) len += sprintf(buf + len, # x ": %" y "\n", priv-> x)
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->status & STATUS_ASSOCIATED) | 
					
						
							|  |  |  | 		len += sprintf(buf + len, "connected: %lu\n", | 
					
						
							|  |  |  | 			       get_seconds() - priv->connect_start); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		len += sprintf(buf + len, "not connected\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	DUMP_VAR(ieee->crypt[priv->ieee->tx_keyidx], "p"); | 
					
						
							|  |  |  | 	DUMP_VAR(status, "08lx"); | 
					
						
							|  |  |  | 	DUMP_VAR(config, "08lx"); | 
					
						
							|  |  |  | 	DUMP_VAR(capability, "08lx"); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	len += | 
					
						
							|  |  |  | 	    sprintf(buf + len, "last_rtc: %lu\n", | 
					
						
							|  |  |  | 		    (unsigned long)priv->last_rtc); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	DUMP_VAR(fatal_error, "d"); | 
					
						
							|  |  |  | 	DUMP_VAR(stop_hang_check, "d"); | 
					
						
							|  |  |  | 	DUMP_VAR(stop_rf_kill, "d"); | 
					
						
							|  |  |  | 	DUMP_VAR(messages_sent, "d"); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	DUMP_VAR(tx_pend_stat.value, "d"); | 
					
						
							|  |  |  | 	DUMP_VAR(tx_pend_stat.hi, "d"); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	DUMP_VAR(tx_free_stat.value, "d"); | 
					
						
							|  |  |  | 	DUMP_VAR(tx_free_stat.lo, "d"); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	DUMP_VAR(msg_free_stat.value, "d"); | 
					
						
							|  |  |  | 	DUMP_VAR(msg_free_stat.lo, "d"); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	DUMP_VAR(msg_pend_stat.value, "d"); | 
					
						
							|  |  |  | 	DUMP_VAR(msg_pend_stat.hi, "d"); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	DUMP_VAR(fw_pend_stat.value, "d"); | 
					
						
							|  |  |  | 	DUMP_VAR(fw_pend_stat.hi, "d"); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	DUMP_VAR(txq_stat.value, "d"); | 
					
						
							|  |  |  | 	DUMP_VAR(txq_stat.lo, "d"); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	DUMP_VAR(ieee->scans, "d"); | 
					
						
							|  |  |  | 	DUMP_VAR(reset_backoff, "d"); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return len; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static DEVICE_ATTR(internals, S_IRUGO, show_internals, NULL); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-20 14:30:35 -07:00
										 |  |  | static ssize_t show_bssinfo(struct device *d, struct device_attribute *attr, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			    char *buf) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = dev_get_drvdata(d); | 
					
						
							|  |  |  | 	char essid[IW_ESSID_MAX_SIZE + 1]; | 
					
						
							|  |  |  | 	u8 bssid[ETH_ALEN]; | 
					
						
							|  |  |  | 	u32 chan = 0; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	char *out = buf; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	int length; | 
					
						
							|  |  |  | 	int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 	if (priv->status & STATUS_RF_KILL_MASK) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	memset(essid, 0, sizeof(essid)); | 
					
						
							|  |  |  | 	memset(bssid, 0, sizeof(bssid)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	length = IW_ESSID_MAX_SIZE; | 
					
						
							|  |  |  | 	ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID, essid, &length); | 
					
						
							|  |  |  | 	if (ret) | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | 
					
						
							|  |  |  | 			       __LINE__); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	length = sizeof(bssid); | 
					
						
							|  |  |  | 	ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID, | 
					
						
							|  |  |  | 				  bssid, &length); | 
					
						
							|  |  |  | 	if (ret) | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | 
					
						
							|  |  |  | 			       __LINE__); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	length = sizeof(u32); | 
					
						
							|  |  |  | 	ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &length); | 
					
						
							|  |  |  | 	if (ret) | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | 
					
						
							|  |  |  | 			       __LINE__); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out += sprintf(out, "ESSID: %s\n", essid); | 
					
						
							|  |  |  | 	out += sprintf(out, "BSSID:   %02x:%02x:%02x:%02x:%02x:%02x\n", | 
					
						
							|  |  |  | 		       bssid[0], bssid[1], bssid[2], | 
					
						
							|  |  |  | 		       bssid[3], bssid[4], bssid[5]); | 
					
						
							|  |  |  | 	out += sprintf(out, "Channel: %d\n", chan); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return out - buf; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static DEVICE_ATTR(bssinfo, S_IRUGO, show_bssinfo, NULL); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-01 01:41:46 -08:00
										 |  |  | #ifdef CONFIG_IPW2100_DEBUG
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | static ssize_t show_debug_level(struct device_driver *d, char *buf) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return sprintf(buf, "0x%08X\n", ipw2100_debug_level); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | static ssize_t store_debug_level(struct device_driver *d, | 
					
						
							|  |  |  | 				 const char *buf, size_t count) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	char *p = (char *)buf; | 
					
						
							|  |  |  | 	u32 val; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { | 
					
						
							|  |  |  | 		p++; | 
					
						
							|  |  |  | 		if (p[0] == 'x' || p[0] == 'X') | 
					
						
							|  |  |  | 			p++; | 
					
						
							|  |  |  | 		val = simple_strtoul(p, &p, 16); | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | 		val = simple_strtoul(p, &p, 10); | 
					
						
							|  |  |  | 	if (p == buf) | 
					
						
							| 
									
										
										
										
											2005-07-04 14:06:00 +08:00
										 |  |  | 		IPW_DEBUG_INFO(": %s is not in hex or decimal form.\n", buf); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		ipw2100_debug_level = val; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return strnlen(buf, count); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, show_debug_level, | 
					
						
							|  |  |  | 		   store_debug_level); | 
					
						
							| 
									
										
										
										
											2005-12-01 01:41:46 -08:00
										 |  |  | #endif				/* CONFIG_IPW2100_DEBUG */
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-20 14:30:35 -07:00
										 |  |  | static ssize_t show_fatal_error(struct device *d, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 				struct device_attribute *attr, char *buf) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = dev_get_drvdata(d); | 
					
						
							|  |  |  | 	char *out = buf; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->fatal_error) | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		out += sprintf(out, "0x%08X\n", priv->fatal_error); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		out += sprintf(out, "0\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 1; i <= IPW2100_ERROR_QUEUE; i++) { | 
					
						
							|  |  |  | 		if (!priv->fatal_errors[(priv->fatal_index - i) % | 
					
						
							|  |  |  | 					IPW2100_ERROR_QUEUE]) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		out += sprintf(out, "%d. 0x%08X\n", i, | 
					
						
							|  |  |  | 			       priv->fatal_errors[(priv->fatal_index - i) % | 
					
						
							|  |  |  | 						  IPW2100_ERROR_QUEUE]); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return out - buf; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-20 14:30:35 -07:00
										 |  |  | static ssize_t store_fatal_error(struct device *d, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 				 struct device_attribute *attr, const char *buf, | 
					
						
							|  |  |  | 				 size_t count) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = dev_get_drvdata(d); | 
					
						
							|  |  |  | 	schedule_reset(priv); | 
					
						
							|  |  |  | 	return count; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static DEVICE_ATTR(fatal_error, S_IWUSR | S_IRUGO, show_fatal_error, | 
					
						
							|  |  |  | 		   store_fatal_error); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-20 14:30:35 -07:00
										 |  |  | static ssize_t show_scan_age(struct device *d, struct device_attribute *attr, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			     char *buf) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = dev_get_drvdata(d); | 
					
						
							|  |  |  | 	return sprintf(buf, "%d\n", priv->ieee->scan_age); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-20 14:30:35 -07:00
										 |  |  | static ssize_t store_scan_age(struct device *d, struct device_attribute *attr, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			      const char *buf, size_t count) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = dev_get_drvdata(d); | 
					
						
							|  |  |  | 	struct net_device *dev = priv->net_dev; | 
					
						
							|  |  |  | 	char buffer[] = "00000000"; | 
					
						
							|  |  |  | 	unsigned long len = | 
					
						
							|  |  |  | 	    (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1; | 
					
						
							|  |  |  | 	unsigned long val; | 
					
						
							|  |  |  | 	char *p = buffer; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-09 00:49:38 -05:00
										 |  |  | 	(void) dev; /* kill unused-var warning for debug-only code */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	IPW_DEBUG_INFO("enter\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	strncpy(buffer, buf, len); | 
					
						
							|  |  |  | 	buffer[len] = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { | 
					
						
							|  |  |  | 		p++; | 
					
						
							|  |  |  | 		if (p[0] == 'x' || p[0] == 'X') | 
					
						
							|  |  |  | 			p++; | 
					
						
							|  |  |  | 		val = simple_strtoul(p, &p, 16); | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | 		val = simple_strtoul(p, &p, 10); | 
					
						
							|  |  |  | 	if (p == buffer) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		priv->ieee->scan_age = val; | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("exit\n"); | 
					
						
							|  |  |  | 	return len; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-20 14:30:35 -07:00
										 |  |  | static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			    char *buf) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* 0 - RF kill not enabled
 | 
					
						
							|  |  |  | 	   1 - SW based RF kill active (sysfs) | 
					
						
							|  |  |  | 	   2 - HW based RF kill active | 
					
						
							|  |  |  | 	   3 - Both HW and SW baed RF kill active */ | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = (struct ipw2100_priv *)d->driver_data; | 
					
						
							|  |  |  | 	int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) | | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	    (rf_kill_active(priv) ? 0x2 : 0x0); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	return sprintf(buf, "%i\n", val); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw_radio_kill_sw(struct ipw2100_priv *priv, int disable_radio) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if ((disable_radio ? 1 : 0) == | 
					
						
							|  |  |  | 	    (priv->status & STATUS_RF_KILL_SW ? 1 : 0)) | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO  %s\n", | 
					
						
							|  |  |  | 			  disable_radio ? "OFF" : "ON"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->action_sem); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (disable_radio) { | 
					
						
							|  |  |  | 		priv->status |= STATUS_RF_KILL_SW; | 
					
						
							|  |  |  | 		ipw2100_down(priv); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		priv->status &= ~STATUS_RF_KILL_SW; | 
					
						
							|  |  |  | 		if (rf_kill_active(priv)) { | 
					
						
							|  |  |  | 			IPW_DEBUG_RF_KILL("Can not turn radio back on - " | 
					
						
							|  |  |  | 					  "disabled by HW switch\n"); | 
					
						
							|  |  |  | 			/* Make sure the RF_KILL check timer is running */ | 
					
						
							|  |  |  | 			priv->stop_rf_kill = 0; | 
					
						
							|  |  |  | 			cancel_delayed_work(&priv->rf_kill); | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		} else | 
					
						
							|  |  |  | 			schedule_reset(priv); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-20 14:30:35 -07:00
										 |  |  | static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			     const char *buf, size_t count) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = dev_get_drvdata(d); | 
					
						
							|  |  |  | 	ipw_radio_kill_sw(priv, buf[0] == '1'); | 
					
						
							|  |  |  | 	return count; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | static struct attribute *ipw2100_sysfs_entries[] = { | 
					
						
							|  |  |  | 	&dev_attr_hardware.attr, | 
					
						
							|  |  |  | 	&dev_attr_registers.attr, | 
					
						
							|  |  |  | 	&dev_attr_ordinals.attr, | 
					
						
							|  |  |  | 	&dev_attr_pci.attr, | 
					
						
							|  |  |  | 	&dev_attr_stats.attr, | 
					
						
							|  |  |  | 	&dev_attr_internals.attr, | 
					
						
							|  |  |  | 	&dev_attr_bssinfo.attr, | 
					
						
							|  |  |  | 	&dev_attr_memory.attr, | 
					
						
							|  |  |  | 	&dev_attr_scan_age.attr, | 
					
						
							|  |  |  | 	&dev_attr_fatal_error.attr, | 
					
						
							|  |  |  | 	&dev_attr_rf_kill.attr, | 
					
						
							|  |  |  | 	&dev_attr_cfg.attr, | 
					
						
							|  |  |  | 	&dev_attr_status.attr, | 
					
						
							|  |  |  | 	&dev_attr_capability.attr, | 
					
						
							|  |  |  | 	NULL, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct attribute_group ipw2100_attribute_group = { | 
					
						
							|  |  |  | 	.attrs = ipw2100_sysfs_entries, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int status_queue_allocate(struct ipw2100_priv *priv, int entries) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_status_queue *q = &priv->status_queue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("enter\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	q->size = entries * sizeof(struct ipw2100_status); | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	q->drv = | 
					
						
							|  |  |  | 	    (struct ipw2100_status *)pci_alloc_consistent(priv->pci_dev, | 
					
						
							|  |  |  | 							  q->size, &q->nic); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	if (!q->drv) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		IPW_DEBUG_WARNING("Can not allocate status queue.\n"); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		return -ENOMEM; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	memset(q->drv, 0, q->size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("exit\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void status_queue_free(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("enter\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->status_queue.drv) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		pci_free_consistent(priv->pci_dev, priv->status_queue.size, | 
					
						
							|  |  |  | 				    priv->status_queue.drv, | 
					
						
							|  |  |  | 				    priv->status_queue.nic); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		priv->status_queue.drv = NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("exit\n"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int bd_queue_allocate(struct ipw2100_priv *priv, | 
					
						
							|  |  |  | 			     struct ipw2100_bd_queue *q, int entries) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("enter\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	memset(q, 0, sizeof(struct ipw2100_bd_queue)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	q->entries = entries; | 
					
						
							|  |  |  | 	q->size = entries * sizeof(struct ipw2100_bd); | 
					
						
							|  |  |  | 	q->drv = pci_alloc_consistent(priv->pci_dev, q->size, &q->nic); | 
					
						
							|  |  |  | 	if (!q->drv) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		IPW_DEBUG_INFO | 
					
						
							|  |  |  | 		    ("can't allocate shared memory for buffer descriptors\n"); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		return -ENOMEM; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	memset(q->drv, 0, q->size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("exit\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static void bd_queue_free(struct ipw2100_priv *priv, struct ipw2100_bd_queue *q) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("enter\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!q) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (q->drv) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		pci_free_consistent(priv->pci_dev, q->size, q->drv, q->nic); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		q->drv = NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("exit\n"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static void bd_queue_initialize(struct ipw2100_priv *priv, | 
					
						
							|  |  |  | 				struct ipw2100_bd_queue *q, u32 base, u32 size, | 
					
						
							|  |  |  | 				u32 r, u32 w) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("enter\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	IPW_DEBUG_INFO("initializing bd queue at virt=%p, phys=%08x\n", q->drv, | 
					
						
							|  |  |  | 		       (u32) q->nic); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	write_register(priv->net_dev, base, q->nic); | 
					
						
							|  |  |  | 	write_register(priv->net_dev, size, q->entries); | 
					
						
							|  |  |  | 	write_register(priv->net_dev, r, q->oldest); | 
					
						
							|  |  |  | 	write_register(priv->net_dev, w, q->next); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("exit\n"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ipw2100_kill_workqueue(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (priv->workqueue) { | 
					
						
							|  |  |  | 		priv->stop_rf_kill = 1; | 
					
						
							|  |  |  | 		priv->stop_hang_check = 1; | 
					
						
							|  |  |  | 		cancel_delayed_work(&priv->reset_work); | 
					
						
							|  |  |  | 		cancel_delayed_work(&priv->security_work); | 
					
						
							|  |  |  | 		cancel_delayed_work(&priv->wx_event_work); | 
					
						
							|  |  |  | 		cancel_delayed_work(&priv->hang_check); | 
					
						
							|  |  |  | 		cancel_delayed_work(&priv->rf_kill); | 
					
						
							|  |  |  | 		destroy_workqueue(priv->workqueue); | 
					
						
							|  |  |  | 		priv->workqueue = NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_tx_allocate(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i, j, err = -EINVAL; | 
					
						
							|  |  |  | 	void *v; | 
					
						
							|  |  |  | 	dma_addr_t p; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("enter\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = bd_queue_allocate(priv, &priv->tx_queue, TX_QUEUE_LENGTH); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							|  |  |  | 		IPW_DEBUG_ERROR("%s: failed bd_queue_allocate\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 				priv->net_dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	priv->tx_buffers = | 
					
						
							|  |  |  | 	    (struct ipw2100_tx_packet *)kmalloc(TX_PENDED_QUEUE_LENGTH * | 
					
						
							|  |  |  | 						sizeof(struct | 
					
						
							|  |  |  | 						       ipw2100_tx_packet), | 
					
						
							|  |  |  | 						GFP_ATOMIC); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	if (!priv->tx_buffers) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		printk(KERN_ERR DRV_NAME | 
					
						
							|  |  |  | 		       ": %s: alloc failed form tx buffers.\n", | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		       priv->net_dev->name); | 
					
						
							|  |  |  | 		bd_queue_free(priv, &priv->tx_queue); | 
					
						
							|  |  |  | 		return -ENOMEM; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		v = pci_alloc_consistent(priv->pci_dev, | 
					
						
							|  |  |  | 					 sizeof(struct ipw2100_data_header), | 
					
						
							|  |  |  | 					 &p); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		if (!v) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			printk(KERN_ERR DRV_NAME | 
					
						
							|  |  |  | 			       ": %s: PCI alloc failed for tx " "buffers.\n", | 
					
						
							|  |  |  | 			       priv->net_dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			err = -ENOMEM; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		priv->tx_buffers[i].type = DATA; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		priv->tx_buffers[i].info.d_struct.data = | 
					
						
							|  |  |  | 		    (struct ipw2100_data_header *)v; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		priv->tx_buffers[i].info.d_struct.data_phys = p; | 
					
						
							|  |  |  | 		priv->tx_buffers[i].info.d_struct.txb = NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (i == TX_PENDED_QUEUE_LENGTH) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (j = 0; j < i; j++) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		pci_free_consistent(priv->pci_dev, | 
					
						
							|  |  |  | 				    sizeof(struct ipw2100_data_header), | 
					
						
							|  |  |  | 				    priv->tx_buffers[j].info.d_struct.data, | 
					
						
							|  |  |  | 				    priv->tx_buffers[j].info.d_struct. | 
					
						
							|  |  |  | 				    data_phys); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	kfree(priv->tx_buffers); | 
					
						
							|  |  |  | 	priv->tx_buffers = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ipw2100_tx_initialize(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("enter\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * reinitialize packet info lists | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	INIT_LIST_HEAD(&priv->fw_pend_list); | 
					
						
							|  |  |  | 	INIT_STAT(&priv->fw_pend_stat); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * reinitialize lists | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	INIT_LIST_HEAD(&priv->tx_pend_list); | 
					
						
							|  |  |  | 	INIT_LIST_HEAD(&priv->tx_free_list); | 
					
						
							|  |  |  | 	INIT_STAT(&priv->tx_pend_stat); | 
					
						
							|  |  |  | 	INIT_STAT(&priv->tx_free_stat); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) { | 
					
						
							|  |  |  | 		/* We simply drop any SKBs that have been queued for
 | 
					
						
							|  |  |  | 		 * transmit */ | 
					
						
							|  |  |  | 		if (priv->tx_buffers[i].info.d_struct.txb) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			ieee80211_txb_free(priv->tx_buffers[i].info.d_struct. | 
					
						
							|  |  |  | 					   txb); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			priv->tx_buffers[i].info.d_struct.txb = NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		list_add_tail(&priv->tx_buffers[i].list, &priv->tx_free_list); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SET_STAT(&priv->tx_free_stat, i); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->tx_queue.oldest = 0; | 
					
						
							|  |  |  | 	priv->tx_queue.available = priv->tx_queue.entries; | 
					
						
							|  |  |  | 	priv->tx_queue.next = 0; | 
					
						
							|  |  |  | 	INIT_STAT(&priv->txq_stat); | 
					
						
							|  |  |  | 	SET_STAT(&priv->txq_stat, priv->tx_queue.available); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bd_queue_initialize(priv, &priv->tx_queue, | 
					
						
							|  |  |  | 			    IPW_MEM_HOST_SHARED_TX_QUEUE_BD_BASE, | 
					
						
							|  |  |  | 			    IPW_MEM_HOST_SHARED_TX_QUEUE_BD_SIZE, | 
					
						
							|  |  |  | 			    IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX, | 
					
						
							|  |  |  | 			    IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("exit\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ipw2100_tx_free(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("enter\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bd_queue_free(priv, &priv->tx_queue); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!priv->tx_buffers) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) { | 
					
						
							|  |  |  | 		if (priv->tx_buffers[i].info.d_struct.txb) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			ieee80211_txb_free(priv->tx_buffers[i].info.d_struct. | 
					
						
							|  |  |  | 					   txb); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			priv->tx_buffers[i].info.d_struct.txb = NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (priv->tx_buffers[i].info.d_struct.data) | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			pci_free_consistent(priv->pci_dev, | 
					
						
							|  |  |  | 					    sizeof(struct ipw2100_data_header), | 
					
						
							|  |  |  | 					    priv->tx_buffers[i].info.d_struct. | 
					
						
							|  |  |  | 					    data, | 
					
						
							|  |  |  | 					    priv->tx_buffers[i].info.d_struct. | 
					
						
							|  |  |  | 					    data_phys); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	kfree(priv->tx_buffers); | 
					
						
							|  |  |  | 	priv->tx_buffers = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("exit\n"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_rx_allocate(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i, j, err = -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("enter\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = bd_queue_allocate(priv, &priv->rx_queue, RX_QUEUE_LENGTH); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("failed bd_queue_allocate\n"); | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = status_queue_allocate(priv, RX_QUEUE_LENGTH); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("failed status_queue_allocate\n"); | 
					
						
							|  |  |  | 		bd_queue_free(priv, &priv->rx_queue); | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * allocate packets | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	priv->rx_buffers = (struct ipw2100_rx_packet *) | 
					
						
							|  |  |  | 	    kmalloc(RX_QUEUE_LENGTH * sizeof(struct ipw2100_rx_packet), | 
					
						
							|  |  |  | 		    GFP_KERNEL); | 
					
						
							|  |  |  | 	if (!priv->rx_buffers) { | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("can't allocate rx packet buffer table\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		bd_queue_free(priv, &priv->rx_queue); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		status_queue_free(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return -ENOMEM; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < RX_QUEUE_LENGTH; i++) { | 
					
						
							|  |  |  | 		struct ipw2100_rx_packet *packet = &priv->rx_buffers[i]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		err = ipw2100_alloc_skb(priv, packet); | 
					
						
							|  |  |  | 		if (unlikely(err)) { | 
					
						
							|  |  |  | 			err = -ENOMEM; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* The BD holds the cache aligned address */ | 
					
						
							|  |  |  | 		priv->rx_queue.drv[i].host_addr = packet->dma_addr; | 
					
						
							|  |  |  | 		priv->rx_queue.drv[i].buf_length = IPW_RX_NIC_BUFFER_LENGTH; | 
					
						
							|  |  |  | 		priv->status_queue.drv[i].status_fields = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (i == RX_QUEUE_LENGTH) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (j = 0; j < i; j++) { | 
					
						
							|  |  |  | 		pci_unmap_single(priv->pci_dev, priv->rx_buffers[j].dma_addr, | 
					
						
							|  |  |  | 				 sizeof(struct ipw2100_rx_packet), | 
					
						
							|  |  |  | 				 PCI_DMA_FROMDEVICE); | 
					
						
							|  |  |  | 		dev_kfree_skb(priv->rx_buffers[j].skb); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	kfree(priv->rx_buffers); | 
					
						
							|  |  |  | 	priv->rx_buffers = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bd_queue_free(priv, &priv->rx_queue); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	status_queue_free(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ipw2100_rx_initialize(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("enter\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->rx_queue.oldest = 0; | 
					
						
							|  |  |  | 	priv->rx_queue.available = priv->rx_queue.entries - 1; | 
					
						
							|  |  |  | 	priv->rx_queue.next = priv->rx_queue.entries - 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	INIT_STAT(&priv->rxq_stat); | 
					
						
							|  |  |  | 	SET_STAT(&priv->rxq_stat, priv->rx_queue.available); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bd_queue_initialize(priv, &priv->rx_queue, | 
					
						
							|  |  |  | 			    IPW_MEM_HOST_SHARED_RX_BD_BASE, | 
					
						
							|  |  |  | 			    IPW_MEM_HOST_SHARED_RX_BD_SIZE, | 
					
						
							|  |  |  | 			    IPW_MEM_HOST_SHARED_RX_READ_INDEX, | 
					
						
							|  |  |  | 			    IPW_MEM_HOST_SHARED_RX_WRITE_INDEX); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* set up the status queue */ | 
					
						
							|  |  |  | 	write_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_STATUS_BASE, | 
					
						
							|  |  |  | 		       priv->status_queue.nic); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("exit\n"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ipw2100_rx_free(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("enter\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bd_queue_free(priv, &priv->rx_queue); | 
					
						
							|  |  |  | 	status_queue_free(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!priv->rx_buffers) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < RX_QUEUE_LENGTH; i++) { | 
					
						
							|  |  |  | 		if (priv->rx_buffers[i].rxp) { | 
					
						
							|  |  |  | 			pci_unmap_single(priv->pci_dev, | 
					
						
							|  |  |  | 					 priv->rx_buffers[i].dma_addr, | 
					
						
							|  |  |  | 					 sizeof(struct ipw2100_rx), | 
					
						
							|  |  |  | 					 PCI_DMA_FROMDEVICE); | 
					
						
							|  |  |  | 			dev_kfree_skb(priv->rx_buffers[i].skb); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	kfree(priv->rx_buffers); | 
					
						
							|  |  |  | 	priv->rx_buffers = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("exit\n"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_read_mac_address(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u32 length = ETH_ALEN; | 
					
						
							|  |  |  | 	u8 mac[ETH_ALEN]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	err = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ADAPTER_MAC, mac, &length); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	if (err) { | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("MAC address read failed\n"); | 
					
						
							|  |  |  | 		return -EIO; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("card MAC is %02X:%02X:%02X:%02X:%02X:%02X\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		       mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	memcpy(priv->net_dev->dev_addr, mac, ETH_ALEN); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /********************************************************************
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Firmware Commands | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  ********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static int ipw2100_set_mac_address(struct ipw2100_priv *priv, int batch_mode) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = ADAPTER_ADDRESS, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = ETH_ALEN | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_HC("SET_MAC_ADDRESS\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("enter\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->config & CFG_CUSTOM_MAC) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		memcpy(cmd.host_command_parameters, priv->mac_addr, ETH_ALEN); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN); | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | 		memcpy(cmd.host_command_parameters, priv->net_dev->dev_addr, | 
					
						
							|  |  |  | 		       ETH_ALEN); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("exit\n"); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static int ipw2100_set_port_type(struct ipw2100_priv *priv, u32 port_type, | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 				 int batch_mode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = PORT_TYPE, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = sizeof(u32) | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (port_type) { | 
					
						
							|  |  |  | 	case IW_MODE_INFRA: | 
					
						
							|  |  |  | 		cmd.host_command_parameters[0] = IPW_BSS; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IW_MODE_ADHOC: | 
					
						
							|  |  |  | 		cmd.host_command_parameters[0] = IPW_IBSS; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_HC("PORT_TYPE: %s\n", | 
					
						
							|  |  |  | 		     port_type == IPW_IBSS ? "Ad-Hoc" : "Managed"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) { | 
					
						
							|  |  |  | 		err = ipw2100_disable_adapter(priv); | 
					
						
							|  |  |  | 		if (err) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			printk(KERN_ERR DRV_NAME | 
					
						
							|  |  |  | 			       ": %s: Could not disable adapter %d\n", | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			       priv->net_dev->name, err); | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* send cmd to firmware */ | 
					
						
							|  |  |  | 	err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) | 
					
						
							|  |  |  | 		ipw2100_enable_adapter(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static int ipw2100_set_channel(struct ipw2100_priv *priv, u32 channel, | 
					
						
							|  |  |  | 			       int batch_mode) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = CHANNEL, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = sizeof(u32) | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cmd.host_command_parameters[0] = channel; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_HC("CHANNEL: %d\n", channel); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* If BSS then we don't support channel selection */ | 
					
						
							|  |  |  | 	if (priv->ieee->iw_mode == IW_MODE_INFRA) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((channel != 0) && | 
					
						
							|  |  |  | 	    ((channel < REG_MIN_CHANNEL) || (channel > REG_MAX_CHANNEL))) | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) { | 
					
						
							|  |  |  | 		err = ipw2100_disable_adapter(priv); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		IPW_DEBUG_INFO("Failed to set channel to %d", channel); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (channel) | 
					
						
							|  |  |  | 		priv->config |= CFG_STATIC_CHANNEL; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		priv->config &= ~CFG_STATIC_CHANNEL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->channel = channel; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) { | 
					
						
							|  |  |  | 		err = ipw2100_enable_adapter(priv); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static int ipw2100_system_config(struct ipw2100_priv *priv, int batch_mode) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = SYSTEM_CONFIG, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = 12, | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	u32 ibss_mask, len = sizeof(u32); | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Set system configuration */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) { | 
					
						
							|  |  |  | 		err = ipw2100_disable_adapter(priv); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->ieee->iw_mode == IW_MODE_ADHOC) | 
					
						
							|  |  |  | 		cmd.host_command_parameters[0] |= IPW_CFG_IBSS_AUTO_START; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cmd.host_command_parameters[0] |= IPW_CFG_IBSS_MASK | | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	    IPW_CFG_BSS_MASK | IPW_CFG_802_1x_ENABLE; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!(priv->config & CFG_LONG_PREAMBLE)) | 
					
						
							|  |  |  | 		cmd.host_command_parameters[0] |= IPW_CFG_PREAMBLE_AUTO; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_get_ordinal(priv, | 
					
						
							|  |  |  | 				  IPW_ORD_EEPROM_IBSS_11B_CHANNELS, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 				  &ibss_mask, &len); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	if (err) | 
					
						
							|  |  |  | 		ibss_mask = IPW_IBSS_11B_DEFAULT_MASK; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cmd.host_command_parameters[1] = REG_CHANNEL_MASK; | 
					
						
							|  |  |  | 	cmd.host_command_parameters[2] = REG_CHANNEL_MASK & ibss_mask; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* 11b only */ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	/*cmd.host_command_parameters[0] |= DIVERSITY_ANTENNA_A; */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* If IPv6 is configured in the kernel then we don't want to filter out all
 | 
					
						
							|  |  |  |  * of the multicast packets as IPv6 needs some. */ | 
					
						
							|  |  |  | #if !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
 | 
					
						
							|  |  |  | 	cmd.host_command = ADD_MULTICAST; | 
					
						
							|  |  |  | 	cmd.host_command_sequence = 0; | 
					
						
							|  |  |  | 	cmd.host_command_length = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	if (!batch_mode) { | 
					
						
							|  |  |  | 		err = ipw2100_enable_adapter(priv); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static int ipw2100_set_tx_rates(struct ipw2100_priv *priv, u32 rate, | 
					
						
							|  |  |  | 				int batch_mode) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = BASIC_TX_RATES, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = 4 | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cmd.host_command_parameters[0] = rate & TX_RATE_MASK; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) { | 
					
						
							|  |  |  | 		err = ipw2100_disable_adapter(priv); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Set BASIC TX Rate first */ | 
					
						
							|  |  |  | 	ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Set TX Rate */ | 
					
						
							|  |  |  | 	cmd.host_command = TX_RATES; | 
					
						
							|  |  |  | 	ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Set MSDU TX Rate */ | 
					
						
							|  |  |  | 	cmd.host_command = MSDU_TX_RATES; | 
					
						
							|  |  |  | 	ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) { | 
					
						
							|  |  |  | 		err = ipw2100_enable_adapter(priv); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->tx_rates = rate; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static int ipw2100_set_power_mode(struct ipw2100_priv *priv, int power_level) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = POWER_MODE, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = 4 | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cmd.host_command_parameters[0] = power_level; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (power_level == IPW_POWER_MODE_CAM) | 
					
						
							|  |  |  | 		priv->power_mode = IPW_POWER_LEVEL(priv->power_mode); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		priv->power_mode = IPW_POWER_ENABLED | power_level; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef CONFIG_IPW2100_TX_POWER
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	if (priv->port_type == IBSS && priv->adhoc_power != DFTL_IBSS_TX_POWER) { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		/* Set beacon interval */ | 
					
						
							|  |  |  | 		cmd.host_command = TX_POWER_INDEX; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		cmd.host_command_parameters[0] = (u32) priv->adhoc_power; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static int ipw2100_set_rts_threshold(struct ipw2100_priv *priv, u32 threshold) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = RTS_THRESHOLD, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = 4 | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (threshold & RTS_DISABLED) | 
					
						
							|  |  |  | 		cmd.host_command_parameters[0] = MAX_RTS_THRESHOLD; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		cmd.host_command_parameters[0] = threshold & ~RTS_DISABLED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->rts_threshold = threshold; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if 0
 | 
					
						
							|  |  |  | int ipw2100_set_fragmentation_threshold(struct ipw2100_priv *priv, | 
					
						
							|  |  |  | 					u32 threshold, int batch_mode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = FRAG_THRESHOLD, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = 4, | 
					
						
							|  |  |  | 		.host_command_parameters[0] = 0, | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) { | 
					
						
							|  |  |  | 		err = ipw2100_disable_adapter(priv); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (threshold == 0) | 
					
						
							|  |  |  | 		threshold = DEFAULT_FRAG_THRESHOLD; | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		threshold = max(threshold, MIN_FRAG_THRESHOLD); | 
					
						
							|  |  |  | 		threshold = min(threshold, MAX_FRAG_THRESHOLD); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cmd.host_command_parameters[0] = threshold; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_HC("FRAG_THRESHOLD: %u\n", threshold); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) | 
					
						
							|  |  |  | 		ipw2100_enable_adapter(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!err) | 
					
						
							|  |  |  | 		priv->frag_threshold = threshold; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static int ipw2100_set_short_retry(struct ipw2100_priv *priv, u32 retry) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = SHORT_RETRY_LIMIT, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = 4 | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cmd.host_command_parameters[0] = retry; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->short_retry_limit = retry; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static int ipw2100_set_long_retry(struct ipw2100_priv *priv, u32 retry) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = LONG_RETRY_LIMIT, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = 4 | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cmd.host_command_parameters[0] = retry; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->long_retry_limit = retry; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static int ipw2100_set_mandatory_bssid(struct ipw2100_priv *priv, u8 * bssid, | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | 				       int batch_mode) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = MANDATORY_BSSID, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = (bssid == NULL) ? 0 : ETH_ALEN | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-01 01:41:46 -08:00
										 |  |  | #ifdef CONFIG_IPW2100_DEBUG
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	if (bssid != NULL) | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		IPW_DEBUG_HC("MANDATORY_BSSID: %02X:%02X:%02X:%02X:%02X:%02X\n", | 
					
						
							|  |  |  | 			     bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], | 
					
						
							|  |  |  | 			     bssid[5]); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		IPW_DEBUG_HC("MANDATORY_BSSID: <clear>\n"); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	/* if BSSID is empty then we disable mandatory bssid mode */ | 
					
						
							|  |  |  | 	if (bssid != NULL) | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 		memcpy(cmd.host_command_parameters, bssid, ETH_ALEN); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) { | 
					
						
							|  |  |  | 		err = ipw2100_disable_adapter(priv); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) | 
					
						
							|  |  |  | 		ipw2100_enable_adapter(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_disassociate_bssid(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = DISASSOCIATION_BSSID, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = ETH_ALEN | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 	int len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_HC("DISASSOCIATION_BSSID\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	len = ETH_ALEN; | 
					
						
							|  |  |  | 	/* The Firmware currently ignores the BSSID and just disassociates from
 | 
					
						
							|  |  |  | 	 * the currently associated AP -- but in the off chance that a future | 
					
						
							|  |  |  | 	 * firmware does use the BSSID provided here, we go ahead and try and | 
					
						
							|  |  |  | 	 * set it to the currently associated AP's BSSID */ | 
					
						
							|  |  |  | 	memcpy(cmd.host_command_parameters, priv->bssid, ETH_ALEN); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_set_wpa_ie(struct ipw2100_priv *, | 
					
						
							|  |  |  | 			      struct ipw2100_wpa_assoc_frame *, int) | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |     __attribute__ ((unused)); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_set_wpa_ie(struct ipw2100_priv *priv, | 
					
						
							|  |  |  | 			      struct ipw2100_wpa_assoc_frame *wpa_frame, | 
					
						
							|  |  |  | 			      int batch_mode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = SET_WPA_IE, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = sizeof(struct ipw2100_wpa_assoc_frame), | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_HC("SET_WPA_IE\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) { | 
					
						
							|  |  |  | 		err = ipw2100_disable_adapter(priv); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	memcpy(cmd.host_command_parameters, wpa_frame, | 
					
						
							|  |  |  | 	       sizeof(struct ipw2100_wpa_assoc_frame)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) { | 
					
						
							|  |  |  | 		if (ipw2100_enable_adapter(priv)) | 
					
						
							|  |  |  | 			err = -EIO; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct security_info_params { | 
					
						
							|  |  |  | 	u32 allowed_ciphers; | 
					
						
							|  |  |  | 	u16 version; | 
					
						
							|  |  |  | 	u8 auth_mode; | 
					
						
							|  |  |  | 	u8 replay_counters_number; | 
					
						
							|  |  |  | 	u8 unicast_using_group; | 
					
						
							|  |  |  | } __attribute__ ((packed)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static int ipw2100_set_security_information(struct ipw2100_priv *priv, | 
					
						
							|  |  |  | 					    int auth_mode, | 
					
						
							|  |  |  | 					    int security_level, | 
					
						
							|  |  |  | 					    int unicast_using_group, | 
					
						
							|  |  |  | 					    int batch_mode) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = SET_SECURITY_INFORMATION, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = sizeof(struct security_info_params) | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	struct security_info_params *security = | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	    (struct security_info_params *)&cmd.host_command_parameters; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	int err; | 
					
						
							|  |  |  | 	memset(security, 0, sizeof(*security)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* If shared key AP authentication is turned on, then we need to
 | 
					
						
							|  |  |  | 	 * configure the firmware to try and use it. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * Actual data encryption/decryption is handled by the host. */ | 
					
						
							|  |  |  | 	security->auth_mode = auth_mode; | 
					
						
							|  |  |  | 	security->unicast_using_group = unicast_using_group; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (security_level) { | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 	case SEC_LEVEL_0: | 
					
						
							|  |  |  | 		security->allowed_ciphers = IPW_NONE_CIPHER; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case SEC_LEVEL_1: | 
					
						
							|  |  |  | 		security->allowed_ciphers = IPW_WEP40_CIPHER | | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		    IPW_WEP104_CIPHER; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case SEC_LEVEL_2: | 
					
						
							|  |  |  | 		security->allowed_ciphers = IPW_WEP40_CIPHER | | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		    IPW_WEP104_CIPHER | IPW_TKIP_CIPHER; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case SEC_LEVEL_2_CKIP: | 
					
						
							|  |  |  | 		security->allowed_ciphers = IPW_WEP40_CIPHER | | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		    IPW_WEP104_CIPHER | IPW_CKIP_CIPHER; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case SEC_LEVEL_3: | 
					
						
							|  |  |  | 		security->allowed_ciphers = IPW_WEP40_CIPHER | | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		    IPW_WEP104_CIPHER | IPW_TKIP_CIPHER | IPW_CCMP_CIPHER; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	IPW_DEBUG_HC | 
					
						
							|  |  |  | 	    ("SET_SECURITY_INFORMATION: auth:%d cipher:0x%02X (level %d)\n", | 
					
						
							|  |  |  | 	     security->auth_mode, security->allowed_ciphers, security_level); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	security->replay_counters_number = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) { | 
					
						
							|  |  |  | 		err = ipw2100_disable_adapter(priv); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) | 
					
						
							|  |  |  | 		ipw2100_enable_adapter(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static int ipw2100_set_tx_power(struct ipw2100_priv *priv, u32 tx_power) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = TX_POWER_INDEX, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = 4 | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int err = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-13 12:29:21 -05:00
										 |  |  | 	if (tx_power != IPW_TX_POWER_DEFAULT) | 
					
						
							|  |  |  | 		tx_power = (tx_power - IPW_TX_POWER_MIN_DBM) * 16 / | 
					
						
							|  |  |  | 		    (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	cmd.host_command_parameters[0] = tx_power; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->ieee->iw_mode == IW_MODE_ADHOC) | 
					
						
							|  |  |  | 		err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 	if (!err) | 
					
						
							|  |  |  | 		priv->tx_power = tx_power; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static int ipw2100_set_ibss_beacon_interval(struct ipw2100_priv *priv, | 
					
						
							|  |  |  | 					    u32 interval, int batch_mode) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = BEACON_INTERVAL, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = 4 | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cmd.host_command_parameters[0] = interval; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("enter\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | 
					
						
							|  |  |  | 		if (!batch_mode) { | 
					
						
							|  |  |  | 			err = ipw2100_disable_adapter(priv); | 
					
						
							|  |  |  | 			if (err) | 
					
						
							|  |  |  | 				return err; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!batch_mode) { | 
					
						
							|  |  |  | 			err = ipw2100_enable_adapter(priv); | 
					
						
							|  |  |  | 			if (err) | 
					
						
							|  |  |  | 				return err; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("exit\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ipw2100_queues_initialize(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ipw2100_tx_initialize(priv); | 
					
						
							|  |  |  | 	ipw2100_rx_initialize(priv); | 
					
						
							|  |  |  | 	ipw2100_msg_initialize(priv); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ipw2100_queues_free(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ipw2100_tx_free(priv); | 
					
						
							|  |  |  | 	ipw2100_rx_free(priv); | 
					
						
							|  |  |  | 	ipw2100_msg_free(priv); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int ipw2100_queues_allocate(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (ipw2100_tx_allocate(priv) || | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	    ipw2100_rx_allocate(priv) || ipw2100_msg_allocate(priv)) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		goto fail; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       fail: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	ipw2100_tx_free(priv); | 
					
						
							|  |  |  | 	ipw2100_rx_free(priv); | 
					
						
							|  |  |  | 	ipw2100_msg_free(priv); | 
					
						
							|  |  |  | 	return -ENOMEM; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define IPW_PRIVACY_CAPABLE 0x0008
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_set_wep_flags(struct ipw2100_priv *priv, u32 flags, | 
					
						
							|  |  |  | 				 int batch_mode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = WEP_FLAGS, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = 4 | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cmd.host_command_parameters[0] = flags; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_HC("WEP_FLAGS: flags = 0x%08X\n", flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) { | 
					
						
							|  |  |  | 		err = ipw2100_disable_adapter(priv); | 
					
						
							|  |  |  | 		if (err) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			printk(KERN_ERR DRV_NAME | 
					
						
							|  |  |  | 			       ": %s: Could not disable adapter %d\n", | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			       priv->net_dev->name, err); | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* send cmd to firmware */ | 
					
						
							|  |  |  | 	err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) | 
					
						
							|  |  |  | 		ipw2100_enable_adapter(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct ipw2100_wep_key { | 
					
						
							|  |  |  | 	u8 idx; | 
					
						
							|  |  |  | 	u8 len; | 
					
						
							|  |  |  | 	u8 key[13]; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Macros to ease up priting WEP keys */ | 
					
						
							|  |  |  | #define WEP_FMT_64  "%02X%02X%02X%02X-%02X"
 | 
					
						
							|  |  |  | #define WEP_FMT_128 "%02X%02X%02X%02X-%02X%02X%02X%02X-%02X%02X%02X"
 | 
					
						
							|  |  |  | #define WEP_STR_64(x) x[0],x[1],x[2],x[3],x[4]
 | 
					
						
							|  |  |  | #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]
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Set a the wep key | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @priv: struct to work on | 
					
						
							|  |  |  |  * @idx: index of the key we want to set | 
					
						
							|  |  |  |  * @key: ptr to the key data to set | 
					
						
							|  |  |  |  * @len: length of the buffer at @key | 
					
						
							|  |  |  |  * @batch_mode: FIXME perform the operation in batch mode, not | 
					
						
							|  |  |  |  *              disabling the device. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @returns 0 if OK, < 0 errno code on error. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Fill out a command structure with the new wep key, length an | 
					
						
							|  |  |  |  * index and send it down the wire. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static int ipw2100_set_key(struct ipw2100_priv *priv, | 
					
						
							|  |  |  | 			   int idx, char *key, int len, int batch_mode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int keylen = len ? (len <= 5 ? 5 : 13) : 0; | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = WEP_KEY_INFO, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = sizeof(struct ipw2100_wep_key), | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		     idx, keylen, len); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* NOTE: We don't check cached values in case the firmware was reset
 | 
					
						
							|  |  |  | 	 * or some other problem is occuring.  If the user is setting the key, | 
					
						
							|  |  |  | 	 * then we push the change */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wep_key->idx = idx; | 
					
						
							|  |  |  | 	wep_key->len = keylen; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (keylen) { | 
					
						
							|  |  |  | 		memcpy(wep_key->key, key, len); | 
					
						
							|  |  |  | 		memset(wep_key->key + len, 0, keylen - len); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Will be optimized out on debug not being configured in */ | 
					
						
							|  |  |  | 	if (keylen == 0) | 
					
						
							|  |  |  | 		IPW_DEBUG_WEP("%s: Clearing key %d\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			      priv->net_dev->name, wep_key->idx); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	else if (keylen == 5) | 
					
						
							|  |  |  | 		IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_64 "\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			      priv->net_dev->name, wep_key->idx, wep_key->len, | 
					
						
							|  |  |  | 			      WEP_STR_64(wep_key->key)); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_128 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			      "\n", | 
					
						
							|  |  |  | 			      priv->net_dev->name, wep_key->idx, wep_key->len, | 
					
						
							|  |  |  | 			      WEP_STR_128(wep_key->key)); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) { | 
					
						
							|  |  |  | 		err = ipw2100_disable_adapter(priv); | 
					
						
							|  |  |  | 		/* FIXME: IPG: shouldn't this prink be in _disable_adapter()? */ | 
					
						
							|  |  |  | 		if (err) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			printk(KERN_ERR DRV_NAME | 
					
						
							|  |  |  | 			       ": %s: Could not disable adapter %d\n", | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			       priv->net_dev->name, err); | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* send cmd to firmware */ | 
					
						
							|  |  |  | 	err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) { | 
					
						
							|  |  |  | 		int err2 = ipw2100_enable_adapter(priv); | 
					
						
							|  |  |  | 		if (err == 0) | 
					
						
							|  |  |  | 			err = err2; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_set_key_index(struct ipw2100_priv *priv, | 
					
						
							|  |  |  | 				 int idx, int batch_mode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct host_command cmd = { | 
					
						
							|  |  |  | 		.host_command = WEP_KEY_INDEX, | 
					
						
							|  |  |  | 		.host_command_sequence = 0, | 
					
						
							|  |  |  | 		.host_command_length = 4, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		.host_command_parameters = {idx}, | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_HC("WEP_KEY_INDEX: index = %d\n", idx); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (idx < 0 || idx > 3) | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) { | 
					
						
							|  |  |  | 		err = ipw2100_disable_adapter(priv); | 
					
						
							|  |  |  | 		if (err) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			printk(KERN_ERR DRV_NAME | 
					
						
							|  |  |  | 			       ": %s: Could not disable adapter %d\n", | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			       priv->net_dev->name, err); | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* send cmd to firmware */ | 
					
						
							|  |  |  | 	err = ipw2100_hw_send_command(priv, &cmd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) | 
					
						
							|  |  |  | 		ipw2100_enable_adapter(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static int ipw2100_configure_security(struct ipw2100_priv *priv, int batch_mode) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i, err, auth_mode, sec_level, use_group; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_RUNNING)) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!batch_mode) { | 
					
						
							|  |  |  | 		err = ipw2100_disable_adapter(priv); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-12 15:45:30 -05:00
										 |  |  | 	if (!priv->ieee->sec.enabled) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		err = | 
					
						
							|  |  |  | 		    ipw2100_set_security_information(priv, IPW_AUTH_OPEN, | 
					
						
							|  |  |  | 						     SEC_LEVEL_0, 0, 1); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		auth_mode = IPW_AUTH_OPEN; | 
					
						
							| 
									
										
										
										
											2005-07-12 15:45:30 -05:00
										 |  |  | 		if ((priv->ieee->sec.flags & SEC_AUTH_MODE) && | 
					
						
							|  |  |  | 		    (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			auth_mode = IPW_AUTH_SHARED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		sec_level = SEC_LEVEL_0; | 
					
						
							| 
									
										
										
										
											2005-07-12 15:45:30 -05:00
										 |  |  | 		if (priv->ieee->sec.flags & SEC_LEVEL) | 
					
						
							|  |  |  | 			sec_level = priv->ieee->sec.level; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		use_group = 0; | 
					
						
							| 
									
										
										
										
											2005-07-12 15:45:30 -05:00
										 |  |  | 		if (priv->ieee->sec.flags & SEC_UNICAST_GROUP) | 
					
						
							|  |  |  | 			use_group = priv->ieee->sec.unicast_uses_group; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		err = | 
					
						
							|  |  |  | 		    ipw2100_set_security_information(priv, auth_mode, sec_level, | 
					
						
							|  |  |  | 						     use_group, 1); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		goto exit; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-12 15:45:30 -05:00
										 |  |  | 	if (priv->ieee->sec.enabled) { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		for (i = 0; i < 4; i++) { | 
					
						
							| 
									
										
										
										
											2005-07-12 15:45:30 -05:00
										 |  |  | 			if (!(priv->ieee->sec.flags & (1 << i))) { | 
					
						
							|  |  |  | 				memset(priv->ieee->sec.keys[i], 0, WEP_KEY_LEN); | 
					
						
							|  |  |  | 				priv->ieee->sec.key_sizes[i] = 0; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				err = ipw2100_set_key(priv, i, | 
					
						
							| 
									
										
										
										
											2005-07-12 15:45:30 -05:00
										 |  |  | 						      priv->ieee->sec.keys[i], | 
					
						
							|  |  |  | 						      priv->ieee->sec. | 
					
						
							|  |  |  | 						      key_sizes[i], 1); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 				if (err) | 
					
						
							|  |  |  | 					goto exit; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ipw2100_set_key_index(priv, priv->ieee->tx_keyidx, 1); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Always enable privacy so the Host can filter WEP packets if
 | 
					
						
							|  |  |  | 	 * encrypted data is sent up */ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	err = | 
					
						
							|  |  |  | 	    ipw2100_set_wep_flags(priv, | 
					
						
							| 
									
										
										
										
											2005-07-12 15:45:30 -05:00
										 |  |  | 				  priv->ieee->sec. | 
					
						
							|  |  |  | 				  enabled ? IPW_PRIVACY_CAPABLE : 0, 1); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	if (err) | 
					
						
							|  |  |  | 		goto exit; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->status &= ~STATUS_SECURITY_UPDATED; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       exit: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	if (!batch_mode) | 
					
						
							|  |  |  | 		ipw2100_enable_adapter(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ipw2100_security_work(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* If we happen to have reconnected before we get a chance to
 | 
					
						
							|  |  |  | 	 * process this, then update the security settings--which causes | 
					
						
							|  |  |  | 	 * a disassociation to occur */ | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_ASSOCIATED) && | 
					
						
							|  |  |  | 	    priv->status & STATUS_SECURITY_UPDATED) | 
					
						
							|  |  |  | 		ipw2100_configure_security(priv, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void shim__set_security(struct net_device *dev, | 
					
						
							|  |  |  | 			       struct ieee80211_security *sec) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	int i, force_update = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->action_sem); | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_INITIALIZED)) | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < 4; i++) { | 
					
						
							|  |  |  | 		if (sec->flags & (1 << i)) { | 
					
						
							| 
									
										
										
										
											2005-07-12 15:45:30 -05:00
										 |  |  | 			priv->ieee->sec.key_sizes[i] = sec->key_sizes[i]; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			if (sec->key_sizes[i] == 0) | 
					
						
							| 
									
										
										
										
											2005-07-12 15:45:30 -05:00
										 |  |  | 				priv->ieee->sec.flags &= ~(1 << i); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			else | 
					
						
							| 
									
										
										
										
											2005-07-12 15:45:30 -05:00
										 |  |  | 				memcpy(priv->ieee->sec.keys[i], sec->keys[i], | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 				       sec->key_sizes[i]); | 
					
						
							| 
									
										
										
										
											2005-08-25 17:45:49 +08:00
										 |  |  | 			if (sec->level == SEC_LEVEL_1) { | 
					
						
							|  |  |  | 				priv->ieee->sec.flags |= (1 << i); | 
					
						
							|  |  |  | 				priv->status |= STATUS_SECURITY_UPDATED; | 
					
						
							|  |  |  | 			} else | 
					
						
							|  |  |  | 				priv->ieee->sec.flags &= ~(1 << i); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((sec->flags & SEC_ACTIVE_KEY) && | 
					
						
							| 
									
										
										
										
											2005-07-12 15:45:30 -05:00
										 |  |  | 	    priv->ieee->sec.active_key != sec->active_key) { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		if (sec->active_key <= 3) { | 
					
						
							| 
									
										
										
										
											2005-07-12 15:45:30 -05:00
										 |  |  | 			priv->ieee->sec.active_key = sec->active_key; | 
					
						
							|  |  |  | 			priv->ieee->sec.flags |= SEC_ACTIVE_KEY; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		} else | 
					
						
							| 
									
										
										
										
											2005-07-12 15:45:30 -05:00
										 |  |  | 			priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		priv->status |= STATUS_SECURITY_UPDATED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((sec->flags & SEC_AUTH_MODE) && | 
					
						
							| 
									
										
										
										
											2005-07-12 15:45:30 -05:00
										 |  |  | 	    (priv->ieee->sec.auth_mode != sec->auth_mode)) { | 
					
						
							|  |  |  | 		priv->ieee->sec.auth_mode = sec->auth_mode; | 
					
						
							|  |  |  | 		priv->ieee->sec.flags |= SEC_AUTH_MODE; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		priv->status |= STATUS_SECURITY_UPDATED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-12 15:45:30 -05:00
										 |  |  | 	if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) { | 
					
						
							|  |  |  | 		priv->ieee->sec.flags |= SEC_ENABLED; | 
					
						
							|  |  |  | 		priv->ieee->sec.enabled = sec->enabled; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		priv->status |= STATUS_SECURITY_UPDATED; | 
					
						
							|  |  |  | 		force_update = 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-12 15:45:30 -05:00
										 |  |  | 	if (sec->flags & SEC_ENCRYPT) | 
					
						
							|  |  |  | 		priv->ieee->sec.encrypt = sec->encrypt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) { | 
					
						
							|  |  |  | 		priv->ieee->sec.level = sec->level; | 
					
						
							|  |  |  | 		priv->ieee->sec.flags |= SEC_LEVEL; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		priv->status |= STATUS_SECURITY_UPDATED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_WEP("Security flags: %c %c%c%c%c %c%c%c%c\n", | 
					
						
							| 
									
										
										
										
											2005-07-12 15:45:30 -05:00
										 |  |  | 		      priv->ieee->sec.flags & (1 << 8) ? '1' : '0', | 
					
						
							|  |  |  | 		      priv->ieee->sec.flags & (1 << 7) ? '1' : '0', | 
					
						
							|  |  |  | 		      priv->ieee->sec.flags & (1 << 6) ? '1' : '0', | 
					
						
							|  |  |  | 		      priv->ieee->sec.flags & (1 << 5) ? '1' : '0', | 
					
						
							|  |  |  | 		      priv->ieee->sec.flags & (1 << 4) ? '1' : '0', | 
					
						
							|  |  |  | 		      priv->ieee->sec.flags & (1 << 3) ? '1' : '0', | 
					
						
							|  |  |  | 		      priv->ieee->sec.flags & (1 << 2) ? '1' : '0', | 
					
						
							|  |  |  | 		      priv->ieee->sec.flags & (1 << 1) ? '1' : '0', | 
					
						
							|  |  |  | 		      priv->ieee->sec.flags & (1 << 0) ? '1' : '0'); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* As a temporary work around to enable WPA until we figure out why
 | 
					
						
							|  |  |  |  * wpa_supplicant toggles the security capability of the driver, which | 
					
						
							|  |  |  |  * forces a disassocation with force_update... | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *	if (force_update || !(priv->status & STATUS_ASSOCIATED))*/ | 
					
						
							|  |  |  | 	if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) | 
					
						
							|  |  |  | 		ipw2100_configure_security(priv, 0); | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       done: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_adapter_setup(struct ipw2100_priv *priv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 	int batch_mode = 1; | 
					
						
							|  |  |  | 	u8 *bssid; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("enter\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_disable_adapter(priv); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | #ifdef CONFIG_IPW2100_MONITOR
 | 
					
						
							|  |  |  | 	if (priv->ieee->iw_mode == IW_MODE_MONITOR) { | 
					
						
							|  |  |  | 		err = ipw2100_set_channel(priv, priv->channel, batch_mode); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("exit\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | #endif				/* CONFIG_IPW2100_MONITOR */
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_read_mac_address(priv); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		return -EIO; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_set_mac_address(priv, batch_mode); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_set_port_type(priv, priv->ieee->iw_mode, batch_mode); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | 
					
						
							|  |  |  | 		err = ipw2100_set_channel(priv, priv->channel, batch_mode); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	err = ipw2100_system_config(priv, batch_mode); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	if (err) | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_set_tx_rates(priv, priv->tx_rates, batch_mode); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Default to power mode OFF */ | 
					
						
							|  |  |  | 	err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_set_rts_threshold(priv, priv->rts_threshold); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->config & CFG_STATIC_BSSID) | 
					
						
							|  |  |  | 		bssid = priv->bssid; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		bssid = NULL; | 
					
						
							|  |  |  | 	err = ipw2100_set_mandatory_bssid(priv, bssid, batch_mode); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->config & CFG_STATIC_ESSID) | 
					
						
							|  |  |  | 		err = ipw2100_set_essid(priv, priv->essid, priv->essid_len, | 
					
						
							|  |  |  | 					batch_mode); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		err = ipw2100_set_essid(priv, NULL, 0, batch_mode); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_configure_security(priv, batch_mode); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		err = | 
					
						
							|  |  |  | 		    ipw2100_set_ibss_beacon_interval(priv, | 
					
						
							|  |  |  | 						     priv->beacon_interval, | 
					
						
							|  |  |  | 						     batch_mode); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		if (err) | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		err = ipw2100_set_tx_power(priv, priv->tx_power); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	   err = ipw2100_set_fragmentation_threshold( | 
					
						
							|  |  |  | 	   priv, priv->frag_threshold, batch_mode); | 
					
						
							|  |  |  | 	   if (err) | 
					
						
							|  |  |  | 	   return err; | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("exit\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*************************************************************************
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * EXTERNALLY CALLED METHODS | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* This method is called by the network layer -- not to be confused with
 | 
					
						
							|  |  |  |  * ipw2100_set_mac_address() declared above called by this driver (and this | 
					
						
							|  |  |  |  * method as well) to talk to the firmware */ | 
					
						
							|  |  |  | static int ipw2100_set_address(struct net_device *dev, void *p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	struct sockaddr *addr = p; | 
					
						
							|  |  |  | 	int err = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!is_valid_ether_addr(addr->sa_data)) | 
					
						
							|  |  |  | 		return -EADDRNOTAVAIL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->action_sem); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->config |= CFG_CUSTOM_MAC; | 
					
						
							|  |  |  | 	memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_set_mac_address(priv, 0); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->reset_backoff = 0; | 
					
						
							|  |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | 	ipw2100_reset_adapter(priv); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       done: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_open(struct net_device *dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("dev->open\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&priv->low_lock, flags); | 
					
						
							| 
									
										
										
										
											2005-08-25 20:07:01 -04:00
										 |  |  | 	if (priv->status & STATUS_ASSOCIATED) { | 
					
						
							|  |  |  | 		netif_carrier_on(dev); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		netif_start_queue(dev); | 
					
						
							| 
									
										
										
										
											2005-08-25 20:07:01 -04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	spin_unlock_irqrestore(&priv->low_lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_close(struct net_device *dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 	struct list_head *element; | 
					
						
							|  |  |  | 	struct ipw2100_tx_packet *packet; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("enter\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&priv->low_lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->status & STATUS_ASSOCIATED) | 
					
						
							|  |  |  | 		netif_carrier_off(dev); | 
					
						
							|  |  |  | 	netif_stop_queue(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Flush the TX queue ... */ | 
					
						
							|  |  |  | 	while (!list_empty(&priv->tx_pend_list)) { | 
					
						
							|  |  |  | 		element = priv->tx_pend_list.next; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		packet = list_entry(element, struct ipw2100_tx_packet, list); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		list_del(element); | 
					
						
							|  |  |  | 		DEC_STAT(&priv->tx_pend_stat); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ieee80211_txb_free(packet->info.d_struct.txb); | 
					
						
							|  |  |  | 		packet->info.d_struct.txb = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		list_add_tail(element, &priv->tx_free_list); | 
					
						
							|  |  |  | 		INC_STAT(&priv->tx_free_stat); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&priv->low_lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("exit\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * TODO:  Fix this function... its just wrong | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static void ipw2100_tx_timeout(struct net_device *dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->ieee->stats.tx_errors++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef CONFIG_IPW2100_MONITOR
 | 
					
						
							|  |  |  | 	if (priv->ieee->iw_mode == IW_MODE_MONITOR) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("%s: TX timed out.  Scheduling firmware restart.\n", | 
					
						
							|  |  |  | 		       dev->name); | 
					
						
							|  |  |  | 	schedule_reset(priv); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * TODO: reimplement it so that it reads statistics | 
					
						
							|  |  |  |  *       from the adapter using ordinal tables | 
					
						
							|  |  |  |  *       instead of/in addition to collecting them | 
					
						
							|  |  |  |  *       in the driver | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static struct net_device_stats *ipw2100_stats(struct net_device *dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return &priv->ieee->stats; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static int ipw2100_wpa_enable(struct ipw2100_priv *priv, int value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 	/* This is called when wpa_supplicant loads and closes the driver
 | 
					
						
							|  |  |  | 	 * interface. */ | 
					
						
							|  |  |  | 	priv->ieee->wpa_enabled = value; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static int ipw2100_wpa_set_auth_algs(struct ipw2100_priv *priv, int value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	struct ieee80211_device *ieee = priv->ieee; | 
					
						
							|  |  |  | 	struct ieee80211_security sec = { | 
					
						
							|  |  |  | 		.flags = SEC_AUTH_MODE, | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int ret = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 	if (value & IW_AUTH_ALG_SHARED_KEY) { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		sec.auth_mode = WLAN_AUTH_SHARED_KEY; | 
					
						
							|  |  |  | 		ieee->open_wep = 0; | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 	} else if (value & IW_AUTH_ALG_OPEN_SYSTEM) { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		sec.auth_mode = WLAN_AUTH_OPEN; | 
					
						
							|  |  |  | 		ieee->open_wep = 1; | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 	} else | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (ieee->set_security) | 
					
						
							|  |  |  | 		ieee->set_security(ieee->dev, &sec); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		ret = -EOPNOTSUPP; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | void ipw2100_wpa_assoc_frame(struct ipw2100_priv *priv, | 
					
						
							|  |  |  | 			     char *wpa_ie, int wpa_ie_len) | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 	struct ipw2100_wpa_assoc_frame frame; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	frame.fixed_ie_mask = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* copy WPA IE */ | 
					
						
							|  |  |  | 	memcpy(frame.var_ie, wpa_ie, wpa_ie_len); | 
					
						
							|  |  |  | 	frame.var_ie_len = wpa_ie_len; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 	/* make sure WPA is enabled */ | 
					
						
							|  |  |  | 	ipw2100_wpa_enable(priv, 1); | 
					
						
							|  |  |  | 	ipw2100_set_wpa_ie(priv, &frame, 0); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void ipw_ethtool_get_drvinfo(struct net_device *dev, | 
					
						
							|  |  |  | 				    struct ethtool_drvinfo *info) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	char fw_ver[64], ucode_ver[64]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	strcpy(info->driver, DRV_NAME); | 
					
						
							|  |  |  | 	strcpy(info->version, DRV_VERSION); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ipw2100_get_fwversion(priv, fw_ver, sizeof(fw_ver)); | 
					
						
							|  |  |  | 	ipw2100_get_ucodeversion(priv, ucode_ver, sizeof(ucode_ver)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	snprintf(info->fw_version, sizeof(info->fw_version), "%s:%d:%s", | 
					
						
							|  |  |  | 		 fw_ver, priv->eeprom_version, ucode_ver); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	strcpy(info->bus_info, pci_name(priv->pci_dev)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static u32 ipw2100_ethtool_get_link(struct net_device *dev) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	return (priv->status & STATUS_ASSOCIATED) ? 1 : 0; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct ethtool_ops ipw2100_ethtool_ops = { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	.get_link = ipw2100_ethtool_get_link, | 
					
						
							|  |  |  | 	.get_drvinfo = ipw_ethtool_get_drvinfo, | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ipw2100_hang_check(void *adapter) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = adapter; | 
					
						
							|  |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 	u32 rtc = 0xa5a5a5a5; | 
					
						
							|  |  |  | 	u32 len = sizeof(rtc); | 
					
						
							|  |  |  | 	int restart = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&priv->low_lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->fatal_error != 0) { | 
					
						
							|  |  |  | 		/* If fatal_error is set then we need to restart */ | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("%s: Hardware fatal error detected.\n", | 
					
						
							|  |  |  | 			       priv->net_dev->name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		restart = 1; | 
					
						
							|  |  |  | 	} else if (ipw2100_get_ordinal(priv, IPW_ORD_RTC_TIME, &rtc, &len) || | 
					
						
							|  |  |  | 		   (rtc == priv->last_rtc)) { | 
					
						
							|  |  |  | 		/* Check if firmware is hung */ | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("%s: Firmware RTC stalled.\n", | 
					
						
							|  |  |  | 			       priv->net_dev->name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		restart = 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (restart) { | 
					
						
							|  |  |  | 		/* Kill timer */ | 
					
						
							|  |  |  | 		priv->stop_hang_check = 1; | 
					
						
							|  |  |  | 		priv->hangs++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Restart the NIC */ | 
					
						
							|  |  |  | 		schedule_reset(priv); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->last_rtc = rtc; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!priv->stop_hang_check) | 
					
						
							|  |  |  | 		queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&priv->low_lock, flags); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ipw2100_rf_kill(void *adapter) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = adapter; | 
					
						
							|  |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&priv->low_lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (rf_kill_active(priv)) { | 
					
						
							|  |  |  | 		IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n"); | 
					
						
							|  |  |  | 		if (!priv->stop_rf_kill) | 
					
						
							|  |  |  | 			queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ); | 
					
						
							|  |  |  | 		goto exit_unlock; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* RF Kill is now disabled, so bring the device back up */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_RF_KILL_MASK)) { | 
					
						
							|  |  |  | 		IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting " | 
					
						
							|  |  |  | 				  "device\n"); | 
					
						
							|  |  |  | 		schedule_reset(priv); | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | 		IPW_DEBUG_RF_KILL("HW RF Kill deactivated.  SW RF Kill still " | 
					
						
							|  |  |  | 				  "enabled\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       exit_unlock: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	spin_unlock_irqrestore(&priv->low_lock, flags); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ipw2100_irq_tasklet(struct ipw2100_priv *priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Look into using netdev destructor to shutdown ieee80211? */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static struct net_device *ipw2100_alloc_device(struct pci_dev *pci_dev, | 
					
						
							|  |  |  | 					       void __iomem * base_addr, | 
					
						
							|  |  |  | 					       unsigned long mem_start, | 
					
						
							|  |  |  | 					       unsigned long mem_len) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv; | 
					
						
							|  |  |  | 	struct net_device *dev; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dev = alloc_ieee80211(sizeof(struct ipw2100_priv)); | 
					
						
							|  |  |  | 	if (!dev) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	priv->ieee = netdev_priv(dev); | 
					
						
							|  |  |  | 	priv->pci_dev = pci_dev; | 
					
						
							|  |  |  | 	priv->net_dev = dev; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->ieee->hard_start_xmit = ipw2100_tx; | 
					
						
							|  |  |  | 	priv->ieee->set_security = shim__set_security; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 	priv->ieee->perfect_rssi = -20; | 
					
						
							|  |  |  | 	priv->ieee->worst_rssi = -85; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	dev->open = ipw2100_open; | 
					
						
							|  |  |  | 	dev->stop = ipw2100_close; | 
					
						
							|  |  |  | 	dev->init = ipw2100_net_init; | 
					
						
							|  |  |  | 	dev->get_stats = ipw2100_stats; | 
					
						
							|  |  |  | 	dev->ethtool_ops = &ipw2100_ethtool_ops; | 
					
						
							|  |  |  | 	dev->tx_timeout = ipw2100_tx_timeout; | 
					
						
							|  |  |  | 	dev->wireless_handlers = &ipw2100_wx_handler_def; | 
					
						
							| 
									
										
										
										
											2005-11-12 12:50:12 -06:00
										 |  |  | 	priv->wireless_data.ieee80211 = priv->ieee; | 
					
						
							|  |  |  | 	dev->wireless_data = &priv->wireless_data; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	dev->set_mac_address = ipw2100_set_address; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	dev->watchdog_timeo = 3 * HZ; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	dev->irq = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dev->base_addr = (unsigned long)base_addr; | 
					
						
							|  |  |  | 	dev->mem_start = mem_start; | 
					
						
							|  |  |  | 	dev->mem_end = dev->mem_start + mem_len - 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* NOTE: We don't use the wireless_handlers hook
 | 
					
						
							|  |  |  | 	 * in dev as the system will start throwing WX requests | 
					
						
							|  |  |  | 	 * to us before we're actually initialized and it just | 
					
						
							|  |  |  | 	 * ends up causing problems.  So, we just handle | 
					
						
							|  |  |  | 	 * the WX extensions through the ipw2100_ioctl interface */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* memset() puts everything to 0, so we only have explicitely set
 | 
					
						
							|  |  |  | 	 * those values that need to be something else */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* If power management is turned on, default to AUTO mode */ | 
					
						
							|  |  |  | 	priv->power_mode = IPW_POWER_AUTO; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | #ifdef CONFIG_IPW2100_MONITOR
 | 
					
						
							|  |  |  | 	priv->config |= CFG_CRC_CHECK; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	priv->ieee->wpa_enabled = 0; | 
					
						
							|  |  |  | 	priv->ieee->drop_unencrypted = 0; | 
					
						
							|  |  |  | 	priv->ieee->privacy_invoked = 0; | 
					
						
							|  |  |  | 	priv->ieee->ieee802_1x = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Set module parameters */ | 
					
						
							|  |  |  | 	switch (mode) { | 
					
						
							|  |  |  | 	case 1: | 
					
						
							|  |  |  | 		priv->ieee->iw_mode = IW_MODE_ADHOC; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | #ifdef CONFIG_IPW2100_MONITOR
 | 
					
						
							|  |  |  | 	case 2: | 
					
						
							|  |  |  | 		priv->ieee->iw_mode = IW_MODE_MONITOR; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 	case 0: | 
					
						
							|  |  |  | 		priv->ieee->iw_mode = IW_MODE_INFRA; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (disable == 1) | 
					
						
							|  |  |  | 		priv->status |= STATUS_RF_KILL_SW; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (channel != 0 && | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	    ((channel >= REG_MIN_CHANNEL) && (channel <= REG_MAX_CHANNEL))) { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		priv->config |= CFG_STATIC_CHANNEL; | 
					
						
							|  |  |  | 		priv->channel = channel; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (associate) | 
					
						
							|  |  |  | 		priv->config |= CFG_ASSOCIATE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->beacon_interval = DEFAULT_BEACON_INTERVAL; | 
					
						
							|  |  |  | 	priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT; | 
					
						
							|  |  |  | 	priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT; | 
					
						
							|  |  |  | 	priv->rts_threshold = DEFAULT_RTS_THRESHOLD | RTS_DISABLED; | 
					
						
							|  |  |  | 	priv->frag_threshold = DEFAULT_FTS | FRAG_DISABLED; | 
					
						
							|  |  |  | 	priv->tx_power = IPW_TX_POWER_DEFAULT; | 
					
						
							|  |  |  | 	priv->tx_rates = DEFAULT_TX_RATES; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	strcpy(priv->nick, "ipw2100"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_init(&priv->low_lock); | 
					
						
							|  |  |  | 	sema_init(&priv->action_sem, 1); | 
					
						
							|  |  |  | 	sema_init(&priv->adapter_sem, 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	init_waitqueue_head(&priv->wait_command_queue); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	netif_carrier_off(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	INIT_LIST_HEAD(&priv->msg_free_list); | 
					
						
							|  |  |  | 	INIT_LIST_HEAD(&priv->msg_pend_list); | 
					
						
							|  |  |  | 	INIT_STAT(&priv->msg_free_stat); | 
					
						
							|  |  |  | 	INIT_STAT(&priv->msg_pend_stat); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	INIT_LIST_HEAD(&priv->tx_free_list); | 
					
						
							|  |  |  | 	INIT_LIST_HEAD(&priv->tx_pend_list); | 
					
						
							|  |  |  | 	INIT_STAT(&priv->tx_free_stat); | 
					
						
							|  |  |  | 	INIT_STAT(&priv->tx_pend_stat); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	INIT_LIST_HEAD(&priv->fw_pend_list); | 
					
						
							|  |  |  | 	INIT_STAT(&priv->fw_pend_stat); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->workqueue = create_workqueue(DRV_NAME); | 
					
						
							| 
									
										
										
										
											2005-09-07 18:39:03 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	INIT_WORK(&priv->reset_work, | 
					
						
							|  |  |  | 		  (void (*)(void *))ipw2100_reset_adapter, priv); | 
					
						
							|  |  |  | 	INIT_WORK(&priv->security_work, | 
					
						
							|  |  |  | 		  (void (*)(void *))ipw2100_security_work, priv); | 
					
						
							|  |  |  | 	INIT_WORK(&priv->wx_event_work, | 
					
						
							|  |  |  | 		  (void (*)(void *))ipw2100_wx_event_work, priv); | 
					
						
							|  |  |  | 	INIT_WORK(&priv->hang_check, ipw2100_hang_check, priv); | 
					
						
							|  |  |  | 	INIT_WORK(&priv->rf_kill, ipw2100_rf_kill, priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) | 
					
						
							|  |  |  | 		     ipw2100_irq_tasklet, (unsigned long)priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* NOTE:  We do not start the deferred work for status checks yet */ | 
					
						
							|  |  |  | 	priv->stop_rf_kill = 1; | 
					
						
							|  |  |  | 	priv->stop_hang_check = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return dev; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_pci_init_one(struct pci_dev *pci_dev, | 
					
						
							|  |  |  | 				const struct pci_device_id *ent) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned long mem_start, mem_len, mem_flags; | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	void __iomem *base_addr = NULL; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	struct net_device *dev = NULL; | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = NULL; | 
					
						
							|  |  |  | 	int err = 0; | 
					
						
							|  |  |  | 	int registered = 0; | 
					
						
							|  |  |  | 	u32 val; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("enter\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mem_start = pci_resource_start(pci_dev, 0); | 
					
						
							|  |  |  | 	mem_len = pci_resource_len(pci_dev, 0); | 
					
						
							|  |  |  | 	mem_flags = pci_resource_flags(pci_dev, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((mem_flags & IORESOURCE_MEM) != IORESOURCE_MEM) { | 
					
						
							|  |  |  | 		IPW_DEBUG_INFO("weird - resource type is not memory\n"); | 
					
						
							|  |  |  | 		err = -ENODEV; | 
					
						
							|  |  |  | 		goto fail; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	base_addr = ioremap_nocache(mem_start, mem_len); | 
					
						
							|  |  |  | 	if (!base_addr) { | 
					
						
							|  |  |  | 		printk(KERN_WARNING DRV_NAME | 
					
						
							|  |  |  | 		       "Error calling ioremap_nocache.\n"); | 
					
						
							|  |  |  | 		err = -EIO; | 
					
						
							|  |  |  | 		goto fail; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* allocate and initialize our net_device */ | 
					
						
							|  |  |  | 	dev = ipw2100_alloc_device(pci_dev, base_addr, mem_start, mem_len); | 
					
						
							|  |  |  | 	if (!dev) { | 
					
						
							|  |  |  | 		printk(KERN_WARNING DRV_NAME | 
					
						
							|  |  |  | 		       "Error calling ipw2100_alloc_device.\n"); | 
					
						
							|  |  |  | 		err = -ENOMEM; | 
					
						
							|  |  |  | 		goto fail; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* set up PCI mappings for device */ | 
					
						
							|  |  |  | 	err = pci_enable_device(pci_dev); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							|  |  |  | 		printk(KERN_WARNING DRV_NAME | 
					
						
							|  |  |  | 		       "Error calling pci_enable_device.\n"); | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pci_set_master(pci_dev); | 
					
						
							|  |  |  | 	pci_set_drvdata(pci_dev, priv); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-20 14:28:40 -07:00
										 |  |  | 	err = pci_set_dma_mask(pci_dev, DMA_32BIT_MASK); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	if (err) { | 
					
						
							|  |  |  | 		printk(KERN_WARNING DRV_NAME | 
					
						
							|  |  |  | 		       "Error calling pci_set_dma_mask.\n"); | 
					
						
							|  |  |  | 		pci_disable_device(pci_dev); | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = pci_request_regions(pci_dev, DRV_NAME); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							|  |  |  | 		printk(KERN_WARNING DRV_NAME | 
					
						
							|  |  |  | 		       "Error calling pci_request_regions.\n"); | 
					
						
							|  |  |  | 		pci_disable_device(pci_dev); | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	/* We disable the RETRY_TIMEOUT register (0x41) to keep
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	 * PCI Tx retries from interfering with C3 CPU state */ | 
					
						
							|  |  |  | 	pci_read_config_dword(pci_dev, 0x40, &val); | 
					
						
							|  |  |  | 	if ((val & 0x0000ff00) != 0) | 
					
						
							|  |  |  | 		pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-20 14:28:43 -07:00
										 |  |  | 	pci_set_power_state(pci_dev, PCI_D0); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!ipw2100_hw_is_adapter_in_system(dev)) { | 
					
						
							|  |  |  | 		printk(KERN_WARNING DRV_NAME | 
					
						
							|  |  |  | 		       "Device not found via register read.\n"); | 
					
						
							|  |  |  | 		err = -ENODEV; | 
					
						
							|  |  |  | 		goto fail; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SET_NETDEV_DEV(dev, &pci_dev->dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Force interrupts to be shut off on the device */ | 
					
						
							|  |  |  | 	priv->status |= STATUS_INT_ENABLED; | 
					
						
							|  |  |  | 	ipw2100_disable_interrupts(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Allocate and initialize the Tx/Rx queues and lists */ | 
					
						
							|  |  |  | 	if (ipw2100_queues_allocate(priv)) { | 
					
						
							|  |  |  | 		printk(KERN_WARNING DRV_NAME | 
					
						
							|  |  |  | 		       "Error calilng ipw2100_queues_allocate.\n"); | 
					
						
							|  |  |  | 		err = -ENOMEM; | 
					
						
							|  |  |  | 		goto fail; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ipw2100_queues_initialize(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = request_irq(pci_dev->irq, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			  ipw2100_interrupt, SA_SHIRQ, dev->name, priv); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	if (err) { | 
					
						
							|  |  |  | 		printk(KERN_WARNING DRV_NAME | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		       "Error calling request_irq: %d.\n", pci_dev->irq); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		goto fail; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	dev->irq = pci_dev->irq; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("Attempting to register device...\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SET_MODULE_OWNER(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	printk(KERN_INFO DRV_NAME | 
					
						
							|  |  |  | 	       ": Detected Intel PRO/Wireless 2100 Network Connection\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Bring up the interface.  Pre 0.46, after we registered the
 | 
					
						
							|  |  |  | 	 * network device we would call ipw2100_up.  This introduced a race | 
					
						
							|  |  |  | 	 * condition with newer hotplug configurations (network was coming | 
					
						
							|  |  |  | 	 * up and making calls before the device was initialized). | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * If we called ipw2100_up before we registered the device, then the | 
					
						
							|  |  |  | 	 * device name wasn't registered.  So, we instead use the net_dev->init | 
					
						
							|  |  |  | 	 * member to call a function that then just turns and calls ipw2100_up. | 
					
						
							|  |  |  | 	 * net_dev->init is called after name allocation but before the | 
					
						
							|  |  |  | 	 * notifier chain is called */ | 
					
						
							|  |  |  | 	down(&priv->action_sem); | 
					
						
							|  |  |  | 	err = register_netdev(dev); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							|  |  |  | 		printk(KERN_WARNING DRV_NAME | 
					
						
							|  |  |  | 		       "Error calling register_netdev.\n"); | 
					
						
							|  |  |  | 		goto fail_unlock; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	registered = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("%s: Bound to %s\n", dev->name, pci_name(pci_dev)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* perform this after register_netdev so that dev->name is set */ | 
					
						
							|  |  |  | 	sysfs_create_group(&pci_dev->dev.kobj, &ipw2100_attribute_group); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* If the RF Kill switch is disabled, go ahead and complete the
 | 
					
						
							|  |  |  | 	 * startup sequence */ | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_RF_KILL_MASK)) { | 
					
						
							|  |  |  | 		/* Enable the adapter - sends HOST_COMPLETE */ | 
					
						
							|  |  |  | 		if (ipw2100_enable_adapter(priv)) { | 
					
						
							|  |  |  | 			printk(KERN_WARNING DRV_NAME | 
					
						
							|  |  |  | 			       ": %s: failed in call to enable adapter.\n", | 
					
						
							|  |  |  | 			       priv->net_dev->name); | 
					
						
							|  |  |  | 			ipw2100_hw_stop_adapter(priv); | 
					
						
							|  |  |  | 			err = -EIO; | 
					
						
							|  |  |  | 			goto fail_unlock; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Start a scan . . . */ | 
					
						
							|  |  |  | 		ipw2100_set_scan_options(priv); | 
					
						
							|  |  |  | 		ipw2100_start_scan(priv); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("exit\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->status |= STATUS_INITIALIZED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       fail_unlock: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       fail: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	if (dev) { | 
					
						
							|  |  |  | 		if (registered) | 
					
						
							|  |  |  | 			unregister_netdev(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ipw2100_hw_stop_adapter(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ipw2100_disable_interrupts(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (dev->irq) | 
					
						
							|  |  |  | 			free_irq(dev->irq, priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ipw2100_kill_workqueue(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* These are safe to call even if they weren't allocated */ | 
					
						
							|  |  |  | 		ipw2100_queues_free(priv); | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		sysfs_remove_group(&pci_dev->dev.kobj, | 
					
						
							|  |  |  | 				   &ipw2100_attribute_group); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		free_ieee80211(dev); | 
					
						
							|  |  |  | 		pci_set_drvdata(pci_dev, NULL); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (base_addr) | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 		iounmap(base_addr); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	pci_release_regions(pci_dev); | 
					
						
							|  |  |  | 	pci_disable_device(pci_dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void __devexit ipw2100_pci_remove_one(struct pci_dev *pci_dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = pci_get_drvdata(pci_dev); | 
					
						
							|  |  |  | 	struct net_device *dev; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv) { | 
					
						
							|  |  |  | 		down(&priv->action_sem); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		priv->status &= ~STATUS_INITIALIZED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		dev = priv->net_dev; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		sysfs_remove_group(&pci_dev->dev.kobj, | 
					
						
							|  |  |  | 				   &ipw2100_attribute_group); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef CONFIG_PM
 | 
					
						
							|  |  |  | 		if (ipw2100_firmware.version) | 
					
						
							|  |  |  | 			ipw2100_release_firmware(priv, &ipw2100_firmware); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 		/* Take down the hardware */ | 
					
						
							|  |  |  | 		ipw2100_down(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Release the semaphore so that the network subsystem can
 | 
					
						
							|  |  |  | 		 * complete any needed calls into the driver... */ | 
					
						
							|  |  |  | 		up(&priv->action_sem); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Unregister the device first - this results in close()
 | 
					
						
							|  |  |  | 		 * being called if the device is open.  If we free storage | 
					
						
							|  |  |  | 		 * first, then close() will crash. */ | 
					
						
							|  |  |  | 		unregister_netdev(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* ipw2100_down will ensure that there is no more pending work
 | 
					
						
							|  |  |  | 		 * in the workqueue's, so we can safely remove them now. */ | 
					
						
							|  |  |  | 		ipw2100_kill_workqueue(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ipw2100_queues_free(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Free potential debugging firmware snapshot */ | 
					
						
							|  |  |  | 		ipw2100_snapshot_free(priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (dev->irq) | 
					
						
							|  |  |  | 			free_irq(dev->irq, priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (dev->base_addr) | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 			iounmap((void __iomem *)dev->base_addr); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		free_ieee80211(dev); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pci_release_regions(pci_dev); | 
					
						
							|  |  |  | 	pci_disable_device(pci_dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("exit\n"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef CONFIG_PM
 | 
					
						
							|  |  |  | static int ipw2100_suspend(struct pci_dev *pci_dev, pm_message_t state) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = pci_get_drvdata(pci_dev); | 
					
						
							|  |  |  | 	struct net_device *dev = priv->net_dev; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	IPW_DEBUG_INFO("%s: Going into suspend...\n", dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->action_sem); | 
					
						
							|  |  |  | 	if (priv->status & STATUS_INITIALIZED) { | 
					
						
							|  |  |  | 		/* Take down the device; powers it off, etc. */ | 
					
						
							|  |  |  | 		ipw2100_down(priv); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Remove the PRESENT state of the device */ | 
					
						
							|  |  |  | 	netif_device_detach(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pci_save_state(pci_dev); | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	pci_disable_device(pci_dev); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	pci_set_power_state(pci_dev, PCI_D3hot); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_resume(struct pci_dev *pci_dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = pci_get_drvdata(pci_dev); | 
					
						
							|  |  |  | 	struct net_device *dev = priv->net_dev; | 
					
						
							|  |  |  | 	u32 val; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (IPW2100_PM_DISABLED) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->action_sem); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	IPW_DEBUG_INFO("%s: Coming out of suspend...\n", dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	pci_set_power_state(pci_dev, PCI_D0); | 
					
						
							|  |  |  | 	pci_enable_device(pci_dev); | 
					
						
							|  |  |  | 	pci_restore_state(pci_dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Suspend/Resume resets the PCI configuration space, so we have to | 
					
						
							|  |  |  | 	 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries | 
					
						
							|  |  |  | 	 * from interfering with C3 CPU state. pci_restore_state won't help | 
					
						
							|  |  |  | 	 * here since it only restores the first 64 bytes pci config header. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	pci_read_config_dword(pci_dev, 0x40, &val); | 
					
						
							|  |  |  | 	if ((val & 0x0000ff00) != 0) | 
					
						
							|  |  |  | 		pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Set the device back into the PRESENT state; this will also wake
 | 
					
						
							|  |  |  | 	 * the queue of needed */ | 
					
						
							|  |  |  | 	netif_device_attach(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	/* Bring the device back up */ | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_RF_KILL_SW)) | 
					
						
							|  |  |  | 		ipw2100_up(priv, 0); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define IPW2100_DEV_ID(x) { PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, x }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct pci_device_id ipw2100_pci_id_table[] __devinitdata = { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	IPW2100_DEV_ID(0x2520),	/* IN 2100A mPCI 3A */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2521),	/* IN 2100A mPCI 3B */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2524),	/* IN 2100A mPCI 3B */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2525),	/* IN 2100A mPCI 3B */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2526),	/* IN 2100A mPCI Gen A3 */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2522),	/* IN 2100 mPCI 3B */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2523),	/* IN 2100 mPCI 3A */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2527),	/* IN 2100 mPCI 3B */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2528),	/* IN 2100 mPCI 3B */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2529),	/* IN 2100 mPCI 3B */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x252B),	/* IN 2100 mPCI 3A */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x252C),	/* IN 2100 mPCI 3A */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x252D),	/* IN 2100 mPCI 3A */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2550),	/* IB 2100A mPCI 3B */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2551),	/* IB 2100 mPCI 3B */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2553),	/* IB 2100 mPCI 3B */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2554),	/* IB 2100 mPCI 3B */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2555),	/* IB 2100 mPCI 3B */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2560),	/* DE 2100A mPCI 3A */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2562),	/* DE 2100A mPCI 3A */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2563),	/* DE 2100A mPCI 3A */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2561),	/* DE 2100 mPCI 3A */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2565),	/* DE 2100 mPCI 3A */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2566),	/* DE 2100 mPCI 3A */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2567),	/* DE 2100 mPCI 3A */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2570),	/* GA 2100 mPCI 3B */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2580),	/* TO 2100A mPCI 3B */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2582),	/* TO 2100A mPCI 3B */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2583),	/* TO 2100A mPCI 3B */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2581),	/* TO 2100 mPCI 3B */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2585),	/* TO 2100 mPCI 3B */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2586),	/* TO 2100 mPCI 3B */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2587),	/* TO 2100 mPCI 3B */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2590),	/* SO 2100A mPCI 3B */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2592),	/* SO 2100A mPCI 3B */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2591),	/* SO 2100 mPCI 3B */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2593),	/* SO 2100 mPCI 3B */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2596),	/* SO 2100 mPCI 3B */ | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x2598),	/* SO 2100 mPCI 3B */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW2100_DEV_ID(0x25A0),	/* HP 2100 mPCI 3B */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	{0,}, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MODULE_DEVICE_TABLE(pci, ipw2100_pci_id_table); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct pci_driver ipw2100_pci_driver = { | 
					
						
							|  |  |  | 	.name = DRV_NAME, | 
					
						
							|  |  |  | 	.id_table = ipw2100_pci_id_table, | 
					
						
							|  |  |  | 	.probe = ipw2100_pci_init_one, | 
					
						
							|  |  |  | 	.remove = __devexit_p(ipw2100_pci_remove_one), | 
					
						
							|  |  |  | #ifdef CONFIG_PM
 | 
					
						
							|  |  |  | 	.suspend = ipw2100_suspend, | 
					
						
							|  |  |  | 	.resume = ipw2100_resume, | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Initialize the ipw2100 driver/module | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @returns 0 if ok, < 0 errno node con error. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Note: we cannot init the /proc stuff until the PCI driver is there, | 
					
						
							|  |  |  |  * or we risk an unlikely race condition on someone accessing | 
					
						
							|  |  |  |  * uninitialized data in the PCI dev struct through /proc. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static int __init ipw2100_init(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	printk(KERN_INFO DRV_NAME ": %s, %s\n", DRV_DESCRIPTION, DRV_VERSION); | 
					
						
							|  |  |  | 	printk(KERN_INFO DRV_NAME ": %s\n", DRV_COPYRIGHT); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ret = pci_module_init(&ipw2100_pci_driver); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-01 01:41:46 -08:00
										 |  |  | #ifdef CONFIG_IPW2100_DEBUG
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	ipw2100_debug_level = debug; | 
					
						
							|  |  |  | 	driver_create_file(&ipw2100_pci_driver.driver, | 
					
						
							|  |  |  | 			   &driver_attr_debug_level); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Cleanup ipw2100 driver registration | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static void __exit ipw2100_exit(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* FIXME: IPG: check that we have no instances of the devices open */ | 
					
						
							| 
									
										
										
										
											2005-12-01 01:41:46 -08:00
										 |  |  | #ifdef CONFIG_IPW2100_DEBUG
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	driver_remove_file(&ipw2100_pci_driver.driver, | 
					
						
							|  |  |  | 			   &driver_attr_debug_level); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	pci_unregister_driver(&ipw2100_pci_driver); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module_init(ipw2100_init); | 
					
						
							|  |  |  | module_exit(ipw2100_exit); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define WEXT_USECHANNELS 1
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static const long ipw2100_frequencies[] = { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	2412, 2417, 2422, 2427, | 
					
						
							|  |  |  | 	2432, 2437, 2442, 2447, | 
					
						
							|  |  |  | 	2452, 2457, 2462, 2467, | 
					
						
							|  |  |  | 	2472, 2484 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define FREQ_COUNT (sizeof(ipw2100_frequencies) / \
 | 
					
						
							|  |  |  |                     sizeof(ipw2100_frequencies[0])) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static const long ipw2100_rates_11b[] = { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	1000000, | 
					
						
							|  |  |  | 	2000000, | 
					
						
							|  |  |  | 	5500000, | 
					
						
							|  |  |  | 	11000000 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define RATE_COUNT (sizeof(ipw2100_rates_11b) / sizeof(ipw2100_rates_11b[0]))
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_get_name(struct net_device *dev, | 
					
						
							|  |  |  | 			       struct iw_request_info *info, | 
					
						
							|  |  |  | 			       union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * This can be called at any time.  No action lock required | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_ASSOCIATED)) | 
					
						
							|  |  |  | 		strcpy(wrqu->name, "unassociated"); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_WX("Name: %s\n", wrqu->name); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_set_freq(struct net_device *dev, | 
					
						
							|  |  |  | 			       struct iw_request_info *info, | 
					
						
							|  |  |  | 			       union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	struct iw_freq *fwrq = &wrqu->freq; | 
					
						
							|  |  |  | 	int err = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->ieee->iw_mode == IW_MODE_INFRA) | 
					
						
							|  |  |  | 		return -EOPNOTSUPP; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->action_sem); | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_INITIALIZED)) { | 
					
						
							|  |  |  | 		err = -EIO; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* if setting by freq convert to channel */ | 
					
						
							|  |  |  | 	if (fwrq->e == 1) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		if ((fwrq->m >= (int)2.412e8 && fwrq->m <= (int)2.487e8)) { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			int f = fwrq->m / 100000; | 
					
						
							|  |  |  | 			int c = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			while ((c < REG_MAX_CHANNEL) && | 
					
						
							|  |  |  | 			       (f != ipw2100_frequencies[c])) | 
					
						
							|  |  |  | 				c++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* hack to fall through */ | 
					
						
							|  |  |  | 			fwrq->e = 0; | 
					
						
							|  |  |  | 			fwrq->m = c + 1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 	if (fwrq->e > 0 || fwrq->m > 1000) { | 
					
						
							|  |  |  | 		err = -EOPNOTSUPP; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} else {		/* Set the channel */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m); | 
					
						
							|  |  |  | 		err = ipw2100_set_channel(priv, fwrq->m, 0); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       done: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_get_freq(struct net_device *dev, | 
					
						
							|  |  |  | 			       struct iw_request_info *info, | 
					
						
							|  |  |  | 			       union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * This can be called at any time.  No action lock required | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wrqu->freq.e = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* If we are associated, trying to associate, or have a statically
 | 
					
						
							|  |  |  | 	 * configured CHANNEL then return that; otherwise return ANY */ | 
					
						
							|  |  |  | 	if (priv->config & CFG_STATIC_CHANNEL || | 
					
						
							|  |  |  | 	    priv->status & STATUS_ASSOCIATED) | 
					
						
							|  |  |  | 		wrqu->freq.m = priv->channel; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		wrqu->freq.m = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_set_mode(struct net_device *dev, | 
					
						
							|  |  |  | 			       struct iw_request_info *info, | 
					
						
							|  |  |  | 			       union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	int err = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_WX("SET Mode -> %d \n", wrqu->mode); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (wrqu->mode == priv->ieee->iw_mode) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->action_sem); | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_INITIALIZED)) { | 
					
						
							|  |  |  | 		err = -EIO; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (wrqu->mode) { | 
					
						
							|  |  |  | #ifdef CONFIG_IPW2100_MONITOR
 | 
					
						
							|  |  |  | 	case IW_MODE_MONITOR: | 
					
						
							|  |  |  | 		err = ipw2100_switch_mode(priv, IW_MODE_MONITOR); | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | #endif				/* CONFIG_IPW2100_MONITOR */
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	case IW_MODE_ADHOC: | 
					
						
							|  |  |  | 		err = ipw2100_switch_mode(priv, IW_MODE_ADHOC); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IW_MODE_INFRA: | 
					
						
							|  |  |  | 	case IW_MODE_AUTO: | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		err = ipw2100_switch_mode(priv, IW_MODE_INFRA); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       done: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	up(&priv->action_sem); | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	return err; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_get_mode(struct net_device *dev, | 
					
						
							|  |  |  | 			       struct iw_request_info *info, | 
					
						
							|  |  |  | 			       union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * This can be called at any time.  No action lock required | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wrqu->mode = priv->ieee->iw_mode; | 
					
						
							|  |  |  | 	IPW_DEBUG_WX("GET Mode -> %d\n", wrqu->mode); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define POWER_MODES 5
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Values are in microsecond */ | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static const s32 timeout_duration[POWER_MODES] = { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	350000, | 
					
						
							|  |  |  | 	250000, | 
					
						
							|  |  |  | 	75000, | 
					
						
							|  |  |  | 	37000, | 
					
						
							|  |  |  | 	25000, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static const s32 period_duration[POWER_MODES] = { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	400000, | 
					
						
							|  |  |  | 	700000, | 
					
						
							|  |  |  | 	1000000, | 
					
						
							|  |  |  | 	1000000, | 
					
						
							|  |  |  | 	1000000 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_get_range(struct net_device *dev, | 
					
						
							|  |  |  | 				struct iw_request_info *info, | 
					
						
							|  |  |  | 				union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * This can be called at any time.  No action lock required | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	struct iw_range *range = (struct iw_range *)extra; | 
					
						
							|  |  |  | 	u16 val; | 
					
						
							|  |  |  | 	int i, level; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wrqu->data.length = sizeof(*range); | 
					
						
							|  |  |  | 	memset(range, 0, sizeof(*range)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Let's try to keep this struct in the same order as in
 | 
					
						
							|  |  |  | 	 * linux/include/wireless.h | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* TODO: See what values we can set, and remove the ones we can't
 | 
					
						
							|  |  |  | 	 * set, or fill them with some default data. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* ~5 Mb/s real (802.11b) */ | 
					
						
							|  |  |  | 	range->throughput = 5 * 1000 * 1000; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | //      range->sensitivity;     /* signal level threshold range */
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	range->max_qual.qual = 100; | 
					
						
							|  |  |  | 	/* TODO: Find real max RSSI and stick here */ | 
					
						
							|  |  |  | 	range->max_qual.level = 0; | 
					
						
							|  |  |  | 	range->max_qual.noise = 0; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	range->max_qual.updated = 7;	/* Updated all three */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	range->avg_qual.qual = 70;	/* > 8% missed beacons is 'bad' */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	/* TODO: Find real 'good' to 'bad' threshol value for RSSI */ | 
					
						
							|  |  |  | 	range->avg_qual.level = 20 + IPW2100_RSSI_TO_DBM; | 
					
						
							|  |  |  | 	range->avg_qual.noise = 0; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	range->avg_qual.updated = 7;	/* Updated all three */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	range->num_bitrates = RATE_COUNT; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++) { | 
					
						
							|  |  |  | 		range->bitrate[i] = ipw2100_rates_11b[i]; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	range->min_rts = MIN_RTS_THRESHOLD; | 
					
						
							|  |  |  | 	range->max_rts = MAX_RTS_THRESHOLD; | 
					
						
							|  |  |  | 	range->min_frag = MIN_FRAG_THRESHOLD; | 
					
						
							|  |  |  | 	range->max_frag = MAX_FRAG_THRESHOLD; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	range->min_pmp = period_duration[0];	/* Minimal PM period */ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	range->max_pmp = period_duration[POWER_MODES - 1];	/* Maximal PM period */ | 
					
						
							|  |  |  | 	range->min_pmt = timeout_duration[POWER_MODES - 1];	/* Minimal PM timeout */ | 
					
						
							|  |  |  | 	range->max_pmt = timeout_duration[0];	/* Maximal PM timeout */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	/* How to decode max/min PM period */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	range->pmp_flags = IW_POWER_PERIOD; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	/* How to decode max/min PM period */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	range->pmt_flags = IW_POWER_TIMEOUT; | 
					
						
							|  |  |  | 	/* What PM options are supported */ | 
					
						
							|  |  |  | 	range->pm_capa = IW_POWER_TIMEOUT | IW_POWER_PERIOD; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	range->encoding_size[0] = 5; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	range->encoding_size[1] = 13;	/* Different token sizes */ | 
					
						
							|  |  |  | 	range->num_encoding_sizes = 2;	/* Number of entry in the list */ | 
					
						
							|  |  |  | 	range->max_encoding_tokens = WEP_KEYS;	/* Max number of tokens */ | 
					
						
							|  |  |  | //      range->encoding_login_index;            /* token index for login token */
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | 
					
						
							|  |  |  | 		range->txpower_capa = IW_TXPOW_DBM; | 
					
						
							|  |  |  | 		range->num_txpower = IW_MAX_TXPOWER; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		for (i = 0, level = (IPW_TX_POWER_MAX_DBM * 16); | 
					
						
							|  |  |  | 		     i < IW_MAX_TXPOWER; | 
					
						
							|  |  |  | 		     i++, level -= | 
					
						
							|  |  |  | 		     ((IPW_TX_POWER_MAX_DBM - | 
					
						
							|  |  |  | 		       IPW_TX_POWER_MIN_DBM) * 16) / (IW_MAX_TXPOWER - 1)) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			range->txpower[i] = level / 16; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		range->txpower_capa = 0; | 
					
						
							|  |  |  | 		range->num_txpower = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Set the Wireless Extension versions */ | 
					
						
							|  |  |  | 	range->we_version_compiled = WIRELESS_EXT; | 
					
						
							| 
									
										
										
										
											2006-01-09 11:04:31 -05:00
										 |  |  | 	range->we_version_source = 18; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | //      range->retry_capa;      /* What retry options are supported */
 | 
					
						
							|  |  |  | //      range->retry_flags;     /* How to decode max/min retry limit */
 | 
					
						
							|  |  |  | //      range->r_time_flags;    /* How to decode max/min retry life */
 | 
					
						
							|  |  |  | //      range->min_retry;       /* Minimal number of retries */
 | 
					
						
							|  |  |  | //      range->max_retry;       /* Maximal number of retries */
 | 
					
						
							|  |  |  | //      range->min_r_time;      /* Minimal retry lifetime */
 | 
					
						
							|  |  |  | //      range->max_r_time;      /* Maximal retry lifetime */
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	range->num_channels = FREQ_COUNT; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	val = 0; | 
					
						
							|  |  |  | 	for (i = 0; i < FREQ_COUNT; i++) { | 
					
						
							|  |  |  | 		// TODO: Include only legal frequencies for some countries
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | //              if (local->channel_mask & (1 << i)) {
 | 
					
						
							|  |  |  | 		range->freq[val].i = i + 1; | 
					
						
							|  |  |  | 		range->freq[val].m = ipw2100_frequencies[i] * 100000; | 
					
						
							|  |  |  | 		range->freq[val].e = 1; | 
					
						
							|  |  |  | 		val++; | 
					
						
							|  |  |  | //              }
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		if (val == IW_MAX_FREQUENCIES) | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	range->num_frequency = val; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-12 12:50:12 -06:00
										 |  |  | 	/* Event capability (kernel + driver) */ | 
					
						
							|  |  |  | 	range->event_capa[0] = (IW_EVENT_CAPA_K_0 | | 
					
						
							|  |  |  | 				IW_EVENT_CAPA_MASK(SIOCGIWAP)); | 
					
						
							|  |  |  | 	range->event_capa[1] = IW_EVENT_CAPA_K_1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-09 11:04:31 -05:00
										 |  |  | 	range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | | 
					
						
							|  |  |  | 		IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	IPW_DEBUG_WX("GET Range\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_set_wap(struct net_device *dev, | 
					
						
							|  |  |  | 			      struct iw_request_info *info, | 
					
						
							|  |  |  | 			      union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	int err = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	static const unsigned char any[] = { | 
					
						
							|  |  |  | 		0xff, 0xff, 0xff, 0xff, 0xff, 0xff | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	static const unsigned char off[] = { | 
					
						
							|  |  |  | 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// sanity checks
 | 
					
						
							|  |  |  | 	if (wrqu->ap_addr.sa_family != ARPHRD_ETHER) | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->action_sem); | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_INITIALIZED)) { | 
					
						
							|  |  |  | 		err = -EIO; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) || | 
					
						
							|  |  |  | 	    !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) { | 
					
						
							|  |  |  | 		/* we disable mandatory BSSID association */ | 
					
						
							|  |  |  | 		IPW_DEBUG_WX("exit - disable mandatory BSSID\n"); | 
					
						
							|  |  |  | 		priv->config &= ~CFG_STATIC_BSSID; | 
					
						
							|  |  |  | 		err = ipw2100_set_mandatory_bssid(priv, NULL, 0); | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->config |= CFG_STATIC_BSSID; | 
					
						
							|  |  |  | 	memcpy(priv->mandatory_bssid_mac, wrqu->ap_addr.sa_data, ETH_ALEN); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_set_mandatory_bssid(priv, wrqu->ap_addr.sa_data, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_WX("SET BSSID -> %02X:%02X:%02X:%02X:%02X:%02X\n", | 
					
						
							|  |  |  | 		     wrqu->ap_addr.sa_data[0] & 0xff, | 
					
						
							|  |  |  | 		     wrqu->ap_addr.sa_data[1] & 0xff, | 
					
						
							|  |  |  | 		     wrqu->ap_addr.sa_data[2] & 0xff, | 
					
						
							|  |  |  | 		     wrqu->ap_addr.sa_data[3] & 0xff, | 
					
						
							|  |  |  | 		     wrqu->ap_addr.sa_data[4] & 0xff, | 
					
						
							|  |  |  | 		     wrqu->ap_addr.sa_data[5] & 0xff); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       done: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_get_wap(struct net_device *dev, | 
					
						
							|  |  |  | 			      struct iw_request_info *info, | 
					
						
							|  |  |  | 			      union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * This can be called at any time.  No action lock required | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* If we are associated, trying to associate, or have a statically
 | 
					
						
							|  |  |  | 	 * configured BSSID then return that; otherwise return ANY */ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	if (priv->config & CFG_STATIC_BSSID || priv->status & STATUS_ASSOCIATED) { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		wrqu->ap_addr.sa_family = ARPHRD_ETHER; | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 		memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} else | 
					
						
							|  |  |  | 		memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n", | 
					
						
							|  |  |  | 		     MAC_ARG(wrqu->ap_addr.sa_data)); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_set_essid(struct net_device *dev, | 
					
						
							|  |  |  | 				struct iw_request_info *info, | 
					
						
							|  |  |  | 				union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	char *essid = "";	/* ANY */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	int length = 0; | 
					
						
							|  |  |  | 	int err = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->action_sem); | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_INITIALIZED)) { | 
					
						
							|  |  |  | 		err = -EIO; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (wrqu->essid.flags && wrqu->essid.length) { | 
					
						
							|  |  |  | 		length = wrqu->essid.length - 1; | 
					
						
							|  |  |  | 		essid = extra; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (length == 0) { | 
					
						
							|  |  |  | 		IPW_DEBUG_WX("Setting ESSID to ANY\n"); | 
					
						
							|  |  |  | 		priv->config &= ~CFG_STATIC_ESSID; | 
					
						
							|  |  |  | 		err = ipw2100_set_essid(priv, NULL, 0, 0); | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	length = min(length, IW_ESSID_MAX_SIZE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->config |= CFG_STATIC_ESSID; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) { | 
					
						
							|  |  |  | 		IPW_DEBUG_WX("ESSID set to current ESSID.\n"); | 
					
						
							|  |  |  | 		err = 0; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length), | 
					
						
							|  |  |  | 		     length); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	priv->essid_len = length; | 
					
						
							|  |  |  | 	memcpy(priv->essid, essid, priv->essid_len); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_set_essid(priv, essid, length, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       done: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_get_essid(struct net_device *dev, | 
					
						
							|  |  |  | 				struct iw_request_info *info, | 
					
						
							|  |  |  | 				union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * This can be called at any time.  No action lock required | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* If we are associated, trying to associate, or have a statically
 | 
					
						
							|  |  |  | 	 * configured ESSID then return that; otherwise return ANY */ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	if (priv->config & CFG_STATIC_ESSID || priv->status & STATUS_ASSOCIATED) { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		IPW_DEBUG_WX("Getting essid: '%s'\n", | 
					
						
							|  |  |  | 			     escape_essid(priv->essid, priv->essid_len)); | 
					
						
							|  |  |  | 		memcpy(extra, priv->essid, priv->essid_len); | 
					
						
							|  |  |  | 		wrqu->essid.length = priv->essid_len; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		wrqu->essid.flags = 1;	/* active */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		IPW_DEBUG_WX("Getting essid: ANY\n"); | 
					
						
							|  |  |  | 		wrqu->essid.length = 0; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		wrqu->essid.flags = 0;	/* active */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_set_nick(struct net_device *dev, | 
					
						
							|  |  |  | 			       struct iw_request_info *info, | 
					
						
							|  |  |  | 			       union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * This can be called at any time.  No action lock required | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (wrqu->data.length > IW_ESSID_MAX_SIZE) | 
					
						
							|  |  |  | 		return -E2BIG; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick)); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	memset(priv->nick, 0, sizeof(priv->nick)); | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	memcpy(priv->nick, extra, wrqu->data.length); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_WX("SET Nickname -> %s \n", priv->nick); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_get_nick(struct net_device *dev, | 
					
						
							|  |  |  | 			       struct iw_request_info *info, | 
					
						
							|  |  |  | 			       union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * This can be called at any time.  No action lock required | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wrqu->data.length = strlen(priv->nick) + 1; | 
					
						
							|  |  |  | 	memcpy(extra, priv->nick, wrqu->data.length); | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	wrqu->data.flags = 1;	/* active */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_WX("GET Nickname -> %s \n", extra); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_set_rate(struct net_device *dev, | 
					
						
							|  |  |  | 			       struct iw_request_info *info, | 
					
						
							|  |  |  | 			       union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	u32 target_rate = wrqu->bitrate.value; | 
					
						
							|  |  |  | 	u32 rate; | 
					
						
							|  |  |  | 	int err = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->action_sem); | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_INITIALIZED)) { | 
					
						
							|  |  |  | 		err = -EIO; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rate = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (target_rate == 1000000 || | 
					
						
							|  |  |  | 	    (!wrqu->bitrate.fixed && target_rate > 1000000)) | 
					
						
							|  |  |  | 		rate |= TX_RATE_1_MBIT; | 
					
						
							|  |  |  | 	if (target_rate == 2000000 || | 
					
						
							|  |  |  | 	    (!wrqu->bitrate.fixed && target_rate > 2000000)) | 
					
						
							|  |  |  | 		rate |= TX_RATE_2_MBIT; | 
					
						
							|  |  |  | 	if (target_rate == 5500000 || | 
					
						
							|  |  |  | 	    (!wrqu->bitrate.fixed && target_rate > 5500000)) | 
					
						
							|  |  |  | 		rate |= TX_RATE_5_5_MBIT; | 
					
						
							|  |  |  | 	if (target_rate == 11000000 || | 
					
						
							|  |  |  | 	    (!wrqu->bitrate.fixed && target_rate > 11000000)) | 
					
						
							|  |  |  | 		rate |= TX_RATE_11_MBIT; | 
					
						
							|  |  |  | 	if (rate == 0) | 
					
						
							|  |  |  | 		rate = DEFAULT_TX_RATES; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_set_tx_rates(priv, rate, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_WX("SET Rate -> %04X \n", rate); | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       done: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_get_rate(struct net_device *dev, | 
					
						
							|  |  |  | 			       struct iw_request_info *info, | 
					
						
							|  |  |  | 			       union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	int val; | 
					
						
							|  |  |  | 	int len = sizeof(val); | 
					
						
							|  |  |  | 	int err = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_ENABLED) || | 
					
						
							|  |  |  | 	    priv->status & STATUS_RF_KILL_MASK || | 
					
						
							|  |  |  | 	    !(priv->status & STATUS_ASSOCIATED)) { | 
					
						
							|  |  |  | 		wrqu->bitrate.value = 0; | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->action_sem); | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_INITIALIZED)) { | 
					
						
							|  |  |  | 		err = -EIO; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &val, &len); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							|  |  |  | 		IPW_DEBUG_WX("failed querying ordinals.\n"); | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (val & TX_RATE_MASK) { | 
					
						
							|  |  |  | 	case TX_RATE_1_MBIT: | 
					
						
							|  |  |  | 		wrqu->bitrate.value = 1000000; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case TX_RATE_2_MBIT: | 
					
						
							|  |  |  | 		wrqu->bitrate.value = 2000000; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case TX_RATE_5_5_MBIT: | 
					
						
							|  |  |  | 		wrqu->bitrate.value = 5500000; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case TX_RATE_11_MBIT: | 
					
						
							|  |  |  | 		wrqu->bitrate.value = 11000000; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		wrqu->bitrate.value = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       done: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_set_rts(struct net_device *dev, | 
					
						
							|  |  |  | 			      struct iw_request_info *info, | 
					
						
							|  |  |  | 			      union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	int value, err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Auto RTS not yet supported */ | 
					
						
							|  |  |  | 	if (wrqu->rts.fixed == 0) | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->action_sem); | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_INITIALIZED)) { | 
					
						
							|  |  |  | 		err = -EIO; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (wrqu->rts.disabled) | 
					
						
							|  |  |  | 		value = priv->rts_threshold | RTS_DISABLED; | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		if (wrqu->rts.value < 1 || wrqu->rts.value > 2304) { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			err = -EINVAL; | 
					
						
							|  |  |  | 			goto done; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		value = wrqu->rts.value; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_set_rts_threshold(priv, value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_WX("SET RTS Threshold -> 0x%08X \n", value); | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       done: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_get_rts(struct net_device *dev, | 
					
						
							|  |  |  | 			      struct iw_request_info *info, | 
					
						
							|  |  |  | 			      union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * This can be called at any time.  No action lock required | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wrqu->rts.value = priv->rts_threshold & ~RTS_DISABLED; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	wrqu->rts.fixed = 1;	/* no auto select */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* If RTS is set to the default value, then it is disabled */ | 
					
						
							|  |  |  | 	wrqu->rts.disabled = (priv->rts_threshold & RTS_DISABLED) ? 1 : 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_WX("GET RTS Threshold -> 0x%08X \n", wrqu->rts.value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_set_txpow(struct net_device *dev, | 
					
						
							|  |  |  | 				struct iw_request_info *info, | 
					
						
							|  |  |  | 				union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	int err = 0, value; | 
					
						
							| 
									
										
										
										
											2006-01-24 13:49:32 +08:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if (ipw_radio_kill_sw(priv, wrqu->txpower.disabled)) | 
					
						
							|  |  |  | 		return -EINPROGRESS; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->ieee->iw_mode != IW_MODE_ADHOC) | 
					
						
							| 
									
										
										
										
											2006-01-24 13:49:32 +08:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((wrqu->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-24 13:49:32 +08:00
										 |  |  | 	if (wrqu->txpower.fixed == 0) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		value = IPW_TX_POWER_DEFAULT; | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		if (wrqu->txpower.value < IPW_TX_POWER_MIN_DBM || | 
					
						
							|  |  |  | 		    wrqu->txpower.value > IPW_TX_POWER_MAX_DBM) | 
					
						
							|  |  |  | 			return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-13 12:29:21 -05:00
										 |  |  | 		value = wrqu->txpower.value; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->action_sem); | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_INITIALIZED)) { | 
					
						
							|  |  |  | 		err = -EIO; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_set_tx_power(priv, value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_WX("SET TX Power -> %d \n", value); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       done: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_get_txpow(struct net_device *dev, | 
					
						
							|  |  |  | 				struct iw_request_info *info, | 
					
						
							|  |  |  | 				union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * This can be called at any time.  No action lock required | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-24 13:49:32 +08:00
										 |  |  | 	wrqu->txpower.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->tx_power == IPW_TX_POWER_DEFAULT) { | 
					
						
							| 
									
										
										
										
											2006-01-24 13:49:32 +08:00
										 |  |  | 		wrqu->txpower.fixed = 0; | 
					
						
							|  |  |  | 		wrqu->txpower.value = IPW_TX_POWER_MAX_DBM; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2006-01-24 13:49:32 +08:00
										 |  |  | 		wrqu->txpower.fixed = 1; | 
					
						
							|  |  |  | 		wrqu->txpower.value = priv->tx_power; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-24 13:49:32 +08:00
										 |  |  | 	wrqu->txpower.flags = IW_TXPOW_DBM; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-24 13:49:32 +08:00
										 |  |  | 	IPW_DEBUG_WX("GET TX Power -> %d \n", wrqu->txpower.value); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_set_frag(struct net_device *dev, | 
					
						
							|  |  |  | 			       struct iw_request_info *info, | 
					
						
							|  |  |  | 			       union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * This can be called at any time.  No action lock required | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!wrqu->frag.fixed) | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (wrqu->frag.disabled) { | 
					
						
							|  |  |  | 		priv->frag_threshold |= FRAG_DISABLED; | 
					
						
							|  |  |  | 		priv->ieee->fts = DEFAULT_FTS; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		if (wrqu->frag.value < MIN_FRAG_THRESHOLD || | 
					
						
							|  |  |  | 		    wrqu->frag.value > MAX_FRAG_THRESHOLD) | 
					
						
							|  |  |  | 			return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		priv->ieee->fts = wrqu->frag.value & ~0x1; | 
					
						
							|  |  |  | 		priv->frag_threshold = priv->ieee->fts; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_WX("SET Frag Threshold -> %d \n", priv->ieee->fts); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_get_frag(struct net_device *dev, | 
					
						
							|  |  |  | 			       struct iw_request_info *info, | 
					
						
							|  |  |  | 			       union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * This can be called at any time.  No action lock required | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	wrqu->frag.value = priv->frag_threshold & ~FRAG_DISABLED; | 
					
						
							|  |  |  | 	wrqu->frag.fixed = 0;	/* no auto select */ | 
					
						
							|  |  |  | 	wrqu->frag.disabled = (priv->frag_threshold & FRAG_DISABLED) ? 1 : 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_set_retry(struct net_device *dev, | 
					
						
							|  |  |  | 				struct iw_request_info *info, | 
					
						
							|  |  |  | 				union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	int err = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(wrqu->retry.flags & IW_RETRY_LIMIT)) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->action_sem); | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_INITIALIZED)) { | 
					
						
							|  |  |  | 		err = -EIO; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (wrqu->retry.flags & IW_RETRY_MIN) { | 
					
						
							|  |  |  | 		err = ipw2100_set_short_retry(priv, wrqu->retry.value); | 
					
						
							|  |  |  | 		IPW_DEBUG_WX("SET Short Retry Limit -> %d \n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			     wrqu->retry.value); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (wrqu->retry.flags & IW_RETRY_MAX) { | 
					
						
							|  |  |  | 		err = ipw2100_set_long_retry(priv, wrqu->retry.value); | 
					
						
							|  |  |  | 		IPW_DEBUG_WX("SET Long Retry Limit -> %d \n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			     wrqu->retry.value); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_set_short_retry(priv, wrqu->retry.value); | 
					
						
							|  |  |  | 	if (!err) | 
					
						
							|  |  |  | 		err = ipw2100_set_long_retry(priv, wrqu->retry.value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_WX("SET Both Retry Limits -> %d \n", wrqu->retry.value); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       done: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_get_retry(struct net_device *dev, | 
					
						
							|  |  |  | 				struct iw_request_info *info, | 
					
						
							|  |  |  | 				union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * This can be called at any time.  No action lock required | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	wrqu->retry.disabled = 0;	/* can't be disabled */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (wrqu->retry.flags & IW_RETRY_MAX) { | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 		wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		wrqu->retry.value = priv->long_retry_limit; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		wrqu->retry.flags = | 
					
						
							|  |  |  | 		    (priv->short_retry_limit != | 
					
						
							|  |  |  | 		     priv->long_retry_limit) ? | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 		    IW_RETRY_LIMIT | IW_RETRY_MIN : IW_RETRY_LIMIT; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		wrqu->retry.value = priv->short_retry_limit; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_WX("GET Retry -> %d \n", wrqu->retry.value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_set_scan(struct net_device *dev, | 
					
						
							|  |  |  | 			       struct iw_request_info *info, | 
					
						
							|  |  |  | 			       union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	int err = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->action_sem); | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_INITIALIZED)) { | 
					
						
							|  |  |  | 		err = -EIO; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_WX("Initiating scan...\n"); | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	if (ipw2100_set_scan_options(priv) || ipw2100_start_scan(priv)) { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		IPW_DEBUG_WX("Start scan failed.\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* TODO: Mark a scan as pending so when hardware initialized
 | 
					
						
							|  |  |  | 		 *       a scan starts */ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       done: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_get_scan(struct net_device *dev, | 
					
						
							|  |  |  | 			       struct iw_request_info *info, | 
					
						
							|  |  |  | 			       union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * This can be called at any time.  No action lock required | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Implementation based on code in hostap-driver v0.1.3 hostap_ioctl.c | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static int ipw2100_wx_set_encode(struct net_device *dev, | 
					
						
							|  |  |  | 				 struct iw_request_info *info, | 
					
						
							|  |  |  | 				 union iwreq_data *wrqu, char *key) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * No check of STATUS_INITIALIZED required | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	return ieee80211_wx_set_encode(priv->ieee, info, wrqu, key); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_get_encode(struct net_device *dev, | 
					
						
							|  |  |  | 				 struct iw_request_info *info, | 
					
						
							|  |  |  | 				 union iwreq_data *wrqu, char *key) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * This can be called at any time.  No action lock required | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_set_power(struct net_device *dev, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 				struct iw_request_info *info, | 
					
						
							|  |  |  | 				union iwreq_data *wrqu, char *extra) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	int err = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->action_sem); | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_INITIALIZED)) { | 
					
						
							|  |  |  | 		err = -EIO; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (wrqu->power.disabled) { | 
					
						
							|  |  |  | 		priv->power_mode = IPW_POWER_LEVEL(priv->power_mode); | 
					
						
							|  |  |  | 		err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM); | 
					
						
							|  |  |  | 		IPW_DEBUG_WX("SET Power Management Mode -> off\n"); | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (wrqu->power.flags & IW_POWER_MODE) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	case IW_POWER_ON:	/* If not specified */ | 
					
						
							|  |  |  | 	case IW_POWER_MODE:	/* If set all mask */ | 
					
						
							|  |  |  | 	case IW_POWER_ALL_R:	/* If explicitely state all */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	default:		/* Otherwise we don't support it */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		IPW_DEBUG_WX("SET PM Mode: %X not supported.\n", | 
					
						
							|  |  |  | 			     wrqu->power.flags); | 
					
						
							|  |  |  | 		err = -EOPNOTSUPP; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* If the user hasn't specified a power management mode yet, default
 | 
					
						
							|  |  |  | 	 * to BATTERY */ | 
					
						
							|  |  |  | 	priv->power_mode = IPW_POWER_ENABLED | priv->power_mode; | 
					
						
							|  |  |  | 	err = ipw2100_set_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       done: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_get_power(struct net_device *dev, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 				struct iw_request_info *info, | 
					
						
							|  |  |  | 				union iwreq_data *wrqu, char *extra) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * This can be called at any time.  No action lock required | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 	if (!(priv->power_mode & IPW_POWER_ENABLED)) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		wrqu->power.disabled = 1; | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		wrqu->power.disabled = 0; | 
					
						
							|  |  |  | 		wrqu->power.flags = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * WE-18 WPA support | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* SIOCSIWGENIE */ | 
					
						
							|  |  |  | static int ipw2100_wx_set_genie(struct net_device *dev, | 
					
						
							|  |  |  | 				struct iw_request_info *info, | 
					
						
							|  |  |  | 				union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	struct ieee80211_device *ieee = priv->ieee; | 
					
						
							|  |  |  | 	u8 *buf; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!ieee->wpa_enabled) | 
					
						
							|  |  |  | 		return -EOPNOTSUPP; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (wrqu->data.length > MAX_WPA_IE_LEN || | 
					
						
							|  |  |  | 	    (wrqu->data.length && extra == NULL)) | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (wrqu->data.length) { | 
					
						
							|  |  |  | 		buf = kmalloc(wrqu->data.length, GFP_KERNEL); | 
					
						
							|  |  |  | 		if (buf == NULL) | 
					
						
							|  |  |  | 			return -ENOMEM; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		memcpy(buf, extra, wrqu->data.length); | 
					
						
							|  |  |  | 		kfree(ieee->wpa_ie); | 
					
						
							|  |  |  | 		ieee->wpa_ie = buf; | 
					
						
							|  |  |  | 		ieee->wpa_ie_len = wrqu->data.length; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		kfree(ieee->wpa_ie); | 
					
						
							|  |  |  | 		ieee->wpa_ie = NULL; | 
					
						
							|  |  |  | 		ieee->wpa_ie_len = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ipw2100_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* SIOCGIWGENIE */ | 
					
						
							|  |  |  | static int ipw2100_wx_get_genie(struct net_device *dev, | 
					
						
							|  |  |  | 				struct iw_request_info *info, | 
					
						
							|  |  |  | 				union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	struct ieee80211_device *ieee = priv->ieee; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) { | 
					
						
							|  |  |  | 		wrqu->data.length = 0; | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (wrqu->data.length < ieee->wpa_ie_len) | 
					
						
							|  |  |  | 		return -E2BIG; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wrqu->data.length = ieee->wpa_ie_len; | 
					
						
							|  |  |  | 	memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* SIOCSIWAUTH */ | 
					
						
							|  |  |  | static int ipw2100_wx_set_auth(struct net_device *dev, | 
					
						
							|  |  |  | 			       struct iw_request_info *info, | 
					
						
							|  |  |  | 			       union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	struct ieee80211_device *ieee = priv->ieee; | 
					
						
							|  |  |  | 	struct iw_param *param = &wrqu->param; | 
					
						
							|  |  |  | 	struct ieee80211_crypt_data *crypt; | 
					
						
							|  |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 	int ret = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (param->flags & IW_AUTH_INDEX) { | 
					
						
							|  |  |  | 	case IW_AUTH_WPA_VERSION: | 
					
						
							|  |  |  | 	case IW_AUTH_CIPHER_PAIRWISE: | 
					
						
							|  |  |  | 	case IW_AUTH_CIPHER_GROUP: | 
					
						
							|  |  |  | 	case IW_AUTH_KEY_MGMT: | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * ipw2200 does not use these parameters | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case IW_AUTH_TKIP_COUNTERMEASURES: | 
					
						
							|  |  |  | 		crypt = priv->ieee->crypt[priv->ieee->tx_keyidx]; | 
					
						
							| 
									
										
										
										
											2005-10-13 09:26:48 +00:00
										 |  |  | 		if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		flags = crypt->ops->get_flags(crypt->priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (param->value) | 
					
						
							|  |  |  | 			flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		crypt->ops->set_flags(flags, crypt->priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case IW_AUTH_DROP_UNENCRYPTED:{ | 
					
						
							|  |  |  | 			/* HACK:
 | 
					
						
							|  |  |  | 			 * | 
					
						
							|  |  |  | 			 * wpa_supplicant calls set_wpa_enabled when the driver | 
					
						
							|  |  |  | 			 * is loaded and unloaded, regardless of if WPA is being | 
					
						
							|  |  |  | 			 * used.  No other calls are made which can be used to | 
					
						
							|  |  |  | 			 * determine if encryption will be used or not prior to | 
					
						
							|  |  |  | 			 * association being expected.  If encryption is not being | 
					
						
							|  |  |  | 			 * used, drop_unencrypted is set to false, else true -- we | 
					
						
							|  |  |  | 			 * can use this to determine if the CAP_PRIVACY_ON bit should | 
					
						
							|  |  |  | 			 * be set. | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 			struct ieee80211_security sec = { | 
					
						
							|  |  |  | 				.flags = SEC_ENABLED, | 
					
						
							|  |  |  | 				.enabled = param->value, | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 			priv->ieee->drop_unencrypted = param->value; | 
					
						
							|  |  |  | 			/* We only change SEC_LEVEL for open mode. Others
 | 
					
						
							|  |  |  | 			 * are set by ipw_wpa_set_encryption. | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 			if (!param->value) { | 
					
						
							|  |  |  | 				sec.flags |= SEC_LEVEL; | 
					
						
							|  |  |  | 				sec.level = SEC_LEVEL_0; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				sec.flags |= SEC_LEVEL; | 
					
						
							|  |  |  | 				sec.level = SEC_LEVEL_1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (priv->ieee->set_security) | 
					
						
							|  |  |  | 				priv->ieee->set_security(priv->ieee->dev, &sec); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case IW_AUTH_80211_AUTH_ALG: | 
					
						
							|  |  |  | 		ret = ipw2100_wpa_set_auth_algs(priv, param->value); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case IW_AUTH_WPA_ENABLED: | 
					
						
							|  |  |  | 		ret = ipw2100_wpa_enable(priv, param->value); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case IW_AUTH_RX_UNENCRYPTED_EAPOL: | 
					
						
							|  |  |  | 		ieee->ieee802_1x = param->value; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//case IW_AUTH_ROAMING_CONTROL:
 | 
					
						
							|  |  |  | 	case IW_AUTH_PRIVACY_INVOKED: | 
					
						
							|  |  |  | 		ieee->privacy_invoked = param->value; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		return -EOPNOTSUPP; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* SIOCGIWAUTH */ | 
					
						
							|  |  |  | static int ipw2100_wx_get_auth(struct net_device *dev, | 
					
						
							|  |  |  | 			       struct iw_request_info *info, | 
					
						
							|  |  |  | 			       union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	struct ieee80211_device *ieee = priv->ieee; | 
					
						
							|  |  |  | 	struct ieee80211_crypt_data *crypt; | 
					
						
							|  |  |  | 	struct iw_param *param = &wrqu->param; | 
					
						
							|  |  |  | 	int ret = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (param->flags & IW_AUTH_INDEX) { | 
					
						
							|  |  |  | 	case IW_AUTH_WPA_VERSION: | 
					
						
							|  |  |  | 	case IW_AUTH_CIPHER_PAIRWISE: | 
					
						
							|  |  |  | 	case IW_AUTH_CIPHER_GROUP: | 
					
						
							|  |  |  | 	case IW_AUTH_KEY_MGMT: | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * wpa_supplicant will control these internally | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		ret = -EOPNOTSUPP; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case IW_AUTH_TKIP_COUNTERMEASURES: | 
					
						
							|  |  |  | 		crypt = priv->ieee->crypt[priv->ieee->tx_keyidx]; | 
					
						
							|  |  |  | 		if (!crypt || !crypt->ops->get_flags) { | 
					
						
							|  |  |  | 			IPW_DEBUG_WARNING("Can't get TKIP countermeasures: " | 
					
						
							|  |  |  | 					  "crypt not set!\n"); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		param->value = (crypt->ops->get_flags(crypt->priv) & | 
					
						
							|  |  |  | 				IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case IW_AUTH_DROP_UNENCRYPTED: | 
					
						
							|  |  |  | 		param->value = ieee->drop_unencrypted; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case IW_AUTH_80211_AUTH_ALG: | 
					
						
							| 
									
										
										
										
											2005-07-12 15:45:30 -05:00
										 |  |  | 		param->value = priv->ieee->sec.auth_mode; | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case IW_AUTH_WPA_ENABLED: | 
					
						
							|  |  |  | 		param->value = ieee->wpa_enabled; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case IW_AUTH_RX_UNENCRYPTED_EAPOL: | 
					
						
							|  |  |  | 		param->value = ieee->ieee802_1x; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case IW_AUTH_ROAMING_CONTROL: | 
					
						
							|  |  |  | 	case IW_AUTH_PRIVACY_INVOKED: | 
					
						
							|  |  |  | 		param->value = ieee->privacy_invoked; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		return -EOPNOTSUPP; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* SIOCSIWENCODEEXT */ | 
					
						
							|  |  |  | static int ipw2100_wx_set_encodeext(struct net_device *dev, | 
					
						
							|  |  |  | 				    struct iw_request_info *info, | 
					
						
							|  |  |  | 				    union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* SIOCGIWENCODEEXT */ | 
					
						
							|  |  |  | static int ipw2100_wx_get_encodeext(struct net_device *dev, | 
					
						
							|  |  |  | 				    struct iw_request_info *info, | 
					
						
							|  |  |  | 				    union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* SIOCSIWMLME */ | 
					
						
							|  |  |  | static int ipw2100_wx_set_mlme(struct net_device *dev, | 
					
						
							|  |  |  | 			       struct iw_request_info *info, | 
					
						
							|  |  |  | 			       union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	struct iw_mlme *mlme = (struct iw_mlme *)extra; | 
					
						
							|  |  |  | 	u16 reason; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	reason = cpu_to_le16(mlme->reason_code); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (mlme->cmd) { | 
					
						
							|  |  |  | 	case IW_MLME_DEAUTH: | 
					
						
							|  |  |  | 		// silently ignore
 | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case IW_MLME_DISASSOC: | 
					
						
							|  |  |  | 		ipw2100_disassociate_bssid(priv); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		return -EOPNOTSUPP; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * IWPRIV handlers | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #ifdef CONFIG_IPW2100_MONITOR
 | 
					
						
							|  |  |  | static int ipw2100_wx_set_promisc(struct net_device *dev, | 
					
						
							|  |  |  | 				  struct iw_request_info *info, | 
					
						
							|  |  |  | 				  union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	int *parms = (int *)extra; | 
					
						
							|  |  |  | 	int enable = (parms[0] > 0); | 
					
						
							|  |  |  | 	int err = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->action_sem); | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_INITIALIZED)) { | 
					
						
							|  |  |  | 		err = -EIO; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (enable) { | 
					
						
							|  |  |  | 		if (priv->ieee->iw_mode == IW_MODE_MONITOR) { | 
					
						
							|  |  |  | 			err = ipw2100_set_channel(priv, parms[1], 0); | 
					
						
							|  |  |  | 			goto done; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		priv->channel = parms[1]; | 
					
						
							|  |  |  | 		err = ipw2100_switch_mode(priv, IW_MODE_MONITOR); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		if (priv->ieee->iw_mode == IW_MODE_MONITOR) | 
					
						
							|  |  |  | 			err = ipw2100_switch_mode(priv, priv->last_mode); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       done: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_reset(struct net_device *dev, | 
					
						
							|  |  |  | 			    struct iw_request_info *info, | 
					
						
							|  |  |  | 			    union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	if (priv->status & STATUS_INITIALIZED) | 
					
						
							|  |  |  | 		schedule_reset(priv); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_set_powermode(struct net_device *dev, | 
					
						
							|  |  |  | 				    struct iw_request_info *info, | 
					
						
							|  |  |  | 				    union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	int err = 0, mode = *(int *)extra; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->action_sem); | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_INITIALIZED)) { | 
					
						
							|  |  |  | 		err = -EIO; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((mode < 1) || (mode > POWER_MODES)) | 
					
						
							|  |  |  | 		mode = IPW_POWER_AUTO; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->power_mode != mode) | 
					
						
							|  |  |  | 		err = ipw2100_set_power_mode(priv, mode); | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       done: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define MAX_POWER_STRING 80
 | 
					
						
							|  |  |  | static int ipw2100_wx_get_powermode(struct net_device *dev, | 
					
						
							|  |  |  | 				    struct iw_request_info *info, | 
					
						
							|  |  |  | 				    union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * This can be called at any time.  No action lock required | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	int level = IPW_POWER_LEVEL(priv->power_mode); | 
					
						
							|  |  |  | 	s32 timeout, period; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(priv->power_mode & IPW_POWER_ENABLED)) { | 
					
						
							|  |  |  | 		snprintf(extra, MAX_POWER_STRING, | 
					
						
							|  |  |  | 			 "Power save level: %d (Off)", level); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		switch (level) { | 
					
						
							|  |  |  | 		case IPW_POWER_MODE_CAM: | 
					
						
							|  |  |  | 			snprintf(extra, MAX_POWER_STRING, | 
					
						
							|  |  |  | 				 "Power save level: %d (None)", level); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case IPW_POWER_AUTO: | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			snprintf(extra, MAX_POWER_STRING, | 
					
						
							|  |  |  | 				 "Power save level: %d (Auto)", 0); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			timeout = timeout_duration[level - 1] / 1000; | 
					
						
							|  |  |  | 			period = period_duration[level - 1] / 1000; | 
					
						
							|  |  |  | 			snprintf(extra, MAX_POWER_STRING, | 
					
						
							|  |  |  | 				 "Power save level: %d " | 
					
						
							|  |  |  | 				 "(Timeout %dms, Period %dms)", | 
					
						
							|  |  |  | 				 level, timeout, period); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wrqu->data.length = strlen(extra) + 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_set_preamble(struct net_device *dev, | 
					
						
							|  |  |  | 				   struct iw_request_info *info, | 
					
						
							|  |  |  | 				   union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	int err, mode = *(int *)extra; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->action_sem); | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_INITIALIZED)) { | 
					
						
							|  |  |  | 		err = -EIO; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (mode == 1) | 
					
						
							|  |  |  | 		priv->config |= CFG_LONG_PREAMBLE; | 
					
						
							|  |  |  | 	else if (mode == 0) | 
					
						
							|  |  |  | 		priv->config &= ~CFG_LONG_PREAMBLE; | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		err = -EINVAL; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ipw2100_system_config(priv, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       done: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_get_preamble(struct net_device *dev, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 				   struct iw_request_info *info, | 
					
						
							|  |  |  | 				   union iwreq_data *wrqu, char *extra) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * This can be called at any time.  No action lock required | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->config & CFG_LONG_PREAMBLE) | 
					
						
							|  |  |  | 		snprintf(wrqu->name, IFNAMSIZ, "long (1)"); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		snprintf(wrqu->name, IFNAMSIZ, "auto (0)"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | #ifdef CONFIG_IPW2100_MONITOR
 | 
					
						
							|  |  |  | static int ipw2100_wx_set_crc_check(struct net_device *dev, | 
					
						
							|  |  |  | 				    struct iw_request_info *info, | 
					
						
							|  |  |  | 				    union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	int err, mode = *(int *)extra; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->action_sem); | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_INITIALIZED)) { | 
					
						
							|  |  |  | 		err = -EIO; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (mode == 1) | 
					
						
							|  |  |  | 		priv->config |= CFG_CRC_CHECK; | 
					
						
							|  |  |  | 	else if (mode == 0) | 
					
						
							|  |  |  | 		priv->config &= ~CFG_CRC_CHECK; | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		err = -EINVAL; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	err = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       done: | 
					
						
							|  |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_wx_get_crc_check(struct net_device *dev, | 
					
						
							|  |  |  | 				    struct iw_request_info *info, | 
					
						
							|  |  |  | 				    union iwreq_data *wrqu, char *extra) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * This can be called at any time.  No action lock required | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->config & CFG_CRC_CHECK) | 
					
						
							|  |  |  | 		snprintf(wrqu->name, IFNAMSIZ, "CRC checked (1)"); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		snprintf(wrqu->name, IFNAMSIZ, "CRC ignored (0)"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif				/* CONFIG_IPW2100_MONITOR */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static iw_handler ipw2100_wx_handlers[] = { | 
					
						
							|  |  |  | 	NULL,			/* SIOCSIWCOMMIT */ | 
					
						
							|  |  |  | 	ipw2100_wx_get_name,	/* SIOCGIWNAME */ | 
					
						
							|  |  |  | 	NULL,			/* SIOCSIWNWID */ | 
					
						
							|  |  |  | 	NULL,			/* SIOCGIWNWID */ | 
					
						
							|  |  |  | 	ipw2100_wx_set_freq,	/* SIOCSIWFREQ */ | 
					
						
							|  |  |  | 	ipw2100_wx_get_freq,	/* SIOCGIWFREQ */ | 
					
						
							|  |  |  | 	ipw2100_wx_set_mode,	/* SIOCSIWMODE */ | 
					
						
							|  |  |  | 	ipw2100_wx_get_mode,	/* SIOCGIWMODE */ | 
					
						
							|  |  |  | 	NULL,			/* SIOCSIWSENS */ | 
					
						
							|  |  |  | 	NULL,			/* SIOCGIWSENS */ | 
					
						
							|  |  |  | 	NULL,			/* SIOCSIWRANGE */ | 
					
						
							|  |  |  | 	ipw2100_wx_get_range,	/* SIOCGIWRANGE */ | 
					
						
							|  |  |  | 	NULL,			/* SIOCSIWPRIV */ | 
					
						
							|  |  |  | 	NULL,			/* SIOCGIWPRIV */ | 
					
						
							|  |  |  | 	NULL,			/* SIOCSIWSTATS */ | 
					
						
							|  |  |  | 	NULL,			/* SIOCGIWSTATS */ | 
					
						
							|  |  |  | 	NULL,			/* SIOCSIWSPY */ | 
					
						
							|  |  |  | 	NULL,			/* SIOCGIWSPY */ | 
					
						
							|  |  |  | 	NULL,			/* SIOCGIWTHRSPY */ | 
					
						
							|  |  |  | 	NULL,			/* SIOCWIWTHRSPY */ | 
					
						
							|  |  |  | 	ipw2100_wx_set_wap,	/* SIOCSIWAP */ | 
					
						
							|  |  |  | 	ipw2100_wx_get_wap,	/* SIOCGIWAP */ | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 	ipw2100_wx_set_mlme,	/* SIOCSIWMLME */ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	NULL,			/* SIOCGIWAPLIST -- deprecated */ | 
					
						
							|  |  |  | 	ipw2100_wx_set_scan,	/* SIOCSIWSCAN */ | 
					
						
							|  |  |  | 	ipw2100_wx_get_scan,	/* SIOCGIWSCAN */ | 
					
						
							|  |  |  | 	ipw2100_wx_set_essid,	/* SIOCSIWESSID */ | 
					
						
							|  |  |  | 	ipw2100_wx_get_essid,	/* SIOCGIWESSID */ | 
					
						
							|  |  |  | 	ipw2100_wx_set_nick,	/* SIOCSIWNICKN */ | 
					
						
							|  |  |  | 	ipw2100_wx_get_nick,	/* SIOCGIWNICKN */ | 
					
						
							|  |  |  | 	NULL,			/* -- hole -- */ | 
					
						
							|  |  |  | 	NULL,			/* -- hole -- */ | 
					
						
							|  |  |  | 	ipw2100_wx_set_rate,	/* SIOCSIWRATE */ | 
					
						
							|  |  |  | 	ipw2100_wx_get_rate,	/* SIOCGIWRATE */ | 
					
						
							|  |  |  | 	ipw2100_wx_set_rts,	/* SIOCSIWRTS */ | 
					
						
							|  |  |  | 	ipw2100_wx_get_rts,	/* SIOCGIWRTS */ | 
					
						
							|  |  |  | 	ipw2100_wx_set_frag,	/* SIOCSIWFRAG */ | 
					
						
							|  |  |  | 	ipw2100_wx_get_frag,	/* SIOCGIWFRAG */ | 
					
						
							|  |  |  | 	ipw2100_wx_set_txpow,	/* SIOCSIWTXPOW */ | 
					
						
							|  |  |  | 	ipw2100_wx_get_txpow,	/* SIOCGIWTXPOW */ | 
					
						
							|  |  |  | 	ipw2100_wx_set_retry,	/* SIOCSIWRETRY */ | 
					
						
							|  |  |  | 	ipw2100_wx_get_retry,	/* SIOCGIWRETRY */ | 
					
						
							|  |  |  | 	ipw2100_wx_set_encode,	/* SIOCSIWENCODE */ | 
					
						
							|  |  |  | 	ipw2100_wx_get_encode,	/* SIOCGIWENCODE */ | 
					
						
							|  |  |  | 	ipw2100_wx_set_power,	/* SIOCSIWPOWER */ | 
					
						
							|  |  |  | 	ipw2100_wx_get_power,	/* SIOCGIWPOWER */ | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 	NULL,			/* -- hole -- */ | 
					
						
							|  |  |  | 	NULL,			/* -- hole -- */ | 
					
						
							|  |  |  | 	ipw2100_wx_set_genie,	/* SIOCSIWGENIE */ | 
					
						
							|  |  |  | 	ipw2100_wx_get_genie,	/* SIOCGIWGENIE */ | 
					
						
							|  |  |  | 	ipw2100_wx_set_auth,	/* SIOCSIWAUTH */ | 
					
						
							|  |  |  | 	ipw2100_wx_get_auth,	/* SIOCGIWAUTH */ | 
					
						
							|  |  |  | 	ipw2100_wx_set_encodeext,	/* SIOCSIWENCODEEXT */ | 
					
						
							|  |  |  | 	ipw2100_wx_get_encodeext,	/* SIOCGIWENCODEEXT */ | 
					
						
							|  |  |  | 	NULL,			/* SIOCSIWPMKSA */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define IPW2100_PRIV_SET_MONITOR	SIOCIWFIRSTPRIV
 | 
					
						
							|  |  |  | #define IPW2100_PRIV_RESET		SIOCIWFIRSTPRIV+1
 | 
					
						
							|  |  |  | #define IPW2100_PRIV_SET_POWER		SIOCIWFIRSTPRIV+2
 | 
					
						
							|  |  |  | #define IPW2100_PRIV_GET_POWER		SIOCIWFIRSTPRIV+3
 | 
					
						
							|  |  |  | #define IPW2100_PRIV_SET_LONGPREAMBLE	SIOCIWFIRSTPRIV+4
 | 
					
						
							|  |  |  | #define IPW2100_PRIV_GET_LONGPREAMBLE	SIOCIWFIRSTPRIV+5
 | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | #define IPW2100_PRIV_SET_CRC_CHECK	SIOCIWFIRSTPRIV+6
 | 
					
						
							|  |  |  | #define IPW2100_PRIV_GET_CRC_CHECK	SIOCIWFIRSTPRIV+7
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | static const struct iw_priv_args ipw2100_private_args[] = { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef CONFIG_IPW2100_MONITOR
 | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	 IPW2100_PRIV_SET_MONITOR, | 
					
						
							|  |  |  | 	 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"}, | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	 IPW2100_PRIV_RESET, | 
					
						
							|  |  |  | 	 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"}, | 
					
						
							|  |  |  | #endif				/* CONFIG_IPW2100_MONITOR */
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	 IPW2100_PRIV_SET_POWER, | 
					
						
							|  |  |  | 	 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_power"}, | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	 IPW2100_PRIV_GET_POWER, | 
					
						
							|  |  |  | 	 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_POWER_STRING, | 
					
						
							|  |  |  | 	 "get_power"}, | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	 IPW2100_PRIV_SET_LONGPREAMBLE, | 
					
						
							|  |  |  | 	 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_preamble"}, | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	 IPW2100_PRIV_GET_LONGPREAMBLE, | 
					
						
							|  |  |  | 	 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_preamble"}, | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | #ifdef CONFIG_IPW2100_MONITOR
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 	 IPW2100_PRIV_SET_CRC_CHECK, | 
					
						
							|  |  |  | 	 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_crc_check"}, | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	 IPW2100_PRIV_GET_CRC_CHECK, | 
					
						
							|  |  |  | 	 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_crc_check"}, | 
					
						
							|  |  |  | #endif				/* CONFIG_IPW2100_MONITOR */
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static iw_handler ipw2100_private_handler[] = { | 
					
						
							|  |  |  | #ifdef CONFIG_IPW2100_MONITOR
 | 
					
						
							|  |  |  | 	ipw2100_wx_set_promisc, | 
					
						
							|  |  |  | 	ipw2100_wx_reset, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | #else				/* CONFIG_IPW2100_MONITOR */
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	NULL, | 
					
						
							|  |  |  | 	NULL, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | #endif				/* CONFIG_IPW2100_MONITOR */
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	ipw2100_wx_set_powermode, | 
					
						
							|  |  |  | 	ipw2100_wx_get_powermode, | 
					
						
							|  |  |  | 	ipw2100_wx_set_preamble, | 
					
						
							|  |  |  | 	ipw2100_wx_get_preamble, | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | #ifdef CONFIG_IPW2100_MONITOR
 | 
					
						
							|  |  |  | 	ipw2100_wx_set_crc_check, | 
					
						
							|  |  |  | 	ipw2100_wx_get_crc_check, | 
					
						
							|  |  |  | #else				/* CONFIG_IPW2100_MONITOR */
 | 
					
						
							|  |  |  | 	NULL, | 
					
						
							|  |  |  | 	NULL, | 
					
						
							|  |  |  | #endif				/* CONFIG_IPW2100_MONITOR */
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Get wireless statistics. | 
					
						
							|  |  |  |  * Called by /proc/net/wireless | 
					
						
							|  |  |  |  * Also called by SIOCGIWSTATS | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device *dev) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	enum { | 
					
						
							|  |  |  | 		POOR = 30, | 
					
						
							|  |  |  | 		FAIR = 60, | 
					
						
							|  |  |  | 		GOOD = 80, | 
					
						
							|  |  |  | 		VERY_GOOD = 90, | 
					
						
							|  |  |  | 		EXCELLENT = 95, | 
					
						
							|  |  |  | 		PERFECT = 100 | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	int rssi_qual; | 
					
						
							|  |  |  | 	int tx_qual; | 
					
						
							|  |  |  | 	int beacon_qual; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ipw2100_priv *priv = ieee80211_priv(dev); | 
					
						
							|  |  |  | 	struct iw_statistics *wstats; | 
					
						
							|  |  |  | 	u32 rssi, quality, tx_retries, missed_beacons, tx_failures; | 
					
						
							|  |  |  | 	u32 ord_len = sizeof(u32); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!priv) | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		return (struct iw_statistics *)NULL; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	wstats = &priv->wstats; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* if hw is disabled, then ipw2100_get_ordinal() can't be called.
 | 
					
						
							|  |  |  | 	 * ipw2100_wx_wireless_stats seems to be called before fw is | 
					
						
							|  |  |  | 	 * initialized.  STATUS_ASSOCIATED will only be set if the hw is up | 
					
						
							|  |  |  | 	 * and associated; if not associcated, the values are all meaningless | 
					
						
							|  |  |  | 	 * anyway, so set them all to NULL and INVALID */ | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_ASSOCIATED)) { | 
					
						
							|  |  |  | 		wstats->miss.beacon = 0; | 
					
						
							|  |  |  | 		wstats->discard.retries = 0; | 
					
						
							|  |  |  | 		wstats->qual.qual = 0; | 
					
						
							|  |  |  | 		wstats->qual.level = 0; | 
					
						
							|  |  |  | 		wstats->qual.noise = 0; | 
					
						
							|  |  |  | 		wstats->qual.updated = 7; | 
					
						
							|  |  |  | 		wstats->qual.updated |= IW_QUAL_NOISE_INVALID | | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		    IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		return wstats; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_MISSED_BCNS, | 
					
						
							|  |  |  | 				&missed_beacons, &ord_len)) | 
					
						
							|  |  |  | 		goto fail_get_ordinal; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	/* If we don't have a connection the quality and level is 0 */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	if (!(priv->status & STATUS_ASSOCIATED)) { | 
					
						
							|  |  |  | 		wstats->qual.qual = 0; | 
					
						
							|  |  |  | 		wstats->qual.level = 0; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		if (ipw2100_get_ordinal(priv, IPW_ORD_RSSI_AVG_CURR, | 
					
						
							|  |  |  | 					&rssi, &ord_len)) | 
					
						
							|  |  |  | 			goto fail_get_ordinal; | 
					
						
							|  |  |  | 		wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM; | 
					
						
							|  |  |  | 		if (rssi < 10) | 
					
						
							|  |  |  | 			rssi_qual = rssi * POOR / 10; | 
					
						
							|  |  |  | 		else if (rssi < 15) | 
					
						
							|  |  |  | 			rssi_qual = (rssi - 10) * (FAIR - POOR) / 5 + POOR; | 
					
						
							|  |  |  | 		else if (rssi < 20) | 
					
						
							|  |  |  | 			rssi_qual = (rssi - 15) * (GOOD - FAIR) / 5 + FAIR; | 
					
						
							|  |  |  | 		else if (rssi < 30) | 
					
						
							|  |  |  | 			rssi_qual = (rssi - 20) * (VERY_GOOD - GOOD) / | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			    10 + GOOD; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		else | 
					
						
							|  |  |  | 			rssi_qual = (rssi - 30) * (PERFECT - VERY_GOOD) / | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			    10 + VERY_GOOD; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_RETRIES, | 
					
						
							|  |  |  | 					&tx_retries, &ord_len)) | 
					
						
							|  |  |  | 			goto fail_get_ordinal; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (tx_retries > 75) | 
					
						
							|  |  |  | 			tx_qual = (90 - tx_retries) * POOR / 15; | 
					
						
							|  |  |  | 		else if (tx_retries > 70) | 
					
						
							|  |  |  | 			tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR; | 
					
						
							|  |  |  | 		else if (tx_retries > 65) | 
					
						
							|  |  |  | 			tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR; | 
					
						
							|  |  |  | 		else if (tx_retries > 50) | 
					
						
							|  |  |  | 			tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) / | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			    15 + GOOD; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		else | 
					
						
							|  |  |  | 			tx_qual = (50 - tx_retries) * | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			    (PERFECT - VERY_GOOD) / 50 + VERY_GOOD; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (missed_beacons > 50) | 
					
						
							|  |  |  | 			beacon_qual = (60 - missed_beacons) * POOR / 10; | 
					
						
							|  |  |  | 		else if (missed_beacons > 40) | 
					
						
							|  |  |  | 			beacon_qual = (50 - missed_beacons) * (FAIR - POOR) / | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			    10 + POOR; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		else if (missed_beacons > 32) | 
					
						
							|  |  |  | 			beacon_qual = (40 - missed_beacons) * (GOOD - FAIR) / | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			    18 + FAIR; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		else if (missed_beacons > 20) | 
					
						
							|  |  |  | 			beacon_qual = (32 - missed_beacons) * | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			    (VERY_GOOD - GOOD) / 20 + GOOD; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		else | 
					
						
							|  |  |  | 			beacon_qual = (20 - missed_beacons) * | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			    (PERFECT - VERY_GOOD) / 20 + VERY_GOOD; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		quality = min(beacon_qual, min(tx_qual, rssi_qual)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-01 01:41:46 -08:00
										 |  |  | #ifdef CONFIG_IPW2100_DEBUG
 | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		if (beacon_qual == quality) | 
					
						
							|  |  |  | 			IPW_DEBUG_WX("Quality clamped by Missed Beacons\n"); | 
					
						
							|  |  |  | 		else if (tx_qual == quality) | 
					
						
							|  |  |  | 			IPW_DEBUG_WX("Quality clamped by Tx Retries\n"); | 
					
						
							|  |  |  | 		else if (quality != 100) | 
					
						
							|  |  |  | 			IPW_DEBUG_WX("Quality clamped by Signal Strength\n"); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			IPW_DEBUG_WX("Quality not clamped.\n"); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		wstats->qual.qual = quality; | 
					
						
							|  |  |  | 		wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wstats->qual.noise = 0; | 
					
						
							|  |  |  | 	wstats->qual.updated = 7; | 
					
						
							|  |  |  | 	wstats->qual.updated |= IW_QUAL_NOISE_INVALID; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	/* FIXME: this is percent and not a # */ | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	wstats->miss.beacon = missed_beacons; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURES, | 
					
						
							|  |  |  | 				&tx_failures, &ord_len)) | 
					
						
							|  |  |  | 		goto fail_get_ordinal; | 
					
						
							|  |  |  | 	wstats->discard.retries = tx_failures; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return wstats; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  |       fail_get_ordinal: | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	IPW_DEBUG_WX("failed querying ordinals.\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	return (struct iw_statistics *)NULL; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-12 12:50:12 -06:00
										 |  |  | static struct iw_handler_def ipw2100_wx_handler_def = { | 
					
						
							|  |  |  | 	.standard = ipw2100_wx_handlers, | 
					
						
							|  |  |  | 	.num_standard = sizeof(ipw2100_wx_handlers) / sizeof(iw_handler), | 
					
						
							|  |  |  | 	.num_private = sizeof(ipw2100_private_handler) / sizeof(iw_handler), | 
					
						
							|  |  |  | 	.num_private_args = sizeof(ipw2100_private_args) / | 
					
						
							|  |  |  | 	    sizeof(struct iw_priv_args), | 
					
						
							|  |  |  | 	.private = (iw_handler *) ipw2100_private_handler, | 
					
						
							|  |  |  | 	.private_args = (struct iw_priv_args *)ipw2100_private_args, | 
					
						
							|  |  |  | 	.get_wireless_stats = ipw2100_wx_wireless_stats, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static void ipw2100_wx_event_work(struct ipw2100_priv *priv) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	union iwreq_data wrqu; | 
					
						
							|  |  |  | 	int len = ETH_ALEN; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (priv->status & STATUS_STOPPING) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down(&priv->action_sem); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_WX("enter\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	up(&priv->action_sem); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wrqu.ap_addr.sa_family = ARPHRD_ETHER; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Fetch BSSID from the hardware */ | 
					
						
							|  |  |  | 	if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) || | 
					
						
							|  |  |  | 	    priv->status & STATUS_RF_KILL_MASK || | 
					
						
							|  |  |  | 	    ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 				&priv->bssid, &len)) { | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		/* We now have the BSSID, so can finish setting to the full
 | 
					
						
							|  |  |  | 		 * associated state */ | 
					
						
							|  |  |  | 		memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN); | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 		memcpy(priv->ieee->bssid, priv->bssid, ETH_ALEN); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		priv->status &= ~STATUS_ASSOCIATING; | 
					
						
							|  |  |  | 		priv->status |= STATUS_ASSOCIATED; | 
					
						
							|  |  |  | 		netif_carrier_on(priv->net_dev); | 
					
						
							| 
									
										
										
										
											2005-08-24 22:33:31 -05:00
										 |  |  | 		netif_wake_queue(priv->net_dev); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(priv->status & STATUS_ASSOCIATED)) { | 
					
						
							|  |  |  | 		IPW_DEBUG_WX("Configuring ESSID\n"); | 
					
						
							|  |  |  | 		down(&priv->action_sem); | 
					
						
							|  |  |  | 		/* This is a disassociation event, so kick the firmware to
 | 
					
						
							|  |  |  | 		 * look for another AP */ | 
					
						
							|  |  |  | 		if (priv->config & CFG_STATIC_ESSID) | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 			ipw2100_set_essid(priv, priv->essid, priv->essid_len, | 
					
						
							|  |  |  | 					  0); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		else | 
					
						
							|  |  |  | 			ipw2100_set_essid(priv, NULL, 0, 0); | 
					
						
							|  |  |  | 		up(&priv->action_sem); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define IPW2100_FW_MAJOR_VERSION 1
 | 
					
						
							|  |  |  | #define IPW2100_FW_MINOR_VERSION 3
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define IPW2100_FW_MINOR(x) ((x & 0xff) >> 8)
 | 
					
						
							|  |  |  | #define IPW2100_FW_MAJOR(x) (x & 0xff)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define IPW2100_FW_VERSION ((IPW2100_FW_MINOR_VERSION << 8) | \
 | 
					
						
							|  |  |  |                              IPW2100_FW_MAJOR_VERSION) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define IPW2100_FW_PREFIX "ipw2100-" __stringify(IPW2100_FW_MAJOR_VERSION) \
 | 
					
						
							|  |  |  | "." __stringify(IPW2100_FW_MINOR_VERSION) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define IPW2100_FW_NAME(x) IPW2100_FW_PREFIX "" x ".fw"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | BINARY FIRMWARE HEADER FORMAT | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | offset      length   desc | 
					
						
							|  |  |  | 0           2        version | 
					
						
							|  |  |  | 2           2        mode == 0:BSS,1:IBSS,2:MONITOR | 
					
						
							|  |  |  | 4           4        fw_len | 
					
						
							|  |  |  | 8           4        uc_len | 
					
						
							|  |  |  | C           fw_len   firmware data | 
					
						
							|  |  |  | 12 + fw_len uc_len   microcode data | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct ipw2100_fw_header { | 
					
						
							|  |  |  | 	short version; | 
					
						
							|  |  |  | 	short mode; | 
					
						
							|  |  |  | 	unsigned int fw_size; | 
					
						
							|  |  |  | 	unsigned int uc_size; | 
					
						
							|  |  |  | } __attribute__ ((packed)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ipw2100_mod_firmware_load(struct ipw2100_fw *fw) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ipw2100_fw_header *h = | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	    (struct ipw2100_fw_header *)fw->fw_entry->data; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (IPW2100_FW_MAJOR(h->version) != IPW2100_FW_MAJOR_VERSION) { | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 		printk(KERN_WARNING DRV_NAME ": Firmware image not compatible " | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		       "(detected version id of %u). " | 
					
						
							|  |  |  | 		       "See Documentation/networking/README.ipw2100\n", | 
					
						
							|  |  |  | 		       h->version); | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	fw->version = h->version; | 
					
						
							|  |  |  | 	fw->fw.data = fw->fw_entry->data + sizeof(struct ipw2100_fw_header); | 
					
						
							|  |  |  | 	fw->fw.size = h->fw_size; | 
					
						
							|  |  |  | 	fw->uc.data = fw->fw.data + h->fw_size; | 
					
						
							|  |  |  | 	fw->uc.size = h->uc_size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static int ipw2100_get_firmware(struct ipw2100_priv *priv, | 
					
						
							|  |  |  | 				struct ipw2100_fw *fw) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	char *fw_name; | 
					
						
							|  |  |  | 	int rc; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IPW_DEBUG_INFO("%s: Using hotplug firmware load.\n", | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		       priv->net_dev->name); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	switch (priv->ieee->iw_mode) { | 
					
						
							|  |  |  | 	case IW_MODE_ADHOC: | 
					
						
							|  |  |  | 		fw_name = IPW2100_FW_NAME("-i"); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | #ifdef CONFIG_IPW2100_MONITOR
 | 
					
						
							|  |  |  | 	case IW_MODE_MONITOR: | 
					
						
							|  |  |  | 		fw_name = IPW2100_FW_NAME("-p"); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	case IW_MODE_INFRA: | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		fw_name = IPW2100_FW_NAME(""); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rc = request_firmware(&fw->fw_entry, fw_name, &priv->pci_dev->dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (rc < 0) { | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 		printk(KERN_ERR DRV_NAME ": " | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		       "%s: Firmware '%s' not available or load failed.\n", | 
					
						
							|  |  |  | 		       priv->net_dev->name, fw_name); | 
					
						
							|  |  |  | 		return rc; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-06-07 14:58:41 +02:00
										 |  |  | 	IPW_DEBUG_INFO("firmware data %p size %zd\n", fw->fw_entry->data, | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		       fw->fw_entry->size); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ipw2100_mod_firmware_load(fw); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static void ipw2100_release_firmware(struct ipw2100_priv *priv, | 
					
						
							|  |  |  | 				     struct ipw2100_fw *fw) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	fw->version = 0; | 
					
						
							|  |  |  | 	if (fw->fw_entry) | 
					
						
							|  |  |  | 		release_firmware(fw->fw_entry); | 
					
						
							|  |  |  | 	fw->fw_entry = NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf, | 
					
						
							|  |  |  | 				 size_t max) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	char ver[MAX_FW_VERSION_LEN]; | 
					
						
							|  |  |  | 	u32 len = MAX_FW_VERSION_LEN; | 
					
						
							|  |  |  | 	u32 tmp; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	/* firmware version is an ascii string (max len of 14) */ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_FW_VER_NUM, ver, &len)) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		return -EIO; | 
					
						
							|  |  |  | 	tmp = max; | 
					
						
							|  |  |  | 	if (len >= max) | 
					
						
							|  |  |  | 		len = max - 1; | 
					
						
							|  |  |  | 	for (i = 0; i < len; i++) | 
					
						
							|  |  |  | 		buf[i] = ver[i]; | 
					
						
							|  |  |  | 	buf[i] = '\0'; | 
					
						
							|  |  |  | 	return tmp; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf, | 
					
						
							|  |  |  | 				    size_t max) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	u32 ver; | 
					
						
							|  |  |  | 	u32 len = sizeof(ver); | 
					
						
							|  |  |  | 	/* microcode version is a 32 bit integer */ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	if (ipw2100_get_ordinal(priv, IPW_ORD_UCODE_VERSION, &ver, &len)) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		return -EIO; | 
					
						
							|  |  |  | 	return snprintf(buf, max, "%08X", ver); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * On exit, the firmware will have been freed from the fw list | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | static int ipw2100_fw_download(struct ipw2100_priv *priv, struct ipw2100_fw *fw) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* firmware is constructed of N contiguous entries, each entry is
 | 
					
						
							|  |  |  | 	 * structured as: | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * offset    sie         desc | 
					
						
							|  |  |  | 	 * 0         4           address to write to | 
					
						
							|  |  |  | 	 * 4         2           length of data run | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 	 * 6         length      data | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	unsigned int addr; | 
					
						
							|  |  |  | 	unsigned short len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const unsigned char *firmware_data = fw->fw.data; | 
					
						
							|  |  |  | 	unsigned int firmware_data_left = fw->fw.size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (firmware_data_left > 0) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		addr = *(u32 *) (firmware_data); | 
					
						
							|  |  |  | 		firmware_data += 4; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		firmware_data_left -= 4; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		len = *(u16 *) (firmware_data); | 
					
						
							|  |  |  | 		firmware_data += 2; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		firmware_data_left -= 2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (len > 32) { | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 			printk(KERN_ERR DRV_NAME ": " | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			       "Invalid firmware run-length of %d bytes\n", | 
					
						
							|  |  |  | 			       len); | 
					
						
							|  |  |  | 			return -EINVAL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		write_nic_memory(priv->net_dev, addr, len, firmware_data); | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		firmware_data += len; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		firmware_data_left -= len; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct symbol_alive_response { | 
					
						
							|  |  |  | 	u8 cmd_id; | 
					
						
							|  |  |  | 	u8 seq_num; | 
					
						
							|  |  |  | 	u8 ucode_rev; | 
					
						
							|  |  |  | 	u8 eeprom_valid; | 
					
						
							|  |  |  | 	u16 valid_flags; | 
					
						
							|  |  |  | 	u8 IEEE_addr[6]; | 
					
						
							|  |  |  | 	u16 flags; | 
					
						
							|  |  |  | 	u16 pcb_rev; | 
					
						
							|  |  |  | 	u16 clock_settle_time;	// 1us LSB
 | 
					
						
							|  |  |  | 	u16 powerup_settle_time;	// 1us LSB
 | 
					
						
							|  |  |  | 	u16 hop_settle_time;	// 1us LSB
 | 
					
						
							|  |  |  | 	u8 date[3];		// month, day, year
 | 
					
						
							|  |  |  | 	u8 time[2];		// hours, minutes
 | 
					
						
							|  |  |  | 	u8 ucode_valid; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 20:04:43 -04:00
										 |  |  | static int ipw2100_ucode_download(struct ipw2100_priv *priv, | 
					
						
							|  |  |  | 				  struct ipw2100_fw *fw) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct net_device *dev = priv->net_dev; | 
					
						
							|  |  |  | 	const unsigned char *microcode_data = fw->uc.data; | 
					
						
							|  |  |  | 	unsigned int microcode_data_left = fw->uc.size; | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	void __iomem *reg = (void __iomem *)dev->base_addr; | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	struct symbol_alive_response response; | 
					
						
							|  |  |  | 	int i, j; | 
					
						
							|  |  |  | 	u8 data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Symbol control */ | 
					
						
							|  |  |  | 	write_nic_word(dev, IPW2100_CONTROL_REG, 0x703); | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	readl(reg); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	write_nic_word(dev, IPW2100_CONTROL_REG, 0x707); | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	readl(reg); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* HW config */ | 
					
						
							|  |  |  | 	write_nic_byte(dev, 0x210014, 0x72);	/* fifo width =16 */ | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	readl(reg); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	write_nic_byte(dev, 0x210014, 0x72);	/* fifo width =16 */ | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	readl(reg); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* EN_CS_ACCESS bit to reset control store pointer */ | 
					
						
							|  |  |  | 	write_nic_byte(dev, 0x210000, 0x40); | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	readl(reg); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	write_nic_byte(dev, 0x210000, 0x0); | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	readl(reg); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	write_nic_byte(dev, 0x210000, 0x40); | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	readl(reg); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* copy microcode from buffer into Symbol */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (microcode_data_left > 0) { | 
					
						
							|  |  |  | 		write_nic_byte(dev, 0x210010, *microcode_data++); | 
					
						
							|  |  |  | 		write_nic_byte(dev, 0x210010, *microcode_data++); | 
					
						
							|  |  |  | 		microcode_data_left -= 2; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* EN_CS_ACCESS bit to reset the control store pointer */ | 
					
						
							|  |  |  | 	write_nic_byte(dev, 0x210000, 0x0); | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	readl(reg); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Enable System (Reg 0)
 | 
					
						
							|  |  |  | 	 * first enable causes garbage in RX FIFO */ | 
					
						
							|  |  |  | 	write_nic_byte(dev, 0x210000, 0x0); | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	readl(reg); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	write_nic_byte(dev, 0x210000, 0x80); | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	readl(reg); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Reset External Baseband Reg */ | 
					
						
							|  |  |  | 	write_nic_word(dev, IPW2100_CONTROL_REG, 0x703); | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	readl(reg); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	write_nic_word(dev, IPW2100_CONTROL_REG, 0x707); | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	readl(reg); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* HW Config (Reg 5) */ | 
					
						
							|  |  |  | 	write_nic_byte(dev, 0x210014, 0x72);	// fifo width =16
 | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	readl(reg); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	write_nic_byte(dev, 0x210014, 0x72);	// fifo width =16
 | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	readl(reg); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Enable System (Reg 0)
 | 
					
						
							|  |  |  | 	 * second enable should be OK */ | 
					
						
							|  |  |  | 	write_nic_byte(dev, 0x210000, 0x00);	// clear enable system
 | 
					
						
							| 
									
										
										
										
											2005-09-05 03:26:08 +01:00
										 |  |  | 	readl(reg); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 	write_nic_byte(dev, 0x210000, 0x80);	// set enable system
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* check Symbol is enabled - upped this from 5 as it wasn't always
 | 
					
						
							|  |  |  | 	 * catching the update */ | 
					
						
							|  |  |  | 	for (i = 0; i < 10; i++) { | 
					
						
							|  |  |  | 		udelay(10); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* check Dino is enabled bit */ | 
					
						
							|  |  |  | 		read_nic_byte(dev, 0x210000, &data); | 
					
						
							|  |  |  | 		if (data & 0x1) | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (i == 10) { | 
					
						
							| 
									
										
										
										
											2005-08-25 20:03:27 -04:00
										 |  |  | 		printk(KERN_ERR DRV_NAME ": %s: Error initializing Symbol\n", | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		       dev->name); | 
					
						
							|  |  |  | 		return -EIO; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Get Symbol alive response */ | 
					
						
							|  |  |  | 	for (i = 0; i < 30; i++) { | 
					
						
							|  |  |  | 		/* Read alive response structure */ | 
					
						
							|  |  |  | 		for (j = 0; | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		     j < (sizeof(struct symbol_alive_response) >> 1); j++) | 
					
						
							|  |  |  | 			read_nic_word(dev, 0x210004, ((u16 *) & response) + j); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		if ((response.cmd_id == 1) && (response.ucode_valid == 0x1)) | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		udelay(10); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (i == 30) { | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		printk(KERN_ERR DRV_NAME | 
					
						
							|  |  |  | 		       ": %s: No response from Symbol - hw not alive\n", | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		       dev->name); | 
					
						
							| 
									
										
										
										
											2005-09-14 09:47:29 -05:00
										 |  |  | 		printk_buf(IPW_DL_ERROR, (u8 *) & response, sizeof(response)); | 
					
						
							| 
									
										
										
										
											2005-03-23 17:32:29 -06:00
										 |  |  | 		return -EIO; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } |