James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1 | /****************************************************************************** |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2 | |
Zhu Yi | 171e7b2 | 2006-02-15 07:17:56 +0800 | [diff] [blame] | 3 | Copyright(c) 2003 - 2006 Intel Corporation. All rights reserved. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4 | |
| 5 | 802.11 status code portion of this file from ethereal-0.10.6: |
| 6 | Copyright 2000, Axis Communications AB |
| 7 | Ethereal - Network traffic analyzer |
| 8 | By Gerald Combs <gerald@ethereal.com> |
| 9 | Copyright 1998 Gerald Combs |
| 10 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11 | This program is free software; you can redistribute it and/or modify it |
| 12 | under the terms of version 2 of the GNU General Public License as |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 13 | published by the Free Software Foundation. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 14 | |
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 18 | more details. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 19 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 20 | You should have received a copy of the GNU General Public License along with |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 21 | this program; if not, write to the Free Software Foundation, Inc., 59 |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 22 | Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 23 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 24 | The full GNU General Public License is included in this distribution in the |
| 25 | file called LICENSE. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 26 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 27 | Contact Information: |
| 28 | James P. Ketrenos <ipw2100-admin@linux.intel.com> |
| 29 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 30 | |
| 31 | ******************************************************************************/ |
| 32 | |
| 33 | #include "ipw2200.h" |
Olaf Hering | 733482e | 2005-11-08 21:34:55 -0800 | [diff] [blame] | 34 | #include <linux/version.h> |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 35 | |
Zhu Yi | ae4af61 | 2006-04-13 17:20:34 +0800 | [diff] [blame] | 36 | |
| 37 | #ifndef KBUILD_EXTMOD |
| 38 | #define VK "k" |
| 39 | #else |
| 40 | #define VK |
| 41 | #endif |
| 42 | |
| 43 | #ifdef CONFIG_IPW2200_DEBUG |
| 44 | #define VD "d" |
| 45 | #else |
| 46 | #define VD |
| 47 | #endif |
| 48 | |
| 49 | #ifdef CONFIG_IPW2200_MONITOR |
| 50 | #define VM "m" |
| 51 | #else |
| 52 | #define VM |
| 53 | #endif |
| 54 | |
| 55 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 56 | #define VP "p" |
| 57 | #else |
| 58 | #define VP |
| 59 | #endif |
| 60 | |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 61 | #ifdef CONFIG_IPW2200_RADIOTAP |
Zhu Yi | ae4af61 | 2006-04-13 17:20:34 +0800 | [diff] [blame] | 62 | #define VR "r" |
| 63 | #else |
| 64 | #define VR |
| 65 | #endif |
| 66 | |
| 67 | #ifdef CONFIG_IPW2200_QOS |
| 68 | #define VQ "q" |
| 69 | #else |
| 70 | #define VQ |
| 71 | #endif |
| 72 | |
Zhu Yi | 8b5f917 | 2006-08-21 11:39:13 +0800 | [diff] [blame^] | 73 | #define IPW2200_VERSION "1.1.4" VK VD VM VP VR VQ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 74 | #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver" |
Zhu Yi | 171e7b2 | 2006-02-15 07:17:56 +0800 | [diff] [blame] | 75 | #define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation" |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 76 | #define DRV_VERSION IPW2200_VERSION |
| 77 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 78 | #define ETH_P_80211_STATS (ETH_P_80211_RAW + 1) |
| 79 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 80 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 81 | MODULE_VERSION(DRV_VERSION); |
| 82 | MODULE_AUTHOR(DRV_COPYRIGHT); |
| 83 | MODULE_LICENSE("GPL"); |
| 84 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 85 | static int cmdlog = 0; |
Zhu Yi | 5dc81c3 | 2006-04-13 17:19:44 +0800 | [diff] [blame] | 86 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 87 | static int debug = 0; |
Zhu Yi | 5dc81c3 | 2006-04-13 17:19:44 +0800 | [diff] [blame] | 88 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 89 | static int channel = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 90 | static int mode = 0; |
| 91 | |
| 92 | static u32 ipw_debug_level; |
| 93 | static int associate = 1; |
| 94 | static int auto_create = 1; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 95 | static int led = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 96 | static int disable = 0; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 97 | static int bt_coexist = 0; |
Zhu Yi | bde37d0 | 2006-01-24 16:38:08 +0800 | [diff] [blame] | 98 | static int hwcrypto = 0; |
Zhu Yi | 4bfdb91 | 2006-01-24 16:37:16 +0800 | [diff] [blame] | 99 | static int roaming = 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 100 | static const char ipw_modes[] = { |
| 101 | 'a', 'b', 'g', '?' |
| 102 | }; |
Zhu Yi | d2b83e1 | 2006-04-13 17:19:36 +0800 | [diff] [blame] | 103 | static int antenna = CFG_SYS_ANTENNA_BOTH; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 104 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 105 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 106 | static int rtap_iface = 0; /* def: 0 -- do not create rtap interface */ |
| 107 | #endif |
| 108 | |
| 109 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 110 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 111 | static int qos_enable = 0; |
| 112 | static int qos_burst_enable = 0; |
| 113 | static int qos_no_ack_mask = 0; |
| 114 | static int burst_duration_CCK = 0; |
| 115 | static int burst_duration_OFDM = 0; |
| 116 | |
| 117 | static struct ieee80211_qos_parameters def_qos_parameters_OFDM = { |
| 118 | {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM, |
| 119 | QOS_TX3_CW_MIN_OFDM}, |
| 120 | {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM, |
| 121 | QOS_TX3_CW_MAX_OFDM}, |
| 122 | {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS}, |
| 123 | {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM}, |
| 124 | {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM, |
| 125 | QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM} |
| 126 | }; |
| 127 | |
| 128 | static struct ieee80211_qos_parameters def_qos_parameters_CCK = { |
| 129 | {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK, |
| 130 | QOS_TX3_CW_MIN_CCK}, |
| 131 | {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK, |
| 132 | QOS_TX3_CW_MAX_CCK}, |
| 133 | {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS}, |
| 134 | {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM}, |
| 135 | {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK, |
| 136 | QOS_TX3_TXOP_LIMIT_CCK} |
| 137 | }; |
| 138 | |
| 139 | static struct ieee80211_qos_parameters def_parameters_OFDM = { |
| 140 | {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM, |
| 141 | DEF_TX3_CW_MIN_OFDM}, |
| 142 | {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM, |
| 143 | DEF_TX3_CW_MAX_OFDM}, |
| 144 | {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS}, |
| 145 | {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM}, |
| 146 | {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM, |
| 147 | DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM} |
| 148 | }; |
| 149 | |
| 150 | static struct ieee80211_qos_parameters def_parameters_CCK = { |
| 151 | {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK, |
| 152 | DEF_TX3_CW_MIN_CCK}, |
| 153 | {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK, |
| 154 | DEF_TX3_CW_MAX_CCK}, |
| 155 | {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS}, |
| 156 | {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM}, |
| 157 | {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK, |
| 158 | DEF_TX3_TXOP_LIMIT_CCK} |
| 159 | }; |
| 160 | |
| 161 | static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 }; |
| 162 | |
| 163 | static int from_priority_to_tx_queue[] = { |
| 164 | IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1, |
| 165 | IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4 |
| 166 | }; |
| 167 | |
| 168 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv); |
| 169 | |
| 170 | static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters |
| 171 | *qos_param); |
| 172 | static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element |
| 173 | *qos_param); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 174 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 175 | |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 176 | static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 177 | static void ipw_remove_current_network(struct ipw_priv *priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 178 | static void ipw_rx(struct ipw_priv *priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 179 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 180 | struct clx2_tx_queue *txq, int qindex); |
| 181 | static int ipw_queue_reset(struct ipw_priv *priv); |
| 182 | |
| 183 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, |
| 184 | int len, int sync); |
| 185 | |
| 186 | static void ipw_tx_queue_free(struct ipw_priv *); |
| 187 | |
| 188 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *); |
| 189 | static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *); |
| 190 | static void ipw_rx_queue_replenish(void *); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 191 | static int ipw_up(struct ipw_priv *); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 192 | static void ipw_bg_up(void *); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 193 | static void ipw_down(struct ipw_priv *); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 194 | static void ipw_bg_down(void *); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 195 | static int ipw_config(struct ipw_priv *); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 196 | static int init_supported_rates(struct ipw_priv *priv, |
| 197 | struct ipw_supported_rates *prates); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 198 | static void ipw_set_hwcrypto_keys(struct ipw_priv *); |
| 199 | static void ipw_send_wep_keys(struct ipw_priv *, int); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 200 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 201 | static int snprint_line(char *buf, size_t count, |
| 202 | const u8 * data, u32 len, u32 ofs) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 203 | { |
| 204 | int out, i, j, l; |
| 205 | char c; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 206 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 207 | out = snprintf(buf, count, "%08X", ofs); |
| 208 | |
| 209 | for (l = 0, i = 0; i < 2; i++) { |
| 210 | out += snprintf(buf + out, count - out, " "); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 211 | for (j = 0; j < 8 && l < len; j++, l++) |
| 212 | out += snprintf(buf + out, count - out, "%02X ", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 213 | data[(i * 8 + j)]); |
| 214 | for (; j < 8; j++) |
| 215 | out += snprintf(buf + out, count - out, " "); |
| 216 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 217 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 218 | out += snprintf(buf + out, count - out, " "); |
| 219 | for (l = 0, i = 0; i < 2; i++) { |
| 220 | out += snprintf(buf + out, count - out, " "); |
| 221 | for (j = 0; j < 8 && l < len; j++, l++) { |
| 222 | c = data[(i * 8 + j)]; |
| 223 | if (!isascii(c) || !isprint(c)) |
| 224 | c = '.'; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 225 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 226 | out += snprintf(buf + out, count - out, "%c", c); |
| 227 | } |
| 228 | |
| 229 | for (; j < 8; j++) |
| 230 | out += snprintf(buf + out, count - out, " "); |
| 231 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 232 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 233 | return out; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 234 | } |
| 235 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 236 | static void printk_buf(int level, const u8 * data, u32 len) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 237 | { |
| 238 | char line[81]; |
| 239 | u32 ofs = 0; |
| 240 | if (!(ipw_debug_level & level)) |
| 241 | return; |
| 242 | |
| 243 | while (len) { |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 244 | snprint_line(line, sizeof(line), &data[ofs], |
| 245 | min(len, 16U), ofs); |
| 246 | printk(KERN_DEBUG "%s\n", line); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 247 | ofs += 16; |
| 248 | len -= min(len, 16U); |
| 249 | } |
| 250 | } |
| 251 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 252 | static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len) |
| 253 | { |
| 254 | size_t out = size; |
| 255 | u32 ofs = 0; |
| 256 | int total = 0; |
| 257 | |
| 258 | while (size && len) { |
| 259 | out = snprint_line(output, size, &data[ofs], |
| 260 | min_t(size_t, len, 16U), ofs); |
| 261 | |
| 262 | ofs += 16; |
| 263 | output += out; |
| 264 | size -= out; |
| 265 | len -= min_t(size_t, len, 16U); |
| 266 | total += out; |
| 267 | } |
| 268 | return total; |
| 269 | } |
| 270 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 271 | /* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 272 | static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg); |
| 273 | #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b) |
| 274 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 275 | /* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 276 | static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg); |
| 277 | #define ipw_read_reg8(a, b) _ipw_read_reg8(a, b) |
| 278 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 279 | /* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 280 | static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value); |
| 281 | static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c) |
| 282 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 283 | IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__, |
| 284 | __LINE__, (u32) (b), (u32) (c)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 285 | _ipw_write_reg8(a, b, c); |
| 286 | } |
| 287 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 288 | /* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 289 | static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value); |
| 290 | static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c) |
| 291 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 292 | IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__, |
| 293 | __LINE__, (u32) (b), (u32) (c)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 294 | _ipw_write_reg16(a, b, c); |
| 295 | } |
| 296 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 297 | /* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 298 | static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value); |
| 299 | static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c) |
| 300 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 301 | IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__, |
| 302 | __LINE__, (u32) (b), (u32) (c)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 303 | _ipw_write_reg32(a, b, c); |
| 304 | } |
| 305 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 306 | /* 8-bit direct write (low 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 307 | #define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs)) |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 308 | |
| 309 | /* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 310 | #define ipw_write8(ipw, ofs, val) \ |
| 311 | IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \ |
| 312 | _ipw_write8(ipw, ofs, val) |
| 313 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 314 | /* 16-bit direct write (low 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 315 | #define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs)) |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 316 | |
| 317 | /* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 318 | #define ipw_write16(ipw, ofs, val) \ |
| 319 | IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \ |
| 320 | _ipw_write16(ipw, ofs, val) |
| 321 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 322 | /* 32-bit direct write (low 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 323 | #define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs)) |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 324 | |
| 325 | /* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 326 | #define ipw_write32(ipw, ofs, val) \ |
| 327 | IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \ |
| 328 | _ipw_write32(ipw, ofs, val) |
| 329 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 330 | /* 8-bit direct read (low 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 331 | #define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs)) |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 332 | |
| 333 | /* 8-bit direct read (low 4K), with debug wrapper */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 334 | static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs) |
| 335 | { |
| 336 | IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 337 | return _ipw_read8(ipw, ofs); |
| 338 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 339 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 340 | /* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 341 | #define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs) |
| 342 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 343 | /* 16-bit direct read (low 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 344 | #define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs)) |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 345 | |
| 346 | /* 16-bit direct read (low 4K), with debug wrapper */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 347 | static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs) |
| 348 | { |
| 349 | IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 350 | return _ipw_read16(ipw, ofs); |
| 351 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 352 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 353 | /* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 354 | #define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs) |
| 355 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 356 | /* 32-bit direct read (low 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 357 | #define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs)) |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 358 | |
| 359 | /* 32-bit direct read (low 4K), with debug wrapper */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 360 | static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs) |
| 361 | { |
| 362 | IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 363 | return _ipw_read32(ipw, ofs); |
| 364 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 365 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 366 | /* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 367 | #define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs) |
| 368 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 369 | /* multi-byte read (above 4K), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 370 | static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 371 | static inline void __ipw_read_indirect(const char *f, int l, |
| 372 | struct ipw_priv *a, u32 b, u8 * c, int d) |
| 373 | { |
| 374 | IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", f, l, (u32) (b), |
| 375 | d); |
| 376 | _ipw_read_indirect(a, b, c, d); |
| 377 | } |
| 378 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 379 | /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */ |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 380 | #define ipw_read_indirect(a, b, c, d) __ipw_read_indirect(__FILE__, __LINE__, a, b, c, d) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 381 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 382 | /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 383 | static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data, |
| 384 | int num); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 385 | #define ipw_write_indirect(a, b, c, d) \ |
| 386 | IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 387 | _ipw_write_indirect(a, b, c, d) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 388 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 389 | /* 32-bit indirect write (above 4K) */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 390 | static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 391 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 392 | IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 393 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg); |
| 394 | _ipw_write32(priv, IPW_INDIRECT_DATA, value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 395 | } |
| 396 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 397 | /* 8-bit indirect write (above 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 398 | static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value) |
| 399 | { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 400 | u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 401 | u32 dif_len = reg - aligned_addr; |
| 402 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 403 | IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 404 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
| 405 | _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 406 | } |
| 407 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 408 | /* 16-bit indirect write (above 4K) */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 409 | static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 410 | { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 411 | u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 412 | u32 dif_len = (reg - aligned_addr) & (~0x1ul); |
| 413 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 414 | IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 415 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
| 416 | _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 417 | } |
| 418 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 419 | /* 8-bit indirect read (above 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 420 | static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg) |
| 421 | { |
| 422 | u32 word; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 423 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 424 | IPW_DEBUG_IO(" reg = 0x%8X : \n", reg); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 425 | word = _ipw_read32(priv, IPW_INDIRECT_DATA); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 426 | return (word >> ((reg & 0x3) * 8)) & 0xff; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 427 | } |
| 428 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 429 | /* 32-bit indirect read (above 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 430 | static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg) |
| 431 | { |
| 432 | u32 value; |
| 433 | |
| 434 | IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg); |
| 435 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 436 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg); |
| 437 | value = _ipw_read32(priv, IPW_INDIRECT_DATA); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 438 | IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value); |
| 439 | return value; |
| 440 | } |
| 441 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 442 | /* General purpose, no alignment requirement, iterative (multi-byte) read, */ |
| 443 | /* for area above 1st 4K of SRAM/reg space */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 444 | static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf, |
| 445 | int num) |
| 446 | { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 447 | u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 448 | u32 dif_len = addr - aligned_addr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 449 | u32 i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 450 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 451 | IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num); |
| 452 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 453 | if (num <= 0) { |
| 454 | return; |
| 455 | } |
| 456 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 457 | /* Read the first dword (or portion) byte by byte */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 458 | if (unlikely(dif_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 459 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 460 | /* Start reading at aligned_addr + dif_len */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 461 | for (i = dif_len; ((i < 4) && (num > 0)); i++, num--) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 462 | *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 463 | aligned_addr += 4; |
| 464 | } |
| 465 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 466 | /* Read all of the middle dwords as dwords, with auto-increment */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 467 | _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 468 | for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 469 | *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 470 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 471 | /* Read the last dword (or portion) byte by byte */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 472 | if (unlikely(num)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 473 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 474 | for (i = 0; num > 0; i++, num--) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 475 | *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 476 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 477 | } |
| 478 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 479 | /* General purpose, no alignment requirement, iterative (multi-byte) write, */ |
| 480 | /* for area above 1st 4K of SRAM/reg space */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 481 | static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 482 | int num) |
| 483 | { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 484 | u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 485 | u32 dif_len = addr - aligned_addr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 486 | u32 i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 487 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 488 | IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 489 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 490 | if (num <= 0) { |
| 491 | return; |
| 492 | } |
| 493 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 494 | /* Write the first dword (or portion) byte by byte */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 495 | if (unlikely(dif_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 496 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 497 | /* Start writing at aligned_addr + dif_len */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 498 | for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 499 | _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 500 | aligned_addr += 4; |
| 501 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 502 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 503 | /* Write all of the middle dwords as dwords, with auto-increment */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 504 | _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 505 | for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 506 | _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 507 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 508 | /* Write the last dword (or portion) byte by byte */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 509 | if (unlikely(num)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 510 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 511 | for (i = 0; num > 0; i++, num--, buf++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 512 | _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 513 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 514 | } |
| 515 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 516 | /* General purpose, no alignment requirement, iterative (multi-byte) write, */ |
| 517 | /* for 1st 4K of SRAM/regs space */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 518 | static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 519 | int num) |
| 520 | { |
| 521 | memcpy_toio((priv->hw_base + addr), buf, num); |
| 522 | } |
| 523 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 524 | /* Set bit(s) in low 4K of SRAM/regs */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 525 | static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask) |
| 526 | { |
| 527 | ipw_write32(priv, reg, ipw_read32(priv, reg) | mask); |
| 528 | } |
| 529 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 530 | /* Clear bit(s) in low 4K of SRAM/regs */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 531 | static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask) |
| 532 | { |
| 533 | ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask); |
| 534 | } |
| 535 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 536 | static inline void __ipw_enable_interrupts(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 537 | { |
| 538 | if (priv->status & STATUS_INT_ENABLED) |
| 539 | return; |
| 540 | priv->status |= STATUS_INT_ENABLED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 541 | ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 542 | } |
| 543 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 544 | static inline void __ipw_disable_interrupts(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 545 | { |
| 546 | if (!(priv->status & STATUS_INT_ENABLED)) |
| 547 | return; |
| 548 | priv->status &= ~STATUS_INT_ENABLED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 549 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 550 | } |
| 551 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 552 | static inline void ipw_enable_interrupts(struct ipw_priv *priv) |
| 553 | { |
| 554 | unsigned long flags; |
| 555 | |
| 556 | spin_lock_irqsave(&priv->irq_lock, flags); |
| 557 | __ipw_enable_interrupts(priv); |
| 558 | spin_unlock_irqrestore(&priv->irq_lock, flags); |
| 559 | } |
| 560 | |
| 561 | static inline void ipw_disable_interrupts(struct ipw_priv *priv) |
| 562 | { |
| 563 | unsigned long flags; |
| 564 | |
| 565 | spin_lock_irqsave(&priv->irq_lock, flags); |
| 566 | __ipw_disable_interrupts(priv); |
| 567 | spin_unlock_irqrestore(&priv->irq_lock, flags); |
| 568 | } |
| 569 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 570 | static char *ipw_error_desc(u32 val) |
| 571 | { |
| 572 | switch (val) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 573 | case IPW_FW_ERROR_OK: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 574 | return "ERROR_OK"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 575 | case IPW_FW_ERROR_FAIL: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 576 | return "ERROR_FAIL"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 577 | case IPW_FW_ERROR_MEMORY_UNDERFLOW: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 578 | return "MEMORY_UNDERFLOW"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 579 | case IPW_FW_ERROR_MEMORY_OVERFLOW: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 580 | return "MEMORY_OVERFLOW"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 581 | case IPW_FW_ERROR_BAD_PARAM: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 582 | return "BAD_PARAM"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 583 | case IPW_FW_ERROR_BAD_CHECKSUM: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 584 | return "BAD_CHECKSUM"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 585 | case IPW_FW_ERROR_NMI_INTERRUPT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 586 | return "NMI_INTERRUPT"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 587 | case IPW_FW_ERROR_BAD_DATABASE: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 588 | return "BAD_DATABASE"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 589 | case IPW_FW_ERROR_ALLOC_FAIL: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 590 | return "ALLOC_FAIL"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 591 | case IPW_FW_ERROR_DMA_UNDERRUN: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 592 | return "DMA_UNDERRUN"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 593 | case IPW_FW_ERROR_DMA_STATUS: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 594 | return "DMA_STATUS"; |
| 595 | case IPW_FW_ERROR_DINO_ERROR: |
| 596 | return "DINO_ERROR"; |
| 597 | case IPW_FW_ERROR_EEPROM_ERROR: |
| 598 | return "EEPROM_ERROR"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 599 | case IPW_FW_ERROR_SYSASSERT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 600 | return "SYSASSERT"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 601 | case IPW_FW_ERROR_FATAL_ERROR: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 602 | return "FATAL_ERROR"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 603 | default: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 604 | return "UNKNOWN_ERROR"; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 605 | } |
| 606 | } |
| 607 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 608 | static void ipw_dump_error_log(struct ipw_priv *priv, |
| 609 | struct ipw_fw_error *error) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 610 | { |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 611 | u32 i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 612 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 613 | if (!error) { |
| 614 | IPW_ERROR("Error allocating and capturing error log. " |
| 615 | "Nothing to dump.\n"); |
| 616 | return; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 617 | } |
| 618 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 619 | IPW_ERROR("Start IPW Error Log Dump:\n"); |
| 620 | IPW_ERROR("Status: 0x%08X, Config: %08X\n", |
| 621 | error->status, error->config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 622 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 623 | for (i = 0; i < error->elem_len; i++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 624 | IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n", |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 625 | ipw_error_desc(error->elem[i].desc), |
| 626 | error->elem[i].time, |
| 627 | error->elem[i].blink1, |
| 628 | error->elem[i].blink2, |
| 629 | error->elem[i].link1, |
| 630 | error->elem[i].link2, error->elem[i].data); |
| 631 | for (i = 0; i < error->log_len; i++) |
| 632 | IPW_ERROR("%i\t0x%08x\t%i\n", |
| 633 | error->log[i].time, |
James Ketrenos | 286568a | 2005-08-30 10:34:25 -0500 | [diff] [blame] | 634 | error->log[i].data, error->log[i].event); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 635 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 636 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 637 | static inline int ipw_is_init(struct ipw_priv *priv) |
| 638 | { |
| 639 | return (priv->status & STATUS_INIT) ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 640 | } |
| 641 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 642 | static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 643 | { |
| 644 | u32 addr, field_info, field_len, field_count, total_len; |
| 645 | |
| 646 | IPW_DEBUG_ORD("ordinal = %i\n", ord); |
| 647 | |
| 648 | if (!priv || !val || !len) { |
| 649 | IPW_DEBUG_ORD("Invalid argument\n"); |
| 650 | return -EINVAL; |
| 651 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 652 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 653 | /* verify device ordinal tables have been initialized */ |
| 654 | if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) { |
| 655 | IPW_DEBUG_ORD("Access ordinals before initialization\n"); |
| 656 | return -EINVAL; |
| 657 | } |
| 658 | |
| 659 | switch (IPW_ORD_TABLE_ID_MASK & ord) { |
| 660 | case IPW_ORD_TABLE_0_MASK: |
| 661 | /* |
| 662 | * TABLE 0: Direct access to a table of 32 bit values |
| 663 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 664 | * This is a very simple table with the data directly |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 665 | * read from the table |
| 666 | */ |
| 667 | |
| 668 | /* remove the table id from the ordinal */ |
| 669 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
| 670 | |
| 671 | /* boundary check */ |
| 672 | if (ord > priv->table0_len) { |
| 673 | IPW_DEBUG_ORD("ordinal value (%i) longer then " |
| 674 | "max (%i)\n", ord, priv->table0_len); |
| 675 | return -EINVAL; |
| 676 | } |
| 677 | |
| 678 | /* verify we have enough room to store the value */ |
| 679 | if (*len < sizeof(u32)) { |
| 680 | IPW_DEBUG_ORD("ordinal buffer length too small, " |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 681 | "need %zd\n", sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 682 | return -EINVAL; |
| 683 | } |
| 684 | |
| 685 | IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 686 | ord, priv->table0_addr + (ord << 2)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 687 | |
| 688 | *len = sizeof(u32); |
| 689 | ord <<= 2; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 690 | *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 691 | break; |
| 692 | |
| 693 | case IPW_ORD_TABLE_1_MASK: |
| 694 | /* |
| 695 | * TABLE 1: Indirect access to a table of 32 bit values |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 696 | * |
| 697 | * This is a fairly large table of u32 values each |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 698 | * representing starting addr for the data (which is |
| 699 | * also a u32) |
| 700 | */ |
| 701 | |
| 702 | /* remove the table id from the ordinal */ |
| 703 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 704 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 705 | /* boundary check */ |
| 706 | if (ord > priv->table1_len) { |
| 707 | IPW_DEBUG_ORD("ordinal value too long\n"); |
| 708 | return -EINVAL; |
| 709 | } |
| 710 | |
| 711 | /* verify we have enough room to store the value */ |
| 712 | if (*len < sizeof(u32)) { |
| 713 | IPW_DEBUG_ORD("ordinal buffer length too small, " |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 714 | "need %zd\n", sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 715 | return -EINVAL; |
| 716 | } |
| 717 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 718 | *((u32 *) val) = |
| 719 | ipw_read_reg32(priv, (priv->table1_addr + (ord << 2))); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 720 | *len = sizeof(u32); |
| 721 | break; |
| 722 | |
| 723 | case IPW_ORD_TABLE_2_MASK: |
| 724 | /* |
| 725 | * TABLE 2: Indirect access to a table of variable sized values |
| 726 | * |
| 727 | * This table consist of six values, each containing |
| 728 | * - dword containing the starting offset of the data |
| 729 | * - dword containing the lengh in the first 16bits |
| 730 | * and the count in the second 16bits |
| 731 | */ |
| 732 | |
| 733 | /* remove the table id from the ordinal */ |
| 734 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
| 735 | |
| 736 | /* boundary check */ |
| 737 | if (ord > priv->table2_len) { |
| 738 | IPW_DEBUG_ORD("ordinal value too long\n"); |
| 739 | return -EINVAL; |
| 740 | } |
| 741 | |
| 742 | /* get the address of statistic */ |
| 743 | addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 744 | |
| 745 | /* get the second DW of statistics ; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 746 | * two 16-bit words - first is length, second is count */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 747 | field_info = |
| 748 | ipw_read_reg32(priv, |
| 749 | priv->table2_addr + (ord << 3) + |
| 750 | sizeof(u32)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 751 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 752 | /* get each entry length */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 753 | field_len = *((u16 *) & field_info); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 754 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 755 | /* get number of entries */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 756 | field_count = *(((u16 *) & field_info) + 1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 757 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 758 | /* abort if not enought memory */ |
| 759 | total_len = field_len * field_count; |
| 760 | if (total_len > *len) { |
| 761 | *len = total_len; |
| 762 | return -EINVAL; |
| 763 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 764 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 765 | *len = total_len; |
| 766 | if (!total_len) |
| 767 | return 0; |
| 768 | |
| 769 | IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 770 | "field_info = 0x%08x\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 771 | addr, total_len, field_info); |
| 772 | ipw_read_indirect(priv, addr, val, total_len); |
| 773 | break; |
| 774 | |
| 775 | default: |
| 776 | IPW_DEBUG_ORD("Invalid ordinal!\n"); |
| 777 | return -EINVAL; |
| 778 | |
| 779 | } |
| 780 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 781 | return 0; |
| 782 | } |
| 783 | |
| 784 | static void ipw_init_ordinals(struct ipw_priv *priv) |
| 785 | { |
| 786 | priv->table0_addr = IPW_ORDINALS_TABLE_LOWER; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 787 | priv->table0_len = ipw_read32(priv, priv->table0_addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 788 | |
| 789 | IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n", |
| 790 | priv->table0_addr, priv->table0_len); |
| 791 | |
| 792 | priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1); |
| 793 | priv->table1_len = ipw_read_reg32(priv, priv->table1_addr); |
| 794 | |
| 795 | IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n", |
| 796 | priv->table1_addr, priv->table1_len); |
| 797 | |
| 798 | priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2); |
| 799 | priv->table2_len = ipw_read_reg32(priv, priv->table2_addr); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 800 | priv->table2_len &= 0x0000ffff; /* use first two bytes */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 801 | |
| 802 | IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n", |
| 803 | priv->table2_addr, priv->table2_len); |
| 804 | |
| 805 | } |
| 806 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 807 | static u32 ipw_register_toggle(u32 reg) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 808 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 809 | reg &= ~IPW_START_STANDBY; |
| 810 | if (reg & IPW_GATE_ODMA) |
| 811 | reg &= ~IPW_GATE_ODMA; |
| 812 | if (reg & IPW_GATE_IDMA) |
| 813 | reg &= ~IPW_GATE_IDMA; |
| 814 | if (reg & IPW_GATE_ADMA) |
| 815 | reg &= ~IPW_GATE_ADMA; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 816 | return reg; |
| 817 | } |
| 818 | |
| 819 | /* |
| 820 | * LED behavior: |
| 821 | * - On radio ON, turn on any LEDs that require to be on during start |
| 822 | * - On initialization, start unassociated blink |
| 823 | * - On association, disable unassociated blink |
| 824 | * - On disassociation, start unassociated blink |
| 825 | * - On radio OFF, turn off any LEDs started during radio on |
| 826 | * |
| 827 | */ |
Zhu Yi | ede6111 | 2006-01-24 16:37:10 +0800 | [diff] [blame] | 828 | #define LD_TIME_LINK_ON msecs_to_jiffies(300) |
| 829 | #define LD_TIME_LINK_OFF msecs_to_jiffies(2700) |
| 830 | #define LD_TIME_ACT_ON msecs_to_jiffies(250) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 831 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 832 | static void ipw_led_link_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 833 | { |
| 834 | unsigned long flags; |
| 835 | u32 led; |
| 836 | |
| 837 | /* If configured to not use LEDs, or nic_type is 1, |
| 838 | * then we don't toggle a LINK led */ |
| 839 | if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) |
| 840 | return; |
| 841 | |
| 842 | spin_lock_irqsave(&priv->lock, flags); |
| 843 | |
| 844 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
| 845 | !(priv->status & STATUS_LED_LINK_ON)) { |
| 846 | IPW_DEBUG_LED("Link LED On\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 847 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 848 | led |= priv->led_association_on; |
| 849 | |
| 850 | led = ipw_register_toggle(led); |
| 851 | |
| 852 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 853 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 854 | |
| 855 | priv->status |= STATUS_LED_LINK_ON; |
| 856 | |
| 857 | /* If we aren't associated, schedule turning the LED off */ |
| 858 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 859 | queue_delayed_work(priv->workqueue, |
| 860 | &priv->led_link_off, |
| 861 | LD_TIME_LINK_ON); |
| 862 | } |
| 863 | |
| 864 | spin_unlock_irqrestore(&priv->lock, flags); |
| 865 | } |
| 866 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 867 | static void ipw_bg_led_link_on(void *data) |
| 868 | { |
| 869 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 870 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 871 | ipw_led_link_on(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 872 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 873 | } |
| 874 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 875 | static void ipw_led_link_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 876 | { |
| 877 | unsigned long flags; |
| 878 | u32 led; |
| 879 | |
| 880 | /* If configured not to use LEDs, or nic type is 1, |
| 881 | * then we don't goggle the LINK led. */ |
| 882 | if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) |
| 883 | return; |
| 884 | |
| 885 | spin_lock_irqsave(&priv->lock, flags); |
| 886 | |
| 887 | if (priv->status & STATUS_LED_LINK_ON) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 888 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 889 | led &= priv->led_association_off; |
| 890 | led = ipw_register_toggle(led); |
| 891 | |
| 892 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 893 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 894 | |
| 895 | IPW_DEBUG_LED("Link LED Off\n"); |
| 896 | |
| 897 | priv->status &= ~STATUS_LED_LINK_ON; |
| 898 | |
| 899 | /* If we aren't associated and the radio is on, schedule |
| 900 | * turning the LED on (blink while unassociated) */ |
| 901 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
| 902 | !(priv->status & STATUS_ASSOCIATED)) |
| 903 | queue_delayed_work(priv->workqueue, &priv->led_link_on, |
| 904 | LD_TIME_LINK_OFF); |
| 905 | |
| 906 | } |
| 907 | |
| 908 | spin_unlock_irqrestore(&priv->lock, flags); |
| 909 | } |
| 910 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 911 | static void ipw_bg_led_link_off(void *data) |
| 912 | { |
| 913 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 914 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 915 | ipw_led_link_off(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 916 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 917 | } |
| 918 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 919 | static void __ipw_led_activity_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 920 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 921 | u32 led; |
| 922 | |
| 923 | if (priv->config & CFG_NO_LED) |
| 924 | return; |
| 925 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 926 | if (priv->status & STATUS_RF_KILL_MASK) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 927 | return; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 928 | |
| 929 | if (!(priv->status & STATUS_LED_ACT_ON)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 930 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 931 | led |= priv->led_activity_on; |
| 932 | |
| 933 | led = ipw_register_toggle(led); |
| 934 | |
| 935 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 936 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 937 | |
| 938 | IPW_DEBUG_LED("Activity LED On\n"); |
| 939 | |
| 940 | priv->status |= STATUS_LED_ACT_ON; |
| 941 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 942 | cancel_delayed_work(&priv->led_act_off); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 943 | queue_delayed_work(priv->workqueue, &priv->led_act_off, |
| 944 | LD_TIME_ACT_ON); |
| 945 | } else { |
| 946 | /* Reschedule LED off for full time period */ |
| 947 | cancel_delayed_work(&priv->led_act_off); |
| 948 | queue_delayed_work(priv->workqueue, &priv->led_act_off, |
| 949 | LD_TIME_ACT_ON); |
| 950 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 951 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 952 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 953 | #if 0 |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 954 | void ipw_led_activity_on(struct ipw_priv *priv) |
| 955 | { |
| 956 | unsigned long flags; |
| 957 | spin_lock_irqsave(&priv->lock, flags); |
| 958 | __ipw_led_activity_on(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 959 | spin_unlock_irqrestore(&priv->lock, flags); |
| 960 | } |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 961 | #endif /* 0 */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 962 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 963 | static void ipw_led_activity_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 964 | { |
| 965 | unsigned long flags; |
| 966 | u32 led; |
| 967 | |
| 968 | if (priv->config & CFG_NO_LED) |
| 969 | return; |
| 970 | |
| 971 | spin_lock_irqsave(&priv->lock, flags); |
| 972 | |
| 973 | if (priv->status & STATUS_LED_ACT_ON) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 974 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 975 | led &= priv->led_activity_off; |
| 976 | |
| 977 | led = ipw_register_toggle(led); |
| 978 | |
| 979 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 980 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 981 | |
| 982 | IPW_DEBUG_LED("Activity LED Off\n"); |
| 983 | |
| 984 | priv->status &= ~STATUS_LED_ACT_ON; |
| 985 | } |
| 986 | |
| 987 | spin_unlock_irqrestore(&priv->lock, flags); |
| 988 | } |
| 989 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 990 | static void ipw_bg_led_activity_off(void *data) |
| 991 | { |
| 992 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 993 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 994 | ipw_led_activity_off(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 995 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 996 | } |
| 997 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 998 | static void ipw_led_band_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 999 | { |
| 1000 | unsigned long flags; |
| 1001 | u32 led; |
| 1002 | |
| 1003 | /* Only nic type 1 supports mode LEDs */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 1004 | if (priv->config & CFG_NO_LED || |
| 1005 | priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1006 | return; |
| 1007 | |
| 1008 | spin_lock_irqsave(&priv->lock, flags); |
| 1009 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1010 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1011 | if (priv->assoc_network->mode == IEEE_A) { |
| 1012 | led |= priv->led_ofdm_on; |
| 1013 | led &= priv->led_association_off; |
| 1014 | IPW_DEBUG_LED("Mode LED On: 802.11a\n"); |
| 1015 | } else if (priv->assoc_network->mode == IEEE_G) { |
| 1016 | led |= priv->led_ofdm_on; |
| 1017 | led |= priv->led_association_on; |
| 1018 | IPW_DEBUG_LED("Mode LED On: 802.11g\n"); |
| 1019 | } else { |
| 1020 | led &= priv->led_ofdm_off; |
| 1021 | led |= priv->led_association_on; |
| 1022 | IPW_DEBUG_LED("Mode LED On: 802.11b\n"); |
| 1023 | } |
| 1024 | |
| 1025 | led = ipw_register_toggle(led); |
| 1026 | |
| 1027 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1028 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1029 | |
| 1030 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1031 | } |
| 1032 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1033 | static void ipw_led_band_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1034 | { |
| 1035 | unsigned long flags; |
| 1036 | u32 led; |
| 1037 | |
| 1038 | /* Only nic type 1 supports mode LEDs */ |
| 1039 | if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1) |
| 1040 | return; |
| 1041 | |
| 1042 | spin_lock_irqsave(&priv->lock, flags); |
| 1043 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1044 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1045 | led &= priv->led_ofdm_off; |
| 1046 | led &= priv->led_association_off; |
| 1047 | |
| 1048 | led = ipw_register_toggle(led); |
| 1049 | |
| 1050 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1051 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1052 | |
| 1053 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1054 | } |
| 1055 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1056 | static void ipw_led_radio_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1057 | { |
| 1058 | ipw_led_link_on(priv); |
| 1059 | } |
| 1060 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1061 | static void ipw_led_radio_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1062 | { |
| 1063 | ipw_led_activity_off(priv); |
| 1064 | ipw_led_link_off(priv); |
| 1065 | } |
| 1066 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1067 | static void ipw_led_link_up(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1068 | { |
| 1069 | /* Set the Link Led on for all nic types */ |
| 1070 | ipw_led_link_on(priv); |
| 1071 | } |
| 1072 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1073 | static void ipw_led_link_down(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1074 | { |
| 1075 | ipw_led_activity_off(priv); |
| 1076 | ipw_led_link_off(priv); |
| 1077 | |
| 1078 | if (priv->status & STATUS_RF_KILL_MASK) |
| 1079 | ipw_led_radio_off(priv); |
| 1080 | } |
| 1081 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1082 | static void ipw_led_init(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1083 | { |
| 1084 | priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE]; |
| 1085 | |
| 1086 | /* Set the default PINs for the link and activity leds */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1087 | priv->led_activity_on = IPW_ACTIVITY_LED; |
| 1088 | priv->led_activity_off = ~(IPW_ACTIVITY_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1089 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1090 | priv->led_association_on = IPW_ASSOCIATED_LED; |
| 1091 | priv->led_association_off = ~(IPW_ASSOCIATED_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1092 | |
| 1093 | /* Set the default PINs for the OFDM leds */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1094 | priv->led_ofdm_on = IPW_OFDM_LED; |
| 1095 | priv->led_ofdm_off = ~(IPW_OFDM_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1096 | |
| 1097 | switch (priv->nic_type) { |
| 1098 | case EEPROM_NIC_TYPE_1: |
| 1099 | /* In this NIC type, the LEDs are reversed.... */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1100 | priv->led_activity_on = IPW_ASSOCIATED_LED; |
| 1101 | priv->led_activity_off = ~(IPW_ASSOCIATED_LED); |
| 1102 | priv->led_association_on = IPW_ACTIVITY_LED; |
| 1103 | priv->led_association_off = ~(IPW_ACTIVITY_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1104 | |
| 1105 | if (!(priv->config & CFG_NO_LED)) |
| 1106 | ipw_led_band_on(priv); |
| 1107 | |
| 1108 | /* And we don't blink link LEDs for this nic, so |
| 1109 | * just return here */ |
| 1110 | return; |
| 1111 | |
| 1112 | case EEPROM_NIC_TYPE_3: |
| 1113 | case EEPROM_NIC_TYPE_2: |
| 1114 | case EEPROM_NIC_TYPE_4: |
| 1115 | case EEPROM_NIC_TYPE_0: |
| 1116 | break; |
| 1117 | |
| 1118 | default: |
| 1119 | IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n", |
| 1120 | priv->nic_type); |
| 1121 | priv->nic_type = EEPROM_NIC_TYPE_0; |
| 1122 | break; |
| 1123 | } |
| 1124 | |
| 1125 | if (!(priv->config & CFG_NO_LED)) { |
| 1126 | if (priv->status & STATUS_ASSOCIATED) |
| 1127 | ipw_led_link_on(priv); |
| 1128 | else |
| 1129 | ipw_led_link_off(priv); |
| 1130 | } |
| 1131 | } |
| 1132 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1133 | static void ipw_led_shutdown(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1134 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1135 | ipw_led_activity_off(priv); |
| 1136 | ipw_led_link_off(priv); |
| 1137 | ipw_led_band_off(priv); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1138 | cancel_delayed_work(&priv->led_link_on); |
| 1139 | cancel_delayed_work(&priv->led_link_off); |
| 1140 | cancel_delayed_work(&priv->led_act_off); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1141 | } |
| 1142 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1143 | /* |
| 1144 | * The following adds a new attribute to the sysfs representation |
| 1145 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/) |
| 1146 | * used for controling the debug level. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1147 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1148 | * See the level definitions in ipw for details. |
| 1149 | */ |
| 1150 | static ssize_t show_debug_level(struct device_driver *d, char *buf) |
| 1151 | { |
| 1152 | return sprintf(buf, "0x%08X\n", ipw_debug_level); |
| 1153 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1154 | |
| 1155 | static ssize_t store_debug_level(struct device_driver *d, const char *buf, |
| 1156 | size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1157 | { |
| 1158 | char *p = (char *)buf; |
| 1159 | u32 val; |
| 1160 | |
| 1161 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { |
| 1162 | p++; |
| 1163 | if (p[0] == 'x' || p[0] == 'X') |
| 1164 | p++; |
| 1165 | val = simple_strtoul(p, &p, 16); |
| 1166 | } else |
| 1167 | val = simple_strtoul(p, &p, 10); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1168 | if (p == buf) |
| 1169 | printk(KERN_INFO DRV_NAME |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1170 | ": %s is not in hex or decimal form.\n", buf); |
| 1171 | else |
| 1172 | ipw_debug_level = val; |
| 1173 | |
| 1174 | return strnlen(buf, count); |
| 1175 | } |
| 1176 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1177 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1178 | show_debug_level, store_debug_level); |
| 1179 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1180 | static inline u32 ipw_get_event_log_len(struct ipw_priv *priv) |
| 1181 | { |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 1182 | /* length = 1st dword in log */ |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1183 | return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG)); |
| 1184 | } |
| 1185 | |
| 1186 | static void ipw_capture_event_log(struct ipw_priv *priv, |
| 1187 | u32 log_len, struct ipw_event *log) |
| 1188 | { |
| 1189 | u32 base; |
| 1190 | |
| 1191 | if (log_len) { |
| 1192 | base = ipw_read32(priv, IPW_EVENT_LOG); |
| 1193 | ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32), |
| 1194 | (u8 *) log, sizeof(*log) * log_len); |
| 1195 | } |
| 1196 | } |
| 1197 | |
| 1198 | static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv) |
| 1199 | { |
| 1200 | struct ipw_fw_error *error; |
| 1201 | u32 log_len = ipw_get_event_log_len(priv); |
| 1202 | u32 base = ipw_read32(priv, IPW_ERROR_LOG); |
| 1203 | u32 elem_len = ipw_read_reg32(priv, base); |
| 1204 | |
| 1205 | error = kmalloc(sizeof(*error) + |
| 1206 | sizeof(*error->elem) * elem_len + |
| 1207 | sizeof(*error->log) * log_len, GFP_ATOMIC); |
| 1208 | if (!error) { |
| 1209 | IPW_ERROR("Memory allocation for firmware error log " |
| 1210 | "failed.\n"); |
| 1211 | return NULL; |
| 1212 | } |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1213 | error->jiffies = jiffies; |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1214 | error->status = priv->status; |
| 1215 | error->config = priv->config; |
| 1216 | error->elem_len = elem_len; |
| 1217 | error->log_len = log_len; |
| 1218 | error->elem = (struct ipw_error_elem *)error->payload; |
Zhu Yi | 3b26b11 | 2005-11-17 13:58:30 +0800 | [diff] [blame] | 1219 | error->log = (struct ipw_event *)(error->elem + elem_len); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1220 | |
| 1221 | ipw_capture_event_log(priv, log_len, error->log); |
| 1222 | |
| 1223 | if (elem_len) |
| 1224 | ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem, |
| 1225 | sizeof(*error->elem) * elem_len); |
| 1226 | |
| 1227 | return error; |
| 1228 | } |
| 1229 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1230 | static ssize_t show_event_log(struct device *d, |
| 1231 | struct device_attribute *attr, char *buf) |
| 1232 | { |
| 1233 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1234 | u32 log_len = ipw_get_event_log_len(priv); |
| 1235 | struct ipw_event log[log_len]; |
| 1236 | u32 len = 0, i; |
| 1237 | |
| 1238 | ipw_capture_event_log(priv, log_len, log); |
| 1239 | |
| 1240 | len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len); |
| 1241 | for (i = 0; i < log_len; i++) |
| 1242 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1243 | "\n%08X%08X%08X", |
| 1244 | log[i].time, log[i].event, log[i].data); |
| 1245 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1246 | return len; |
| 1247 | } |
| 1248 | |
| 1249 | static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL); |
| 1250 | |
| 1251 | static ssize_t show_error(struct device *d, |
| 1252 | struct device_attribute *attr, char *buf) |
| 1253 | { |
| 1254 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1255 | u32 len = 0, i; |
| 1256 | if (!priv->error) |
| 1257 | return 0; |
| 1258 | len += snprintf(buf + len, PAGE_SIZE - len, |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1259 | "%08lX%08X%08X%08X", |
| 1260 | priv->error->jiffies, |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1261 | priv->error->status, |
| 1262 | priv->error->config, priv->error->elem_len); |
| 1263 | for (i = 0; i < priv->error->elem_len; i++) |
| 1264 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1265 | "\n%08X%08X%08X%08X%08X%08X%08X", |
| 1266 | priv->error->elem[i].time, |
| 1267 | priv->error->elem[i].desc, |
| 1268 | priv->error->elem[i].blink1, |
| 1269 | priv->error->elem[i].blink2, |
| 1270 | priv->error->elem[i].link1, |
| 1271 | priv->error->elem[i].link2, |
| 1272 | priv->error->elem[i].data); |
| 1273 | |
| 1274 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1275 | "\n%08X", priv->error->log_len); |
| 1276 | for (i = 0; i < priv->error->log_len; i++) |
| 1277 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1278 | "\n%08X%08X%08X", |
| 1279 | priv->error->log[i].time, |
| 1280 | priv->error->log[i].event, |
| 1281 | priv->error->log[i].data); |
| 1282 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1283 | return len; |
| 1284 | } |
| 1285 | |
| 1286 | static ssize_t clear_error(struct device *d, |
| 1287 | struct device_attribute *attr, |
| 1288 | const char *buf, size_t count) |
| 1289 | { |
| 1290 | struct ipw_priv *priv = dev_get_drvdata(d); |
Jesper Juhl | 8f76078 | 2006-06-27 02:55:06 -0700 | [diff] [blame] | 1291 | |
| 1292 | kfree(priv->error); |
| 1293 | priv->error = NULL; |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1294 | return count; |
| 1295 | } |
| 1296 | |
| 1297 | static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error); |
| 1298 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1299 | static ssize_t show_cmd_log(struct device *d, |
| 1300 | struct device_attribute *attr, char *buf) |
| 1301 | { |
| 1302 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1303 | u32 len = 0, i; |
| 1304 | if (!priv->cmdlog) |
| 1305 | return 0; |
| 1306 | for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len; |
| 1307 | (i != priv->cmdlog_pos) && (PAGE_SIZE - len); |
| 1308 | i = (i + 1) % priv->cmdlog_len) { |
| 1309 | len += |
| 1310 | snprintf(buf + len, PAGE_SIZE - len, |
| 1311 | "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies, |
| 1312 | priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd, |
| 1313 | priv->cmdlog[i].cmd.len); |
| 1314 | len += |
| 1315 | snprintk_buf(buf + len, PAGE_SIZE - len, |
| 1316 | (u8 *) priv->cmdlog[i].cmd.param, |
| 1317 | priv->cmdlog[i].cmd.len); |
| 1318 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1319 | } |
| 1320 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1321 | return len; |
| 1322 | } |
| 1323 | |
| 1324 | static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL); |
| 1325 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 1326 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 1327 | static void ipw_prom_free(struct ipw_priv *priv); |
| 1328 | static int ipw_prom_alloc(struct ipw_priv *priv); |
| 1329 | static ssize_t store_rtap_iface(struct device *d, |
| 1330 | struct device_attribute *attr, |
| 1331 | const char *buf, size_t count) |
| 1332 | { |
| 1333 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1334 | int rc = 0; |
| 1335 | |
| 1336 | if (count < 1) |
| 1337 | return -EINVAL; |
| 1338 | |
| 1339 | switch (buf[0]) { |
| 1340 | case '0': |
| 1341 | if (!rtap_iface) |
| 1342 | return count; |
| 1343 | |
| 1344 | if (netif_running(priv->prom_net_dev)) { |
| 1345 | IPW_WARNING("Interface is up. Cannot unregister.\n"); |
| 1346 | return count; |
| 1347 | } |
| 1348 | |
| 1349 | ipw_prom_free(priv); |
| 1350 | rtap_iface = 0; |
| 1351 | break; |
| 1352 | |
| 1353 | case '1': |
| 1354 | if (rtap_iface) |
| 1355 | return count; |
| 1356 | |
| 1357 | rc = ipw_prom_alloc(priv); |
| 1358 | if (!rc) |
| 1359 | rtap_iface = 1; |
| 1360 | break; |
| 1361 | |
| 1362 | default: |
| 1363 | return -EINVAL; |
| 1364 | } |
| 1365 | |
| 1366 | if (rc) { |
| 1367 | IPW_ERROR("Failed to register promiscuous network " |
| 1368 | "device (error %d).\n", rc); |
| 1369 | } |
| 1370 | |
| 1371 | return count; |
| 1372 | } |
| 1373 | |
| 1374 | static ssize_t show_rtap_iface(struct device *d, |
| 1375 | struct device_attribute *attr, |
| 1376 | char *buf) |
| 1377 | { |
| 1378 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1379 | if (rtap_iface) |
| 1380 | return sprintf(buf, "%s", priv->prom_net_dev->name); |
| 1381 | else { |
| 1382 | buf[0] = '-'; |
| 1383 | buf[1] = '1'; |
| 1384 | buf[2] = '\0'; |
| 1385 | return 3; |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface, |
| 1390 | store_rtap_iface); |
| 1391 | |
| 1392 | static ssize_t store_rtap_filter(struct device *d, |
| 1393 | struct device_attribute *attr, |
| 1394 | const char *buf, size_t count) |
| 1395 | { |
| 1396 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1397 | |
| 1398 | if (!priv->prom_priv) { |
| 1399 | IPW_ERROR("Attempting to set filter without " |
| 1400 | "rtap_iface enabled.\n"); |
| 1401 | return -EPERM; |
| 1402 | } |
| 1403 | |
| 1404 | priv->prom_priv->filter = simple_strtol(buf, NULL, 0); |
| 1405 | |
| 1406 | IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n", |
| 1407 | BIT_ARG16(priv->prom_priv->filter)); |
| 1408 | |
| 1409 | return count; |
| 1410 | } |
| 1411 | |
| 1412 | static ssize_t show_rtap_filter(struct device *d, |
| 1413 | struct device_attribute *attr, |
| 1414 | char *buf) |
| 1415 | { |
| 1416 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1417 | return sprintf(buf, "0x%04X", |
| 1418 | priv->prom_priv ? priv->prom_priv->filter : 0); |
| 1419 | } |
| 1420 | |
| 1421 | static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter, |
| 1422 | store_rtap_filter); |
| 1423 | #endif |
| 1424 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1425 | static ssize_t show_scan_age(struct device *d, struct device_attribute *attr, |
| 1426 | char *buf) |
| 1427 | { |
| 1428 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1429 | return sprintf(buf, "%d\n", priv->ieee->scan_age); |
| 1430 | } |
| 1431 | |
| 1432 | static ssize_t store_scan_age(struct device *d, struct device_attribute *attr, |
| 1433 | const char *buf, size_t count) |
| 1434 | { |
| 1435 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1436 | struct net_device *dev = priv->net_dev; |
| 1437 | char buffer[] = "00000000"; |
| 1438 | unsigned long len = |
| 1439 | (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1; |
| 1440 | unsigned long val; |
| 1441 | char *p = buffer; |
| 1442 | |
| 1443 | IPW_DEBUG_INFO("enter\n"); |
| 1444 | |
| 1445 | strncpy(buffer, buf, len); |
| 1446 | buffer[len] = 0; |
| 1447 | |
| 1448 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { |
| 1449 | p++; |
| 1450 | if (p[0] == 'x' || p[0] == 'X') |
| 1451 | p++; |
| 1452 | val = simple_strtoul(p, &p, 16); |
| 1453 | } else |
| 1454 | val = simple_strtoul(p, &p, 10); |
| 1455 | if (p == buffer) { |
| 1456 | IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name); |
| 1457 | } else { |
| 1458 | priv->ieee->scan_age = val; |
| 1459 | IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age); |
| 1460 | } |
| 1461 | |
| 1462 | IPW_DEBUG_INFO("exit\n"); |
| 1463 | return len; |
| 1464 | } |
| 1465 | |
| 1466 | static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age); |
| 1467 | |
| 1468 | static ssize_t show_led(struct device *d, struct device_attribute *attr, |
| 1469 | char *buf) |
| 1470 | { |
| 1471 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1472 | return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1); |
| 1473 | } |
| 1474 | |
| 1475 | static ssize_t store_led(struct device *d, struct device_attribute *attr, |
| 1476 | const char *buf, size_t count) |
| 1477 | { |
| 1478 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1479 | |
| 1480 | IPW_DEBUG_INFO("enter\n"); |
| 1481 | |
| 1482 | if (count == 0) |
| 1483 | return 0; |
| 1484 | |
| 1485 | if (*buf == 0) { |
| 1486 | IPW_DEBUG_LED("Disabling LED control.\n"); |
| 1487 | priv->config |= CFG_NO_LED; |
| 1488 | ipw_led_shutdown(priv); |
| 1489 | } else { |
| 1490 | IPW_DEBUG_LED("Enabling LED control.\n"); |
| 1491 | priv->config &= ~CFG_NO_LED; |
| 1492 | ipw_led_init(priv); |
| 1493 | } |
| 1494 | |
| 1495 | IPW_DEBUG_INFO("exit\n"); |
| 1496 | return count; |
| 1497 | } |
| 1498 | |
| 1499 | static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led); |
| 1500 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1501 | static ssize_t show_status(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1502 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1503 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1504 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1505 | return sprintf(buf, "0x%08x\n", (int)p->status); |
| 1506 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1507 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1508 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 1509 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1510 | static ssize_t show_cfg(struct device *d, struct device_attribute *attr, |
| 1511 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1512 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1513 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1514 | return sprintf(buf, "0x%08x\n", (int)p->config); |
| 1515 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1516 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1517 | static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL); |
| 1518 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1519 | static ssize_t show_nic_type(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1520 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1521 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1522 | struct ipw_priv *priv = d->driver_data; |
| 1523 | return sprintf(buf, "TYPE: %d\n", priv->nic_type); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1524 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1525 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1526 | static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL); |
| 1527 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1528 | static ssize_t show_ucode_version(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1529 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1530 | { |
| 1531 | u32 len = sizeof(u32), tmp = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1532 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1533 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1534 | if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1535 | return 0; |
| 1536 | |
| 1537 | return sprintf(buf, "0x%08x\n", tmp); |
| 1538 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1539 | |
| 1540 | static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1541 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1542 | static ssize_t show_rtc(struct device *d, struct device_attribute *attr, |
| 1543 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1544 | { |
| 1545 | u32 len = sizeof(u32), tmp = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1546 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1547 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1548 | if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1549 | return 0; |
| 1550 | |
| 1551 | return sprintf(buf, "0x%08x\n", tmp); |
| 1552 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1553 | |
| 1554 | static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1555 | |
| 1556 | /* |
| 1557 | * Add a device attribute to view/control the delay between eeprom |
| 1558 | * operations. |
| 1559 | */ |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1560 | static ssize_t show_eeprom_delay(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1561 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1562 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1563 | int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1564 | return sprintf(buf, "%i\n", n); |
| 1565 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1566 | static ssize_t store_eeprom_delay(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1567 | struct device_attribute *attr, |
| 1568 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1569 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1570 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1571 | sscanf(buf, "%i", &p->eeprom_delay); |
| 1572 | return strnlen(buf, count); |
| 1573 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1574 | |
| 1575 | static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO, |
| 1576 | show_eeprom_delay, store_eeprom_delay); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1577 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1578 | static ssize_t show_command_event_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1579 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1580 | { |
| 1581 | u32 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1582 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1583 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1584 | reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1585 | return sprintf(buf, "0x%08x\n", reg); |
| 1586 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1587 | static ssize_t store_command_event_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1588 | struct device_attribute *attr, |
| 1589 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1590 | { |
| 1591 | u32 reg; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1592 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1593 | |
| 1594 | sscanf(buf, "%x", ®); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1595 | ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1596 | return strnlen(buf, count); |
| 1597 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1598 | |
| 1599 | static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO, |
| 1600 | show_command_event_reg, store_command_event_reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1601 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1602 | static ssize_t show_mem_gpio_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1603 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1604 | { |
| 1605 | u32 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1606 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1607 | |
| 1608 | reg = ipw_read_reg32(p, 0x301100); |
| 1609 | return sprintf(buf, "0x%08x\n", reg); |
| 1610 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1611 | static ssize_t store_mem_gpio_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1612 | struct device_attribute *attr, |
| 1613 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1614 | { |
| 1615 | u32 reg; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1616 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1617 | |
| 1618 | sscanf(buf, "%x", ®); |
| 1619 | ipw_write_reg32(p, 0x301100, reg); |
| 1620 | return strnlen(buf, count); |
| 1621 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1622 | |
| 1623 | static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO, |
| 1624 | show_mem_gpio_reg, store_mem_gpio_reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1625 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1626 | static ssize_t show_indirect_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1627 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1628 | { |
| 1629 | u32 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1630 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1631 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1632 | if (priv->status & STATUS_INDIRECT_DWORD) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1633 | reg = ipw_read_reg32(priv, priv->indirect_dword); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1634 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1635 | reg = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1636 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1637 | return sprintf(buf, "0x%08x\n", reg); |
| 1638 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1639 | static ssize_t store_indirect_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1640 | struct device_attribute *attr, |
| 1641 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1642 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1643 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1644 | |
| 1645 | sscanf(buf, "%x", &priv->indirect_dword); |
| 1646 | priv->status |= STATUS_INDIRECT_DWORD; |
| 1647 | return strnlen(buf, count); |
| 1648 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1649 | |
| 1650 | static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO, |
| 1651 | show_indirect_dword, store_indirect_dword); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1652 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1653 | static ssize_t show_indirect_byte(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1654 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1655 | { |
| 1656 | u8 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1657 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1658 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1659 | if (priv->status & STATUS_INDIRECT_BYTE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1660 | reg = ipw_read_reg8(priv, priv->indirect_byte); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1661 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1662 | reg = 0; |
| 1663 | |
| 1664 | return sprintf(buf, "0x%02x\n", reg); |
| 1665 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1666 | static ssize_t store_indirect_byte(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1667 | struct device_attribute *attr, |
| 1668 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1669 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1670 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1671 | |
| 1672 | sscanf(buf, "%x", &priv->indirect_byte); |
| 1673 | priv->status |= STATUS_INDIRECT_BYTE; |
| 1674 | return strnlen(buf, count); |
| 1675 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1676 | |
| 1677 | static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1678 | show_indirect_byte, store_indirect_byte); |
| 1679 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1680 | static ssize_t show_direct_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1681 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1682 | { |
| 1683 | u32 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1684 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1685 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1686 | if (priv->status & STATUS_DIRECT_DWORD) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1687 | reg = ipw_read32(priv, priv->direct_dword); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1688 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1689 | reg = 0; |
| 1690 | |
| 1691 | return sprintf(buf, "0x%08x\n", reg); |
| 1692 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1693 | static ssize_t store_direct_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1694 | struct device_attribute *attr, |
| 1695 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1696 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1697 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1698 | |
| 1699 | sscanf(buf, "%x", &priv->direct_dword); |
| 1700 | priv->status |= STATUS_DIRECT_DWORD; |
| 1701 | return strnlen(buf, count); |
| 1702 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1703 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1704 | static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO, |
| 1705 | show_direct_dword, store_direct_dword); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1706 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1707 | static int rf_kill_active(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1708 | { |
| 1709 | if (0 == (ipw_read32(priv, 0x30) & 0x10000)) |
| 1710 | priv->status |= STATUS_RF_KILL_HW; |
| 1711 | else |
| 1712 | priv->status &= ~STATUS_RF_KILL_HW; |
| 1713 | |
| 1714 | return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0; |
| 1715 | } |
| 1716 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1717 | static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1718 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1719 | { |
| 1720 | /* 0 - RF kill not enabled |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1721 | 1 - SW based RF kill active (sysfs) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1722 | 2 - HW based RF kill active |
| 1723 | 3 - Both HW and SW baed RF kill active */ |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1724 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1725 | int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1726 | (rf_kill_active(priv) ? 0x2 : 0x0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1727 | return sprintf(buf, "%i\n", val); |
| 1728 | } |
| 1729 | |
| 1730 | static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio) |
| 1731 | { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1732 | if ((disable_radio ? 1 : 0) == |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 1733 | ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0)) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1734 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1735 | |
| 1736 | IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n", |
| 1737 | disable_radio ? "OFF" : "ON"); |
| 1738 | |
| 1739 | if (disable_radio) { |
| 1740 | priv->status |= STATUS_RF_KILL_SW; |
| 1741 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1742 | if (priv->workqueue) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1743 | cancel_delayed_work(&priv->request_scan); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1744 | queue_work(priv->workqueue, &priv->down); |
| 1745 | } else { |
| 1746 | priv->status &= ~STATUS_RF_KILL_SW; |
| 1747 | if (rf_kill_active(priv)) { |
| 1748 | IPW_DEBUG_RF_KILL("Can not turn radio back on - " |
| 1749 | "disabled by HW switch\n"); |
| 1750 | /* Make sure the RF_KILL check timer is running */ |
| 1751 | cancel_delayed_work(&priv->rf_kill); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1752 | queue_delayed_work(priv->workqueue, &priv->rf_kill, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1753 | 2 * HZ); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1754 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1755 | queue_work(priv->workqueue, &priv->up); |
| 1756 | } |
| 1757 | |
| 1758 | return 1; |
| 1759 | } |
| 1760 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1761 | static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr, |
| 1762 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1763 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1764 | struct ipw_priv *priv = d->driver_data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1765 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1766 | ipw_radio_kill_sw(priv, buf[0] == '1'); |
| 1767 | |
| 1768 | return count; |
| 1769 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1770 | |
| 1771 | static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1772 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1773 | static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr, |
| 1774 | char *buf) |
| 1775 | { |
| 1776 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; |
| 1777 | int pos = 0, len = 0; |
| 1778 | if (priv->config & CFG_SPEED_SCAN) { |
| 1779 | while (priv->speed_scan[pos] != 0) |
| 1780 | len += sprintf(&buf[len], "%d ", |
| 1781 | priv->speed_scan[pos++]); |
| 1782 | return len + sprintf(&buf[len], "\n"); |
| 1783 | } |
| 1784 | |
| 1785 | return sprintf(buf, "0\n"); |
| 1786 | } |
| 1787 | |
| 1788 | static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr, |
| 1789 | const char *buf, size_t count) |
| 1790 | { |
| 1791 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; |
| 1792 | int channel, pos = 0; |
| 1793 | const char *p = buf; |
| 1794 | |
| 1795 | /* list of space separated channels to scan, optionally ending with 0 */ |
| 1796 | while ((channel = simple_strtol(p, NULL, 0))) { |
| 1797 | if (pos == MAX_SPEED_SCAN - 1) { |
| 1798 | priv->speed_scan[pos] = 0; |
| 1799 | break; |
| 1800 | } |
| 1801 | |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 1802 | if (ieee80211_is_valid_channel(priv->ieee, channel)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1803 | priv->speed_scan[pos++] = channel; |
| 1804 | else |
| 1805 | IPW_WARNING("Skipping invalid channel request: %d\n", |
| 1806 | channel); |
| 1807 | p = strchr(p, ' '); |
| 1808 | if (!p) |
| 1809 | break; |
| 1810 | while (*p == ' ' || *p == '\t') |
| 1811 | p++; |
| 1812 | } |
| 1813 | |
| 1814 | if (pos == 0) |
| 1815 | priv->config &= ~CFG_SPEED_SCAN; |
| 1816 | else { |
| 1817 | priv->speed_scan_pos = 0; |
| 1818 | priv->config |= CFG_SPEED_SCAN; |
| 1819 | } |
| 1820 | |
| 1821 | return count; |
| 1822 | } |
| 1823 | |
| 1824 | static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan, |
| 1825 | store_speed_scan); |
| 1826 | |
| 1827 | static ssize_t show_net_stats(struct device *d, struct device_attribute *attr, |
| 1828 | char *buf) |
| 1829 | { |
| 1830 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; |
| 1831 | return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0'); |
| 1832 | } |
| 1833 | |
| 1834 | static ssize_t store_net_stats(struct device *d, struct device_attribute *attr, |
| 1835 | const char *buf, size_t count) |
| 1836 | { |
| 1837 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; |
| 1838 | if (buf[0] == '1') |
| 1839 | priv->config |= CFG_NET_STATS; |
| 1840 | else |
| 1841 | priv->config &= ~CFG_NET_STATS; |
| 1842 | |
| 1843 | return count; |
| 1844 | } |
| 1845 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1846 | static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO, |
| 1847 | show_net_stats, store_net_stats); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1848 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 1849 | static void notify_wx_assoc_event(struct ipw_priv *priv) |
| 1850 | { |
| 1851 | union iwreq_data wrqu; |
| 1852 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 1853 | if (priv->status & STATUS_ASSOCIATED) |
| 1854 | memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN); |
| 1855 | else |
| 1856 | memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); |
| 1857 | wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL); |
| 1858 | } |
| 1859 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1860 | static void ipw_irq_tasklet(struct ipw_priv *priv) |
| 1861 | { |
| 1862 | u32 inta, inta_mask, handled = 0; |
| 1863 | unsigned long flags; |
| 1864 | int rc = 0; |
| 1865 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 1866 | spin_lock_irqsave(&priv->irq_lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1867 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1868 | inta = ipw_read32(priv, IPW_INTA_RW); |
| 1869 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); |
| 1870 | inta &= (IPW_INTA_MASK_ALL & inta_mask); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1871 | |
| 1872 | /* Add any cached INTA values that need to be handled */ |
| 1873 | inta |= priv->isr_inta; |
| 1874 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 1875 | spin_unlock_irqrestore(&priv->irq_lock, flags); |
| 1876 | |
| 1877 | spin_lock_irqsave(&priv->lock, flags); |
| 1878 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1879 | /* handle all the justifications for the interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1880 | if (inta & IPW_INTA_BIT_RX_TRANSFER) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1881 | ipw_rx(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1882 | handled |= IPW_INTA_BIT_RX_TRANSFER; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1883 | } |
| 1884 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1885 | if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1886 | IPW_DEBUG_HC("Command completed.\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1887 | rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1888 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 1889 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1890 | handled |= IPW_INTA_BIT_TX_CMD_QUEUE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1891 | } |
| 1892 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1893 | if (inta & IPW_INTA_BIT_TX_QUEUE_1) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1894 | IPW_DEBUG_TX("TX_QUEUE_1\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1895 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1896 | handled |= IPW_INTA_BIT_TX_QUEUE_1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1897 | } |
| 1898 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1899 | if (inta & IPW_INTA_BIT_TX_QUEUE_2) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1900 | IPW_DEBUG_TX("TX_QUEUE_2\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1901 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1902 | handled |= IPW_INTA_BIT_TX_QUEUE_2; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1903 | } |
| 1904 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1905 | if (inta & IPW_INTA_BIT_TX_QUEUE_3) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1906 | IPW_DEBUG_TX("TX_QUEUE_3\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1907 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1908 | handled |= IPW_INTA_BIT_TX_QUEUE_3; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1909 | } |
| 1910 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1911 | if (inta & IPW_INTA_BIT_TX_QUEUE_4) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1912 | IPW_DEBUG_TX("TX_QUEUE_4\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1913 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1914 | handled |= IPW_INTA_BIT_TX_QUEUE_4; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1915 | } |
| 1916 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1917 | if (inta & IPW_INTA_BIT_STATUS_CHANGE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1918 | IPW_WARNING("STATUS_CHANGE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1919 | handled |= IPW_INTA_BIT_STATUS_CHANGE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1920 | } |
| 1921 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1922 | if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1923 | IPW_WARNING("TX_PERIOD_EXPIRED\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1924 | handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1925 | } |
| 1926 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1927 | if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1928 | IPW_WARNING("HOST_CMD_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1929 | handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1930 | } |
| 1931 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1932 | if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1933 | IPW_WARNING("FW_INITIALIZATION_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1934 | handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1935 | } |
| 1936 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1937 | if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1938 | IPW_WARNING("PHY_OFF_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1939 | handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1940 | } |
| 1941 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1942 | if (inta & IPW_INTA_BIT_RF_KILL_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1943 | IPW_DEBUG_RF_KILL("RF_KILL_DONE\n"); |
| 1944 | priv->status |= STATUS_RF_KILL_HW; |
| 1945 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 1946 | priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1947 | cancel_delayed_work(&priv->request_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1948 | schedule_work(&priv->link_down); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1949 | queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1950 | handled |= IPW_INTA_BIT_RF_KILL_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1951 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1952 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1953 | if (inta & IPW_INTA_BIT_FATAL_ERROR) { |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 1954 | IPW_WARNING("Firmware error detected. Restarting.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1955 | if (priv->error) { |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 1956 | IPW_DEBUG_FW("Sysfs 'error' log already exists.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1957 | if (ipw_debug_level & IPW_DL_FW_ERRORS) { |
| 1958 | struct ipw_fw_error *error = |
| 1959 | ipw_alloc_error_log(priv); |
| 1960 | ipw_dump_error_log(priv, error); |
Jesper Juhl | 8f76078 | 2006-06-27 02:55:06 -0700 | [diff] [blame] | 1961 | kfree(error); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1962 | } |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1963 | } else { |
| 1964 | priv->error = ipw_alloc_error_log(priv); |
| 1965 | if (priv->error) |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 1966 | IPW_DEBUG_FW("Sysfs 'error' log captured.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1967 | else |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 1968 | IPW_DEBUG_FW("Error allocating sysfs 'error' " |
| 1969 | "log.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1970 | if (ipw_debug_level & IPW_DL_FW_ERRORS) |
| 1971 | ipw_dump_error_log(priv, priv->error); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1972 | } |
| 1973 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1974 | /* XXX: If hardware encryption is for WPA/WPA2, |
| 1975 | * we have to notify the supplicant. */ |
| 1976 | if (priv->ieee->sec.encrypt) { |
| 1977 | priv->status &= ~STATUS_ASSOCIATED; |
| 1978 | notify_wx_assoc_event(priv); |
| 1979 | } |
| 1980 | |
| 1981 | /* Keep the restart process from trying to send host |
| 1982 | * commands by clearing the INIT status bit */ |
| 1983 | priv->status &= ~STATUS_INIT; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1984 | |
| 1985 | /* Cancel currently queued command. */ |
| 1986 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 1987 | wake_up_interruptible(&priv->wait_command_queue); |
| 1988 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1989 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1990 | handled |= IPW_INTA_BIT_FATAL_ERROR; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1991 | } |
| 1992 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1993 | if (inta & IPW_INTA_BIT_PARITY_ERROR) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1994 | IPW_ERROR("Parity error\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1995 | handled |= IPW_INTA_BIT_PARITY_ERROR; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | if (handled != inta) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1999 | IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2000 | } |
| 2001 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 2002 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2003 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2004 | /* enable all interrupts */ |
| 2005 | ipw_enable_interrupts(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2006 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2007 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2008 | #define IPW_CMD(x) case IPW_CMD_ ## x : return #x |
| 2009 | static char *get_cmd_string(u8 cmd) |
| 2010 | { |
| 2011 | switch (cmd) { |
| 2012 | IPW_CMD(HOST_COMPLETE); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2013 | IPW_CMD(POWER_DOWN); |
| 2014 | IPW_CMD(SYSTEM_CONFIG); |
| 2015 | IPW_CMD(MULTICAST_ADDRESS); |
| 2016 | IPW_CMD(SSID); |
| 2017 | IPW_CMD(ADAPTER_ADDRESS); |
| 2018 | IPW_CMD(PORT_TYPE); |
| 2019 | IPW_CMD(RTS_THRESHOLD); |
| 2020 | IPW_CMD(FRAG_THRESHOLD); |
| 2021 | IPW_CMD(POWER_MODE); |
| 2022 | IPW_CMD(WEP_KEY); |
| 2023 | IPW_CMD(TGI_TX_KEY); |
| 2024 | IPW_CMD(SCAN_REQUEST); |
| 2025 | IPW_CMD(SCAN_REQUEST_EXT); |
| 2026 | IPW_CMD(ASSOCIATE); |
| 2027 | IPW_CMD(SUPPORTED_RATES); |
| 2028 | IPW_CMD(SCAN_ABORT); |
| 2029 | IPW_CMD(TX_FLUSH); |
| 2030 | IPW_CMD(QOS_PARAMETERS); |
| 2031 | IPW_CMD(DINO_CONFIG); |
| 2032 | IPW_CMD(RSN_CAPABILITIES); |
| 2033 | IPW_CMD(RX_KEY); |
| 2034 | IPW_CMD(CARD_DISABLE); |
| 2035 | IPW_CMD(SEED_NUMBER); |
| 2036 | IPW_CMD(TX_POWER); |
| 2037 | IPW_CMD(COUNTRY_INFO); |
| 2038 | IPW_CMD(AIRONET_INFO); |
| 2039 | IPW_CMD(AP_TX_POWER); |
| 2040 | IPW_CMD(CCKM_INFO); |
| 2041 | IPW_CMD(CCX_VER_INFO); |
| 2042 | IPW_CMD(SET_CALIBRATION); |
| 2043 | IPW_CMD(SENSITIVITY_CALIB); |
| 2044 | IPW_CMD(RETRY_LIMIT); |
| 2045 | IPW_CMD(IPW_PRE_POWER_DOWN); |
| 2046 | IPW_CMD(VAP_BEACON_TEMPLATE); |
| 2047 | IPW_CMD(VAP_DTIM_PERIOD); |
| 2048 | IPW_CMD(EXT_SUPPORTED_RATES); |
| 2049 | IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT); |
| 2050 | IPW_CMD(VAP_QUIET_INTERVALS); |
| 2051 | IPW_CMD(VAP_CHANNEL_SWITCH); |
| 2052 | IPW_CMD(VAP_MANDATORY_CHANNELS); |
| 2053 | IPW_CMD(VAP_CELL_PWR_LIMIT); |
| 2054 | IPW_CMD(VAP_CF_PARAM_SET); |
| 2055 | IPW_CMD(VAP_SET_BEACONING_STATE); |
| 2056 | IPW_CMD(MEASUREMENT); |
| 2057 | IPW_CMD(POWER_CAPABILITY); |
| 2058 | IPW_CMD(SUPPORTED_CHANNELS); |
| 2059 | IPW_CMD(TPC_REPORT); |
| 2060 | IPW_CMD(WME_INFO); |
| 2061 | IPW_CMD(PRODUCTION_COMMAND); |
| 2062 | default: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2063 | return "UNKNOWN"; |
| 2064 | } |
| 2065 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2066 | |
| 2067 | #define HOST_COMPLETE_TIMEOUT HZ |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2068 | |
| 2069 | static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2070 | { |
| 2071 | int rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2072 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2073 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2074 | spin_lock_irqsave(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2075 | if (priv->status & STATUS_HCMD_ACTIVE) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2076 | IPW_ERROR("Failed to send %s: Already sending a command.\n", |
| 2077 | get_cmd_string(cmd->cmd)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2078 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2079 | return -EAGAIN; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | priv->status |= STATUS_HCMD_ACTIVE; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2083 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2084 | if (priv->cmdlog) { |
| 2085 | priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies; |
| 2086 | priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd; |
| 2087 | priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len; |
| 2088 | memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param, |
| 2089 | cmd->len); |
| 2090 | priv->cmdlog[priv->cmdlog_pos].retcode = -1; |
| 2091 | } |
| 2092 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2093 | IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n", |
| 2094 | get_cmd_string(cmd->cmd), cmd->cmd, cmd->len, |
| 2095 | priv->status); |
Zhu Yi | f516dbc | 2006-01-24 16:36:44 +0800 | [diff] [blame] | 2096 | |
| 2097 | #ifndef DEBUG_CMD_WEP_KEY |
| 2098 | if (cmd->cmd == IPW_CMD_WEP_KEY) |
| 2099 | IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n"); |
| 2100 | else |
| 2101 | #endif |
| 2102 | printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len); |
| 2103 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2104 | rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2105 | if (rc) { |
| 2106 | priv->status &= ~STATUS_HCMD_ACTIVE; |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2107 | IPW_ERROR("Failed to send %s: Reason %d\n", |
| 2108 | get_cmd_string(cmd->cmd), rc); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2109 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2110 | goto exit; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2111 | } |
| 2112 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2113 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2114 | rc = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 2115 | !(priv-> |
| 2116 | status & STATUS_HCMD_ACTIVE), |
| 2117 | HOST_COMPLETE_TIMEOUT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2118 | if (rc == 0) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2119 | spin_lock_irqsave(&priv->lock, flags); |
| 2120 | if (priv->status & STATUS_HCMD_ACTIVE) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2121 | IPW_ERROR("Failed to send %s: Command timed out.\n", |
| 2122 | get_cmd_string(cmd->cmd)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2123 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 2124 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2125 | rc = -EIO; |
| 2126 | goto exit; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2127 | } |
| 2128 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 2129 | } else |
| 2130 | rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2131 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2132 | if (priv->status & STATUS_RF_KILL_HW) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2133 | IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n", |
| 2134 | get_cmd_string(cmd->cmd)); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2135 | rc = -EIO; |
| 2136 | goto exit; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2137 | } |
| 2138 | |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2139 | exit: |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2140 | if (priv->cmdlog) { |
| 2141 | priv->cmdlog[priv->cmdlog_pos++].retcode = rc; |
| 2142 | priv->cmdlog_pos %= priv->cmdlog_len; |
| 2143 | } |
| 2144 | return rc; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2145 | } |
| 2146 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2147 | static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2148 | { |
| 2149 | struct host_cmd cmd = { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2150 | .cmd = command, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2151 | }; |
| 2152 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2153 | return __ipw_send_cmd(priv, &cmd); |
| 2154 | } |
| 2155 | |
| 2156 | static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len, |
| 2157 | void *data) |
| 2158 | { |
| 2159 | struct host_cmd cmd = { |
| 2160 | .cmd = command, |
| 2161 | .len = len, |
| 2162 | .param = data, |
| 2163 | }; |
| 2164 | |
| 2165 | return __ipw_send_cmd(priv, &cmd); |
| 2166 | } |
| 2167 | |
| 2168 | static int ipw_send_host_complete(struct ipw_priv *priv) |
| 2169 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2170 | if (!priv) { |
| 2171 | IPW_ERROR("Invalid args\n"); |
| 2172 | return -1; |
| 2173 | } |
| 2174 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2175 | return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2176 | } |
| 2177 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 2178 | static int ipw_send_system_config(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2179 | { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 2180 | return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG, |
| 2181 | sizeof(priv->sys_config), |
| 2182 | &priv->sys_config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2183 | } |
| 2184 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2185 | static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2186 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2187 | if (!priv || !ssid) { |
| 2188 | IPW_ERROR("Invalid args\n"); |
| 2189 | return -1; |
| 2190 | } |
| 2191 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2192 | return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2193 | ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2194 | } |
| 2195 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2196 | static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2197 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2198 | if (!priv || !mac) { |
| 2199 | IPW_ERROR("Invalid args\n"); |
| 2200 | return -1; |
| 2201 | } |
| 2202 | |
| 2203 | IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n", |
| 2204 | priv->net_dev->name, MAC_ARG(mac)); |
| 2205 | |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2206 | return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2207 | } |
| 2208 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2209 | /* |
| 2210 | * NOTE: This must be executed from our workqueue as it results in udelay |
| 2211 | * being called which may corrupt the keyboard if executed on default |
| 2212 | * workqueue |
| 2213 | */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2214 | static void ipw_adapter_restart(void *adapter) |
| 2215 | { |
| 2216 | struct ipw_priv *priv = adapter; |
| 2217 | |
| 2218 | if (priv->status & STATUS_RF_KILL_MASK) |
| 2219 | return; |
| 2220 | |
| 2221 | ipw_down(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2222 | |
| 2223 | if (priv->assoc_network && |
| 2224 | (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS)) |
| 2225 | ipw_remove_current_network(priv); |
| 2226 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2227 | if (ipw_up(priv)) { |
| 2228 | IPW_ERROR("Failed to up device\n"); |
| 2229 | return; |
| 2230 | } |
| 2231 | } |
| 2232 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2233 | static void ipw_bg_adapter_restart(void *data) |
| 2234 | { |
| 2235 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2236 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2237 | ipw_adapter_restart(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2238 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2239 | } |
| 2240 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2241 | #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ) |
| 2242 | |
| 2243 | static void ipw_scan_check(void *data) |
| 2244 | { |
| 2245 | struct ipw_priv *priv = data; |
| 2246 | if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) { |
| 2247 | IPW_DEBUG_SCAN("Scan completion watchdog resetting " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2248 | "adapter after (%dms).\n", |
| 2249 | jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2250 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2251 | } |
| 2252 | } |
| 2253 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2254 | static void ipw_bg_scan_check(void *data) |
| 2255 | { |
| 2256 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2257 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2258 | ipw_scan_check(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2259 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2260 | } |
| 2261 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2262 | static int ipw_send_scan_request_ext(struct ipw_priv *priv, |
| 2263 | struct ipw_scan_request_ext *request) |
| 2264 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2265 | return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2266 | sizeof(*request), request); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2267 | } |
| 2268 | |
| 2269 | static int ipw_send_scan_abort(struct ipw_priv *priv) |
| 2270 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2271 | if (!priv) { |
| 2272 | IPW_ERROR("Invalid args\n"); |
| 2273 | return -1; |
| 2274 | } |
| 2275 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2276 | return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2277 | } |
| 2278 | |
| 2279 | static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens) |
| 2280 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2281 | struct ipw_sensitivity_calib calib = { |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 2282 | .beacon_rssi_raw = cpu_to_le16(sens), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2283 | }; |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2284 | |
| 2285 | return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2286 | &calib); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2287 | } |
| 2288 | |
| 2289 | static int ipw_send_associate(struct ipw_priv *priv, |
| 2290 | struct ipw_associate *associate) |
| 2291 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2292 | struct ipw_associate tmp_associate; |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2293 | |
| 2294 | if (!priv || !associate) { |
| 2295 | IPW_ERROR("Invalid args\n"); |
| 2296 | return -1; |
| 2297 | } |
| 2298 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2299 | memcpy(&tmp_associate, associate, sizeof(*associate)); |
| 2300 | tmp_associate.policy_support = |
| 2301 | cpu_to_le16(tmp_associate.policy_support); |
| 2302 | tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw); |
| 2303 | tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw); |
| 2304 | tmp_associate.capability = cpu_to_le16(tmp_associate.capability); |
| 2305 | tmp_associate.listen_interval = |
| 2306 | cpu_to_le16(tmp_associate.listen_interval); |
| 2307 | tmp_associate.beacon_interval = |
| 2308 | cpu_to_le16(tmp_associate.beacon_interval); |
| 2309 | tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window); |
| 2310 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2311 | return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(tmp_associate), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2312 | &tmp_associate); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2313 | } |
| 2314 | |
| 2315 | static int ipw_send_supported_rates(struct ipw_priv *priv, |
| 2316 | struct ipw_supported_rates *rates) |
| 2317 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2318 | if (!priv || !rates) { |
| 2319 | IPW_ERROR("Invalid args\n"); |
| 2320 | return -1; |
| 2321 | } |
| 2322 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2323 | return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2324 | rates); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2325 | } |
| 2326 | |
| 2327 | static int ipw_set_random_seed(struct ipw_priv *priv) |
| 2328 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2329 | u32 val; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2330 | |
| 2331 | if (!priv) { |
| 2332 | IPW_ERROR("Invalid args\n"); |
| 2333 | return -1; |
| 2334 | } |
| 2335 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2336 | get_random_bytes(&val, sizeof(val)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2337 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2338 | return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2339 | } |
| 2340 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2341 | static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off) |
| 2342 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2343 | if (!priv) { |
| 2344 | IPW_ERROR("Invalid args\n"); |
| 2345 | return -1; |
| 2346 | } |
| 2347 | |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 2348 | phy_off = cpu_to_le32(phy_off); |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2349 | return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(phy_off), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2350 | &phy_off); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2351 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2352 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2353 | static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2354 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2355 | if (!priv || !power) { |
| 2356 | IPW_ERROR("Invalid args\n"); |
| 2357 | return -1; |
| 2358 | } |
| 2359 | |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2360 | return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2361 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2362 | |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 2363 | static int ipw_set_tx_power(struct ipw_priv *priv) |
| 2364 | { |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 2365 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 2366 | struct ipw_tx_power tx_power; |
| 2367 | s8 max_power; |
| 2368 | int i; |
| 2369 | |
| 2370 | memset(&tx_power, 0, sizeof(tx_power)); |
| 2371 | |
| 2372 | /* configure device for 'G' band */ |
| 2373 | tx_power.ieee_mode = IPW_G_MODE; |
| 2374 | tx_power.num_channels = geo->bg_channels; |
| 2375 | for (i = 0; i < geo->bg_channels; i++) { |
| 2376 | max_power = geo->bg[i].max_power; |
| 2377 | tx_power.channels_tx_power[i].channel_number = |
| 2378 | geo->bg[i].channel; |
| 2379 | tx_power.channels_tx_power[i].tx_power = max_power ? |
| 2380 | min(max_power, priv->tx_power) : priv->tx_power; |
| 2381 | } |
| 2382 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2383 | return -EIO; |
| 2384 | |
| 2385 | /* configure device to also handle 'B' band */ |
| 2386 | tx_power.ieee_mode = IPW_B_MODE; |
| 2387 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2388 | return -EIO; |
| 2389 | |
| 2390 | /* configure device to also handle 'A' band */ |
| 2391 | if (priv->ieee->abg_true) { |
| 2392 | tx_power.ieee_mode = IPW_A_MODE; |
| 2393 | tx_power.num_channels = geo->a_channels; |
| 2394 | for (i = 0; i < tx_power.num_channels; i++) { |
| 2395 | max_power = geo->a[i].max_power; |
| 2396 | tx_power.channels_tx_power[i].channel_number = |
| 2397 | geo->a[i].channel; |
| 2398 | tx_power.channels_tx_power[i].tx_power = max_power ? |
| 2399 | min(max_power, priv->tx_power) : priv->tx_power; |
| 2400 | } |
| 2401 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2402 | return -EIO; |
| 2403 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2404 | return 0; |
| 2405 | } |
| 2406 | |
| 2407 | static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts) |
| 2408 | { |
| 2409 | struct ipw_rts_threshold rts_threshold = { |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 2410 | .rts_threshold = cpu_to_le16(rts), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2411 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2412 | |
| 2413 | if (!priv) { |
| 2414 | IPW_ERROR("Invalid args\n"); |
| 2415 | return -1; |
| 2416 | } |
| 2417 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2418 | return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD, |
| 2419 | sizeof(rts_threshold), &rts_threshold); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2420 | } |
| 2421 | |
| 2422 | static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag) |
| 2423 | { |
| 2424 | struct ipw_frag_threshold frag_threshold = { |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 2425 | .frag_threshold = cpu_to_le16(frag), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2426 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2427 | |
| 2428 | if (!priv) { |
| 2429 | IPW_ERROR("Invalid args\n"); |
| 2430 | return -1; |
| 2431 | } |
| 2432 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2433 | return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD, |
| 2434 | sizeof(frag_threshold), &frag_threshold); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2435 | } |
| 2436 | |
| 2437 | static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode) |
| 2438 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2439 | u32 param; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2440 | |
| 2441 | if (!priv) { |
| 2442 | IPW_ERROR("Invalid args\n"); |
| 2443 | return -1; |
| 2444 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2445 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2446 | /* If on battery, set to 3, if AC set to CAM, else user |
| 2447 | * level */ |
| 2448 | switch (mode) { |
| 2449 | case IPW_POWER_BATTERY: |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2450 | param = IPW_POWER_INDEX_3; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2451 | break; |
| 2452 | case IPW_POWER_AC: |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2453 | param = IPW_POWER_MODE_CAM; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2454 | break; |
| 2455 | default: |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2456 | param = mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2457 | break; |
| 2458 | } |
| 2459 | |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 2460 | param = cpu_to_le32(mode); |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2461 | return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2462 | ¶m); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2463 | } |
| 2464 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2465 | static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit) |
| 2466 | { |
| 2467 | struct ipw_retry_limit retry_limit = { |
| 2468 | .short_retry_limit = slimit, |
| 2469 | .long_retry_limit = llimit |
| 2470 | }; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2471 | |
| 2472 | if (!priv) { |
| 2473 | IPW_ERROR("Invalid args\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2474 | return -1; |
| 2475 | } |
| 2476 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2477 | return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2478 | &retry_limit); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2479 | } |
| 2480 | |
| 2481 | /* |
| 2482 | * The IPW device contains a Microwire compatible EEPROM that stores |
| 2483 | * various data like the MAC address. Usually the firmware has exclusive |
| 2484 | * access to the eeprom, but during device initialization (before the |
| 2485 | * device driver has sent the HostComplete command to the firmware) the |
| 2486 | * device driver has read access to the EEPROM by way of indirect addressing |
| 2487 | * through a couple of memory mapped registers. |
| 2488 | * |
| 2489 | * The following is a simplified implementation for pulling data out of the |
| 2490 | * the eeprom, along with some helper functions to find information in |
| 2491 | * the per device private data's copy of the eeprom. |
| 2492 | * |
| 2493 | * NOTE: To better understand how these functions work (i.e what is a chip |
| 2494 | * select and why do have to keep driving the eeprom clock?), read |
| 2495 | * just about any data sheet for a Microwire compatible EEPROM. |
| 2496 | */ |
| 2497 | |
| 2498 | /* write a 32 bit value into the indirect accessor register */ |
| 2499 | static inline void eeprom_write_reg(struct ipw_priv *p, u32 data) |
| 2500 | { |
| 2501 | ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2502 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2503 | /* the eeprom requires some time to complete the operation */ |
| 2504 | udelay(p->eeprom_delay); |
| 2505 | |
| 2506 | return; |
| 2507 | } |
| 2508 | |
| 2509 | /* perform a chip select operation */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2510 | static void eeprom_cs(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2511 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2512 | eeprom_write_reg(priv, 0); |
| 2513 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2514 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); |
| 2515 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | /* perform a chip select operation */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2519 | static void eeprom_disable_cs(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2520 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2521 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2522 | eeprom_write_reg(priv, 0); |
| 2523 | eeprom_write_reg(priv, EEPROM_BIT_SK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2524 | } |
| 2525 | |
| 2526 | /* push a single bit down to the eeprom */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2527 | static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2528 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2529 | int d = (bit ? EEPROM_BIT_DI : 0); |
| 2530 | eeprom_write_reg(p, EEPROM_BIT_CS | d); |
| 2531 | eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2532 | } |
| 2533 | |
| 2534 | /* push an opcode followed by an address down to the eeprom */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2535 | static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2536 | { |
| 2537 | int i; |
| 2538 | |
| 2539 | eeprom_cs(priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2540 | eeprom_write_bit(priv, 1); |
| 2541 | eeprom_write_bit(priv, op & 2); |
| 2542 | eeprom_write_bit(priv, op & 1); |
| 2543 | for (i = 7; i >= 0; i--) { |
| 2544 | eeprom_write_bit(priv, addr & (1 << i)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2545 | } |
| 2546 | } |
| 2547 | |
| 2548 | /* pull 16 bits off the eeprom, one bit at a time */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2549 | static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2550 | { |
| 2551 | int i; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2552 | u16 r = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2553 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2554 | /* Send READ Opcode */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2555 | eeprom_op(priv, EEPROM_CMD_READ, addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2556 | |
| 2557 | /* Send dummy bit */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2558 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2559 | |
| 2560 | /* Read the byte off the eeprom one bit at a time */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2561 | for (i = 0; i < 16; i++) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2562 | u32 data = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2563 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); |
| 2564 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2565 | data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS); |
| 2566 | r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2567 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2568 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2569 | /* Send another dummy bit */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2570 | eeprom_write_reg(priv, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2571 | eeprom_disable_cs(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2572 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2573 | return r; |
| 2574 | } |
| 2575 | |
| 2576 | /* helper function for pulling the mac address out of the private */ |
| 2577 | /* data's copy of the eeprom data */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2578 | static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2579 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2580 | memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2581 | } |
| 2582 | |
| 2583 | /* |
| 2584 | * Either the device driver (i.e. the host) or the firmware can |
| 2585 | * load eeprom data into the designated region in SRAM. If neither |
| 2586 | * happens then the FW will shutdown with a fatal error. |
| 2587 | * |
| 2588 | * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE |
| 2589 | * bit needs region of shared SRAM needs to be non-zero. |
| 2590 | */ |
| 2591 | static void ipw_eeprom_init_sram(struct ipw_priv *priv) |
| 2592 | { |
| 2593 | int i; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2594 | u16 *eeprom = (u16 *) priv->eeprom; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2595 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2596 | IPW_DEBUG_TRACE(">>\n"); |
| 2597 | |
| 2598 | /* read entire contents of eeprom into private buffer */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2599 | for (i = 0; i < 128; i++) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2600 | eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2601 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2602 | /* |
| 2603 | If the data looks correct, then copy it to our private |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2604 | copy. Otherwise let the firmware know to perform the operation |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2605 | on its own. |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2606 | */ |
Alexey Dobriyan | 386093e | 2006-02-01 03:04:57 -0800 | [diff] [blame] | 2607 | if (priv->eeprom[EEPROM_VERSION] != 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2608 | IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n"); |
| 2609 | |
| 2610 | /* write the eeprom data to sram */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2611 | for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2612 | ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2613 | |
| 2614 | /* Do not load eeprom data on fatal error or suspend */ |
| 2615 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); |
| 2616 | } else { |
| 2617 | IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n"); |
| 2618 | |
| 2619 | /* Load eeprom data on fatal error or suspend */ |
| 2620 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1); |
| 2621 | } |
| 2622 | |
| 2623 | IPW_DEBUG_TRACE("<<\n"); |
| 2624 | } |
| 2625 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2626 | static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2627 | { |
| 2628 | count >>= 2; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2629 | if (!count) |
| 2630 | return; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2631 | _ipw_write32(priv, IPW_AUTOINC_ADDR, start); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2632 | while (count--) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2633 | _ipw_write32(priv, IPW_AUTOINC_DATA, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2634 | } |
| 2635 | |
| 2636 | static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv) |
| 2637 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2638 | ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2639 | CB_NUMBER_OF_ELEMENTS_SMALL * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2640 | sizeof(struct command_block)); |
| 2641 | } |
| 2642 | |
| 2643 | static int ipw_fw_dma_enable(struct ipw_priv *priv) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2644 | { /* start dma engine but no transfers yet */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2645 | |
| 2646 | IPW_DEBUG_FW(">> : \n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2647 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2648 | /* Start the dma */ |
| 2649 | ipw_fw_dma_reset_command_blocks(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2650 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2651 | /* Write CB base address */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2652 | ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2653 | |
| 2654 | IPW_DEBUG_FW("<< : \n"); |
| 2655 | return 0; |
| 2656 | } |
| 2657 | |
| 2658 | static void ipw_fw_dma_abort(struct ipw_priv *priv) |
| 2659 | { |
| 2660 | u32 control = 0; |
| 2661 | |
| 2662 | IPW_DEBUG_FW(">> :\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2663 | |
Pavel Machek | 67fd6b4 | 2006-07-11 15:34:05 +0200 | [diff] [blame] | 2664 | /* set the Stop and Abort bit */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2665 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2666 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2667 | priv->sram_desc.last_cb_index = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2668 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2669 | IPW_DEBUG_FW("<< \n"); |
| 2670 | } |
| 2671 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2672 | static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index, |
| 2673 | struct command_block *cb) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2674 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2675 | u32 address = |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2676 | IPW_SHARED_SRAM_DMA_CONTROL + |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2677 | (sizeof(struct command_block) * index); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2678 | IPW_DEBUG_FW(">> :\n"); |
| 2679 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2680 | ipw_write_indirect(priv, address, (u8 *) cb, |
| 2681 | (int)sizeof(struct command_block)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2682 | |
| 2683 | IPW_DEBUG_FW("<< :\n"); |
| 2684 | return 0; |
| 2685 | |
| 2686 | } |
| 2687 | |
| 2688 | static int ipw_fw_dma_kick(struct ipw_priv *priv) |
| 2689 | { |
| 2690 | u32 control = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2691 | u32 index = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2692 | |
| 2693 | IPW_DEBUG_FW(">> :\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2694 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2695 | for (index = 0; index < priv->sram_desc.last_cb_index; index++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2696 | ipw_fw_dma_write_command_block(priv, index, |
| 2697 | &priv->sram_desc.cb_list[index]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2698 | |
| 2699 | /* Enable the DMA in the CSR register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2700 | ipw_clear_bit(priv, IPW_RESET_REG, |
| 2701 | IPW_RESET_REG_MASTER_DISABLED | |
| 2702 | IPW_RESET_REG_STOP_MASTER); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2703 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2704 | /* Set the Start bit. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2705 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2706 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2707 | |
| 2708 | IPW_DEBUG_FW("<< :\n"); |
| 2709 | return 0; |
| 2710 | } |
| 2711 | |
| 2712 | static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv) |
| 2713 | { |
| 2714 | u32 address; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2715 | u32 register_value = 0; |
| 2716 | u32 cb_fields_address = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2717 | |
| 2718 | IPW_DEBUG_FW(">> :\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2719 | address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2720 | IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2721 | |
| 2722 | /* Read the DMA Controlor register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2723 | register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL); |
| 2724 | IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2725 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2726 | /* Print the CB values */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2727 | cb_fields_address = address; |
| 2728 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2729 | IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2730 | |
| 2731 | cb_fields_address += sizeof(u32); |
| 2732 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2733 | IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2734 | |
| 2735 | cb_fields_address += sizeof(u32); |
| 2736 | register_value = ipw_read_reg32(priv, cb_fields_address); |
| 2737 | IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n", |
| 2738 | register_value); |
| 2739 | |
| 2740 | cb_fields_address += sizeof(u32); |
| 2741 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2742 | IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2743 | |
| 2744 | IPW_DEBUG_FW(">> :\n"); |
| 2745 | } |
| 2746 | |
| 2747 | static int ipw_fw_dma_command_block_index(struct ipw_priv *priv) |
| 2748 | { |
| 2749 | u32 current_cb_address = 0; |
| 2750 | u32 current_cb_index = 0; |
| 2751 | |
| 2752 | IPW_DEBUG_FW("<< :\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2753 | current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2754 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2755 | current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2756 | sizeof(struct command_block); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2757 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2758 | IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2759 | current_cb_index, current_cb_address); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2760 | |
| 2761 | IPW_DEBUG_FW(">> :\n"); |
| 2762 | return current_cb_index; |
| 2763 | |
| 2764 | } |
| 2765 | |
| 2766 | static int ipw_fw_dma_add_command_block(struct ipw_priv *priv, |
| 2767 | u32 src_address, |
| 2768 | u32 dest_address, |
| 2769 | u32 length, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2770 | int interrupt_enabled, int is_last) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2771 | { |
| 2772 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2773 | u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2774 | CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG | |
| 2775 | CB_DEST_SIZE_LONG; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2776 | struct command_block *cb; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2777 | u32 last_cb_element = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2778 | |
| 2779 | IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n", |
| 2780 | src_address, dest_address, length); |
| 2781 | |
| 2782 | if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL) |
| 2783 | return -1; |
| 2784 | |
| 2785 | last_cb_element = priv->sram_desc.last_cb_index; |
| 2786 | cb = &priv->sram_desc.cb_list[last_cb_element]; |
| 2787 | priv->sram_desc.last_cb_index++; |
| 2788 | |
| 2789 | /* Calculate the new CB control word */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2790 | if (interrupt_enabled) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2791 | control |= CB_INT_ENABLED; |
| 2792 | |
| 2793 | if (is_last) |
| 2794 | control |= CB_LAST_VALID; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2795 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2796 | control |= length; |
| 2797 | |
| 2798 | /* Calculate the CB Element's checksum value */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2799 | cb->status = control ^ src_address ^ dest_address; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2800 | |
| 2801 | /* Copy the Source and Destination addresses */ |
| 2802 | cb->dest_addr = dest_address; |
| 2803 | cb->source_addr = src_address; |
| 2804 | |
| 2805 | /* Copy the Control Word last */ |
| 2806 | cb->control = control; |
| 2807 | |
| 2808 | return 0; |
| 2809 | } |
| 2810 | |
| 2811 | static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2812 | u32 src_phys, u32 dest_address, u32 length) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2813 | { |
| 2814 | u32 bytes_left = length; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2815 | u32 src_offset = 0; |
| 2816 | u32 dest_offset = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2817 | int status = 0; |
| 2818 | IPW_DEBUG_FW(">> \n"); |
| 2819 | IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n", |
| 2820 | src_phys, dest_address, length); |
| 2821 | while (bytes_left > CB_MAX_LENGTH) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2822 | status = ipw_fw_dma_add_command_block(priv, |
| 2823 | src_phys + src_offset, |
| 2824 | dest_address + |
| 2825 | dest_offset, |
| 2826 | CB_MAX_LENGTH, 0, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2827 | if (status) { |
| 2828 | IPW_DEBUG_FW_INFO(": Failed\n"); |
| 2829 | return -1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2830 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2831 | IPW_DEBUG_FW_INFO(": Added new cb\n"); |
| 2832 | |
| 2833 | src_offset += CB_MAX_LENGTH; |
| 2834 | dest_offset += CB_MAX_LENGTH; |
| 2835 | bytes_left -= CB_MAX_LENGTH; |
| 2836 | } |
| 2837 | |
| 2838 | /* add the buffer tail */ |
| 2839 | if (bytes_left > 0) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2840 | status = |
| 2841 | ipw_fw_dma_add_command_block(priv, src_phys + src_offset, |
| 2842 | dest_address + dest_offset, |
| 2843 | bytes_left, 0, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2844 | if (status) { |
| 2845 | IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n"); |
| 2846 | return -1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2847 | } else |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2848 | IPW_DEBUG_FW_INFO |
| 2849 | (": Adding new cb - the buffer tail\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2850 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2851 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2852 | IPW_DEBUG_FW("<< \n"); |
| 2853 | return 0; |
| 2854 | } |
| 2855 | |
| 2856 | static int ipw_fw_dma_wait(struct ipw_priv *priv) |
| 2857 | { |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2858 | u32 current_index = 0, previous_index; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2859 | u32 watchdog = 0; |
| 2860 | |
| 2861 | IPW_DEBUG_FW(">> : \n"); |
| 2862 | |
| 2863 | current_index = ipw_fw_dma_command_block_index(priv); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2864 | IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2865 | (int)priv->sram_desc.last_cb_index); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2866 | |
| 2867 | while (current_index < priv->sram_desc.last_cb_index) { |
| 2868 | udelay(50); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2869 | previous_index = current_index; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2870 | current_index = ipw_fw_dma_command_block_index(priv); |
| 2871 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2872 | if (previous_index < current_index) { |
| 2873 | watchdog = 0; |
| 2874 | continue; |
| 2875 | } |
| 2876 | if (++watchdog > 400) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2877 | IPW_DEBUG_FW_INFO("Timeout\n"); |
| 2878 | ipw_fw_dma_dump_command_block(priv); |
| 2879 | ipw_fw_dma_abort(priv); |
| 2880 | return -1; |
| 2881 | } |
| 2882 | } |
| 2883 | |
| 2884 | ipw_fw_dma_abort(priv); |
| 2885 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2886 | /*Disable the DMA in the CSR register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2887 | ipw_set_bit(priv, IPW_RESET_REG, |
| 2888 | IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2889 | |
| 2890 | IPW_DEBUG_FW("<< dmaWaitSync \n"); |
| 2891 | return 0; |
| 2892 | } |
| 2893 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2894 | static void ipw_remove_current_network(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2895 | { |
| 2896 | struct list_head *element, *safe; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2897 | struct ieee80211_network *network = NULL; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2898 | unsigned long flags; |
| 2899 | |
| 2900 | spin_lock_irqsave(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2901 | list_for_each_safe(element, safe, &priv->ieee->network_list) { |
| 2902 | network = list_entry(element, struct ieee80211_network, list); |
| 2903 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
| 2904 | list_del(element); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2905 | list_add_tail(&network->list, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2906 | &priv->ieee->network_free_list); |
| 2907 | } |
| 2908 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2909 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2910 | } |
| 2911 | |
| 2912 | /** |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2913 | * Check that card is still alive. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2914 | * Reads debug register from domain0. |
| 2915 | * If card is present, pre-defined value should |
| 2916 | * be found there. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2917 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2918 | * @param priv |
| 2919 | * @return 1 if card is present, 0 otherwise |
| 2920 | */ |
| 2921 | static inline int ipw_alive(struct ipw_priv *priv) |
| 2922 | { |
| 2923 | return ipw_read32(priv, 0x90) == 0xd55555d5; |
| 2924 | } |
| 2925 | |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2926 | /* timeout in msec, attempted in 10-msec quanta */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2927 | static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2928 | int timeout) |
| 2929 | { |
| 2930 | int i = 0; |
| 2931 | |
| 2932 | do { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2933 | if ((ipw_read32(priv, addr) & mask) == mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2934 | return i; |
| 2935 | mdelay(10); |
| 2936 | i += 10; |
| 2937 | } while (i < timeout); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2938 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2939 | return -ETIME; |
| 2940 | } |
| 2941 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2942 | /* These functions load the firmware and micro code for the operation of |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2943 | * the ipw hardware. It assumes the buffer has all the bits for the |
| 2944 | * image and the caller is handling the memory allocation and clean up. |
| 2945 | */ |
| 2946 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2947 | static int ipw_stop_master(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2948 | { |
| 2949 | int rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2950 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2951 | IPW_DEBUG_TRACE(">> \n"); |
| 2952 | /* stop master. typical delay - 0 */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2953 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2954 | |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2955 | /* timeout is in msec, polled in 10-msec quanta */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2956 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
| 2957 | IPW_RESET_REG_MASTER_DISABLED, 100); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2958 | if (rc < 0) { |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2959 | IPW_ERROR("wait for stop master failed after 100ms\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2960 | return -1; |
| 2961 | } |
| 2962 | |
| 2963 | IPW_DEBUG_INFO("stop master %dms\n", rc); |
| 2964 | |
| 2965 | return rc; |
| 2966 | } |
| 2967 | |
| 2968 | static void ipw_arc_release(struct ipw_priv *priv) |
| 2969 | { |
| 2970 | IPW_DEBUG_TRACE(">> \n"); |
| 2971 | mdelay(5); |
| 2972 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2973 | ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2974 | |
| 2975 | /* no one knows timing, for safety add some delay */ |
| 2976 | mdelay(5); |
| 2977 | } |
| 2978 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2979 | struct fw_chunk { |
| 2980 | u32 address; |
| 2981 | u32 length; |
| 2982 | }; |
| 2983 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2984 | static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2985 | { |
| 2986 | int rc = 0, i, addr; |
| 2987 | u8 cr = 0; |
| 2988 | u16 *image; |
| 2989 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2990 | image = (u16 *) data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2991 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2992 | IPW_DEBUG_TRACE(">> \n"); |
| 2993 | |
| 2994 | rc = ipw_stop_master(priv); |
| 2995 | |
| 2996 | if (rc < 0) |
| 2997 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2998 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2999 | for (addr = IPW_SHARED_LOWER_BOUND; |
| 3000 | addr < IPW_REGISTER_DOMAIN1_END; addr += 4) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3001 | ipw_write32(priv, addr, 0); |
| 3002 | } |
| 3003 | |
| 3004 | /* no ucode (yet) */ |
| 3005 | memset(&priv->dino_alive, 0, sizeof(priv->dino_alive)); |
| 3006 | /* destroy DMA queues */ |
| 3007 | /* reset sequence */ |
| 3008 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3009 | ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3010 | ipw_arc_release(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3011 | ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3012 | mdelay(1); |
| 3013 | |
| 3014 | /* reset PHY */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3015 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3016 | mdelay(1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3017 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3018 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3019 | mdelay(1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3020 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3021 | /* enable ucode store */ |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 3022 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0); |
| 3023 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3024 | mdelay(1); |
| 3025 | |
| 3026 | /* write ucode */ |
| 3027 | /** |
| 3028 | * @bug |
| 3029 | * Do NOT set indirect address register once and then |
| 3030 | * store data to indirect data register in the loop. |
| 3031 | * It seems very reasonable, but in this case DINO do not |
| 3032 | * accept ucode. It is essential to set address each time. |
| 3033 | */ |
| 3034 | /* load new ipw uCode */ |
| 3035 | for (i = 0; i < len / 2; i++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3036 | ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3037 | cpu_to_le16(image[i])); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3038 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3039 | /* enable DINO */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3040 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
| 3041 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3042 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3043 | /* this is where the igx / win driver deveates from the VAP driver. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3044 | |
| 3045 | /* wait for alive response */ |
| 3046 | for (i = 0; i < 100; i++) { |
| 3047 | /* poll for incoming data */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3048 | cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3049 | if (cr & DINO_RXFIFO_DATA) |
| 3050 | break; |
| 3051 | mdelay(1); |
| 3052 | } |
| 3053 | |
| 3054 | if (cr & DINO_RXFIFO_DATA) { |
| 3055 | /* alive_command_responce size is NOT multiple of 4 */ |
| 3056 | u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4]; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3057 | |
| 3058 | for (i = 0; i < ARRAY_SIZE(response_buffer); i++) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3059 | response_buffer[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3060 | le32_to_cpu(ipw_read_reg32(priv, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3061 | IPW_BASEBAND_RX_FIFO_READ)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3062 | memcpy(&priv->dino_alive, response_buffer, |
| 3063 | sizeof(priv->dino_alive)); |
| 3064 | if (priv->dino_alive.alive_command == 1 |
| 3065 | && priv->dino_alive.ucode_valid == 1) { |
| 3066 | rc = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3067 | IPW_DEBUG_INFO |
| 3068 | ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) " |
| 3069 | "of %02d/%02d/%02d %02d:%02d\n", |
| 3070 | priv->dino_alive.software_revision, |
| 3071 | priv->dino_alive.software_revision, |
| 3072 | priv->dino_alive.device_identifier, |
| 3073 | priv->dino_alive.device_identifier, |
| 3074 | priv->dino_alive.time_stamp[0], |
| 3075 | priv->dino_alive.time_stamp[1], |
| 3076 | priv->dino_alive.time_stamp[2], |
| 3077 | priv->dino_alive.time_stamp[3], |
| 3078 | priv->dino_alive.time_stamp[4]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3079 | } else { |
| 3080 | IPW_DEBUG_INFO("Microcode is not alive\n"); |
| 3081 | rc = -EINVAL; |
| 3082 | } |
| 3083 | } else { |
| 3084 | IPW_DEBUG_INFO("No alive response from DINO\n"); |
| 3085 | rc = -ETIME; |
| 3086 | } |
| 3087 | |
| 3088 | /* disable DINO, otherwise for some reason |
| 3089 | firmware have problem getting alive resp. */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3090 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3091 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3092 | return rc; |
| 3093 | } |
| 3094 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3095 | static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3096 | { |
| 3097 | int rc = -1; |
| 3098 | int offset = 0; |
| 3099 | struct fw_chunk *chunk; |
| 3100 | dma_addr_t shared_phys; |
| 3101 | u8 *shared_virt; |
| 3102 | |
| 3103 | IPW_DEBUG_TRACE("<< : \n"); |
| 3104 | shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys); |
| 3105 | |
| 3106 | if (!shared_virt) |
| 3107 | return -ENOMEM; |
| 3108 | |
| 3109 | memmove(shared_virt, data, len); |
| 3110 | |
| 3111 | /* Start the Dma */ |
| 3112 | rc = ipw_fw_dma_enable(priv); |
| 3113 | |
| 3114 | if (priv->sram_desc.last_cb_index > 0) { |
| 3115 | /* the DMA is already ready this would be a bug. */ |
| 3116 | BUG(); |
| 3117 | goto out; |
| 3118 | } |
| 3119 | |
| 3120 | do { |
| 3121 | chunk = (struct fw_chunk *)(data + offset); |
| 3122 | offset += sizeof(struct fw_chunk); |
| 3123 | /* build DMA packet and queue up for sending */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3124 | /* dma to chunk->address, the chunk->length bytes from data + |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3125 | * offeset*/ |
| 3126 | /* Dma loading */ |
| 3127 | rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3128 | le32_to_cpu(chunk->address), |
| 3129 | le32_to_cpu(chunk->length)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3130 | if (rc) { |
| 3131 | IPW_DEBUG_INFO("dmaAddBuffer Failed\n"); |
| 3132 | goto out; |
| 3133 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3134 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3135 | offset += le32_to_cpu(chunk->length); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3136 | } while (offset < len); |
| 3137 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3138 | /* Run the DMA and wait for the answer */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3139 | rc = ipw_fw_dma_kick(priv); |
| 3140 | if (rc) { |
| 3141 | IPW_ERROR("dmaKick Failed\n"); |
| 3142 | goto out; |
| 3143 | } |
| 3144 | |
| 3145 | rc = ipw_fw_dma_wait(priv); |
| 3146 | if (rc) { |
| 3147 | IPW_ERROR("dmaWaitSync Failed\n"); |
| 3148 | goto out; |
| 3149 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3150 | out: |
| 3151 | pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3152 | return rc; |
| 3153 | } |
| 3154 | |
| 3155 | /* stop nic */ |
| 3156 | static int ipw_stop_nic(struct ipw_priv *priv) |
| 3157 | { |
| 3158 | int rc = 0; |
| 3159 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3160 | /* stop */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3161 | ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3162 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3163 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
| 3164 | IPW_RESET_REG_MASTER_DISABLED, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3165 | if (rc < 0) { |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3166 | IPW_ERROR("wait for reg master disabled failed after 500ms\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3167 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3168 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3169 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3170 | ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3171 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3172 | return rc; |
| 3173 | } |
| 3174 | |
| 3175 | static void ipw_start_nic(struct ipw_priv *priv) |
| 3176 | { |
| 3177 | IPW_DEBUG_TRACE(">>\n"); |
| 3178 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3179 | /* prvHwStartNic release ARC */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3180 | ipw_clear_bit(priv, IPW_RESET_REG, |
| 3181 | IPW_RESET_REG_MASTER_DISABLED | |
| 3182 | IPW_RESET_REG_STOP_MASTER | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3183 | CBD_RESET_REG_PRINCETON_RESET); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3184 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3185 | /* enable power management */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3186 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, |
| 3187 | IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3188 | |
| 3189 | IPW_DEBUG_TRACE("<<\n"); |
| 3190 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3191 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3192 | static int ipw_init_nic(struct ipw_priv *priv) |
| 3193 | { |
| 3194 | int rc; |
| 3195 | |
| 3196 | IPW_DEBUG_TRACE(">>\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3197 | /* reset */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3198 | /*prvHwInitNic */ |
| 3199 | /* set "initialization complete" bit to move adapter to D0 state */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3200 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3201 | |
| 3202 | /* low-level PLL activation */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3203 | ipw_write32(priv, IPW_READ_INT_REGISTER, |
| 3204 | IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3205 | |
| 3206 | /* wait for clock stabilization */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3207 | rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW, |
| 3208 | IPW_GP_CNTRL_BIT_CLOCK_READY, 250); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3209 | if (rc < 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3210 | IPW_DEBUG_INFO("FAILED wait for clock stablization\n"); |
| 3211 | |
| 3212 | /* assert SW reset */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3213 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3214 | |
| 3215 | udelay(10); |
| 3216 | |
| 3217 | /* set "initialization complete" bit to move adapter to D0 state */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3218 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3219 | |
| 3220 | IPW_DEBUG_TRACE(">>\n"); |
| 3221 | return 0; |
| 3222 | } |
| 3223 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3224 | /* Call this function from process context, it will sleep in request_firmware. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3225 | * Probe is an ok place to call this from. |
| 3226 | */ |
| 3227 | static int ipw_reset_nic(struct ipw_priv *priv) |
| 3228 | { |
| 3229 | int rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3230 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3231 | |
| 3232 | IPW_DEBUG_TRACE(">>\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3233 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3234 | rc = ipw_init_nic(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3235 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3236 | spin_lock_irqsave(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3237 | /* Clear the 'host command active' bit... */ |
| 3238 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 3239 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3240 | priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); |
| 3241 | wake_up_interruptible(&priv->wait_state); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3242 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3243 | |
| 3244 | IPW_DEBUG_TRACE("<<\n"); |
| 3245 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3246 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3247 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3248 | |
| 3249 | struct ipw_fw { |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3250 | __le32 ver; |
| 3251 | __le32 boot_size; |
| 3252 | __le32 ucode_size; |
| 3253 | __le32 fw_size; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3254 | u8 data[0]; |
| 3255 | }; |
| 3256 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3257 | static int ipw_get_fw(struct ipw_priv *priv, |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3258 | const struct firmware **raw, const char *name) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3259 | { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3260 | struct ipw_fw *fw; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3261 | int rc; |
| 3262 | |
| 3263 | /* ask firmware_class module to get the boot firmware off disk */ |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3264 | rc = request_firmware(raw, name, &priv->pci_dev->dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3265 | if (rc < 0) { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3266 | IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3267 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3268 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3269 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3270 | if ((*raw)->size < sizeof(*fw)) { |
| 3271 | IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3272 | return -EINVAL; |
| 3273 | } |
| 3274 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3275 | fw = (void *)(*raw)->data; |
| 3276 | |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3277 | if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) + |
| 3278 | le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3279 | IPW_ERROR("%s is too small or corrupt (%zd)\n", |
| 3280 | name, (*raw)->size); |
| 3281 | return -EINVAL; |
| 3282 | } |
| 3283 | |
| 3284 | IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3285 | name, |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3286 | le32_to_cpu(fw->ver) >> 16, |
| 3287 | le32_to_cpu(fw->ver) & 0xff, |
| 3288 | (*raw)->size - sizeof(*fw)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3289 | return 0; |
| 3290 | } |
| 3291 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3292 | #define IPW_RX_BUF_SIZE (3000) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3293 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3294 | static void ipw_rx_queue_reset(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3295 | struct ipw_rx_queue *rxq) |
| 3296 | { |
| 3297 | unsigned long flags; |
| 3298 | int i; |
| 3299 | |
| 3300 | spin_lock_irqsave(&rxq->lock, flags); |
| 3301 | |
| 3302 | INIT_LIST_HEAD(&rxq->rx_free); |
| 3303 | INIT_LIST_HEAD(&rxq->rx_used); |
| 3304 | |
| 3305 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 3306 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { |
| 3307 | /* In the reset function, these buffers may have been allocated |
| 3308 | * to an SKB, so we need to unmap and free potential storage */ |
| 3309 | if (rxq->pool[i].skb != NULL) { |
| 3310 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3311 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3312 | dev_kfree_skb(rxq->pool[i].skb); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3313 | rxq->pool[i].skb = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3314 | } |
| 3315 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 3316 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3317 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3318 | /* Set us so that we have processed and used all buffers, but have |
| 3319 | * not restocked the Rx queue with fresh buffers */ |
| 3320 | rxq->read = rxq->write = 0; |
| 3321 | rxq->processed = RX_QUEUE_SIZE - 1; |
| 3322 | rxq->free_count = 0; |
| 3323 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3324 | } |
| 3325 | |
| 3326 | #ifdef CONFIG_PM |
| 3327 | static int fw_loaded = 0; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3328 | static const struct firmware *raw = NULL; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3329 | |
| 3330 | static void free_firmware(void) |
| 3331 | { |
| 3332 | if (fw_loaded) { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3333 | release_firmware(raw); |
| 3334 | raw = NULL; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3335 | fw_loaded = 0; |
| 3336 | } |
| 3337 | } |
| 3338 | #else |
| 3339 | #define free_firmware() do {} while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3340 | #endif |
| 3341 | |
| 3342 | static int ipw_load(struct ipw_priv *priv) |
| 3343 | { |
| 3344 | #ifndef CONFIG_PM |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3345 | const struct firmware *raw = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3346 | #endif |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3347 | struct ipw_fw *fw; |
| 3348 | u8 *boot_img, *ucode_img, *fw_img; |
| 3349 | u8 *name = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3350 | int rc = 0, retries = 3; |
| 3351 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3352 | switch (priv->ieee->iw_mode) { |
| 3353 | case IW_MODE_ADHOC: |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3354 | name = "ipw2200-ibss.fw"; |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3355 | break; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3356 | #ifdef CONFIG_IPW2200_MONITOR |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3357 | case IW_MODE_MONITOR: |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3358 | name = "ipw2200-sniffer.fw"; |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3359 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3360 | #endif |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3361 | case IW_MODE_INFRA: |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3362 | name = "ipw2200-bss.fw"; |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3363 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3364 | } |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3365 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3366 | if (!name) { |
| 3367 | rc = -EINVAL; |
| 3368 | goto error; |
| 3369 | } |
| 3370 | |
| 3371 | #ifdef CONFIG_PM |
| 3372 | if (!fw_loaded) { |
| 3373 | #endif |
| 3374 | rc = ipw_get_fw(priv, &raw, name); |
| 3375 | if (rc < 0) |
| 3376 | goto error; |
| 3377 | #ifdef CONFIG_PM |
| 3378 | } |
| 3379 | #endif |
| 3380 | |
| 3381 | fw = (void *)raw->data; |
| 3382 | boot_img = &fw->data[0]; |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3383 | ucode_img = &fw->data[le32_to_cpu(fw->boot_size)]; |
| 3384 | fw_img = &fw->data[le32_to_cpu(fw->boot_size) + |
| 3385 | le32_to_cpu(fw->ucode_size)]; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3386 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3387 | if (rc < 0) |
| 3388 | goto error; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3389 | |
| 3390 | if (!priv->rxq) |
| 3391 | priv->rxq = ipw_rx_queue_alloc(priv); |
| 3392 | else |
| 3393 | ipw_rx_queue_reset(priv, priv->rxq); |
| 3394 | if (!priv->rxq) { |
| 3395 | IPW_ERROR("Unable to initialize Rx queue\n"); |
| 3396 | goto error; |
| 3397 | } |
| 3398 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3399 | retry: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3400 | /* Ensure interrupts are disabled */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3401 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3402 | priv->status &= ~STATUS_INT_ENABLED; |
| 3403 | |
| 3404 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3405 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3406 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3407 | ipw_stop_nic(priv); |
| 3408 | |
| 3409 | rc = ipw_reset_nic(priv); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3410 | if (rc < 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3411 | IPW_ERROR("Unable to reset NIC\n"); |
| 3412 | goto error; |
| 3413 | } |
| 3414 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3415 | ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND, |
| 3416 | IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3417 | |
| 3418 | /* DMA the initial boot firmware into the device */ |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3419 | rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3420 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3421 | IPW_ERROR("Unable to load boot firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3422 | goto error; |
| 3423 | } |
| 3424 | |
| 3425 | /* kick start the device */ |
| 3426 | ipw_start_nic(priv); |
| 3427 | |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3428 | /* wait for the device to finish its initial startup sequence */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3429 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
| 3430 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3431 | if (rc < 0) { |
| 3432 | IPW_ERROR("device failed to boot initial fw image\n"); |
| 3433 | goto error; |
| 3434 | } |
| 3435 | IPW_DEBUG_INFO("initial device response after %dms\n", rc); |
| 3436 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3437 | /* ack fw init done interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3438 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3439 | |
| 3440 | /* DMA the ucode into the device */ |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3441 | rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3442 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3443 | IPW_ERROR("Unable to load ucode: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3444 | goto error; |
| 3445 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3446 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3447 | /* stop nic */ |
| 3448 | ipw_stop_nic(priv); |
| 3449 | |
| 3450 | /* DMA bss firmware into the device */ |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3451 | rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3452 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3453 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3454 | goto error; |
| 3455 | } |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3456 | #ifdef CONFIG_PM |
| 3457 | fw_loaded = 1; |
| 3458 | #endif |
| 3459 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3460 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); |
| 3461 | |
| 3462 | rc = ipw_queue_reset(priv); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3463 | if (rc < 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3464 | IPW_ERROR("Unable to initialize queues\n"); |
| 3465 | goto error; |
| 3466 | } |
| 3467 | |
| 3468 | /* Ensure interrupts are disabled */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3469 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3470 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3471 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3472 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3473 | /* kick start the device */ |
| 3474 | ipw_start_nic(priv); |
| 3475 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3476 | if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3477 | if (retries > 0) { |
| 3478 | IPW_WARNING("Parity error. Retrying init.\n"); |
| 3479 | retries--; |
| 3480 | goto retry; |
| 3481 | } |
| 3482 | |
| 3483 | IPW_ERROR("TODO: Handle parity error -- schedule restart?\n"); |
| 3484 | rc = -EIO; |
| 3485 | goto error; |
| 3486 | } |
| 3487 | |
| 3488 | /* wait for the device */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3489 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
| 3490 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3491 | if (rc < 0) { |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3492 | IPW_ERROR("device failed to start within 500ms\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3493 | goto error; |
| 3494 | } |
| 3495 | IPW_DEBUG_INFO("device response after %dms\n", rc); |
| 3496 | |
| 3497 | /* ack fw init done interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3498 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3499 | |
| 3500 | /* read eeprom data and initialize the eeprom region of sram */ |
| 3501 | priv->eeprom_delay = 1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3502 | ipw_eeprom_init_sram(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3503 | |
| 3504 | /* enable interrupts */ |
| 3505 | ipw_enable_interrupts(priv); |
| 3506 | |
| 3507 | /* Ensure our queue has valid packets */ |
| 3508 | ipw_rx_queue_replenish(priv); |
| 3509 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3510 | ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3511 | |
| 3512 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3513 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3514 | |
| 3515 | #ifndef CONFIG_PM |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3516 | release_firmware(raw); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3517 | #endif |
| 3518 | return 0; |
| 3519 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3520 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3521 | if (priv->rxq) { |
| 3522 | ipw_rx_queue_free(priv, priv->rxq); |
| 3523 | priv->rxq = NULL; |
| 3524 | } |
| 3525 | ipw_tx_queue_free(priv); |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3526 | if (raw) |
| 3527 | release_firmware(raw); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3528 | #ifdef CONFIG_PM |
| 3529 | fw_loaded = 0; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3530 | raw = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3531 | #endif |
| 3532 | |
| 3533 | return rc; |
| 3534 | } |
| 3535 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3536 | /** |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3537 | * DMA services |
| 3538 | * |
| 3539 | * Theory of operation |
| 3540 | * |
| 3541 | * A queue is a circular buffers with 'Read' and 'Write' pointers. |
| 3542 | * 2 empty entries always kept in the buffer to protect from overflow. |
| 3543 | * |
| 3544 | * For Tx queue, there are low mark and high mark limits. If, after queuing |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3545 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 3546 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3547 | * Tx queue resumed. |
| 3548 | * |
| 3549 | * The IPW operates with six queues, one receive queue in the device's |
| 3550 | * sram, one transmit queue for sending commands to the device firmware, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3551 | * and four transmit queues for data. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3552 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3553 | * The four transmit queues allow for performing quality of service (qos) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3554 | * transmissions as per the 802.11 protocol. Currently Linux does not |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3555 | * provide a mechanism to the user for utilizing prioritized queues, so |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3556 | * we only utilize the first data transmit queue (queue1). |
| 3557 | */ |
| 3558 | |
| 3559 | /** |
| 3560 | * Driver allocates buffers of this size for Rx |
| 3561 | */ |
| 3562 | |
| 3563 | static inline int ipw_queue_space(const struct clx2_queue *q) |
| 3564 | { |
| 3565 | int s = q->last_used - q->first_empty; |
| 3566 | if (s <= 0) |
| 3567 | s += q->n_bd; |
| 3568 | s -= 2; /* keep some reserve to not confuse empty and full situations */ |
| 3569 | if (s < 0) |
| 3570 | s = 0; |
| 3571 | return s; |
| 3572 | } |
| 3573 | |
| 3574 | static inline int ipw_queue_inc_wrap(int index, int n_bd) |
| 3575 | { |
| 3576 | return (++index == n_bd) ? 0 : index; |
| 3577 | } |
| 3578 | |
| 3579 | /** |
| 3580 | * Initialize common DMA queue structure |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3581 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3582 | * @param q queue to init |
| 3583 | * @param count Number of BD's to allocate. Should be power of 2 |
| 3584 | * @param read_register Address for 'read' register |
| 3585 | * (not offset within BAR, full address) |
| 3586 | * @param write_register Address for 'write' register |
| 3587 | * (not offset within BAR, full address) |
| 3588 | * @param base_register Address for 'base' register |
| 3589 | * (not offset within BAR, full address) |
| 3590 | * @param size Address for 'size' register |
| 3591 | * (not offset within BAR, full address) |
| 3592 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3593 | static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3594 | int count, u32 read, u32 write, u32 base, u32 size) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3595 | { |
| 3596 | q->n_bd = count; |
| 3597 | |
| 3598 | q->low_mark = q->n_bd / 4; |
| 3599 | if (q->low_mark < 4) |
| 3600 | q->low_mark = 4; |
| 3601 | |
| 3602 | q->high_mark = q->n_bd / 8; |
| 3603 | if (q->high_mark < 2) |
| 3604 | q->high_mark = 2; |
| 3605 | |
| 3606 | q->first_empty = q->last_used = 0; |
| 3607 | q->reg_r = read; |
| 3608 | q->reg_w = write; |
| 3609 | |
| 3610 | ipw_write32(priv, base, q->dma_addr); |
| 3611 | ipw_write32(priv, size, count); |
| 3612 | ipw_write32(priv, read, 0); |
| 3613 | ipw_write32(priv, write, 0); |
| 3614 | |
| 3615 | _ipw_read32(priv, 0x90); |
| 3616 | } |
| 3617 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3618 | static int ipw_queue_tx_init(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3619 | struct clx2_tx_queue *q, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3620 | int count, u32 read, u32 write, u32 base, u32 size) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3621 | { |
| 3622 | struct pci_dev *dev = priv->pci_dev; |
| 3623 | |
| 3624 | q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL); |
| 3625 | if (!q->txb) { |
| 3626 | IPW_ERROR("vmalloc for auxilary BD structures failed\n"); |
| 3627 | return -ENOMEM; |
| 3628 | } |
| 3629 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3630 | q->bd = |
| 3631 | pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3632 | if (!q->bd) { |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 3633 | IPW_ERROR("pci_alloc_consistent(%zd) failed\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3634 | sizeof(q->bd[0]) * count); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3635 | kfree(q->txb); |
| 3636 | q->txb = NULL; |
| 3637 | return -ENOMEM; |
| 3638 | } |
| 3639 | |
| 3640 | ipw_queue_init(priv, &q->q, count, read, write, base, size); |
| 3641 | return 0; |
| 3642 | } |
| 3643 | |
| 3644 | /** |
| 3645 | * Free one TFD, those at index [txq->q.last_used]. |
| 3646 | * Do NOT advance any indexes |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3647 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3648 | * @param dev |
| 3649 | * @param txq |
| 3650 | */ |
| 3651 | static void ipw_queue_tx_free_tfd(struct ipw_priv *priv, |
| 3652 | struct clx2_tx_queue *txq) |
| 3653 | { |
| 3654 | struct tfd_frame *bd = &txq->bd[txq->q.last_used]; |
| 3655 | struct pci_dev *dev = priv->pci_dev; |
| 3656 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3657 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3658 | /* classify bd */ |
| 3659 | if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE) |
| 3660 | /* nothing to cleanup after for host commands */ |
| 3661 | return; |
| 3662 | |
| 3663 | /* sanity check */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3664 | if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) { |
| 3665 | IPW_ERROR("Too many chunks: %i\n", |
| 3666 | le32_to_cpu(bd->u.data.num_chunks)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3667 | /** @todo issue fatal error, it is quite serious situation */ |
| 3668 | return; |
| 3669 | } |
| 3670 | |
| 3671 | /* unmap chunks if any */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3672 | for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) { |
| 3673 | pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]), |
| 3674 | le16_to_cpu(bd->u.data.chunk_len[i]), |
| 3675 | PCI_DMA_TODEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3676 | if (txq->txb[txq->q.last_used]) { |
| 3677 | ieee80211_txb_free(txq->txb[txq->q.last_used]); |
| 3678 | txq->txb[txq->q.last_used] = NULL; |
| 3679 | } |
| 3680 | } |
| 3681 | } |
| 3682 | |
| 3683 | /** |
| 3684 | * Deallocate DMA queue. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3685 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3686 | * Empty queue by removing and destroying all BD's. |
| 3687 | * Free all buffers. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3688 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3689 | * @param dev |
| 3690 | * @param q |
| 3691 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3692 | static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3693 | { |
| 3694 | struct clx2_queue *q = &txq->q; |
| 3695 | struct pci_dev *dev = priv->pci_dev; |
| 3696 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3697 | if (q->n_bd == 0) |
| 3698 | return; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3699 | |
| 3700 | /* first, empty all BD's */ |
| 3701 | for (; q->first_empty != q->last_used; |
| 3702 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { |
| 3703 | ipw_queue_tx_free_tfd(priv, txq); |
| 3704 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3705 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3706 | /* free buffers belonging to queue itself */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3707 | pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3708 | q->dma_addr); |
| 3709 | kfree(txq->txb); |
| 3710 | |
| 3711 | /* 0 fill whole structure */ |
| 3712 | memset(txq, 0, sizeof(*txq)); |
| 3713 | } |
| 3714 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3715 | /** |
| 3716 | * Destroy all DMA queues and structures |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3717 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3718 | * @param priv |
| 3719 | */ |
| 3720 | static void ipw_tx_queue_free(struct ipw_priv *priv) |
| 3721 | { |
| 3722 | /* Tx CMD queue */ |
| 3723 | ipw_queue_tx_free(priv, &priv->txq_cmd); |
| 3724 | |
| 3725 | /* Tx queues */ |
| 3726 | ipw_queue_tx_free(priv, &priv->txq[0]); |
| 3727 | ipw_queue_tx_free(priv, &priv->txq[1]); |
| 3728 | ipw_queue_tx_free(priv, &priv->txq[2]); |
| 3729 | ipw_queue_tx_free(priv, &priv->txq[3]); |
| 3730 | } |
| 3731 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3732 | static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3733 | { |
| 3734 | /* First 3 bytes are manufacturer */ |
| 3735 | bssid[0] = priv->mac_addr[0]; |
| 3736 | bssid[1] = priv->mac_addr[1]; |
| 3737 | bssid[2] = priv->mac_addr[2]; |
| 3738 | |
| 3739 | /* Last bytes are random */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3740 | get_random_bytes(&bssid[3], ETH_ALEN - 3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3741 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3742 | bssid[0] &= 0xfe; /* clear multicast bit */ |
| 3743 | bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3744 | } |
| 3745 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3746 | static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3747 | { |
| 3748 | struct ipw_station_entry entry; |
| 3749 | int i; |
| 3750 | |
| 3751 | for (i = 0; i < priv->num_stations; i++) { |
| 3752 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) { |
| 3753 | /* Another node is active in network */ |
| 3754 | priv->missed_adhoc_beacons = 0; |
| 3755 | if (!(priv->config & CFG_STATIC_CHANNEL)) |
| 3756 | /* when other nodes drop out, we drop out */ |
| 3757 | priv->config &= ~CFG_ADHOC_PERSIST; |
| 3758 | |
| 3759 | return i; |
| 3760 | } |
| 3761 | } |
| 3762 | |
| 3763 | if (i == MAX_STATIONS) |
| 3764 | return IPW_INVALID_STATION; |
| 3765 | |
| 3766 | IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid)); |
| 3767 | |
| 3768 | entry.reserved = 0; |
| 3769 | entry.support_mode = 0; |
| 3770 | memcpy(entry.mac_addr, bssid, ETH_ALEN); |
| 3771 | memcpy(priv->stations[i], bssid, ETH_ALEN); |
| 3772 | ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3773 | &entry, sizeof(entry)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3774 | priv->num_stations++; |
| 3775 | |
| 3776 | return i; |
| 3777 | } |
| 3778 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3779 | static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3780 | { |
| 3781 | int i; |
| 3782 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3783 | for (i = 0; i < priv->num_stations; i++) |
| 3784 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3785 | return i; |
| 3786 | |
| 3787 | return IPW_INVALID_STATION; |
| 3788 | } |
| 3789 | |
| 3790 | static void ipw_send_disassociate(struct ipw_priv *priv, int quiet) |
| 3791 | { |
| 3792 | int err; |
| 3793 | |
Hong Liu | 7b99659 | 2005-08-25 17:36:13 +0800 | [diff] [blame] | 3794 | if (priv->status & STATUS_ASSOCIATING) { |
| 3795 | IPW_DEBUG_ASSOC("Disassociating while associating.\n"); |
| 3796 | queue_work(priv->workqueue, &priv->disassociate); |
| 3797 | return; |
| 3798 | } |
| 3799 | |
| 3800 | if (!(priv->status & STATUS_ASSOCIATED)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3801 | IPW_DEBUG_ASSOC("Disassociating while not associated.\n"); |
| 3802 | return; |
| 3803 | } |
| 3804 | |
| 3805 | IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " " |
| 3806 | "on channel %d.\n", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3807 | MAC_ARG(priv->assoc_request.bssid), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3808 | priv->assoc_request.channel); |
| 3809 | |
| 3810 | priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED); |
| 3811 | priv->status |= STATUS_DISASSOCIATING; |
| 3812 | |
| 3813 | if (quiet) |
| 3814 | priv->assoc_request.assoc_type = HC_DISASSOC_QUIET; |
| 3815 | else |
| 3816 | priv->assoc_request.assoc_type = HC_DISASSOCIATE; |
Hong Liu | e632472 | 2005-09-14 21:04:15 -0500 | [diff] [blame] | 3817 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3818 | err = ipw_send_associate(priv, &priv->assoc_request); |
| 3819 | if (err) { |
| 3820 | IPW_DEBUG_HC("Attempt to send [dis]associate command " |
| 3821 | "failed.\n"); |
| 3822 | return; |
| 3823 | } |
| 3824 | |
| 3825 | } |
| 3826 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3827 | static int ipw_disassociate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3828 | { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3829 | struct ipw_priv *priv = data; |
| 3830 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) |
| 3831 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3832 | ipw_send_disassociate(data, 0); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3833 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3834 | } |
| 3835 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3836 | static void ipw_bg_disassociate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3837 | { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3838 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 3839 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3840 | ipw_disassociate(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 3841 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3842 | } |
| 3843 | |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 3844 | static void ipw_system_config(void *data) |
| 3845 | { |
| 3846 | struct ipw_priv *priv = data; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 3847 | |
| 3848 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 3849 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) { |
| 3850 | priv->sys_config.accept_all_data_frames = 1; |
| 3851 | priv->sys_config.accept_non_directed_frames = 1; |
| 3852 | priv->sys_config.accept_all_mgmt_bcpr = 1; |
| 3853 | priv->sys_config.accept_all_mgmt_frames = 1; |
| 3854 | } |
| 3855 | #endif |
| 3856 | |
| 3857 | ipw_send_system_config(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3858 | } |
| 3859 | |
| 3860 | struct ipw_status_code { |
| 3861 | u16 status; |
| 3862 | const char *reason; |
| 3863 | }; |
| 3864 | |
| 3865 | static const struct ipw_status_code ipw_status_codes[] = { |
| 3866 | {0x00, "Successful"}, |
| 3867 | {0x01, "Unspecified failure"}, |
| 3868 | {0x0A, "Cannot support all requested capabilities in the " |
| 3869 | "Capability information field"}, |
| 3870 | {0x0B, "Reassociation denied due to inability to confirm that " |
| 3871 | "association exists"}, |
| 3872 | {0x0C, "Association denied due to reason outside the scope of this " |
| 3873 | "standard"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3874 | {0x0D, |
| 3875 | "Responding station does not support the specified authentication " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3876 | "algorithm"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3877 | {0x0E, |
| 3878 | "Received an Authentication frame with authentication sequence " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3879 | "transaction sequence number out of expected sequence"}, |
| 3880 | {0x0F, "Authentication rejected because of challenge failure"}, |
| 3881 | {0x10, "Authentication rejected due to timeout waiting for next " |
| 3882 | "frame in sequence"}, |
| 3883 | {0x11, "Association denied because AP is unable to handle additional " |
| 3884 | "associated stations"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3885 | {0x12, |
| 3886 | "Association denied due to requesting station not supporting all " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3887 | "of the datarates in the BSSBasicServiceSet Parameter"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3888 | {0x13, |
| 3889 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3890 | "short preamble operation"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3891 | {0x14, |
| 3892 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3893 | "PBCC encoding"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3894 | {0x15, |
| 3895 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3896 | "channel agility"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3897 | {0x19, |
| 3898 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3899 | "short slot operation"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3900 | {0x1A, |
| 3901 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3902 | "DSSS-OFDM operation"}, |
| 3903 | {0x28, "Invalid Information Element"}, |
| 3904 | {0x29, "Group Cipher is not valid"}, |
| 3905 | {0x2A, "Pairwise Cipher is not valid"}, |
| 3906 | {0x2B, "AKMP is not valid"}, |
| 3907 | {0x2C, "Unsupported RSN IE version"}, |
| 3908 | {0x2D, "Invalid RSN IE Capabilities"}, |
| 3909 | {0x2E, "Cipher suite is rejected per security policy"}, |
| 3910 | }; |
| 3911 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3912 | static const char *ipw_get_status_code(u16 status) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3913 | { |
| 3914 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3915 | for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 3916 | if (ipw_status_codes[i].status == (status & 0xff)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3917 | return ipw_status_codes[i].reason; |
| 3918 | return "Unknown status value."; |
| 3919 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3920 | |
| 3921 | static void inline average_init(struct average *avg) |
| 3922 | { |
| 3923 | memset(avg, 0, sizeof(*avg)); |
| 3924 | } |
| 3925 | |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 3926 | #define DEPTH_RSSI 8 |
| 3927 | #define DEPTH_NOISE 16 |
| 3928 | static s16 exponential_average(s16 prev_avg, s16 val, u8 depth) |
| 3929 | { |
| 3930 | return ((depth-1)*prev_avg + val)/depth; |
| 3931 | } |
| 3932 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3933 | static void average_add(struct average *avg, s16 val) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3934 | { |
| 3935 | avg->sum -= avg->entries[avg->pos]; |
| 3936 | avg->sum += val; |
| 3937 | avg->entries[avg->pos++] = val; |
| 3938 | if (unlikely(avg->pos == AVG_ENTRIES)) { |
| 3939 | avg->init = 1; |
| 3940 | avg->pos = 0; |
| 3941 | } |
| 3942 | } |
| 3943 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3944 | static s16 average_value(struct average *avg) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3945 | { |
| 3946 | if (!unlikely(avg->init)) { |
| 3947 | if (avg->pos) |
| 3948 | return avg->sum / avg->pos; |
| 3949 | return 0; |
| 3950 | } |
| 3951 | |
| 3952 | return avg->sum / AVG_ENTRIES; |
| 3953 | } |
| 3954 | |
| 3955 | static void ipw_reset_stats(struct ipw_priv *priv) |
| 3956 | { |
| 3957 | u32 len = sizeof(u32); |
| 3958 | |
| 3959 | priv->quality = 0; |
| 3960 | |
| 3961 | average_init(&priv->average_missed_beacons); |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 3962 | priv->exp_avg_rssi = -60; |
| 3963 | priv->exp_avg_noise = -85 + 0x100; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3964 | |
| 3965 | priv->last_rate = 0; |
| 3966 | priv->last_missed_beacons = 0; |
| 3967 | priv->last_rx_packets = 0; |
| 3968 | priv->last_tx_packets = 0; |
| 3969 | priv->last_tx_failures = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3970 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3971 | /* Firmware managed, reset only when NIC is restarted, so we have to |
| 3972 | * normalize on the current value */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3973 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3974 | &priv->last_rx_err, &len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3975 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3976 | &priv->last_tx_failures, &len); |
| 3977 | |
| 3978 | /* Driver managed, reset with each association */ |
| 3979 | priv->missed_adhoc_beacons = 0; |
| 3980 | priv->missed_beacons = 0; |
| 3981 | priv->tx_packets = 0; |
| 3982 | priv->rx_packets = 0; |
| 3983 | |
| 3984 | } |
| 3985 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3986 | static u32 ipw_get_max_rate(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3987 | { |
| 3988 | u32 i = 0x80000000; |
| 3989 | u32 mask = priv->rates_mask; |
| 3990 | /* If currently associated in B mode, restrict the maximum |
| 3991 | * rate match to B rates */ |
| 3992 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) |
| 3993 | mask &= IEEE80211_CCK_RATES_MASK; |
| 3994 | |
| 3995 | /* TODO: Verify that the rate is supported by the current rates |
| 3996 | * list. */ |
| 3997 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3998 | while (i && !(mask & i)) |
| 3999 | i >>= 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4000 | switch (i) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4001 | case IEEE80211_CCK_RATE_1MB_MASK: |
| 4002 | return 1000000; |
| 4003 | case IEEE80211_CCK_RATE_2MB_MASK: |
| 4004 | return 2000000; |
| 4005 | case IEEE80211_CCK_RATE_5MB_MASK: |
| 4006 | return 5500000; |
| 4007 | case IEEE80211_OFDM_RATE_6MB_MASK: |
| 4008 | return 6000000; |
| 4009 | case IEEE80211_OFDM_RATE_9MB_MASK: |
| 4010 | return 9000000; |
| 4011 | case IEEE80211_CCK_RATE_11MB_MASK: |
| 4012 | return 11000000; |
| 4013 | case IEEE80211_OFDM_RATE_12MB_MASK: |
| 4014 | return 12000000; |
| 4015 | case IEEE80211_OFDM_RATE_18MB_MASK: |
| 4016 | return 18000000; |
| 4017 | case IEEE80211_OFDM_RATE_24MB_MASK: |
| 4018 | return 24000000; |
| 4019 | case IEEE80211_OFDM_RATE_36MB_MASK: |
| 4020 | return 36000000; |
| 4021 | case IEEE80211_OFDM_RATE_48MB_MASK: |
| 4022 | return 48000000; |
| 4023 | case IEEE80211_OFDM_RATE_54MB_MASK: |
| 4024 | return 54000000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4025 | } |
| 4026 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4027 | if (priv->ieee->mode == IEEE_B) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4028 | return 11000000; |
| 4029 | else |
| 4030 | return 54000000; |
| 4031 | } |
| 4032 | |
| 4033 | static u32 ipw_get_current_rate(struct ipw_priv *priv) |
| 4034 | { |
| 4035 | u32 rate, len = sizeof(rate); |
| 4036 | int err; |
| 4037 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4038 | if (!(priv->status & STATUS_ASSOCIATED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4039 | return 0; |
| 4040 | |
| 4041 | if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4042 | err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4043 | &len); |
| 4044 | if (err) { |
| 4045 | IPW_DEBUG_INFO("failed querying ordinals.\n"); |
| 4046 | return 0; |
| 4047 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4048 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4049 | return ipw_get_max_rate(priv); |
| 4050 | |
| 4051 | switch (rate) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4052 | case IPW_TX_RATE_1MB: |
| 4053 | return 1000000; |
| 4054 | case IPW_TX_RATE_2MB: |
| 4055 | return 2000000; |
| 4056 | case IPW_TX_RATE_5MB: |
| 4057 | return 5500000; |
| 4058 | case IPW_TX_RATE_6MB: |
| 4059 | return 6000000; |
| 4060 | case IPW_TX_RATE_9MB: |
| 4061 | return 9000000; |
| 4062 | case IPW_TX_RATE_11MB: |
| 4063 | return 11000000; |
| 4064 | case IPW_TX_RATE_12MB: |
| 4065 | return 12000000; |
| 4066 | case IPW_TX_RATE_18MB: |
| 4067 | return 18000000; |
| 4068 | case IPW_TX_RATE_24MB: |
| 4069 | return 24000000; |
| 4070 | case IPW_TX_RATE_36MB: |
| 4071 | return 36000000; |
| 4072 | case IPW_TX_RATE_48MB: |
| 4073 | return 48000000; |
| 4074 | case IPW_TX_RATE_54MB: |
| 4075 | return 54000000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4076 | } |
| 4077 | |
| 4078 | return 0; |
| 4079 | } |
| 4080 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4081 | #define IPW_STATS_INTERVAL (2 * HZ) |
| 4082 | static void ipw_gather_stats(struct ipw_priv *priv) |
| 4083 | { |
| 4084 | u32 rx_err, rx_err_delta, rx_packets_delta; |
| 4085 | u32 tx_failures, tx_failures_delta, tx_packets_delta; |
| 4086 | u32 missed_beacons_percent, missed_beacons_delta; |
| 4087 | u32 quality = 0; |
| 4088 | u32 len = sizeof(u32); |
| 4089 | s16 rssi; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4090 | u32 beacon_quality, signal_quality, tx_quality, rx_quality, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4091 | rate_quality; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4092 | u32 max_rate; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4093 | |
| 4094 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 4095 | priv->quality = 0; |
| 4096 | return; |
| 4097 | } |
| 4098 | |
| 4099 | /* Update the statistics */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4100 | ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4101 | &priv->missed_beacons, &len); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4102 | missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4103 | priv->last_missed_beacons = priv->missed_beacons; |
| 4104 | if (priv->assoc_request.beacon_interval) { |
| 4105 | missed_beacons_percent = missed_beacons_delta * |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4106 | (HZ * priv->assoc_request.beacon_interval) / |
| 4107 | (IPW_STATS_INTERVAL * 10); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4108 | } else { |
| 4109 | missed_beacons_percent = 0; |
| 4110 | } |
| 4111 | average_add(&priv->average_missed_beacons, missed_beacons_percent); |
| 4112 | |
| 4113 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len); |
| 4114 | rx_err_delta = rx_err - priv->last_rx_err; |
| 4115 | priv->last_rx_err = rx_err; |
| 4116 | |
| 4117 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len); |
| 4118 | tx_failures_delta = tx_failures - priv->last_tx_failures; |
| 4119 | priv->last_tx_failures = tx_failures; |
| 4120 | |
| 4121 | rx_packets_delta = priv->rx_packets - priv->last_rx_packets; |
| 4122 | priv->last_rx_packets = priv->rx_packets; |
| 4123 | |
| 4124 | tx_packets_delta = priv->tx_packets - priv->last_tx_packets; |
| 4125 | priv->last_tx_packets = priv->tx_packets; |
| 4126 | |
| 4127 | /* Calculate quality based on the following: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4128 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4129 | * Missed beacon: 100% = 0, 0% = 70% missed |
| 4130 | * Rate: 60% = 1Mbs, 100% = Max |
| 4131 | * Rx and Tx errors represent a straight % of total Rx/Tx |
| 4132 | * RSSI: 100% = > -50, 0% = < -80 |
| 4133 | * Rx errors: 100% = 0, 0% = 50% missed |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4134 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4135 | * The lowest computed quality is used. |
| 4136 | * |
| 4137 | */ |
| 4138 | #define BEACON_THRESHOLD 5 |
| 4139 | beacon_quality = 100 - missed_beacons_percent; |
| 4140 | if (beacon_quality < BEACON_THRESHOLD) |
| 4141 | beacon_quality = 0; |
| 4142 | else |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4143 | beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4144 | (100 - BEACON_THRESHOLD); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4145 | IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4146 | beacon_quality, missed_beacons_percent); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4147 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4148 | priv->last_rate = ipw_get_current_rate(priv); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4149 | max_rate = ipw_get_max_rate(priv); |
| 4150 | rate_quality = priv->last_rate * 40 / max_rate + 60; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4151 | IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n", |
| 4152 | rate_quality, priv->last_rate / 1000000); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4153 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4154 | if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4155 | rx_quality = 100 - (rx_err_delta * 100) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4156 | (rx_packets_delta + rx_err_delta); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4157 | else |
| 4158 | rx_quality = 100; |
| 4159 | IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n", |
| 4160 | rx_quality, rx_err_delta, rx_packets_delta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4161 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4162 | if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4163 | tx_quality = 100 - (tx_failures_delta * 100) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4164 | (tx_packets_delta + tx_failures_delta); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4165 | else |
| 4166 | tx_quality = 100; |
| 4167 | IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n", |
| 4168 | tx_quality, tx_failures_delta, tx_packets_delta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4169 | |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 4170 | rssi = priv->exp_avg_rssi; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4171 | signal_quality = |
| 4172 | (100 * |
| 4173 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * |
| 4174 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) - |
| 4175 | (priv->ieee->perfect_rssi - rssi) * |
| 4176 | (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) + |
| 4177 | 62 * (priv->ieee->perfect_rssi - rssi))) / |
| 4178 | ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * |
| 4179 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi)); |
| 4180 | if (signal_quality > 100) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4181 | signal_quality = 100; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4182 | else if (signal_quality < 1) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4183 | signal_quality = 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4184 | |
Zhu Yi | 61fb9ed | 2006-04-13 17:19:55 +0800 | [diff] [blame] | 4185 | IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4186 | signal_quality, rssi); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4187 | |
| 4188 | quality = min(beacon_quality, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4189 | min(rate_quality, |
| 4190 | min(tx_quality, min(rx_quality, signal_quality)))); |
| 4191 | if (quality == beacon_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4192 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n", |
| 4193 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4194 | if (quality == rate_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4195 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n", |
| 4196 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4197 | if (quality == tx_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4198 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n", |
| 4199 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4200 | if (quality == rx_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4201 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n", |
| 4202 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4203 | if (quality == signal_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4204 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n", |
| 4205 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4206 | |
| 4207 | priv->quality = quality; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4208 | |
| 4209 | queue_delayed_work(priv->workqueue, &priv->gather_stats, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4210 | IPW_STATS_INTERVAL); |
| 4211 | } |
| 4212 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4213 | static void ipw_bg_gather_stats(void *data) |
| 4214 | { |
| 4215 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 4216 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4217 | ipw_gather_stats(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 4218 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4219 | } |
| 4220 | |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4221 | /* Missed beacon behavior: |
| 4222 | * 1st missed -> roaming_threshold, just wait, don't do any scan/roam. |
| 4223 | * roaming_threshold -> disassociate_threshold, scan and roam for better signal. |
| 4224 | * Above disassociate threshold, give up and stop scanning. |
| 4225 | * Roaming is disabled if disassociate_threshold <= roaming_threshold */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4226 | static void ipw_handle_missed_beacon(struct ipw_priv *priv, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4227 | int missed_count) |
| 4228 | { |
| 4229 | priv->notif_missed_beacons = missed_count; |
| 4230 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4231 | if (missed_count > priv->disassociate_threshold && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4232 | priv->status & STATUS_ASSOCIATED) { |
| 4233 | /* If associated and we've hit the missed |
| 4234 | * beacon threshold, disassociate, turn |
| 4235 | * off roaming, and abort any active scans */ |
| 4236 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4237 | IPW_DL_STATE | IPW_DL_ASSOC, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4238 | "Missed beacon: %d - disassociate\n", missed_count); |
| 4239 | priv->status &= ~STATUS_ROAMING; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4240 | if (priv->status & STATUS_SCANNING) { |
| 4241 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
| 4242 | IPW_DL_STATE, |
| 4243 | "Aborting scan with missed beacon.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4244 | queue_work(priv->workqueue, &priv->abort_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4245 | } |
| 4246 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4247 | queue_work(priv->workqueue, &priv->disassociate); |
| 4248 | return; |
| 4249 | } |
| 4250 | |
| 4251 | if (priv->status & STATUS_ROAMING) { |
| 4252 | /* If we are currently roaming, then just |
| 4253 | * print a debug statement... */ |
| 4254 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4255 | "Missed beacon: %d - roam in progress\n", |
| 4256 | missed_count); |
| 4257 | return; |
| 4258 | } |
| 4259 | |
Zhu Yi | 4bfdb91 | 2006-01-24 16:37:16 +0800 | [diff] [blame] | 4260 | if (roaming && |
| 4261 | (missed_count > priv->roaming_threshold && |
| 4262 | missed_count <= priv->disassociate_threshold)) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4263 | /* If we are not already roaming, set the ROAM |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4264 | * bit in the status and kick off a scan. |
| 4265 | * This can happen several times before we reach |
| 4266 | * disassociate_threshold. */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4267 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4268 | "Missed beacon: %d - initiate " |
| 4269 | "roaming\n", missed_count); |
| 4270 | if (!(priv->status & STATUS_ROAMING)) { |
| 4271 | priv->status |= STATUS_ROAMING; |
| 4272 | if (!(priv->status & STATUS_SCANNING)) |
| 4273 | queue_work(priv->workqueue, |
| 4274 | &priv->request_scan); |
| 4275 | } |
| 4276 | return; |
| 4277 | } |
| 4278 | |
| 4279 | if (priv->status & STATUS_SCANNING) { |
| 4280 | /* Stop scan to keep fw from getting |
| 4281 | * stuck (only if we aren't roaming -- |
| 4282 | * otherwise we'll never scan more than 2 or 3 |
| 4283 | * channels..) */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4284 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE, |
| 4285 | "Aborting scan with missed beacon.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4286 | queue_work(priv->workqueue, &priv->abort_scan); |
| 4287 | } |
| 4288 | |
| 4289 | IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4290 | } |
| 4291 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4292 | /** |
| 4293 | * Handle host notification packet. |
| 4294 | * Called from interrupt routine |
| 4295 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4296 | static void ipw_rx_notification(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4297 | struct ipw_rx_notification *notif) |
| 4298 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4299 | notif->size = le16_to_cpu(notif->size); |
| 4300 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4301 | IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4302 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4303 | switch (notif->subtype) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4304 | case HOST_NOTIFICATION_STATUS_ASSOCIATED:{ |
| 4305 | struct notif_association *assoc = ¬if->u.assoc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4306 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4307 | switch (assoc->state) { |
| 4308 | case CMAS_ASSOCIATED:{ |
| 4309 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4310 | IPW_DL_ASSOC, |
| 4311 | "associated: '%s' " MAC_FMT |
| 4312 | " \n", |
| 4313 | escape_essid(priv->essid, |
| 4314 | priv->essid_len), |
| 4315 | MAC_ARG(priv->bssid)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4316 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4317 | switch (priv->ieee->iw_mode) { |
| 4318 | case IW_MODE_INFRA: |
| 4319 | memcpy(priv->ieee->bssid, |
| 4320 | priv->bssid, ETH_ALEN); |
| 4321 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4322 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4323 | case IW_MODE_ADHOC: |
| 4324 | memcpy(priv->ieee->bssid, |
| 4325 | priv->bssid, ETH_ALEN); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4326 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4327 | /* clear out the station table */ |
| 4328 | priv->num_stations = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4329 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4330 | IPW_DEBUG_ASSOC |
| 4331 | ("queueing adhoc check\n"); |
| 4332 | queue_delayed_work(priv-> |
| 4333 | workqueue, |
| 4334 | &priv-> |
| 4335 | adhoc_check, |
| 4336 | priv-> |
| 4337 | assoc_request. |
| 4338 | beacon_interval); |
| 4339 | break; |
| 4340 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4341 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4342 | priv->status &= ~STATUS_ASSOCIATING; |
| 4343 | priv->status |= STATUS_ASSOCIATED; |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 4344 | queue_work(priv->workqueue, |
| 4345 | &priv->system_config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4346 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 4347 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4348 | #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \ |
| 4349 | le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl)) |
| 4350 | if ((priv->status & STATUS_AUTH) && |
| 4351 | (IPW_GET_PACKET_STYPE(¬if->u.raw) |
| 4352 | == IEEE80211_STYPE_ASSOC_RESP)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4353 | if ((sizeof |
| 4354 | (struct |
James Ketrenos | 2b184d5 | 2005-08-03 20:33:14 -0500 | [diff] [blame] | 4355 | ieee80211_assoc_response) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4356 | <= notif->size) |
| 4357 | && (notif->size <= 2314)) { |
| 4358 | struct |
| 4359 | ieee80211_rx_stats |
| 4360 | stats = { |
| 4361 | .len = |
| 4362 | notif-> |
| 4363 | size - 1, |
| 4364 | }; |
| 4365 | |
| 4366 | IPW_DEBUG_QOS |
| 4367 | ("QoS Associate " |
| 4368 | "size %d\n", |
| 4369 | notif->size); |
| 4370 | ieee80211_rx_mgt(priv-> |
| 4371 | ieee, |
| 4372 | (struct |
James Ketrenos | 2b184d5 | 2005-08-03 20:33:14 -0500 | [diff] [blame] | 4373 | ieee80211_hdr_4addr |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4374 | *) |
| 4375 | ¬if->u.raw, &stats); |
| 4376 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4377 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4378 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4379 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4380 | schedule_work(&priv->link_up); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4381 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4382 | break; |
| 4383 | } |
| 4384 | |
| 4385 | case CMAS_AUTHENTICATED:{ |
| 4386 | if (priv-> |
| 4387 | status & (STATUS_ASSOCIATED | |
| 4388 | STATUS_AUTH)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4389 | struct notif_authenticate *auth |
| 4390 | = ¬if->u.auth; |
| 4391 | IPW_DEBUG(IPW_DL_NOTIF | |
| 4392 | IPW_DL_STATE | |
| 4393 | IPW_DL_ASSOC, |
| 4394 | "deauthenticated: '%s' " |
| 4395 | MAC_FMT |
| 4396 | ": (0x%04X) - %s \n", |
| 4397 | escape_essid(priv-> |
| 4398 | essid, |
| 4399 | priv-> |
| 4400 | essid_len), |
| 4401 | MAC_ARG(priv->bssid), |
| 4402 | ntohs(auth->status), |
| 4403 | ipw_get_status_code |
| 4404 | (ntohs |
| 4405 | (auth->status))); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4406 | |
| 4407 | priv->status &= |
| 4408 | ~(STATUS_ASSOCIATING | |
| 4409 | STATUS_AUTH | |
| 4410 | STATUS_ASSOCIATED); |
| 4411 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4412 | schedule_work(&priv->link_down); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4413 | break; |
| 4414 | } |
| 4415 | |
| 4416 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4417 | IPW_DL_ASSOC, |
| 4418 | "authenticated: '%s' " MAC_FMT |
| 4419 | "\n", |
| 4420 | escape_essid(priv->essid, |
| 4421 | priv->essid_len), |
| 4422 | MAC_ARG(priv->bssid)); |
| 4423 | break; |
| 4424 | } |
| 4425 | |
| 4426 | case CMAS_INIT:{ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4427 | if (priv->status & STATUS_AUTH) { |
| 4428 | struct |
| 4429 | ieee80211_assoc_response |
| 4430 | *resp; |
| 4431 | resp = |
| 4432 | (struct |
| 4433 | ieee80211_assoc_response |
| 4434 | *)¬if->u.raw; |
| 4435 | IPW_DEBUG(IPW_DL_NOTIF | |
| 4436 | IPW_DL_STATE | |
| 4437 | IPW_DL_ASSOC, |
| 4438 | "association failed (0x%04X): %s\n", |
| 4439 | ntohs(resp->status), |
| 4440 | ipw_get_status_code |
| 4441 | (ntohs |
| 4442 | (resp->status))); |
| 4443 | } |
| 4444 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4445 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4446 | IPW_DL_ASSOC, |
| 4447 | "disassociated: '%s' " MAC_FMT |
| 4448 | " \n", |
| 4449 | escape_essid(priv->essid, |
| 4450 | priv->essid_len), |
| 4451 | MAC_ARG(priv->bssid)); |
| 4452 | |
| 4453 | priv->status &= |
| 4454 | ~(STATUS_DISASSOCIATING | |
| 4455 | STATUS_ASSOCIATING | |
| 4456 | STATUS_ASSOCIATED | STATUS_AUTH); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4457 | if (priv->assoc_network |
| 4458 | && (priv->assoc_network-> |
| 4459 | capability & |
| 4460 | WLAN_CAPABILITY_IBSS)) |
| 4461 | ipw_remove_current_network |
| 4462 | (priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4463 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4464 | schedule_work(&priv->link_down); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4465 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4466 | break; |
| 4467 | } |
| 4468 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4469 | case CMAS_RX_ASSOC_RESP: |
| 4470 | break; |
| 4471 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4472 | default: |
| 4473 | IPW_ERROR("assoc: unknown (%d)\n", |
| 4474 | assoc->state); |
| 4475 | break; |
| 4476 | } |
| 4477 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4478 | break; |
| 4479 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4480 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4481 | case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{ |
| 4482 | struct notif_authenticate *auth = ¬if->u.auth; |
| 4483 | switch (auth->state) { |
| 4484 | case CMAS_AUTHENTICATED: |
| 4485 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4486 | "authenticated: '%s' " MAC_FMT " \n", |
| 4487 | escape_essid(priv->essid, |
| 4488 | priv->essid_len), |
| 4489 | MAC_ARG(priv->bssid)); |
| 4490 | priv->status |= STATUS_AUTH; |
| 4491 | break; |
| 4492 | |
| 4493 | case CMAS_INIT: |
| 4494 | if (priv->status & STATUS_AUTH) { |
| 4495 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4496 | IPW_DL_ASSOC, |
| 4497 | "authentication failed (0x%04X): %s\n", |
| 4498 | ntohs(auth->status), |
| 4499 | ipw_get_status_code(ntohs |
| 4500 | (auth-> |
| 4501 | status))); |
| 4502 | } |
| 4503 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4504 | IPW_DL_ASSOC, |
| 4505 | "deauthenticated: '%s' " MAC_FMT "\n", |
| 4506 | escape_essid(priv->essid, |
| 4507 | priv->essid_len), |
| 4508 | MAC_ARG(priv->bssid)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4509 | |
| 4510 | priv->status &= ~(STATUS_ASSOCIATING | |
| 4511 | STATUS_AUTH | |
| 4512 | STATUS_ASSOCIATED); |
| 4513 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4514 | schedule_work(&priv->link_down); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4515 | break; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4516 | |
| 4517 | case CMAS_TX_AUTH_SEQ_1: |
| 4518 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4519 | IPW_DL_ASSOC, "AUTH_SEQ_1\n"); |
| 4520 | break; |
| 4521 | case CMAS_RX_AUTH_SEQ_2: |
| 4522 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4523 | IPW_DL_ASSOC, "AUTH_SEQ_2\n"); |
| 4524 | break; |
| 4525 | case CMAS_AUTH_SEQ_1_PASS: |
| 4526 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4527 | IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n"); |
| 4528 | break; |
| 4529 | case CMAS_AUTH_SEQ_1_FAIL: |
| 4530 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4531 | IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n"); |
| 4532 | break; |
| 4533 | case CMAS_TX_AUTH_SEQ_3: |
| 4534 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4535 | IPW_DL_ASSOC, "AUTH_SEQ_3\n"); |
| 4536 | break; |
| 4537 | case CMAS_RX_AUTH_SEQ_4: |
| 4538 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4539 | IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n"); |
| 4540 | break; |
| 4541 | case CMAS_AUTH_SEQ_2_PASS: |
| 4542 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4543 | IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n"); |
| 4544 | break; |
| 4545 | case CMAS_AUTH_SEQ_2_FAIL: |
| 4546 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4547 | IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n"); |
| 4548 | break; |
| 4549 | case CMAS_TX_ASSOC: |
| 4550 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4551 | IPW_DL_ASSOC, "TX_ASSOC\n"); |
| 4552 | break; |
| 4553 | case CMAS_RX_ASSOC_RESP: |
| 4554 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4555 | IPW_DL_ASSOC, "RX_ASSOC_RESP\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4556 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4557 | break; |
| 4558 | case CMAS_ASSOCIATED: |
| 4559 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4560 | IPW_DL_ASSOC, "ASSOCIATED\n"); |
| 4561 | break; |
| 4562 | default: |
| 4563 | IPW_DEBUG_NOTIF("auth: failure - %d\n", |
| 4564 | auth->state); |
| 4565 | break; |
| 4566 | } |
| 4567 | break; |
| 4568 | } |
| 4569 | |
| 4570 | case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{ |
| 4571 | struct notif_channel_result *x = |
| 4572 | ¬if->u.channel_result; |
| 4573 | |
| 4574 | if (notif->size == sizeof(*x)) { |
| 4575 | IPW_DEBUG_SCAN("Scan result for channel %d\n", |
| 4576 | x->channel_num); |
| 4577 | } else { |
| 4578 | IPW_DEBUG_SCAN("Scan result of wrong size %d " |
| 4579 | "(should be %zd)\n", |
| 4580 | notif->size, sizeof(*x)); |
| 4581 | } |
| 4582 | break; |
| 4583 | } |
| 4584 | |
| 4585 | case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{ |
| 4586 | struct notif_scan_complete *x = ¬if->u.scan_complete; |
| 4587 | if (notif->size == sizeof(*x)) { |
| 4588 | IPW_DEBUG_SCAN |
| 4589 | ("Scan completed: type %d, %d channels, " |
| 4590 | "%d status\n", x->scan_type, |
| 4591 | x->num_channels, x->status); |
| 4592 | } else { |
| 4593 | IPW_ERROR("Scan completed of wrong size %d " |
| 4594 | "(should be %zd)\n", |
| 4595 | notif->size, sizeof(*x)); |
| 4596 | } |
| 4597 | |
| 4598 | priv->status &= |
| 4599 | ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); |
| 4600 | |
James Ketrenos | a0e04ab | 2005-08-25 00:49:43 -0500 | [diff] [blame] | 4601 | wake_up_interruptible(&priv->wait_state); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4602 | cancel_delayed_work(&priv->scan_check); |
| 4603 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4604 | if (priv->status & STATUS_EXIT_PENDING) |
| 4605 | break; |
| 4606 | |
| 4607 | priv->ieee->scans++; |
| 4608 | |
| 4609 | #ifdef CONFIG_IPW2200_MONITOR |
| 4610 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4611 | priv->status |= STATUS_SCAN_FORCED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4612 | queue_work(priv->workqueue, |
| 4613 | &priv->request_scan); |
| 4614 | break; |
| 4615 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4616 | priv->status &= ~STATUS_SCAN_FORCED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4617 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 4618 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4619 | if (!(priv->status & (STATUS_ASSOCIATED | |
| 4620 | STATUS_ASSOCIATING | |
| 4621 | STATUS_ROAMING | |
| 4622 | STATUS_DISASSOCIATING))) |
| 4623 | queue_work(priv->workqueue, &priv->associate); |
| 4624 | else if (priv->status & STATUS_ROAMING) { |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4625 | if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) |
| 4626 | /* If a scan completed and we are in roam mode, then |
| 4627 | * the scan that completed was the one requested as a |
| 4628 | * result of entering roam... so, schedule the |
| 4629 | * roam work */ |
| 4630 | queue_work(priv->workqueue, |
| 4631 | &priv->roam); |
| 4632 | else |
| 4633 | /* Don't schedule if we aborted the scan */ |
| 4634 | priv->status &= ~STATUS_ROAMING; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4635 | } else if (priv->status & STATUS_SCAN_PENDING) |
| 4636 | queue_work(priv->workqueue, |
| 4637 | &priv->request_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4638 | else if (priv->config & CFG_BACKGROUND_SCAN |
| 4639 | && priv->status & STATUS_ASSOCIATED) |
| 4640 | queue_delayed_work(priv->workqueue, |
| 4641 | &priv->request_scan, HZ); |
Zhu Yi | 07f02e4 | 2006-04-13 17:19:25 +0800 | [diff] [blame] | 4642 | |
| 4643 | /* Send an empty event to user space. |
| 4644 | * We don't send the received data on the event because |
| 4645 | * it would require us to do complex transcoding, and |
| 4646 | * we want to minimise the work done in the irq handler |
| 4647 | * Use a request to extract the data. |
| 4648 | * Also, we generate this even for any scan, regardless |
| 4649 | * on how the scan was initiated. User space can just |
| 4650 | * sync on periodic scan to get fresh data... |
| 4651 | * Jean II */ |
| 4652 | if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) { |
| 4653 | union iwreq_data wrqu; |
| 4654 | |
| 4655 | wrqu.data.length = 0; |
| 4656 | wrqu.data.flags = 0; |
| 4657 | wireless_send_event(priv->net_dev, SIOCGIWSCAN, |
| 4658 | &wrqu, NULL); |
| 4659 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4660 | break; |
| 4661 | } |
| 4662 | |
| 4663 | case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{ |
| 4664 | struct notif_frag_length *x = ¬if->u.frag_len; |
| 4665 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4666 | if (notif->size == sizeof(*x)) |
| 4667 | IPW_ERROR("Frag length: %d\n", |
| 4668 | le16_to_cpu(x->frag_length)); |
| 4669 | else |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4670 | IPW_ERROR("Frag length of wrong size %d " |
| 4671 | "(should be %zd)\n", |
| 4672 | notif->size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4673 | break; |
| 4674 | } |
| 4675 | |
| 4676 | case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{ |
| 4677 | struct notif_link_deterioration *x = |
| 4678 | ¬if->u.link_deterioration; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4679 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4680 | if (notif->size == sizeof(*x)) { |
| 4681 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
Cahill, Ben M | 1297715 | 2006-03-08 02:58:02 +0800 | [diff] [blame] | 4682 | "link deterioration: type %d, cnt %d\n", |
| 4683 | x->silence_notification_type, |
| 4684 | x->silence_count); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4685 | memcpy(&priv->last_link_deterioration, x, |
| 4686 | sizeof(*x)); |
| 4687 | } else { |
| 4688 | IPW_ERROR("Link Deterioration of wrong size %d " |
| 4689 | "(should be %zd)\n", |
| 4690 | notif->size, sizeof(*x)); |
| 4691 | } |
| 4692 | break; |
| 4693 | } |
| 4694 | |
| 4695 | case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{ |
| 4696 | IPW_ERROR("Dino config\n"); |
| 4697 | if (priv->hcmd |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4698 | && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4699 | IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4700 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4701 | break; |
| 4702 | } |
| 4703 | |
| 4704 | case HOST_NOTIFICATION_STATUS_BEACON_STATE:{ |
| 4705 | struct notif_beacon_state *x = ¬if->u.beacon_state; |
| 4706 | if (notif->size != sizeof(*x)) { |
| 4707 | IPW_ERROR |
| 4708 | ("Beacon state of wrong size %d (should " |
| 4709 | "be %zd)\n", notif->size, sizeof(*x)); |
| 4710 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4711 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4712 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4713 | if (le32_to_cpu(x->state) == |
| 4714 | HOST_NOTIFICATION_STATUS_BEACON_MISSING) |
| 4715 | ipw_handle_missed_beacon(priv, |
| 4716 | le32_to_cpu(x-> |
| 4717 | number)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4718 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4719 | break; |
| 4720 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4721 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4722 | case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{ |
| 4723 | struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key; |
| 4724 | if (notif->size == sizeof(*x)) { |
| 4725 | IPW_ERROR("TGi Tx Key: state 0x%02x sec type " |
| 4726 | "0x%02x station %d\n", |
| 4727 | x->key_state, x->security_type, |
| 4728 | x->station_index); |
| 4729 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4730 | } |
| 4731 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4732 | IPW_ERROR |
| 4733 | ("TGi Tx Key of wrong size %d (should be %zd)\n", |
| 4734 | notif->size, sizeof(*x)); |
| 4735 | break; |
| 4736 | } |
| 4737 | |
| 4738 | case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{ |
| 4739 | struct notif_calibration *x = ¬if->u.calibration; |
| 4740 | |
| 4741 | if (notif->size == sizeof(*x)) { |
| 4742 | memcpy(&priv->calib, x, sizeof(*x)); |
| 4743 | IPW_DEBUG_INFO("TODO: Calibration\n"); |
| 4744 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4745 | } |
| 4746 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4747 | IPW_ERROR |
| 4748 | ("Calibration of wrong size %d (should be %zd)\n", |
| 4749 | notif->size, sizeof(*x)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4750 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4751 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4752 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4753 | case HOST_NOTIFICATION_NOISE_STATS:{ |
| 4754 | if (notif->size == sizeof(u32)) { |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 4755 | priv->exp_avg_noise = |
| 4756 | exponential_average(priv->exp_avg_noise, |
| 4757 | (u8) (le32_to_cpu(notif->u.noise.value) & 0xff), |
| 4758 | DEPTH_NOISE); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4759 | break; |
| 4760 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4761 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4762 | IPW_ERROR |
| 4763 | ("Noise stat is wrong size %d (should be %zd)\n", |
| 4764 | notif->size, sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4765 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4766 | } |
| 4767 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4768 | default: |
Zhu Yi | 1dd31b6 | 2006-02-20 18:28:09 -0800 | [diff] [blame] | 4769 | IPW_DEBUG_NOTIF("Unknown notification: " |
| 4770 | "subtype=%d,flags=0x%2x,size=%d\n", |
| 4771 | notif->subtype, notif->flags, notif->size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4772 | } |
| 4773 | } |
| 4774 | |
| 4775 | /** |
| 4776 | * Destroys all DMA structures and initialise them again |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4777 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4778 | * @param priv |
| 4779 | * @return error code |
| 4780 | */ |
| 4781 | static int ipw_queue_reset(struct ipw_priv *priv) |
| 4782 | { |
| 4783 | int rc = 0; |
| 4784 | /** @todo customize queue sizes */ |
| 4785 | int nTx = 64, nTxCmd = 8; |
| 4786 | ipw_tx_queue_free(priv); |
| 4787 | /* Tx CMD queue */ |
| 4788 | rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4789 | IPW_TX_CMD_QUEUE_READ_INDEX, |
| 4790 | IPW_TX_CMD_QUEUE_WRITE_INDEX, |
| 4791 | IPW_TX_CMD_QUEUE_BD_BASE, |
| 4792 | IPW_TX_CMD_QUEUE_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4793 | if (rc) { |
| 4794 | IPW_ERROR("Tx Cmd queue init failed\n"); |
| 4795 | goto error; |
| 4796 | } |
| 4797 | /* Tx queue(s) */ |
| 4798 | rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4799 | IPW_TX_QUEUE_0_READ_INDEX, |
| 4800 | IPW_TX_QUEUE_0_WRITE_INDEX, |
| 4801 | IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4802 | if (rc) { |
| 4803 | IPW_ERROR("Tx 0 queue init failed\n"); |
| 4804 | goto error; |
| 4805 | } |
| 4806 | rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4807 | IPW_TX_QUEUE_1_READ_INDEX, |
| 4808 | IPW_TX_QUEUE_1_WRITE_INDEX, |
| 4809 | IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4810 | if (rc) { |
| 4811 | IPW_ERROR("Tx 1 queue init failed\n"); |
| 4812 | goto error; |
| 4813 | } |
| 4814 | rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4815 | IPW_TX_QUEUE_2_READ_INDEX, |
| 4816 | IPW_TX_QUEUE_2_WRITE_INDEX, |
| 4817 | IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4818 | if (rc) { |
| 4819 | IPW_ERROR("Tx 2 queue init failed\n"); |
| 4820 | goto error; |
| 4821 | } |
| 4822 | rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4823 | IPW_TX_QUEUE_3_READ_INDEX, |
| 4824 | IPW_TX_QUEUE_3_WRITE_INDEX, |
| 4825 | IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4826 | if (rc) { |
| 4827 | IPW_ERROR("Tx 3 queue init failed\n"); |
| 4828 | goto error; |
| 4829 | } |
| 4830 | /* statistics */ |
| 4831 | priv->rx_bufs_min = 0; |
| 4832 | priv->rx_pend_max = 0; |
| 4833 | return rc; |
| 4834 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4835 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4836 | ipw_tx_queue_free(priv); |
| 4837 | return rc; |
| 4838 | } |
| 4839 | |
| 4840 | /** |
| 4841 | * Reclaim Tx queue entries no more used by NIC. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4842 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4843 | * When FW adwances 'R' index, all entries between old and |
| 4844 | * new 'R' index need to be reclaimed. As result, some free space |
| 4845 | * forms. If there is enough free space (> low mark), wake Tx queue. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4846 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4847 | * @note Need to protect against garbage in 'R' index |
| 4848 | * @param priv |
| 4849 | * @param txq |
| 4850 | * @param qindex |
| 4851 | * @return Number of used entries remains in the queue |
| 4852 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4853 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4854 | struct clx2_tx_queue *txq, int qindex) |
| 4855 | { |
| 4856 | u32 hw_tail; |
| 4857 | int used; |
| 4858 | struct clx2_queue *q = &txq->q; |
| 4859 | |
| 4860 | hw_tail = ipw_read32(priv, q->reg_r); |
| 4861 | if (hw_tail >= q->n_bd) { |
| 4862 | IPW_ERROR |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4863 | ("Read index for DMA queue (%d) is out of range [0-%d)\n", |
| 4864 | hw_tail, q->n_bd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4865 | goto done; |
| 4866 | } |
| 4867 | for (; q->last_used != hw_tail; |
| 4868 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { |
| 4869 | ipw_queue_tx_free_tfd(priv, txq); |
| 4870 | priv->tx_packets++; |
| 4871 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4872 | done: |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 4873 | if ((ipw_queue_space(q) > q->low_mark) && |
| 4874 | (qindex >= 0) && |
| 4875 | (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev)) |
| 4876 | netif_wake_queue(priv->net_dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4877 | used = q->first_empty - q->last_used; |
| 4878 | if (used < 0) |
| 4879 | used += q->n_bd; |
| 4880 | |
| 4881 | return used; |
| 4882 | } |
| 4883 | |
| 4884 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, |
| 4885 | int len, int sync) |
| 4886 | { |
| 4887 | struct clx2_tx_queue *txq = &priv->txq_cmd; |
| 4888 | struct clx2_queue *q = &txq->q; |
| 4889 | struct tfd_frame *tfd; |
| 4890 | |
| 4891 | if (ipw_queue_space(q) < (sync ? 1 : 2)) { |
| 4892 | IPW_ERROR("No space for Tx\n"); |
| 4893 | return -EBUSY; |
| 4894 | } |
| 4895 | |
| 4896 | tfd = &txq->bd[q->first_empty]; |
| 4897 | txq->txb[q->first_empty] = NULL; |
| 4898 | |
| 4899 | memset(tfd, 0, sizeof(*tfd)); |
| 4900 | tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE; |
| 4901 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; |
| 4902 | priv->hcmd_seq++; |
| 4903 | tfd->u.cmd.index = hcmd; |
| 4904 | tfd->u.cmd.length = len; |
| 4905 | memcpy(tfd->u.cmd.payload, buf, len); |
| 4906 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); |
| 4907 | ipw_write32(priv, q->reg_w, q->first_empty); |
| 4908 | _ipw_read32(priv, 0x90); |
| 4909 | |
| 4910 | return 0; |
| 4911 | } |
| 4912 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4913 | /* |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4914 | * Rx theory of operation |
| 4915 | * |
| 4916 | * The host allocates 32 DMA target addresses and passes the host address |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4917 | * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4918 | * 0 to 31 |
| 4919 | * |
| 4920 | * Rx Queue Indexes |
| 4921 | * The host/firmware share two index registers for managing the Rx buffers. |
| 4922 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4923 | * The READ index maps to the first position that the firmware may be writing |
| 4924 | * to -- the driver can read up to (but not including) this position and get |
| 4925 | * good data. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4926 | * The READ index is managed by the firmware once the card is enabled. |
| 4927 | * |
| 4928 | * The WRITE index maps to the last position the driver has read from -- the |
| 4929 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 4930 | * |
| 4931 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4932 | * WRITE = READ. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4933 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4934 | * During initialization the host sets up the READ queue position to the first |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4935 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 4936 | * |
| 4937 | * When the firmware places a packet in a buffer it will advance the READ index |
| 4938 | * and fire the RX interrupt. The driver can then query the READ index and |
| 4939 | * process as many packets as possible, moving the WRITE index forward as it |
| 4940 | * resets the Rx queue buffers with new memory. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4941 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4942 | * The management in the driver is as follows: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4943 | * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4944 | * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4945 | * to replensish the ipw->rxq->rx_free. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4946 | * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the |
| 4947 | * ipw->rxq is replenished and the READ INDEX is updated (updating the |
| 4948 | * 'processed' and 'read' driver indexes as well) |
| 4949 | * + A received packet is processed and handed to the kernel network stack, |
| 4950 | * detached from the ipw->rxq. The driver 'processed' index is updated. |
| 4951 | * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4952 | * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ |
| 4953 | * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4954 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 4955 | * |
| 4956 | * |
| 4957 | * Driver sequence: |
| 4958 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4959 | * ipw_rx_queue_alloc() Allocates rx_free |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4960 | * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls |
| 4961 | * ipw_rx_queue_restock |
| 4962 | * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx |
| 4963 | * queue, updates firmware pointers, and updates |
| 4964 | * the WRITE index. If insufficient rx_free buffers |
| 4965 | * are available, schedules ipw_rx_queue_replenish |
| 4966 | * |
| 4967 | * -- enable interrupts -- |
| 4968 | * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4969 | * READ INDEX, detaching the SKB from the pool. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4970 | * Moves the packet buffer from queue to rx_used. |
| 4971 | * Calls ipw_rx_queue_restock to refill any empty |
| 4972 | * slots. |
| 4973 | * ... |
| 4974 | * |
| 4975 | */ |
| 4976 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4977 | /* |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4978 | * If there are slots in the RX queue that need to be restocked, |
| 4979 | * and we have free pre-allocated buffers, fill the ranks as much |
| 4980 | * as we can pulling from rx_free. |
| 4981 | * |
| 4982 | * This moves the 'write' index forward to catch up with 'processed', and |
| 4983 | * also updates the memory address in the firmware to reference the new |
| 4984 | * target buffer. |
| 4985 | */ |
| 4986 | static void ipw_rx_queue_restock(struct ipw_priv *priv) |
| 4987 | { |
| 4988 | struct ipw_rx_queue *rxq = priv->rxq; |
| 4989 | struct list_head *element; |
| 4990 | struct ipw_rx_mem_buffer *rxb; |
| 4991 | unsigned long flags; |
| 4992 | int write; |
| 4993 | |
| 4994 | spin_lock_irqsave(&rxq->lock, flags); |
| 4995 | write = rxq->write; |
| 4996 | while ((rxq->write != rxq->processed) && (rxq->free_count)) { |
| 4997 | element = rxq->rx_free.next; |
| 4998 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); |
| 4999 | list_del(element); |
| 5000 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5001 | ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5002 | rxb->dma_addr); |
| 5003 | rxq->queue[rxq->write] = rxb; |
| 5004 | rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE; |
| 5005 | rxq->free_count--; |
| 5006 | } |
| 5007 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 5008 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5009 | /* If the pre-allocated buffer pool is dropping low, schedule to |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5010 | * refill it */ |
| 5011 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 5012 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 5013 | |
| 5014 | /* If we've added more space for the firmware to place data, tell it */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5015 | if (write != rxq->write) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5016 | ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5017 | } |
| 5018 | |
| 5019 | /* |
| 5020 | * Move all used packet from rx_used to rx_free, allocating a new SKB for each. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5021 | * Also restock the Rx queue via ipw_rx_queue_restock. |
| 5022 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5023 | * This is called as a scheduled work item (except for during intialization) |
| 5024 | */ |
| 5025 | static void ipw_rx_queue_replenish(void *data) |
| 5026 | { |
| 5027 | struct ipw_priv *priv = data; |
| 5028 | struct ipw_rx_queue *rxq = priv->rxq; |
| 5029 | struct list_head *element; |
| 5030 | struct ipw_rx_mem_buffer *rxb; |
| 5031 | unsigned long flags; |
| 5032 | |
| 5033 | spin_lock_irqsave(&rxq->lock, flags); |
| 5034 | while (!list_empty(&rxq->rx_used)) { |
| 5035 | element = rxq->rx_used.next; |
| 5036 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5037 | rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5038 | if (!rxb->skb) { |
| 5039 | printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n", |
| 5040 | priv->net_dev->name); |
| 5041 | /* We don't reschedule replenish work here -- we will |
| 5042 | * call the restock method and if it still needs |
| 5043 | * more buffers it will schedule replenish */ |
| 5044 | break; |
| 5045 | } |
| 5046 | list_del(element); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5047 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5048 | rxb->dma_addr = |
| 5049 | pci_map_single(priv->pci_dev, rxb->skb->data, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5050 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5051 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5052 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 5053 | rxq->free_count++; |
| 5054 | } |
| 5055 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 5056 | |
| 5057 | ipw_rx_queue_restock(priv); |
| 5058 | } |
| 5059 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5060 | static void ipw_bg_rx_queue_replenish(void *data) |
| 5061 | { |
| 5062 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5063 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5064 | ipw_rx_queue_replenish(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5065 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5066 | } |
| 5067 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5068 | /* Assumes that the skb field of the buffers in 'pool' is kept accurate. |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5069 | * If an SKB has been detached, the POOL needs to have its SKB set to NULL |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5070 | * This free routine walks the list of POOL entries and if SKB is set to |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5071 | * non NULL it is unmapped and freed |
| 5072 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5073 | static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5074 | { |
| 5075 | int i; |
| 5076 | |
| 5077 | if (!rxq) |
| 5078 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5079 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5080 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
| 5081 | if (rxq->pool[i].skb != NULL) { |
| 5082 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5083 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5084 | dev_kfree_skb(rxq->pool[i].skb); |
| 5085 | } |
| 5086 | } |
| 5087 | |
| 5088 | kfree(rxq); |
| 5089 | } |
| 5090 | |
| 5091 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv) |
| 5092 | { |
| 5093 | struct ipw_rx_queue *rxq; |
| 5094 | int i; |
| 5095 | |
Takis | c75f474 | 2005-12-01 01:41:45 -0800 | [diff] [blame] | 5096 | rxq = kzalloc(sizeof(*rxq), GFP_KERNEL); |
Panagiotis Issaris | ad18b0e | 2005-09-05 04:14:10 +0200 | [diff] [blame] | 5097 | if (unlikely(!rxq)) { |
| 5098 | IPW_ERROR("memory allocation failed\n"); |
| 5099 | return NULL; |
| 5100 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5101 | spin_lock_init(&rxq->lock); |
| 5102 | INIT_LIST_HEAD(&rxq->rx_free); |
| 5103 | INIT_LIST_HEAD(&rxq->rx_used); |
| 5104 | |
| 5105 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5106 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5107 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 5108 | |
| 5109 | /* Set us so that we have processed and used all buffers, but have |
| 5110 | * not restocked the Rx queue with fresh buffers */ |
| 5111 | rxq->read = rxq->write = 0; |
| 5112 | rxq->processed = RX_QUEUE_SIZE - 1; |
| 5113 | rxq->free_count = 0; |
| 5114 | |
| 5115 | return rxq; |
| 5116 | } |
| 5117 | |
| 5118 | static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate) |
| 5119 | { |
| 5120 | rate &= ~IEEE80211_BASIC_RATE_MASK; |
| 5121 | if (ieee_mode == IEEE_A) { |
| 5122 | switch (rate) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5123 | case IEEE80211_OFDM_RATE_6MB: |
| 5124 | return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5125 | 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5126 | case IEEE80211_OFDM_RATE_9MB: |
| 5127 | return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5128 | 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5129 | case IEEE80211_OFDM_RATE_12MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5130 | return priv-> |
| 5131 | rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5132 | case IEEE80211_OFDM_RATE_18MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5133 | return priv-> |
| 5134 | rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5135 | case IEEE80211_OFDM_RATE_24MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5136 | return priv-> |
| 5137 | rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5138 | case IEEE80211_OFDM_RATE_36MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5139 | return priv-> |
| 5140 | rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5141 | case IEEE80211_OFDM_RATE_48MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5142 | return priv-> |
| 5143 | rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5144 | case IEEE80211_OFDM_RATE_54MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5145 | return priv-> |
| 5146 | rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5147 | default: |
| 5148 | return 0; |
| 5149 | } |
| 5150 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5151 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5152 | /* B and G mixed */ |
| 5153 | switch (rate) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5154 | case IEEE80211_CCK_RATE_1MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5155 | return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5156 | case IEEE80211_CCK_RATE_2MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5157 | return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5158 | case IEEE80211_CCK_RATE_5MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5159 | return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5160 | case IEEE80211_CCK_RATE_11MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5161 | return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0; |
| 5162 | } |
| 5163 | |
| 5164 | /* If we are limited to B modulations, bail at this point */ |
| 5165 | if (ieee_mode == IEEE_B) |
| 5166 | return 0; |
| 5167 | |
| 5168 | /* G */ |
| 5169 | switch (rate) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5170 | case IEEE80211_OFDM_RATE_6MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5171 | return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5172 | case IEEE80211_OFDM_RATE_9MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5173 | return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5174 | case IEEE80211_OFDM_RATE_12MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5175 | return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5176 | case IEEE80211_OFDM_RATE_18MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5177 | return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5178 | case IEEE80211_OFDM_RATE_24MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5179 | return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5180 | case IEEE80211_OFDM_RATE_36MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5181 | return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5182 | case IEEE80211_OFDM_RATE_48MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5183 | return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5184 | case IEEE80211_OFDM_RATE_54MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5185 | return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0; |
| 5186 | } |
| 5187 | |
| 5188 | return 0; |
| 5189 | } |
| 5190 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5191 | static int ipw_compatible_rates(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5192 | const struct ieee80211_network *network, |
| 5193 | struct ipw_supported_rates *rates) |
| 5194 | { |
| 5195 | int num_rates, i; |
| 5196 | |
| 5197 | memset(rates, 0, sizeof(*rates)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5198 | num_rates = min(network->rates_len, (u8) IPW_MAX_RATES); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5199 | rates->num_rates = 0; |
| 5200 | for (i = 0; i < num_rates; i++) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5201 | if (!ipw_is_rate_in_mask(priv, network->mode, |
| 5202 | network->rates[i])) { |
| 5203 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5204 | if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5205 | IPW_DEBUG_SCAN("Adding masked mandatory " |
| 5206 | "rate %02X\n", |
| 5207 | network->rates[i]); |
| 5208 | rates->supported_rates[rates->num_rates++] = |
| 5209 | network->rates[i]; |
| 5210 | continue; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5211 | } |
| 5212 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5213 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
| 5214 | network->rates[i], priv->rates_mask); |
| 5215 | continue; |
| 5216 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5217 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5218 | rates->supported_rates[rates->num_rates++] = network->rates[i]; |
| 5219 | } |
| 5220 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5221 | num_rates = min(network->rates_ex_len, |
| 5222 | (u8) (IPW_MAX_RATES - num_rates)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5223 | for (i = 0; i < num_rates; i++) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5224 | if (!ipw_is_rate_in_mask(priv, network->mode, |
| 5225 | network->rates_ex[i])) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5226 | if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5227 | IPW_DEBUG_SCAN("Adding masked mandatory " |
| 5228 | "rate %02X\n", |
| 5229 | network->rates_ex[i]); |
| 5230 | rates->supported_rates[rates->num_rates++] = |
| 5231 | network->rates[i]; |
| 5232 | continue; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5233 | } |
| 5234 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5235 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
| 5236 | network->rates_ex[i], priv->rates_mask); |
| 5237 | continue; |
| 5238 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5239 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5240 | rates->supported_rates[rates->num_rates++] = |
| 5241 | network->rates_ex[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5242 | } |
| 5243 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5244 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5245 | } |
| 5246 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 5247 | static void ipw_copy_rates(struct ipw_supported_rates *dest, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5248 | const struct ipw_supported_rates *src) |
| 5249 | { |
| 5250 | u8 i; |
| 5251 | for (i = 0; i < src->num_rates; i++) |
| 5252 | dest->supported_rates[i] = src->supported_rates[i]; |
| 5253 | dest->num_rates = src->num_rates; |
| 5254 | } |
| 5255 | |
| 5256 | /* TODO: Look at sniffed packets in the air to determine if the basic rate |
| 5257 | * mask should ever be used -- right now all callers to add the scan rates are |
| 5258 | * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */ |
| 5259 | static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5260 | u8 modulation, u32 rate_mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5261 | { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5262 | u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5263 | IEEE80211_BASIC_RATE_MASK : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5264 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5265 | if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5266 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5267 | IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5268 | |
| 5269 | if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5270 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5271 | IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5272 | |
| 5273 | if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5274 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5275 | IEEE80211_CCK_RATE_5MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5276 | |
| 5277 | if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5278 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5279 | IEEE80211_CCK_RATE_11MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5280 | } |
| 5281 | |
| 5282 | static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5283 | u8 modulation, u32 rate_mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5284 | { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5285 | u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5286 | IEEE80211_BASIC_RATE_MASK : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5287 | |
| 5288 | if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5289 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5290 | IEEE80211_OFDM_RATE_6MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5291 | |
| 5292 | if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5293 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5294 | IEEE80211_OFDM_RATE_9MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5295 | |
| 5296 | if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5297 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5298 | IEEE80211_OFDM_RATE_12MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5299 | |
| 5300 | if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5301 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5302 | IEEE80211_OFDM_RATE_18MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5303 | |
| 5304 | if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5305 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5306 | IEEE80211_OFDM_RATE_24MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5307 | |
| 5308 | if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5309 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5310 | IEEE80211_OFDM_RATE_36MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5311 | |
| 5312 | if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5313 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5314 | IEEE80211_OFDM_RATE_48MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5315 | |
| 5316 | if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5317 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5318 | IEEE80211_OFDM_RATE_54MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5319 | } |
| 5320 | |
| 5321 | struct ipw_network_match { |
| 5322 | struct ieee80211_network *network; |
| 5323 | struct ipw_supported_rates rates; |
| 5324 | }; |
| 5325 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5326 | static int ipw_find_adhoc_network(struct ipw_priv *priv, |
| 5327 | struct ipw_network_match *match, |
| 5328 | struct ieee80211_network *network, |
| 5329 | int roaming) |
| 5330 | { |
| 5331 | struct ipw_supported_rates rates; |
| 5332 | |
| 5333 | /* Verify that this network's capability is compatible with the |
| 5334 | * current mode (AdHoc or Infrastructure) */ |
| 5335 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 5336 | !(network->capability & WLAN_CAPABILITY_IBSS))) { |
| 5337 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to " |
| 5338 | "capability mismatch.\n", |
| 5339 | escape_essid(network->ssid, network->ssid_len), |
| 5340 | MAC_ARG(network->bssid)); |
| 5341 | return 0; |
| 5342 | } |
| 5343 | |
| 5344 | /* If we do not have an ESSID for this AP, we can not associate with |
| 5345 | * it */ |
| 5346 | if (network->flags & NETWORK_EMPTY_ESSID) { |
| 5347 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5348 | "because of hidden ESSID.\n", |
| 5349 | escape_essid(network->ssid, network->ssid_len), |
| 5350 | MAC_ARG(network->bssid)); |
| 5351 | return 0; |
| 5352 | } |
| 5353 | |
| 5354 | if (unlikely(roaming)) { |
| 5355 | /* If we are roaming, then ensure check if this is a valid |
| 5356 | * network to try and roam to */ |
| 5357 | if ((network->ssid_len != match->network->ssid_len) || |
| 5358 | memcmp(network->ssid, match->network->ssid, |
| 5359 | network->ssid_len)) { |
| 5360 | IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded " |
| 5361 | "because of non-network ESSID.\n", |
| 5362 | escape_essid(network->ssid, |
| 5363 | network->ssid_len), |
| 5364 | MAC_ARG(network->bssid)); |
| 5365 | return 0; |
| 5366 | } |
| 5367 | } else { |
| 5368 | /* If an ESSID has been configured then compare the broadcast |
| 5369 | * ESSID to ours */ |
| 5370 | if ((priv->config & CFG_STATIC_ESSID) && |
| 5371 | ((network->ssid_len != priv->essid_len) || |
| 5372 | memcmp(network->ssid, priv->essid, |
| 5373 | min(network->ssid_len, priv->essid_len)))) { |
| 5374 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5375 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5376 | strncpy(escaped, |
| 5377 | escape_essid(network->ssid, network->ssid_len), |
| 5378 | sizeof(escaped)); |
| 5379 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5380 | "because of ESSID mismatch: '%s'.\n", |
| 5381 | escaped, MAC_ARG(network->bssid), |
| 5382 | escape_essid(priv->essid, |
| 5383 | priv->essid_len)); |
| 5384 | return 0; |
| 5385 | } |
| 5386 | } |
| 5387 | |
| 5388 | /* If the old network rate is better than this one, don't bother |
| 5389 | * testing everything else. */ |
| 5390 | |
| 5391 | if (network->time_stamp[0] < match->network->time_stamp[0]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5392 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
| 5393 | "current network.\n", |
| 5394 | escape_essid(match->network->ssid, |
| 5395 | match->network->ssid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5396 | return 0; |
| 5397 | } else if (network->time_stamp[1] < match->network->time_stamp[1]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5398 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
| 5399 | "current network.\n", |
| 5400 | escape_essid(match->network->ssid, |
| 5401 | match->network->ssid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5402 | return 0; |
| 5403 | } |
| 5404 | |
| 5405 | /* Now go through and see if the requested network is valid... */ |
| 5406 | if (priv->ieee->scan_age != 0 && |
| 5407 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
| 5408 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5409 | "because of age: %ums.\n", |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5410 | escape_essid(network->ssid, network->ssid_len), |
| 5411 | MAC_ARG(network->bssid), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5412 | jiffies_to_msecs(jiffies - |
| 5413 | network->last_scanned)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5414 | return 0; |
| 5415 | } |
| 5416 | |
| 5417 | if ((priv->config & CFG_STATIC_CHANNEL) && |
| 5418 | (network->channel != priv->channel)) { |
| 5419 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5420 | "because of channel mismatch: %d != %d.\n", |
| 5421 | escape_essid(network->ssid, network->ssid_len), |
| 5422 | MAC_ARG(network->bssid), |
| 5423 | network->channel, priv->channel); |
| 5424 | return 0; |
| 5425 | } |
| 5426 | |
| 5427 | /* Verify privacy compatability */ |
| 5428 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
| 5429 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
| 5430 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5431 | "because of privacy mismatch: %s != %s.\n", |
| 5432 | escape_essid(network->ssid, network->ssid_len), |
| 5433 | MAC_ARG(network->bssid), |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5434 | priv-> |
| 5435 | capability & CAP_PRIVACY_ON ? "on" : "off", |
| 5436 | network-> |
| 5437 | capability & WLAN_CAPABILITY_PRIVACY ? "on" : |
| 5438 | "off"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5439 | return 0; |
| 5440 | } |
| 5441 | |
| 5442 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
| 5443 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5444 | "because of the same BSSID match: " MAC_FMT |
| 5445 | ".\n", escape_essid(network->ssid, |
| 5446 | network->ssid_len), |
| 5447 | MAC_ARG(network->bssid), MAC_ARG(priv->bssid)); |
| 5448 | return 0; |
| 5449 | } |
| 5450 | |
| 5451 | /* Filter out any incompatible freq / mode combinations */ |
| 5452 | if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) { |
| 5453 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5454 | "because of invalid frequency/mode " |
| 5455 | "combination.\n", |
| 5456 | escape_essid(network->ssid, network->ssid_len), |
| 5457 | MAC_ARG(network->bssid)); |
| 5458 | return 0; |
| 5459 | } |
| 5460 | |
| 5461 | /* Ensure that the rates supported by the driver are compatible with |
| 5462 | * this AP, including verification of basic rates (mandatory) */ |
| 5463 | if (!ipw_compatible_rates(priv, network, &rates)) { |
| 5464 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5465 | "because configured rate mask excludes " |
| 5466 | "AP mandatory rate.\n", |
| 5467 | escape_essid(network->ssid, network->ssid_len), |
| 5468 | MAC_ARG(network->bssid)); |
| 5469 | return 0; |
| 5470 | } |
| 5471 | |
| 5472 | if (rates.num_rates == 0) { |
| 5473 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5474 | "because of no compatible rates.\n", |
| 5475 | escape_essid(network->ssid, network->ssid_len), |
| 5476 | MAC_ARG(network->bssid)); |
| 5477 | return 0; |
| 5478 | } |
| 5479 | |
| 5480 | /* TODO: Perform any further minimal comparititive tests. We do not |
| 5481 | * want to put too much policy logic here; intelligent scan selection |
| 5482 | * should occur within a generic IEEE 802.11 user space tool. */ |
| 5483 | |
| 5484 | /* Set up 'new' AP to this network */ |
| 5485 | ipw_copy_rates(&match->rates, &rates); |
| 5486 | match->network = network; |
| 5487 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n", |
| 5488 | escape_essid(network->ssid, network->ssid_len), |
| 5489 | MAC_ARG(network->bssid)); |
| 5490 | |
| 5491 | return 1; |
| 5492 | } |
| 5493 | |
| 5494 | static void ipw_merge_adhoc_network(void *data) |
| 5495 | { |
| 5496 | struct ipw_priv *priv = data; |
| 5497 | struct ieee80211_network *network = NULL; |
| 5498 | struct ipw_network_match match = { |
| 5499 | .network = priv->assoc_network |
| 5500 | }; |
| 5501 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5502 | if ((priv->status & STATUS_ASSOCIATED) && |
| 5503 | (priv->ieee->iw_mode == IW_MODE_ADHOC)) { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5504 | /* First pass through ROAM process -- look for a better |
| 5505 | * network */ |
| 5506 | unsigned long flags; |
| 5507 | |
| 5508 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 5509 | list_for_each_entry(network, &priv->ieee->network_list, list) { |
| 5510 | if (network != priv->assoc_network) |
| 5511 | ipw_find_adhoc_network(priv, &match, network, |
| 5512 | 1); |
| 5513 | } |
| 5514 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 5515 | |
| 5516 | if (match.network == priv->assoc_network) { |
| 5517 | IPW_DEBUG_MERGE("No better ADHOC in this network to " |
| 5518 | "merge to.\n"); |
| 5519 | return; |
| 5520 | } |
| 5521 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5522 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5523 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) { |
| 5524 | IPW_DEBUG_MERGE("remove network %s\n", |
| 5525 | escape_essid(priv->essid, |
| 5526 | priv->essid_len)); |
| 5527 | ipw_remove_current_network(priv); |
| 5528 | } |
| 5529 | |
| 5530 | ipw_disassociate(priv); |
| 5531 | priv->assoc_network = match.network; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5532 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5533 | return; |
| 5534 | } |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5535 | } |
| 5536 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5537 | static int ipw_best_network(struct ipw_priv *priv, |
| 5538 | struct ipw_network_match *match, |
| 5539 | struct ieee80211_network *network, int roaming) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5540 | { |
| 5541 | struct ipw_supported_rates rates; |
| 5542 | |
| 5543 | /* Verify that this network's capability is compatible with the |
| 5544 | * current mode (AdHoc or Infrastructure) */ |
| 5545 | if ((priv->ieee->iw_mode == IW_MODE_INFRA && |
Jouni Malinen | 2474385 | 2005-08-14 20:59:59 -0700 | [diff] [blame] | 5546 | !(network->capability & WLAN_CAPABILITY_ESS)) || |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5547 | (priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 5548 | !(network->capability & WLAN_CAPABILITY_IBSS))) { |
| 5549 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5550 | "capability mismatch.\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5551 | escape_essid(network->ssid, network->ssid_len), |
| 5552 | MAC_ARG(network->bssid)); |
| 5553 | return 0; |
| 5554 | } |
| 5555 | |
| 5556 | /* If we do not have an ESSID for this AP, we can not associate with |
| 5557 | * it */ |
| 5558 | if (network->flags & NETWORK_EMPTY_ESSID) { |
| 5559 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5560 | "because of hidden ESSID.\n", |
| 5561 | escape_essid(network->ssid, network->ssid_len), |
| 5562 | MAC_ARG(network->bssid)); |
| 5563 | return 0; |
| 5564 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5565 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5566 | if (unlikely(roaming)) { |
| 5567 | /* If we are roaming, then ensure check if this is a valid |
| 5568 | * network to try and roam to */ |
| 5569 | if ((network->ssid_len != match->network->ssid_len) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5570 | memcmp(network->ssid, match->network->ssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5571 | network->ssid_len)) { |
| 5572 | IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded " |
| 5573 | "because of non-network ESSID.\n", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5574 | escape_essid(network->ssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5575 | network->ssid_len), |
| 5576 | MAC_ARG(network->bssid)); |
| 5577 | return 0; |
| 5578 | } |
| 5579 | } else { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5580 | /* If an ESSID has been configured then compare the broadcast |
| 5581 | * ESSID to ours */ |
| 5582 | if ((priv->config & CFG_STATIC_ESSID) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5583 | ((network->ssid_len != priv->essid_len) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5584 | memcmp(network->ssid, priv->essid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5585 | min(network->ssid_len, priv->essid_len)))) { |
| 5586 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5587 | strncpy(escaped, |
| 5588 | escape_essid(network->ssid, network->ssid_len), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5589 | sizeof(escaped)); |
| 5590 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5591 | "because of ESSID mismatch: '%s'.\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5592 | escaped, MAC_ARG(network->bssid), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5593 | escape_essid(priv->essid, |
| 5594 | priv->essid_len)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5595 | return 0; |
| 5596 | } |
| 5597 | } |
| 5598 | |
| 5599 | /* If the old network rate is better than this one, don't bother |
| 5600 | * testing everything else. */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5601 | if (match->network && match->network->stats.rssi > network->stats.rssi) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5602 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5603 | strncpy(escaped, |
| 5604 | escape_essid(network->ssid, network->ssid_len), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5605 | sizeof(escaped)); |
| 5606 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because " |
| 5607 | "'%s (" MAC_FMT ")' has a stronger signal.\n", |
| 5608 | escaped, MAC_ARG(network->bssid), |
| 5609 | escape_essid(match->network->ssid, |
| 5610 | match->network->ssid_len), |
| 5611 | MAC_ARG(match->network->bssid)); |
| 5612 | return 0; |
| 5613 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5614 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5615 | /* If this network has already had an association attempt within the |
| 5616 | * last 3 seconds, do not try and associate again... */ |
| 5617 | if (network->last_associate && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5618 | time_after(network->last_associate + (HZ * 3UL), jiffies)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5619 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5620 | "because of storming (%ums since last " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5621 | "assoc attempt).\n", |
| 5622 | escape_essid(network->ssid, network->ssid_len), |
| 5623 | MAC_ARG(network->bssid), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5624 | jiffies_to_msecs(jiffies - |
| 5625 | network->last_associate)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5626 | return 0; |
| 5627 | } |
| 5628 | |
| 5629 | /* Now go through and see if the requested network is valid... */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5630 | if (priv->ieee->scan_age != 0 && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5631 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5632 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5633 | "because of age: %ums.\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5634 | escape_essid(network->ssid, network->ssid_len), |
| 5635 | MAC_ARG(network->bssid), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5636 | jiffies_to_msecs(jiffies - |
| 5637 | network->last_scanned)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5638 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5639 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5640 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5641 | if ((priv->config & CFG_STATIC_CHANNEL) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5642 | (network->channel != priv->channel)) { |
| 5643 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5644 | "because of channel mismatch: %d != %d.\n", |
| 5645 | escape_essid(network->ssid, network->ssid_len), |
| 5646 | MAC_ARG(network->bssid), |
| 5647 | network->channel, priv->channel); |
| 5648 | return 0; |
| 5649 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5650 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5651 | /* Verify privacy compatability */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5652 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5653 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
| 5654 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5655 | "because of privacy mismatch: %s != %s.\n", |
| 5656 | escape_essid(network->ssid, network->ssid_len), |
| 5657 | MAC_ARG(network->bssid), |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5658 | priv->capability & CAP_PRIVACY_ON ? "on" : |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5659 | "off", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5660 | network->capability & |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5661 | WLAN_CAPABILITY_PRIVACY ? "on" : "off"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5662 | return 0; |
| 5663 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5664 | |
| 5665 | if ((priv->config & CFG_STATIC_BSSID) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5666 | memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
| 5667 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5668 | "because of BSSID mismatch: " MAC_FMT ".\n", |
| 5669 | escape_essid(network->ssid, network->ssid_len), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5670 | MAC_ARG(network->bssid), MAC_ARG(priv->bssid)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5671 | return 0; |
| 5672 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5673 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5674 | /* Filter out any incompatible freq / mode combinations */ |
| 5675 | if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) { |
| 5676 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5677 | "because of invalid frequency/mode " |
| 5678 | "combination.\n", |
| 5679 | escape_essid(network->ssid, network->ssid_len), |
| 5680 | MAC_ARG(network->bssid)); |
| 5681 | return 0; |
| 5682 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5683 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5684 | /* Filter out invalid channel in current GEO */ |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 5685 | if (!ieee80211_is_valid_channel(priv->ieee, network->channel)) { |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5686 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5687 | "because of invalid channel in current GEO\n", |
| 5688 | escape_essid(network->ssid, network->ssid_len), |
| 5689 | MAC_ARG(network->bssid)); |
| 5690 | return 0; |
| 5691 | } |
| 5692 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5693 | /* Ensure that the rates supported by the driver are compatible with |
| 5694 | * this AP, including verification of basic rates (mandatory) */ |
| 5695 | if (!ipw_compatible_rates(priv, network, &rates)) { |
| 5696 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5697 | "because configured rate mask excludes " |
| 5698 | "AP mandatory rate.\n", |
| 5699 | escape_essid(network->ssid, network->ssid_len), |
| 5700 | MAC_ARG(network->bssid)); |
| 5701 | return 0; |
| 5702 | } |
| 5703 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5704 | if (rates.num_rates == 0) { |
| 5705 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5706 | "because of no compatible rates.\n", |
| 5707 | escape_essid(network->ssid, network->ssid_len), |
| 5708 | MAC_ARG(network->bssid)); |
| 5709 | return 0; |
| 5710 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5711 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5712 | /* TODO: Perform any further minimal comparititive tests. We do not |
| 5713 | * want to put too much policy logic here; intelligent scan selection |
| 5714 | * should occur within a generic IEEE 802.11 user space tool. */ |
| 5715 | |
| 5716 | /* Set up 'new' AP to this network */ |
| 5717 | ipw_copy_rates(&match->rates, &rates); |
| 5718 | match->network = network; |
| 5719 | |
| 5720 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n", |
| 5721 | escape_essid(network->ssid, network->ssid_len), |
| 5722 | MAC_ARG(network->bssid)); |
| 5723 | |
| 5724 | return 1; |
| 5725 | } |
| 5726 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5727 | static void ipw_adhoc_create(struct ipw_priv *priv, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5728 | struct ieee80211_network *network) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5729 | { |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 5730 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5731 | int i; |
| 5732 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5733 | /* |
| 5734 | * For the purposes of scanning, we can set our wireless mode |
| 5735 | * to trigger scans across combinations of bands, but when it |
| 5736 | * comes to creating a new ad-hoc network, we have tell the FW |
| 5737 | * exactly which band to use. |
| 5738 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5739 | * We also have the possibility of an invalid channel for the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5740 | * chossen band. Attempting to create a new ad-hoc network |
| 5741 | * with an invalid channel for wireless mode will trigger a |
| 5742 | * FW fatal error. |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5743 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5744 | */ |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 5745 | switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5746 | case IEEE80211_52GHZ_BAND: |
| 5747 | network->mode = IEEE_A; |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 5748 | i = ieee80211_channel_to_index(priv->ieee, priv->channel); |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 5749 | BUG_ON(i == -1); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5750 | if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) { |
| 5751 | IPW_WARNING("Overriding invalid channel\n"); |
| 5752 | priv->channel = geo->a[0].channel; |
| 5753 | } |
| 5754 | break; |
| 5755 | |
| 5756 | case IEEE80211_24GHZ_BAND: |
| 5757 | if (priv->ieee->mode & IEEE_G) |
| 5758 | network->mode = IEEE_G; |
| 5759 | else |
| 5760 | network->mode = IEEE_B; |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 5761 | i = ieee80211_channel_to_index(priv->ieee, priv->channel); |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 5762 | BUG_ON(i == -1); |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5763 | if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) { |
| 5764 | IPW_WARNING("Overriding invalid channel\n"); |
| 5765 | priv->channel = geo->bg[0].channel; |
| 5766 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5767 | break; |
| 5768 | |
| 5769 | default: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5770 | IPW_WARNING("Overriding invalid channel\n"); |
| 5771 | if (priv->ieee->mode & IEEE_A) { |
| 5772 | network->mode = IEEE_A; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5773 | priv->channel = geo->a[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5774 | } else if (priv->ieee->mode & IEEE_G) { |
| 5775 | network->mode = IEEE_G; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5776 | priv->channel = geo->bg[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5777 | } else { |
| 5778 | network->mode = IEEE_B; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5779 | priv->channel = geo->bg[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5780 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5781 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5782 | } |
| 5783 | |
| 5784 | network->channel = priv->channel; |
| 5785 | priv->config |= CFG_ADHOC_PERSIST; |
| 5786 | ipw_create_bssid(priv, network->bssid); |
| 5787 | network->ssid_len = priv->essid_len; |
| 5788 | memcpy(network->ssid, priv->essid, priv->essid_len); |
| 5789 | memset(&network->stats, 0, sizeof(network->stats)); |
| 5790 | network->capability = WLAN_CAPABILITY_IBSS; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5791 | if (!(priv->config & CFG_PREAMBLE_LONG)) |
| 5792 | network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5793 | if (priv->capability & CAP_PRIVACY_ON) |
| 5794 | network->capability |= WLAN_CAPABILITY_PRIVACY; |
| 5795 | network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5796 | memcpy(network->rates, priv->rates.supported_rates, network->rates_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5797 | network->rates_ex_len = priv->rates.num_rates - network->rates_len; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5798 | memcpy(network->rates_ex, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5799 | &priv->rates.supported_rates[network->rates_len], |
| 5800 | network->rates_ex_len); |
| 5801 | network->last_scanned = 0; |
| 5802 | network->flags = 0; |
| 5803 | network->last_associate = 0; |
| 5804 | network->time_stamp[0] = 0; |
| 5805 | network->time_stamp[1] = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5806 | network->beacon_interval = 100; /* Default */ |
| 5807 | network->listen_interval = 10; /* Default */ |
| 5808 | network->atim_window = 0; /* Default */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5809 | network->wpa_ie_len = 0; |
| 5810 | network->rsn_ie_len = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5811 | } |
| 5812 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5813 | static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index) |
| 5814 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5815 | struct ipw_tgi_tx_key key; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5816 | |
| 5817 | if (!(priv->ieee->sec.flags & (1 << index))) |
| 5818 | return; |
| 5819 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5820 | key.key_id = index; |
| 5821 | memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH); |
| 5822 | key.security_type = type; |
| 5823 | key.station_index = 0; /* always 0 for BSS */ |
| 5824 | key.flags = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5825 | /* 0 for new key; previous value of counter (after fatal error) */ |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 5826 | key.tx_counter[0] = cpu_to_le32(0); |
| 5827 | key.tx_counter[1] = cpu_to_le32(0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5828 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5829 | ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5830 | } |
| 5831 | |
| 5832 | static void ipw_send_wep_keys(struct ipw_priv *priv, int type) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5833 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5834 | struct ipw_wep_key key; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5835 | int i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5836 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5837 | key.cmd_id = DINO_CMD_WEP_KEY; |
| 5838 | key.seq_num = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5839 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5840 | /* Note: AES keys cannot be set for multiple times. |
| 5841 | * Only set it at the first time. */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5842 | for (i = 0; i < 4; i++) { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5843 | key.key_index = i | type; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5844 | if (!(priv->ieee->sec.flags & (1 << i))) { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5845 | key.key_size = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5846 | continue; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5847 | } |
| 5848 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5849 | key.key_size = priv->ieee->sec.key_sizes[i]; |
| 5850 | memcpy(key.key, priv->ieee->sec.keys[i], key.key_size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5851 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5852 | ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5853 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5854 | } |
| 5855 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 5856 | static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level) |
| 5857 | { |
| 5858 | if (priv->ieee->host_encrypt) |
| 5859 | return; |
| 5860 | |
| 5861 | switch (level) { |
| 5862 | case SEC_LEVEL_3: |
| 5863 | priv->sys_config.disable_unicast_decryption = 0; |
| 5864 | priv->ieee->host_decrypt = 0; |
| 5865 | break; |
| 5866 | case SEC_LEVEL_2: |
| 5867 | priv->sys_config.disable_unicast_decryption = 1; |
| 5868 | priv->ieee->host_decrypt = 1; |
| 5869 | break; |
| 5870 | case SEC_LEVEL_1: |
| 5871 | priv->sys_config.disable_unicast_decryption = 0; |
| 5872 | priv->ieee->host_decrypt = 0; |
| 5873 | break; |
| 5874 | case SEC_LEVEL_0: |
| 5875 | priv->sys_config.disable_unicast_decryption = 1; |
| 5876 | break; |
| 5877 | default: |
| 5878 | break; |
| 5879 | } |
| 5880 | } |
| 5881 | |
| 5882 | static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level) |
| 5883 | { |
| 5884 | if (priv->ieee->host_encrypt) |
| 5885 | return; |
| 5886 | |
| 5887 | switch (level) { |
| 5888 | case SEC_LEVEL_3: |
| 5889 | priv->sys_config.disable_multicast_decryption = 0; |
| 5890 | break; |
| 5891 | case SEC_LEVEL_2: |
| 5892 | priv->sys_config.disable_multicast_decryption = 1; |
| 5893 | break; |
| 5894 | case SEC_LEVEL_1: |
| 5895 | priv->sys_config.disable_multicast_decryption = 0; |
| 5896 | break; |
| 5897 | case SEC_LEVEL_0: |
| 5898 | priv->sys_config.disable_multicast_decryption = 1; |
| 5899 | break; |
| 5900 | default: |
| 5901 | break; |
| 5902 | } |
| 5903 | } |
| 5904 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5905 | static void ipw_set_hwcrypto_keys(struct ipw_priv *priv) |
| 5906 | { |
| 5907 | switch (priv->ieee->sec.level) { |
| 5908 | case SEC_LEVEL_3: |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 5909 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
| 5910 | ipw_send_tgi_tx_key(priv, |
| 5911 | DCT_FLAG_EXT_SECURITY_CCM, |
| 5912 | priv->ieee->sec.active_key); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5913 | |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 5914 | if (!priv->ieee->host_mc_decrypt) |
| 5915 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5916 | break; |
| 5917 | case SEC_LEVEL_2: |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 5918 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
| 5919 | ipw_send_tgi_tx_key(priv, |
| 5920 | DCT_FLAG_EXT_SECURITY_TKIP, |
| 5921 | priv->ieee->sec.active_key); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5922 | break; |
| 5923 | case SEC_LEVEL_1: |
| 5924 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); |
Hong Liu | 29cb843 | 2005-09-12 10:43:33 -0500 | [diff] [blame] | 5925 | ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level); |
| 5926 | ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5927 | break; |
| 5928 | case SEC_LEVEL_0: |
| 5929 | default: |
| 5930 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5931 | } |
| 5932 | } |
| 5933 | |
| 5934 | static void ipw_adhoc_check(void *data) |
| 5935 | { |
| 5936 | struct ipw_priv *priv = data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5937 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5938 | if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5939 | !(priv->config & CFG_ADHOC_PERSIST)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5940 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
| 5941 | IPW_DL_STATE | IPW_DL_ASSOC, |
| 5942 | "Missed beacon: %d - disassociate\n", |
| 5943 | priv->missed_adhoc_beacons); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5944 | ipw_remove_current_network(priv); |
| 5945 | ipw_disassociate(priv); |
| 5946 | return; |
| 5947 | } |
| 5948 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5949 | queue_delayed_work(priv->workqueue, &priv->adhoc_check, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5950 | priv->assoc_request.beacon_interval); |
| 5951 | } |
| 5952 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5953 | static void ipw_bg_adhoc_check(void *data) |
| 5954 | { |
| 5955 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5956 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5957 | ipw_adhoc_check(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5958 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5959 | } |
| 5960 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5961 | static void ipw_debug_config(struct ipw_priv *priv) |
| 5962 | { |
| 5963 | IPW_DEBUG_INFO("Scan completed, no valid APs matched " |
| 5964 | "[CFG 0x%08X]\n", priv->config); |
| 5965 | if (priv->config & CFG_STATIC_CHANNEL) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5966 | IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5967 | else |
| 5968 | IPW_DEBUG_INFO("Channel unlocked.\n"); |
| 5969 | if (priv->config & CFG_STATIC_ESSID) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5970 | IPW_DEBUG_INFO("ESSID locked to '%s'\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5971 | escape_essid(priv->essid, priv->essid_len)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5972 | else |
| 5973 | IPW_DEBUG_INFO("ESSID unlocked.\n"); |
| 5974 | if (priv->config & CFG_STATIC_BSSID) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5975 | IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n", |
| 5976 | MAC_ARG(priv->bssid)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5977 | else |
| 5978 | IPW_DEBUG_INFO("BSSID unlocked.\n"); |
| 5979 | if (priv->capability & CAP_PRIVACY_ON) |
| 5980 | IPW_DEBUG_INFO("PRIVACY on\n"); |
| 5981 | else |
| 5982 | IPW_DEBUG_INFO("PRIVACY off\n"); |
| 5983 | IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask); |
| 5984 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5985 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 5986 | static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5987 | { |
| 5988 | /* TODO: Verify that this works... */ |
| 5989 | struct ipw_fixed_rate fr = { |
| 5990 | .tx_rates = priv->rates_mask |
| 5991 | }; |
| 5992 | u32 reg; |
| 5993 | u16 mask = 0; |
| 5994 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5995 | /* Identify 'current FW band' and match it with the fixed |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5996 | * Tx rates */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5997 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5998 | switch (priv->ieee->freq_band) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5999 | case IEEE80211_52GHZ_BAND: /* A only */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6000 | /* IEEE_A */ |
| 6001 | if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) { |
| 6002 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6003 | IPW_DEBUG_WX |
| 6004 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6005 | fr.tx_rates = 0; |
| 6006 | break; |
| 6007 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6008 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6009 | fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A; |
| 6010 | break; |
| 6011 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 6012 | default: /* 2.4Ghz or Mixed */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6013 | /* IEEE_B */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6014 | if (mode == IEEE_B) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6015 | if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) { |
| 6016 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6017 | IPW_DEBUG_WX |
| 6018 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6019 | fr.tx_rates = 0; |
| 6020 | } |
| 6021 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6022 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6023 | |
| 6024 | /* IEEE_G */ |
| 6025 | if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK | |
| 6026 | IEEE80211_OFDM_RATES_MASK)) { |
| 6027 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6028 | IPW_DEBUG_WX |
| 6029 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6030 | fr.tx_rates = 0; |
| 6031 | break; |
| 6032 | } |
| 6033 | |
| 6034 | if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) { |
| 6035 | mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1); |
| 6036 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK; |
| 6037 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6038 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6039 | if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) { |
| 6040 | mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1); |
| 6041 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK; |
| 6042 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6043 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6044 | if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) { |
| 6045 | mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1); |
| 6046 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK; |
| 6047 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6048 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6049 | fr.tx_rates |= mask; |
| 6050 | break; |
| 6051 | } |
| 6052 | |
| 6053 | reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 6054 | ipw_write_reg32(priv, reg, *(u32 *) & fr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6055 | } |
| 6056 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6057 | static void ipw_abort_scan(struct ipw_priv *priv) |
| 6058 | { |
| 6059 | int err; |
| 6060 | |
| 6061 | if (priv->status & STATUS_SCAN_ABORTING) { |
| 6062 | IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n"); |
| 6063 | return; |
| 6064 | } |
| 6065 | priv->status |= STATUS_SCAN_ABORTING; |
| 6066 | |
| 6067 | err = ipw_send_scan_abort(priv); |
| 6068 | if (err) |
| 6069 | IPW_DEBUG_HC("Request to abort scan failed.\n"); |
| 6070 | } |
| 6071 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6072 | static void ipw_add_scan_channels(struct ipw_priv *priv, |
| 6073 | struct ipw_scan_request_ext *scan, |
| 6074 | int scan_type) |
| 6075 | { |
| 6076 | int channel_index = 0; |
| 6077 | const struct ieee80211_geo *geo; |
| 6078 | int i; |
| 6079 | |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 6080 | geo = ieee80211_get_geo(priv->ieee); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6081 | |
| 6082 | if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) { |
| 6083 | int start = channel_index; |
| 6084 | for (i = 0; i < geo->a_channels; i++) { |
| 6085 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6086 | geo->a[i].channel == priv->channel) |
| 6087 | continue; |
| 6088 | channel_index++; |
| 6089 | scan->channels_list[channel_index] = geo->a[i].channel; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6090 | ipw_set_scan_type(scan, channel_index, |
| 6091 | geo->a[i]. |
| 6092 | flags & IEEE80211_CH_PASSIVE_ONLY ? |
| 6093 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN : |
| 6094 | scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6095 | } |
| 6096 | |
| 6097 | if (start != channel_index) { |
| 6098 | scan->channels_list[start] = (u8) (IPW_A_MODE << 6) | |
| 6099 | (channel_index - start); |
| 6100 | channel_index++; |
| 6101 | } |
| 6102 | } |
| 6103 | |
| 6104 | if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) { |
| 6105 | int start = channel_index; |
| 6106 | if (priv->config & CFG_SPEED_SCAN) { |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6107 | int index; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6108 | u8 channels[IEEE80211_24GHZ_CHANNELS] = { |
| 6109 | /* nop out the list */ |
| 6110 | [0] = 0 |
| 6111 | }; |
| 6112 | |
| 6113 | u8 channel; |
| 6114 | while (channel_index < IPW_SCAN_CHANNELS) { |
| 6115 | channel = |
| 6116 | priv->speed_scan[priv->speed_scan_pos]; |
| 6117 | if (channel == 0) { |
| 6118 | priv->speed_scan_pos = 0; |
| 6119 | channel = priv->speed_scan[0]; |
| 6120 | } |
| 6121 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6122 | channel == priv->channel) { |
| 6123 | priv->speed_scan_pos++; |
| 6124 | continue; |
| 6125 | } |
| 6126 | |
| 6127 | /* If this channel has already been |
| 6128 | * added in scan, break from loop |
| 6129 | * and this will be the first channel |
| 6130 | * in the next scan. |
| 6131 | */ |
| 6132 | if (channels[channel - 1] != 0) |
| 6133 | break; |
| 6134 | |
| 6135 | channels[channel - 1] = 1; |
| 6136 | priv->speed_scan_pos++; |
| 6137 | channel_index++; |
| 6138 | scan->channels_list[channel_index] = channel; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6139 | index = |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 6140 | ieee80211_channel_to_index(priv->ieee, channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6141 | ipw_set_scan_type(scan, channel_index, |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6142 | geo->bg[index]. |
| 6143 | flags & |
| 6144 | IEEE80211_CH_PASSIVE_ONLY ? |
| 6145 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN |
| 6146 | : scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6147 | } |
| 6148 | } else { |
| 6149 | for (i = 0; i < geo->bg_channels; i++) { |
| 6150 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6151 | geo->bg[i].channel == priv->channel) |
| 6152 | continue; |
| 6153 | channel_index++; |
| 6154 | scan->channels_list[channel_index] = |
| 6155 | geo->bg[i].channel; |
| 6156 | ipw_set_scan_type(scan, channel_index, |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6157 | geo->bg[i]. |
| 6158 | flags & |
| 6159 | IEEE80211_CH_PASSIVE_ONLY ? |
| 6160 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN |
| 6161 | : scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6162 | } |
| 6163 | } |
| 6164 | |
| 6165 | if (start != channel_index) { |
| 6166 | scan->channels_list[start] = (u8) (IPW_B_MODE << 6) | |
| 6167 | (channel_index - start); |
| 6168 | } |
| 6169 | } |
| 6170 | } |
| 6171 | |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6172 | static int ipw_request_scan_helper(struct ipw_priv *priv, int type) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6173 | { |
| 6174 | struct ipw_scan_request_ext scan; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6175 | int err = 0, scan_type; |
| 6176 | |
| 6177 | if (!(priv->status & STATUS_INIT) || |
| 6178 | (priv->status & STATUS_EXIT_PENDING)) |
| 6179 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6180 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6181 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6182 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6183 | if (priv->status & STATUS_SCANNING) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6184 | IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6185 | priv->status |= STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6186 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6187 | } |
| 6188 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6189 | if (!(priv->status & STATUS_SCAN_FORCED) && |
| 6190 | priv->status & STATUS_SCAN_ABORTING) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6191 | IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 6192 | priv->status |= STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6193 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6194 | } |
| 6195 | |
| 6196 | if (priv->status & STATUS_RF_KILL_MASK) { |
| 6197 | IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 6198 | priv->status |= STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6199 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6200 | } |
| 6201 | |
| 6202 | memset(&scan, 0, sizeof(scan)); |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6203 | scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee)); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6204 | |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6205 | if (type == IW_SCAN_TYPE_PASSIVE) { |
| 6206 | IPW_DEBUG_WX("use passive scanning\n"); |
| 6207 | scan_type = IPW_SCAN_PASSIVE_FULL_DWELL_SCAN; |
| 6208 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
| 6209 | cpu_to_le16(120); |
| 6210 | ipw_add_scan_channels(priv, &scan, scan_type); |
| 6211 | goto send_request; |
| 6212 | } |
| 6213 | |
| 6214 | /* Use active scan by default. */ |
| 6215 | if (priv->config & CFG_SPEED_SCAN) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6216 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6217 | cpu_to_le16(30); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6218 | else |
| 6219 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6220 | cpu_to_le16(20); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6221 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6222 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6223 | cpu_to_le16(20); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6224 | |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6225 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6226 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6227 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6228 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6229 | u8 channel; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6230 | u8 band = 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6231 | |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 6232 | switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6233 | case IEEE80211_52GHZ_BAND: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6234 | band = (u8) (IPW_A_MODE << 6) | 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6235 | channel = priv->channel; |
| 6236 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6237 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6238 | case IEEE80211_24GHZ_BAND: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6239 | band = (u8) (IPW_B_MODE << 6) | 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6240 | channel = priv->channel; |
| 6241 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6242 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6243 | default: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6244 | band = (u8) (IPW_B_MODE << 6) | 1; |
| 6245 | channel = 9; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6246 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6247 | } |
| 6248 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6249 | scan.channels_list[0] = band; |
| 6250 | scan.channels_list[1] = channel; |
| 6251 | ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6252 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6253 | /* NOTE: The card will sit on this channel for this time |
| 6254 | * period. Scan aborts are timing sensitive and frequently |
| 6255 | * result in firmware restarts. As such, it is best to |
| 6256 | * set a small dwell_time here and just keep re-issuing |
| 6257 | * scans. Otherwise fast channel hopping will not actually |
| 6258 | * hop channels. |
| 6259 | * |
| 6260 | * TODO: Move SPEED SCAN support to all modes and bands */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6261 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6262 | cpu_to_le16(2000); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6263 | } else { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6264 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 6265 | /* If we are roaming, then make this a directed scan for the |
| 6266 | * current network. Otherwise, ensure that every other scan |
| 6267 | * is a fast channel hop scan */ |
| 6268 | if ((priv->status & STATUS_ROAMING) |
| 6269 | || (!(priv->status & STATUS_ASSOCIATED) |
| 6270 | && (priv->config & CFG_STATIC_ESSID) |
| 6271 | && (le32_to_cpu(scan.full_scan_index) % 2))) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6272 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
| 6273 | if (err) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6274 | IPW_DEBUG_HC("Attempt to send SSID command " |
| 6275 | "failed.\n"); |
| 6276 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6277 | } |
| 6278 | |
| 6279 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6280 | } else |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6281 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6282 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6283 | ipw_add_scan_channels(priv, &scan, scan_type); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6284 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6285 | } |
| 6286 | #endif |
| 6287 | |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6288 | send_request: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6289 | err = ipw_send_scan_request_ext(priv, &scan); |
| 6290 | if (err) { |
| 6291 | IPW_DEBUG_HC("Sending scan command failed: %08X\n", err); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6292 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6293 | } |
| 6294 | |
| 6295 | priv->status |= STATUS_SCANNING; |
| 6296 | priv->status &= ~STATUS_SCAN_PENDING; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6297 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 6298 | IPW_SCAN_CHECK_WATCHDOG); |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6299 | done: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6300 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6301 | return err; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6302 | } |
| 6303 | |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6304 | static int ipw_request_passive_scan(struct ipw_priv *priv) { |
| 6305 | return ipw_request_scan_helper(priv, IW_SCAN_TYPE_PASSIVE); |
| 6306 | } |
| 6307 | |
| 6308 | static int ipw_request_scan(struct ipw_priv *priv) { |
| 6309 | return ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE); |
| 6310 | } |
| 6311 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6312 | static void ipw_bg_abort_scan(void *data) |
| 6313 | { |
| 6314 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6315 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6316 | ipw_abort_scan(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6317 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6318 | } |
| 6319 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6320 | static int ipw_wpa_enable(struct ipw_priv *priv, int value) |
| 6321 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6322 | /* This is called when wpa_supplicant loads and closes the driver |
| 6323 | * interface. */ |
Hong Liu | cdd1fa1 | 2005-08-31 18:14:27 +0800 | [diff] [blame] | 6324 | priv->ieee->wpa_enabled = value; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6325 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6326 | } |
| 6327 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6328 | static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value) |
| 6329 | { |
| 6330 | struct ieee80211_device *ieee = priv->ieee; |
| 6331 | struct ieee80211_security sec = { |
| 6332 | .flags = SEC_AUTH_MODE, |
| 6333 | }; |
| 6334 | int ret = 0; |
| 6335 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6336 | if (value & IW_AUTH_ALG_SHARED_KEY) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6337 | sec.auth_mode = WLAN_AUTH_SHARED_KEY; |
| 6338 | ieee->open_wep = 0; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6339 | } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6340 | sec.auth_mode = WLAN_AUTH_OPEN; |
| 6341 | ieee->open_wep = 1; |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 6342 | } else if (value & IW_AUTH_ALG_LEAP) { |
| 6343 | sec.auth_mode = WLAN_AUTH_LEAP; |
| 6344 | ieee->open_wep = 1; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6345 | } else |
| 6346 | return -EINVAL; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6347 | |
| 6348 | if (ieee->set_security) |
| 6349 | ieee->set_security(ieee->dev, &sec); |
| 6350 | else |
| 6351 | ret = -EOPNOTSUPP; |
| 6352 | |
| 6353 | return ret; |
| 6354 | } |
| 6355 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 6356 | static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, |
| 6357 | int wpa_ie_len) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6358 | { |
| 6359 | /* make sure WPA is enabled */ |
| 6360 | ipw_wpa_enable(priv, 1); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6361 | } |
| 6362 | |
| 6363 | static int ipw_set_rsn_capa(struct ipw_priv *priv, |
| 6364 | char *capabilities, int length) |
| 6365 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6366 | IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n"); |
| 6367 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6368 | return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 6369 | capabilities); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6370 | } |
| 6371 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6372 | /* |
| 6373 | * WE-18 support |
| 6374 | */ |
| 6375 | |
| 6376 | /* SIOCSIWGENIE */ |
| 6377 | static int ipw_wx_set_genie(struct net_device *dev, |
| 6378 | struct iw_request_info *info, |
| 6379 | union iwreq_data *wrqu, char *extra) |
| 6380 | { |
| 6381 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6382 | struct ieee80211_device *ieee = priv->ieee; |
| 6383 | u8 *buf; |
| 6384 | int err = 0; |
| 6385 | |
| 6386 | if (wrqu->data.length > MAX_WPA_IE_LEN || |
| 6387 | (wrqu->data.length && extra == NULL)) |
| 6388 | return -EINVAL; |
| 6389 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6390 | if (wrqu->data.length) { |
| 6391 | buf = kmalloc(wrqu->data.length, GFP_KERNEL); |
| 6392 | if (buf == NULL) { |
| 6393 | err = -ENOMEM; |
| 6394 | goto out; |
| 6395 | } |
| 6396 | |
| 6397 | memcpy(buf, extra, wrqu->data.length); |
| 6398 | kfree(ieee->wpa_ie); |
| 6399 | ieee->wpa_ie = buf; |
| 6400 | ieee->wpa_ie_len = wrqu->data.length; |
| 6401 | } else { |
| 6402 | kfree(ieee->wpa_ie); |
| 6403 | ieee->wpa_ie = NULL; |
| 6404 | ieee->wpa_ie_len = 0; |
| 6405 | } |
| 6406 | |
| 6407 | ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len); |
| 6408 | out: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6409 | return err; |
| 6410 | } |
| 6411 | |
| 6412 | /* SIOCGIWGENIE */ |
| 6413 | static int ipw_wx_get_genie(struct net_device *dev, |
| 6414 | struct iw_request_info *info, |
| 6415 | union iwreq_data *wrqu, char *extra) |
| 6416 | { |
| 6417 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6418 | struct ieee80211_device *ieee = priv->ieee; |
| 6419 | int err = 0; |
| 6420 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6421 | if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) { |
| 6422 | wrqu->data.length = 0; |
| 6423 | goto out; |
| 6424 | } |
| 6425 | |
| 6426 | if (wrqu->data.length < ieee->wpa_ie_len) { |
| 6427 | err = -E2BIG; |
| 6428 | goto out; |
| 6429 | } |
| 6430 | |
| 6431 | wrqu->data.length = ieee->wpa_ie_len; |
| 6432 | memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len); |
| 6433 | |
| 6434 | out: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6435 | return err; |
| 6436 | } |
| 6437 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6438 | static int wext_cipher2level(int cipher) |
| 6439 | { |
| 6440 | switch (cipher) { |
| 6441 | case IW_AUTH_CIPHER_NONE: |
| 6442 | return SEC_LEVEL_0; |
| 6443 | case IW_AUTH_CIPHER_WEP40: |
| 6444 | case IW_AUTH_CIPHER_WEP104: |
| 6445 | return SEC_LEVEL_1; |
| 6446 | case IW_AUTH_CIPHER_TKIP: |
| 6447 | return SEC_LEVEL_2; |
| 6448 | case IW_AUTH_CIPHER_CCMP: |
| 6449 | return SEC_LEVEL_3; |
| 6450 | default: |
| 6451 | return -1; |
| 6452 | } |
| 6453 | } |
| 6454 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6455 | /* SIOCSIWAUTH */ |
| 6456 | static int ipw_wx_set_auth(struct net_device *dev, |
| 6457 | struct iw_request_info *info, |
| 6458 | union iwreq_data *wrqu, char *extra) |
| 6459 | { |
| 6460 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6461 | struct ieee80211_device *ieee = priv->ieee; |
| 6462 | struct iw_param *param = &wrqu->param; |
| 6463 | struct ieee80211_crypt_data *crypt; |
| 6464 | unsigned long flags; |
| 6465 | int ret = 0; |
| 6466 | |
| 6467 | switch (param->flags & IW_AUTH_INDEX) { |
| 6468 | case IW_AUTH_WPA_VERSION: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6469 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6470 | case IW_AUTH_CIPHER_PAIRWISE: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6471 | ipw_set_hw_decrypt_unicast(priv, |
| 6472 | wext_cipher2level(param->value)); |
| 6473 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6474 | case IW_AUTH_CIPHER_GROUP: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6475 | ipw_set_hw_decrypt_multicast(priv, |
| 6476 | wext_cipher2level(param->value)); |
| 6477 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6478 | case IW_AUTH_KEY_MGMT: |
| 6479 | /* |
| 6480 | * ipw2200 does not use these parameters |
| 6481 | */ |
| 6482 | break; |
| 6483 | |
| 6484 | case IW_AUTH_TKIP_COUNTERMEASURES: |
| 6485 | crypt = priv->ieee->crypt[priv->ieee->tx_keyidx]; |
James Ketrenos | 991d1cc | 2005-10-13 09:26:48 +0000 | [diff] [blame] | 6486 | if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6487 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6488 | |
| 6489 | flags = crypt->ops->get_flags(crypt->priv); |
| 6490 | |
| 6491 | if (param->value) |
| 6492 | flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; |
| 6493 | else |
| 6494 | flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; |
| 6495 | |
| 6496 | crypt->ops->set_flags(flags, crypt->priv); |
| 6497 | |
| 6498 | break; |
| 6499 | |
| 6500 | case IW_AUTH_DROP_UNENCRYPTED:{ |
| 6501 | /* HACK: |
| 6502 | * |
| 6503 | * wpa_supplicant calls set_wpa_enabled when the driver |
| 6504 | * is loaded and unloaded, regardless of if WPA is being |
| 6505 | * used. No other calls are made which can be used to |
| 6506 | * determine if encryption will be used or not prior to |
| 6507 | * association being expected. If encryption is not being |
| 6508 | * used, drop_unencrypted is set to false, else true -- we |
| 6509 | * can use this to determine if the CAP_PRIVACY_ON bit should |
| 6510 | * be set. |
| 6511 | */ |
| 6512 | struct ieee80211_security sec = { |
| 6513 | .flags = SEC_ENABLED, |
| 6514 | .enabled = param->value, |
| 6515 | }; |
| 6516 | priv->ieee->drop_unencrypted = param->value; |
| 6517 | /* We only change SEC_LEVEL for open mode. Others |
| 6518 | * are set by ipw_wpa_set_encryption. |
| 6519 | */ |
| 6520 | if (!param->value) { |
| 6521 | sec.flags |= SEC_LEVEL; |
| 6522 | sec.level = SEC_LEVEL_0; |
| 6523 | } else { |
| 6524 | sec.flags |= SEC_LEVEL; |
| 6525 | sec.level = SEC_LEVEL_1; |
| 6526 | } |
| 6527 | if (priv->ieee->set_security) |
| 6528 | priv->ieee->set_security(priv->ieee->dev, &sec); |
| 6529 | break; |
| 6530 | } |
| 6531 | |
| 6532 | case IW_AUTH_80211_AUTH_ALG: |
| 6533 | ret = ipw_wpa_set_auth_algs(priv, param->value); |
| 6534 | break; |
| 6535 | |
| 6536 | case IW_AUTH_WPA_ENABLED: |
| 6537 | ret = ipw_wpa_enable(priv, param->value); |
Zhu Yi | e3c5a64 | 2006-04-13 17:21:13 +0800 | [diff] [blame] | 6538 | ipw_disassociate(priv); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6539 | break; |
| 6540 | |
| 6541 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 6542 | ieee->ieee802_1x = param->value; |
| 6543 | break; |
| 6544 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6545 | case IW_AUTH_PRIVACY_INVOKED: |
| 6546 | ieee->privacy_invoked = param->value; |
| 6547 | break; |
| 6548 | |
| 6549 | default: |
| 6550 | return -EOPNOTSUPP; |
| 6551 | } |
| 6552 | return ret; |
| 6553 | } |
| 6554 | |
| 6555 | /* SIOCGIWAUTH */ |
| 6556 | static int ipw_wx_get_auth(struct net_device *dev, |
| 6557 | struct iw_request_info *info, |
| 6558 | union iwreq_data *wrqu, char *extra) |
| 6559 | { |
| 6560 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6561 | struct ieee80211_device *ieee = priv->ieee; |
| 6562 | struct ieee80211_crypt_data *crypt; |
| 6563 | struct iw_param *param = &wrqu->param; |
| 6564 | int ret = 0; |
| 6565 | |
| 6566 | switch (param->flags & IW_AUTH_INDEX) { |
| 6567 | case IW_AUTH_WPA_VERSION: |
| 6568 | case IW_AUTH_CIPHER_PAIRWISE: |
| 6569 | case IW_AUTH_CIPHER_GROUP: |
| 6570 | case IW_AUTH_KEY_MGMT: |
| 6571 | /* |
| 6572 | * wpa_supplicant will control these internally |
| 6573 | */ |
| 6574 | ret = -EOPNOTSUPP; |
| 6575 | break; |
| 6576 | |
| 6577 | case IW_AUTH_TKIP_COUNTERMEASURES: |
| 6578 | crypt = priv->ieee->crypt[priv->ieee->tx_keyidx]; |
James Ketrenos | 991d1cc | 2005-10-13 09:26:48 +0000 | [diff] [blame] | 6579 | if (!crypt || !crypt->ops->get_flags) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6580 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6581 | |
| 6582 | param->value = (crypt->ops->get_flags(crypt->priv) & |
| 6583 | IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0; |
| 6584 | |
| 6585 | break; |
| 6586 | |
| 6587 | case IW_AUTH_DROP_UNENCRYPTED: |
| 6588 | param->value = ieee->drop_unencrypted; |
| 6589 | break; |
| 6590 | |
| 6591 | case IW_AUTH_80211_AUTH_ALG: |
| 6592 | param->value = ieee->sec.auth_mode; |
| 6593 | break; |
| 6594 | |
| 6595 | case IW_AUTH_WPA_ENABLED: |
| 6596 | param->value = ieee->wpa_enabled; |
| 6597 | break; |
| 6598 | |
| 6599 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 6600 | param->value = ieee->ieee802_1x; |
| 6601 | break; |
| 6602 | |
| 6603 | case IW_AUTH_ROAMING_CONTROL: |
| 6604 | case IW_AUTH_PRIVACY_INVOKED: |
| 6605 | param->value = ieee->privacy_invoked; |
| 6606 | break; |
| 6607 | |
| 6608 | default: |
| 6609 | return -EOPNOTSUPP; |
| 6610 | } |
| 6611 | return 0; |
| 6612 | } |
| 6613 | |
| 6614 | /* SIOCSIWENCODEEXT */ |
| 6615 | static int ipw_wx_set_encodeext(struct net_device *dev, |
| 6616 | struct iw_request_info *info, |
| 6617 | union iwreq_data *wrqu, char *extra) |
| 6618 | { |
| 6619 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6620 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; |
| 6621 | |
| 6622 | if (hwcrypto) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6623 | if (ext->alg == IW_ENCODE_ALG_TKIP) { |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 6624 | /* IPW HW can't build TKIP MIC, |
| 6625 | host decryption still needed */ |
| 6626 | if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) |
| 6627 | priv->ieee->host_mc_decrypt = 1; |
| 6628 | else { |
| 6629 | priv->ieee->host_encrypt = 0; |
| 6630 | priv->ieee->host_encrypt_msdu = 1; |
| 6631 | priv->ieee->host_decrypt = 1; |
| 6632 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6633 | } else { |
| 6634 | priv->ieee->host_encrypt = 0; |
| 6635 | priv->ieee->host_encrypt_msdu = 0; |
| 6636 | priv->ieee->host_decrypt = 0; |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 6637 | priv->ieee->host_mc_decrypt = 0; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6638 | } |
| 6639 | } |
| 6640 | |
| 6641 | return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra); |
| 6642 | } |
| 6643 | |
| 6644 | /* SIOCGIWENCODEEXT */ |
| 6645 | static int ipw_wx_get_encodeext(struct net_device *dev, |
| 6646 | struct iw_request_info *info, |
| 6647 | union iwreq_data *wrqu, char *extra) |
| 6648 | { |
| 6649 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6650 | return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra); |
| 6651 | } |
| 6652 | |
| 6653 | /* SIOCSIWMLME */ |
| 6654 | static int ipw_wx_set_mlme(struct net_device *dev, |
| 6655 | struct iw_request_info *info, |
| 6656 | union iwreq_data *wrqu, char *extra) |
| 6657 | { |
| 6658 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6659 | struct iw_mlme *mlme = (struct iw_mlme *)extra; |
| 6660 | u16 reason; |
| 6661 | |
| 6662 | reason = cpu_to_le16(mlme->reason_code); |
| 6663 | |
| 6664 | switch (mlme->cmd) { |
| 6665 | case IW_MLME_DEAUTH: |
Pavel Machek | 67fd6b4 | 2006-07-11 15:34:05 +0200 | [diff] [blame] | 6666 | /* silently ignore */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6667 | break; |
| 6668 | |
| 6669 | case IW_MLME_DISASSOC: |
| 6670 | ipw_disassociate(priv); |
| 6671 | break; |
| 6672 | |
| 6673 | default: |
| 6674 | return -EOPNOTSUPP; |
| 6675 | } |
| 6676 | return 0; |
| 6677 | } |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6678 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 6679 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6680 | |
| 6681 | /* QoS */ |
| 6682 | /* |
| 6683 | * get the modulation type of the current network or |
| 6684 | * the card current mode |
| 6685 | */ |
Adrian Bunk | 53d0bcf | 2006-03-04 13:14:31 +0100 | [diff] [blame] | 6686 | static u8 ipw_qos_current_mode(struct ipw_priv * priv) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6687 | { |
| 6688 | u8 mode = 0; |
| 6689 | |
| 6690 | if (priv->status & STATUS_ASSOCIATED) { |
| 6691 | unsigned long flags; |
| 6692 | |
| 6693 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 6694 | mode = priv->assoc_network->mode; |
| 6695 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 6696 | } else { |
| 6697 | mode = priv->ieee->mode; |
| 6698 | } |
| 6699 | IPW_DEBUG_QOS("QoS network/card mode %d \n", mode); |
| 6700 | return mode; |
| 6701 | } |
| 6702 | |
| 6703 | /* |
| 6704 | * Handle management frame beacon and probe response |
| 6705 | */ |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 6706 | static int ipw_qos_handle_probe_response(struct ipw_priv *priv, |
| 6707 | int active_network, |
| 6708 | struct ieee80211_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6709 | { |
| 6710 | u32 size = sizeof(struct ieee80211_qos_parameters); |
| 6711 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6712 | if (network->capability & WLAN_CAPABILITY_IBSS) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6713 | network->qos_data.active = network->qos_data.supported; |
| 6714 | |
| 6715 | if (network->flags & NETWORK_HAS_QOS_MASK) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6716 | if (active_network && |
| 6717 | (network->flags & NETWORK_HAS_QOS_PARAMETERS)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6718 | network->qos_data.active = network->qos_data.supported; |
| 6719 | |
| 6720 | if ((network->qos_data.active == 1) && (active_network == 1) && |
| 6721 | (network->flags & NETWORK_HAS_QOS_PARAMETERS) && |
| 6722 | (network->qos_data.old_param_count != |
| 6723 | network->qos_data.param_count)) { |
| 6724 | network->qos_data.old_param_count = |
| 6725 | network->qos_data.param_count; |
| 6726 | schedule_work(&priv->qos_activate); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6727 | IPW_DEBUG_QOS("QoS parameters change call " |
| 6728 | "qos_activate\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6729 | } |
| 6730 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6731 | if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B)) |
| 6732 | memcpy(&network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6733 | &def_parameters_CCK, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6734 | else |
| 6735 | memcpy(&network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6736 | &def_parameters_OFDM, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6737 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6738 | if ((network->qos_data.active == 1) && (active_network == 1)) { |
| 6739 | IPW_DEBUG_QOS("QoS was disabled call qos_activate \n"); |
| 6740 | schedule_work(&priv->qos_activate); |
| 6741 | } |
| 6742 | |
| 6743 | network->qos_data.active = 0; |
| 6744 | network->qos_data.supported = 0; |
| 6745 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6746 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6747 | (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) { |
| 6748 | if (memcmp(network->bssid, priv->bssid, ETH_ALEN)) |
| 6749 | if ((network->capability & WLAN_CAPABILITY_IBSS) && |
| 6750 | !(network->flags & NETWORK_EMPTY_ESSID)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6751 | if ((network->ssid_len == |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6752 | priv->assoc_network->ssid_len) && |
| 6753 | !memcmp(network->ssid, |
| 6754 | priv->assoc_network->ssid, |
| 6755 | network->ssid_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6756 | queue_work(priv->workqueue, |
| 6757 | &priv->merge_networks); |
| 6758 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6759 | } |
| 6760 | |
| 6761 | return 0; |
| 6762 | } |
| 6763 | |
| 6764 | /* |
| 6765 | * This function set up the firmware to support QoS. It sends |
| 6766 | * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO |
| 6767 | */ |
| 6768 | static int ipw_qos_activate(struct ipw_priv *priv, |
| 6769 | struct ieee80211_qos_data *qos_network_data) |
| 6770 | { |
| 6771 | int err; |
| 6772 | struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS]; |
| 6773 | struct ieee80211_qos_parameters *active_one = NULL; |
| 6774 | u32 size = sizeof(struct ieee80211_qos_parameters); |
| 6775 | u32 burst_duration; |
| 6776 | int i; |
| 6777 | u8 type; |
| 6778 | |
| 6779 | type = ipw_qos_current_mode(priv); |
| 6780 | |
| 6781 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]); |
| 6782 | memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size); |
| 6783 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]); |
| 6784 | memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size); |
| 6785 | |
| 6786 | if (qos_network_data == NULL) { |
| 6787 | if (type == IEEE_B) { |
| 6788 | IPW_DEBUG_QOS("QoS activate network mode %d\n", type); |
| 6789 | active_one = &def_parameters_CCK; |
| 6790 | } else |
| 6791 | active_one = &def_parameters_OFDM; |
| 6792 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6793 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6794 | burst_duration = ipw_qos_get_burst_duration(priv); |
| 6795 | for (i = 0; i < QOS_QUEUE_NUM; i++) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6796 | qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] = |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 6797 | (u16)burst_duration; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6798 | } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6799 | if (type == IEEE_B) { |
| 6800 | IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n", |
| 6801 | type); |
| 6802 | if (priv->qos_data.qos_enable == 0) |
| 6803 | active_one = &def_parameters_CCK; |
| 6804 | else |
| 6805 | active_one = priv->qos_data.def_qos_parm_CCK; |
| 6806 | } else { |
| 6807 | if (priv->qos_data.qos_enable == 0) |
| 6808 | active_one = &def_parameters_OFDM; |
| 6809 | else |
| 6810 | active_one = priv->qos_data.def_qos_parm_OFDM; |
| 6811 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6812 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6813 | } else { |
| 6814 | unsigned long flags; |
| 6815 | int active; |
| 6816 | |
| 6817 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 6818 | active_one = &(qos_network_data->parameters); |
| 6819 | qos_network_data->old_param_count = |
| 6820 | qos_network_data->param_count; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6821 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6822 | active = qos_network_data->supported; |
| 6823 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 6824 | |
| 6825 | if (active == 0) { |
| 6826 | burst_duration = ipw_qos_get_burst_duration(priv); |
| 6827 | for (i = 0; i < QOS_QUEUE_NUM; i++) |
| 6828 | qos_parameters[QOS_PARAM_SET_ACTIVE]. |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 6829 | tx_op_limit[i] = (u16)burst_duration; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6830 | } |
| 6831 | } |
| 6832 | |
| 6833 | IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n"); |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 6834 | for (i = 0; i < 3; i++) { |
| 6835 | int j; |
| 6836 | for (j = 0; j < QOS_QUEUE_NUM; j++) { |
| 6837 | qos_parameters[i].cw_min[j] = cpu_to_le16(qos_parameters[i].cw_min[j]); |
| 6838 | qos_parameters[i].cw_max[j] = cpu_to_le16(qos_parameters[i].cw_max[j]); |
| 6839 | qos_parameters[i].tx_op_limit[j] = cpu_to_le16(qos_parameters[i].tx_op_limit[j]); |
| 6840 | } |
| 6841 | } |
| 6842 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6843 | err = ipw_send_qos_params_command(priv, |
| 6844 | (struct ieee80211_qos_parameters *) |
| 6845 | &(qos_parameters[0])); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6846 | if (err) |
| 6847 | IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n"); |
| 6848 | |
| 6849 | return err; |
| 6850 | } |
| 6851 | |
| 6852 | /* |
| 6853 | * send IPW_CMD_WME_INFO to the firmware |
| 6854 | */ |
| 6855 | static int ipw_qos_set_info_element(struct ipw_priv *priv) |
| 6856 | { |
| 6857 | int ret = 0; |
| 6858 | struct ieee80211_qos_information_element qos_info; |
| 6859 | |
| 6860 | if (priv == NULL) |
| 6861 | return -1; |
| 6862 | |
| 6863 | qos_info.elementID = QOS_ELEMENT_ID; |
| 6864 | qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2; |
| 6865 | |
| 6866 | qos_info.version = QOS_VERSION_1; |
| 6867 | qos_info.ac_info = 0; |
| 6868 | |
| 6869 | memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN); |
| 6870 | qos_info.qui_type = QOS_OUI_TYPE; |
| 6871 | qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE; |
| 6872 | |
| 6873 | ret = ipw_send_qos_info_command(priv, &qos_info); |
| 6874 | if (ret != 0) { |
| 6875 | IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n"); |
| 6876 | } |
| 6877 | return ret; |
| 6878 | } |
| 6879 | |
| 6880 | /* |
| 6881 | * Set the QoS parameter with the association request structure |
| 6882 | */ |
| 6883 | static int ipw_qos_association(struct ipw_priv *priv, |
| 6884 | struct ieee80211_network *network) |
| 6885 | { |
| 6886 | int err = 0; |
| 6887 | struct ieee80211_qos_data *qos_data = NULL; |
| 6888 | struct ieee80211_qos_data ibss_data = { |
| 6889 | .supported = 1, |
| 6890 | .active = 1, |
| 6891 | }; |
| 6892 | |
| 6893 | switch (priv->ieee->iw_mode) { |
| 6894 | case IW_MODE_ADHOC: |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 6895 | BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6896 | |
| 6897 | qos_data = &ibss_data; |
| 6898 | break; |
| 6899 | |
| 6900 | case IW_MODE_INFRA: |
| 6901 | qos_data = &network->qos_data; |
| 6902 | break; |
| 6903 | |
| 6904 | default: |
| 6905 | BUG(); |
| 6906 | break; |
| 6907 | } |
| 6908 | |
| 6909 | err = ipw_qos_activate(priv, qos_data); |
| 6910 | if (err) { |
| 6911 | priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC; |
| 6912 | return err; |
| 6913 | } |
| 6914 | |
| 6915 | if (priv->qos_data.qos_enable && qos_data->supported) { |
| 6916 | IPW_DEBUG_QOS("QoS will be enabled for this association\n"); |
| 6917 | priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC; |
| 6918 | return ipw_qos_set_info_element(priv); |
| 6919 | } |
| 6920 | |
| 6921 | return 0; |
| 6922 | } |
| 6923 | |
| 6924 | /* |
| 6925 | * handling the beaconing responces. if we get different QoS setting |
| 6926 | * of the network from the the associated setting adjust the QoS |
| 6927 | * setting |
| 6928 | */ |
| 6929 | static int ipw_qos_association_resp(struct ipw_priv *priv, |
| 6930 | struct ieee80211_network *network) |
| 6931 | { |
| 6932 | int ret = 0; |
| 6933 | unsigned long flags; |
| 6934 | u32 size = sizeof(struct ieee80211_qos_parameters); |
| 6935 | int set_qos_param = 0; |
| 6936 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6937 | if ((priv == NULL) || (network == NULL) || |
| 6938 | (priv->assoc_network == NULL)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6939 | return ret; |
| 6940 | |
| 6941 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 6942 | return ret; |
| 6943 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6944 | if ((priv->ieee->iw_mode != IW_MODE_INFRA)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6945 | return ret; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6946 | |
| 6947 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 6948 | if (network->flags & NETWORK_HAS_QOS_PARAMETERS) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6949 | memcpy(&priv->assoc_network->qos_data, &network->qos_data, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6950 | sizeof(struct ieee80211_qos_data)); |
| 6951 | priv->assoc_network->qos_data.active = 1; |
| 6952 | if ((network->qos_data.old_param_count != |
| 6953 | network->qos_data.param_count)) { |
| 6954 | set_qos_param = 1; |
| 6955 | network->qos_data.old_param_count = |
| 6956 | network->qos_data.param_count; |
| 6957 | } |
| 6958 | |
| 6959 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6960 | if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B)) |
| 6961 | memcpy(&priv->assoc_network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6962 | &def_parameters_CCK, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6963 | else |
| 6964 | memcpy(&priv->assoc_network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6965 | &def_parameters_OFDM, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6966 | priv->assoc_network->qos_data.active = 0; |
| 6967 | priv->assoc_network->qos_data.supported = 0; |
| 6968 | set_qos_param = 1; |
| 6969 | } |
| 6970 | |
| 6971 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 6972 | |
| 6973 | if (set_qos_param == 1) |
| 6974 | schedule_work(&priv->qos_activate); |
| 6975 | |
| 6976 | return ret; |
| 6977 | } |
| 6978 | |
| 6979 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv) |
| 6980 | { |
| 6981 | u32 ret = 0; |
| 6982 | |
| 6983 | if ((priv == NULL)) |
| 6984 | return 0; |
| 6985 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6986 | if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6987 | ret = priv->qos_data.burst_duration_CCK; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6988 | else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6989 | ret = priv->qos_data.burst_duration_OFDM; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6990 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6991 | return ret; |
| 6992 | } |
| 6993 | |
| 6994 | /* |
| 6995 | * Initialize the setting of QoS global |
| 6996 | */ |
| 6997 | static void ipw_qos_init(struct ipw_priv *priv, int enable, |
| 6998 | int burst_enable, u32 burst_duration_CCK, |
| 6999 | u32 burst_duration_OFDM) |
| 7000 | { |
| 7001 | priv->qos_data.qos_enable = enable; |
| 7002 | |
| 7003 | if (priv->qos_data.qos_enable) { |
| 7004 | priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK; |
| 7005 | priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM; |
| 7006 | IPW_DEBUG_QOS("QoS is enabled\n"); |
| 7007 | } else { |
| 7008 | priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK; |
| 7009 | priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM; |
| 7010 | IPW_DEBUG_QOS("QoS is not enabled\n"); |
| 7011 | } |
| 7012 | |
| 7013 | priv->qos_data.burst_enable = burst_enable; |
| 7014 | |
| 7015 | if (burst_enable) { |
| 7016 | priv->qos_data.burst_duration_CCK = burst_duration_CCK; |
| 7017 | priv->qos_data.burst_duration_OFDM = burst_duration_OFDM; |
| 7018 | } else { |
| 7019 | priv->qos_data.burst_duration_CCK = 0; |
| 7020 | priv->qos_data.burst_duration_OFDM = 0; |
| 7021 | } |
| 7022 | } |
| 7023 | |
| 7024 | /* |
| 7025 | * map the packet priority to the right TX Queue |
| 7026 | */ |
| 7027 | static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority) |
| 7028 | { |
| 7029 | if (priority > 7 || !priv->qos_data.qos_enable) |
| 7030 | priority = 0; |
| 7031 | |
| 7032 | return from_priority_to_tx_queue[priority] - 1; |
| 7033 | } |
| 7034 | |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7035 | static int ipw_is_qos_active(struct net_device *dev, |
| 7036 | struct sk_buff *skb) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7037 | { |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7038 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7039 | struct ieee80211_qos_data *qos_data = NULL; |
| 7040 | int active, supported; |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7041 | u8 *daddr = skb->data + ETH_ALEN; |
| 7042 | int unicast = !is_multicast_ether_addr(daddr); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7043 | |
| 7044 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 7045 | return 0; |
| 7046 | |
| 7047 | qos_data = &priv->assoc_network->qos_data; |
| 7048 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7049 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
| 7050 | if (unicast == 0) |
| 7051 | qos_data->active = 0; |
| 7052 | else |
| 7053 | qos_data->active = qos_data->supported; |
| 7054 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7055 | active = qos_data->active; |
| 7056 | supported = qos_data->supported; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7057 | IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d " |
| 7058 | "unicast %d\n", |
| 7059 | priv->qos_data.qos_enable, active, supported, unicast); |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7060 | if (active && priv->qos_data.qos_enable) |
| 7061 | return 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7062 | |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7063 | return 0; |
| 7064 | |
| 7065 | } |
| 7066 | /* |
| 7067 | * add QoS parameter to the TX command |
| 7068 | */ |
| 7069 | static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv, |
| 7070 | u16 priority, |
| 7071 | struct tfd_data *tfd) |
| 7072 | { |
| 7073 | int tx_queue_id = 0; |
| 7074 | |
| 7075 | |
| 7076 | tx_queue_id = from_priority_to_tx_queue[priority] - 1; |
| 7077 | tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED; |
| 7078 | |
| 7079 | if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) { |
| 7080 | tfd->tx_flags &= ~DCT_FLAG_ACK_REQD; |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 7081 | tfd->tfd.tfd_26.mchdr.qos_ctrl |= cpu_to_le16(CTRL_QOS_NO_ACK); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7082 | } |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7083 | return 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7084 | } |
| 7085 | |
| 7086 | /* |
| 7087 | * background support to run QoS activate functionality |
| 7088 | */ |
| 7089 | static void ipw_bg_qos_activate(void *data) |
| 7090 | { |
| 7091 | struct ipw_priv *priv = data; |
| 7092 | |
| 7093 | if (priv == NULL) |
| 7094 | return; |
| 7095 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7096 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7097 | |
| 7098 | if (priv->status & STATUS_ASSOCIATED) |
| 7099 | ipw_qos_activate(priv, &(priv->assoc_network->qos_data)); |
| 7100 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7101 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7102 | } |
| 7103 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7104 | static int ipw_handle_probe_response(struct net_device *dev, |
| 7105 | struct ieee80211_probe_response *resp, |
| 7106 | struct ieee80211_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7107 | { |
| 7108 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7109 | int active_network = ((priv->status & STATUS_ASSOCIATED) && |
| 7110 | (network == priv->assoc_network)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7111 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7112 | ipw_qos_handle_probe_response(priv, active_network, network); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7113 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7114 | return 0; |
| 7115 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7116 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7117 | static int ipw_handle_beacon(struct net_device *dev, |
| 7118 | struct ieee80211_beacon *resp, |
| 7119 | struct ieee80211_network *network) |
| 7120 | { |
| 7121 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 7122 | int active_network = ((priv->status & STATUS_ASSOCIATED) && |
| 7123 | (network == priv->assoc_network)); |
| 7124 | |
| 7125 | ipw_qos_handle_probe_response(priv, active_network, network); |
| 7126 | |
| 7127 | return 0; |
| 7128 | } |
| 7129 | |
| 7130 | static int ipw_handle_assoc_response(struct net_device *dev, |
| 7131 | struct ieee80211_assoc_response *resp, |
| 7132 | struct ieee80211_network *network) |
| 7133 | { |
| 7134 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 7135 | ipw_qos_association_resp(priv, network); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7136 | return 0; |
| 7137 | } |
| 7138 | |
| 7139 | static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters |
| 7140 | *qos_param) |
| 7141 | { |
Zhu Yi | 4e22699 | 2006-01-24 16:37:36 +0800 | [diff] [blame] | 7142 | return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS, |
| 7143 | sizeof(*qos_param) * 3, qos_param); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7144 | } |
| 7145 | |
| 7146 | static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element |
| 7147 | *qos_param) |
| 7148 | { |
Zhu Yi | 4e22699 | 2006-01-24 16:37:36 +0800 | [diff] [blame] | 7149 | return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param), |
| 7150 | qos_param); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7151 | } |
| 7152 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 7153 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7154 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7155 | static int ipw_associate_network(struct ipw_priv *priv, |
| 7156 | struct ieee80211_network *network, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7157 | struct ipw_supported_rates *rates, int roaming) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7158 | { |
| 7159 | int err; |
| 7160 | |
| 7161 | if (priv->config & CFG_FIXED_RATE) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7162 | ipw_set_fixed_rate(priv, network->mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7163 | |
| 7164 | if (!(priv->config & CFG_STATIC_ESSID)) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7165 | priv->essid_len = min(network->ssid_len, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7166 | (u8) IW_ESSID_MAX_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7167 | memcpy(priv->essid, network->ssid, priv->essid_len); |
| 7168 | } |
| 7169 | |
| 7170 | network->last_associate = jiffies; |
| 7171 | |
| 7172 | memset(&priv->assoc_request, 0, sizeof(priv->assoc_request)); |
| 7173 | priv->assoc_request.channel = network->channel; |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7174 | priv->assoc_request.auth_key = 0; |
| 7175 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7176 | if ((priv->capability & CAP_PRIVACY_ON) && |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7177 | (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7178 | priv->assoc_request.auth_type = AUTH_SHARED_KEY; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7179 | priv->assoc_request.auth_key = priv->ieee->sec.active_key; |
| 7180 | |
Zhu Yi | 1ba61e0 | 2006-02-15 13:00:55 +0800 | [diff] [blame] | 7181 | if (priv->ieee->sec.level == SEC_LEVEL_1) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7182 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7183 | |
| 7184 | } else if ((priv->capability & CAP_PRIVACY_ON) && |
| 7185 | (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP)) |
| 7186 | priv->assoc_request.auth_type = AUTH_LEAP; |
| 7187 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7188 | priv->assoc_request.auth_type = AUTH_OPEN; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7189 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7190 | if (priv->ieee->wpa_ie_len) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7191 | priv->assoc_request.policy_support = 0x02; /* RSN active */ |
| 7192 | ipw_set_rsn_capa(priv, priv->ieee->wpa_ie, |
| 7193 | priv->ieee->wpa_ie_len); |
| 7194 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7195 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7196 | /* |
| 7197 | * It is valid for our ieee device to support multiple modes, but |
| 7198 | * when it comes to associating to a given network we have to choose |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7199 | * just one mode. |
| 7200 | */ |
| 7201 | if (network->mode & priv->ieee->mode & IEEE_A) |
| 7202 | priv->assoc_request.ieee_mode = IPW_A_MODE; |
| 7203 | else if (network->mode & priv->ieee->mode & IEEE_G) |
| 7204 | priv->assoc_request.ieee_mode = IPW_G_MODE; |
| 7205 | else if (network->mode & priv->ieee->mode & IEEE_B) |
| 7206 | priv->assoc_request.ieee_mode = IPW_B_MODE; |
| 7207 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7208 | priv->assoc_request.capability = network->capability; |
| 7209 | if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 7210 | && !(priv->config & CFG_PREAMBLE_LONG)) { |
| 7211 | priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE; |
| 7212 | } else { |
| 7213 | priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE; |
| 7214 | |
| 7215 | /* Clear the short preamble if we won't be supporting it */ |
| 7216 | priv->assoc_request.capability &= |
| 7217 | ~WLAN_CAPABILITY_SHORT_PREAMBLE; |
| 7218 | } |
| 7219 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7220 | /* Clear capability bits that aren't used in Ad Hoc */ |
| 7221 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 7222 | priv->assoc_request.capability &= |
| 7223 | ~WLAN_CAPABILITY_SHORT_SLOT_TIME; |
| 7224 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7225 | IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, " |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7226 | "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7227 | roaming ? "Rea" : "A", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7228 | escape_essid(priv->essid, priv->essid_len), |
| 7229 | network->channel, |
| 7230 | ipw_modes[priv->assoc_request.ieee_mode], |
| 7231 | rates->num_rates, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7232 | (priv->assoc_request.preamble_length == |
| 7233 | DCT_FLAG_LONG_PREAMBLE) ? "long" : "short", |
| 7234 | network->capability & |
| 7235 | WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7236 | priv->capability & CAP_PRIVACY_ON ? "on " : "off", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7237 | priv->capability & CAP_PRIVACY_ON ? |
| 7238 | (priv->capability & CAP_SHARED_KEY ? "(shared)" : |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7239 | "(open)") : "", |
| 7240 | priv->capability & CAP_PRIVACY_ON ? " key=" : "", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7241 | priv->capability & CAP_PRIVACY_ON ? |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7242 | '1' + priv->ieee->sec.active_key : '.', |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7243 | priv->capability & CAP_PRIVACY_ON ? '.' : ' '); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7244 | |
| 7245 | priv->assoc_request.beacon_interval = network->beacon_interval; |
| 7246 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7247 | (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7248 | priv->assoc_request.assoc_type = HC_IBSS_START; |
| 7249 | priv->assoc_request.assoc_tsf_msw = 0; |
| 7250 | priv->assoc_request.assoc_tsf_lsw = 0; |
| 7251 | } else { |
| 7252 | if (unlikely(roaming)) |
| 7253 | priv->assoc_request.assoc_type = HC_REASSOCIATE; |
| 7254 | else |
| 7255 | priv->assoc_request.assoc_type = HC_ASSOCIATE; |
| 7256 | priv->assoc_request.assoc_tsf_msw = network->time_stamp[1]; |
| 7257 | priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0]; |
| 7258 | } |
| 7259 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7260 | memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7261 | |
| 7262 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
| 7263 | memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN); |
| 7264 | priv->assoc_request.atim_window = network->atim_window; |
| 7265 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7266 | memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7267 | priv->assoc_request.atim_window = 0; |
| 7268 | } |
| 7269 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7270 | priv->assoc_request.listen_interval = network->listen_interval; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7271 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7272 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
| 7273 | if (err) { |
| 7274 | IPW_DEBUG_HC("Attempt to send SSID command failed.\n"); |
| 7275 | return err; |
| 7276 | } |
| 7277 | |
| 7278 | rates->ieee_mode = priv->assoc_request.ieee_mode; |
| 7279 | rates->purpose = IPW_RATE_CONNECT; |
| 7280 | ipw_send_supported_rates(priv, rates); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7281 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7282 | if (priv->assoc_request.ieee_mode == IPW_G_MODE) |
| 7283 | priv->sys_config.dot11g_auto_detection = 1; |
| 7284 | else |
| 7285 | priv->sys_config.dot11g_auto_detection = 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7286 | |
| 7287 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 7288 | priv->sys_config.answer_broadcast_ssid_probe = 1; |
| 7289 | else |
| 7290 | priv->sys_config.answer_broadcast_ssid_probe = 0; |
| 7291 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7292 | err = ipw_send_system_config(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7293 | if (err) { |
| 7294 | IPW_DEBUG_HC("Attempt to send sys config command failed.\n"); |
| 7295 | return err; |
| 7296 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7297 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7298 | IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7299 | err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7300 | if (err) { |
| 7301 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); |
| 7302 | return err; |
| 7303 | } |
| 7304 | |
| 7305 | /* |
| 7306 | * If preemption is enabled, it is possible for the association |
| 7307 | * to complete before we return from ipw_send_associate. Therefore |
| 7308 | * we have to be sure and update our priviate data first. |
| 7309 | */ |
| 7310 | priv->channel = network->channel; |
| 7311 | memcpy(priv->bssid, network->bssid, ETH_ALEN); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7312 | priv->status |= STATUS_ASSOCIATING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7313 | priv->status &= ~STATUS_SECURITY_UPDATED; |
| 7314 | |
| 7315 | priv->assoc_network = network; |
| 7316 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 7317 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7318 | ipw_qos_association(priv, network); |
| 7319 | #endif |
| 7320 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7321 | err = ipw_send_associate(priv, &priv->assoc_request); |
| 7322 | if (err) { |
| 7323 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); |
| 7324 | return err; |
| 7325 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7326 | |
| 7327 | IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7328 | escape_essid(priv->essid, priv->essid_len), |
| 7329 | MAC_ARG(priv->bssid)); |
| 7330 | |
| 7331 | return 0; |
| 7332 | } |
| 7333 | |
| 7334 | static void ipw_roam(void *data) |
| 7335 | { |
| 7336 | struct ipw_priv *priv = data; |
| 7337 | struct ieee80211_network *network = NULL; |
| 7338 | struct ipw_network_match match = { |
| 7339 | .network = priv->assoc_network |
| 7340 | }; |
| 7341 | |
| 7342 | /* The roaming process is as follows: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7343 | * |
| 7344 | * 1. Missed beacon threshold triggers the roaming process by |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7345 | * setting the status ROAM bit and requesting a scan. |
| 7346 | * 2. When the scan completes, it schedules the ROAM work |
| 7347 | * 3. The ROAM work looks at all of the known networks for one that |
| 7348 | * is a better network than the currently associated. If none |
| 7349 | * found, the ROAM process is over (ROAM bit cleared) |
| 7350 | * 4. If a better network is found, a disassociation request is |
| 7351 | * sent. |
| 7352 | * 5. When the disassociation completes, the roam work is again |
| 7353 | * scheduled. The second time through, the driver is no longer |
| 7354 | * associated, and the newly selected network is sent an |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7355 | * association request. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7356 | * 6. At this point ,the roaming process is complete and the ROAM |
| 7357 | * status bit is cleared. |
| 7358 | */ |
| 7359 | |
| 7360 | /* If we are no longer associated, and the roaming bit is no longer |
| 7361 | * set, then we are not actively roaming, so just return */ |
| 7362 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING))) |
| 7363 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7364 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7365 | if (priv->status & STATUS_ASSOCIATED) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7366 | /* First pass through ROAM process -- look for a better |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7367 | * network */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7368 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7369 | u8 rssi = priv->assoc_network->stats.rssi; |
| 7370 | priv->assoc_network->stats.rssi = -128; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7371 | spin_lock_irqsave(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7372 | list_for_each_entry(network, &priv->ieee->network_list, list) { |
| 7373 | if (network != priv->assoc_network) |
| 7374 | ipw_best_network(priv, &match, network, 1); |
| 7375 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7376 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7377 | priv->assoc_network->stats.rssi = rssi; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7378 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7379 | if (match.network == priv->assoc_network) { |
| 7380 | IPW_DEBUG_ASSOC("No better APs in this network to " |
| 7381 | "roam to.\n"); |
| 7382 | priv->status &= ~STATUS_ROAMING; |
| 7383 | ipw_debug_config(priv); |
| 7384 | return; |
| 7385 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7386 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7387 | ipw_send_disassociate(priv, 1); |
| 7388 | priv->assoc_network = match.network; |
| 7389 | |
| 7390 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7391 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7392 | |
| 7393 | /* Second pass through ROAM process -- request association */ |
| 7394 | ipw_compatible_rates(priv, priv->assoc_network, &match.rates); |
| 7395 | ipw_associate_network(priv, priv->assoc_network, &match.rates, 1); |
| 7396 | priv->status &= ~STATUS_ROAMING; |
| 7397 | } |
| 7398 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7399 | static void ipw_bg_roam(void *data) |
| 7400 | { |
| 7401 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7402 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7403 | ipw_roam(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7404 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7405 | } |
| 7406 | |
| 7407 | static int ipw_associate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7408 | { |
| 7409 | struct ipw_priv *priv = data; |
| 7410 | |
| 7411 | struct ieee80211_network *network = NULL; |
| 7412 | struct ipw_network_match match = { |
| 7413 | .network = NULL |
| 7414 | }; |
| 7415 | struct ipw_supported_rates *rates; |
| 7416 | struct list_head *element; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7417 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7418 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7419 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
| 7420 | IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n"); |
| 7421 | return 0; |
| 7422 | } |
| 7423 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7424 | if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7425 | IPW_DEBUG_ASSOC("Not attempting association (already in " |
| 7426 | "progress)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7427 | return 0; |
| 7428 | } |
| 7429 | |
Hong Liu | e632472 | 2005-09-14 21:04:15 -0500 | [diff] [blame] | 7430 | if (priv->status & STATUS_DISASSOCIATING) { |
| 7431 | IPW_DEBUG_ASSOC("Not attempting association (in " |
| 7432 | "disassociating)\n "); |
| 7433 | queue_work(priv->workqueue, &priv->associate); |
| 7434 | return 0; |
| 7435 | } |
| 7436 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7437 | if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7438 | IPW_DEBUG_ASSOC("Not attempting association (scanning or not " |
| 7439 | "initialized)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7440 | return 0; |
| 7441 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7442 | |
| 7443 | if (!(priv->config & CFG_ASSOCIATE) && |
| 7444 | !(priv->config & (CFG_STATIC_ESSID | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7445 | CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7446 | IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7447 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7448 | } |
| 7449 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7450 | /* Protect our use of the network_list */ |
| 7451 | spin_lock_irqsave(&priv->ieee->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7452 | list_for_each_entry(network, &priv->ieee->network_list, list) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7453 | ipw_best_network(priv, &match, network, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7454 | |
| 7455 | network = match.network; |
| 7456 | rates = &match.rates; |
| 7457 | |
| 7458 | if (network == NULL && |
| 7459 | priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 7460 | priv->config & CFG_ADHOC_CREATE && |
| 7461 | priv->config & CFG_STATIC_ESSID && |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7462 | priv->config & CFG_STATIC_CHANNEL && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7463 | !list_empty(&priv->ieee->network_free_list)) { |
| 7464 | element = priv->ieee->network_free_list.next; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7465 | network = list_entry(element, struct ieee80211_network, list); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7466 | ipw_adhoc_create(priv, network); |
| 7467 | rates = &priv->rates; |
| 7468 | list_del(element); |
| 7469 | list_add_tail(&network->list, &priv->ieee->network_list); |
| 7470 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7471 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7472 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7473 | /* If we reached the end of the list, then we don't have any valid |
| 7474 | * matching APs */ |
| 7475 | if (!network) { |
| 7476 | ipw_debug_config(priv); |
| 7477 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7478 | if (!(priv->status & STATUS_SCANNING)) { |
| 7479 | if (!(priv->config & CFG_SPEED_SCAN)) |
| 7480 | queue_delayed_work(priv->workqueue, |
| 7481 | &priv->request_scan, |
| 7482 | SCAN_INTERVAL); |
| 7483 | else |
| 7484 | queue_work(priv->workqueue, |
| 7485 | &priv->request_scan); |
| 7486 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7487 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7488 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7489 | } |
| 7490 | |
| 7491 | ipw_associate_network(priv, network, rates, 0); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7492 | |
| 7493 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7494 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7495 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7496 | static void ipw_bg_associate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7497 | { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7498 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7499 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7500 | ipw_associate(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7501 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7502 | } |
| 7503 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7504 | static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv, |
| 7505 | struct sk_buff *skb) |
| 7506 | { |
| 7507 | struct ieee80211_hdr *hdr; |
| 7508 | u16 fc; |
| 7509 | |
| 7510 | hdr = (struct ieee80211_hdr *)skb->data; |
| 7511 | fc = le16_to_cpu(hdr->frame_ctl); |
| 7512 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 7513 | return; |
| 7514 | |
| 7515 | fc &= ~IEEE80211_FCTL_PROTECTED; |
| 7516 | hdr->frame_ctl = cpu_to_le16(fc); |
| 7517 | switch (priv->ieee->sec.level) { |
| 7518 | case SEC_LEVEL_3: |
| 7519 | /* Remove CCMP HDR */ |
| 7520 | memmove(skb->data + IEEE80211_3ADDR_LEN, |
| 7521 | skb->data + IEEE80211_3ADDR_LEN + 8, |
| 7522 | skb->len - IEEE80211_3ADDR_LEN - 8); |
Zhu Yi | f4ff497 | 2005-09-12 10:48:48 -0500 | [diff] [blame] | 7523 | skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7524 | break; |
| 7525 | case SEC_LEVEL_2: |
| 7526 | break; |
| 7527 | case SEC_LEVEL_1: |
| 7528 | /* Remove IV */ |
| 7529 | memmove(skb->data + IEEE80211_3ADDR_LEN, |
| 7530 | skb->data + IEEE80211_3ADDR_LEN + 4, |
| 7531 | skb->len - IEEE80211_3ADDR_LEN - 4); |
Zhu Yi | f4ff497 | 2005-09-12 10:48:48 -0500 | [diff] [blame] | 7532 | skb_trim(skb, skb->len - 8); /* IV + ICV */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7533 | break; |
| 7534 | case SEC_LEVEL_0: |
| 7535 | break; |
| 7536 | default: |
| 7537 | printk(KERN_ERR "Unknow security level %d\n", |
| 7538 | priv->ieee->sec.level); |
| 7539 | break; |
| 7540 | } |
| 7541 | } |
| 7542 | |
| 7543 | static void ipw_handle_data_packet(struct ipw_priv *priv, |
| 7544 | struct ipw_rx_mem_buffer *rxb, |
| 7545 | struct ieee80211_rx_stats *stats) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7546 | { |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 7547 | struct ieee80211_hdr_4addr *hdr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7548 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7549 | |
| 7550 | /* We received data from the HW, so stop the watchdog */ |
| 7551 | priv->net_dev->trans_start = jiffies; |
| 7552 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7553 | /* We only process data packets if the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7554 | * interface is open */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7555 | if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) > |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7556 | skb_tailroom(rxb->skb))) { |
| 7557 | priv->ieee->stats.rx_errors++; |
| 7558 | priv->wstats.discard.misc++; |
| 7559 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 7560 | return; |
| 7561 | } else if (unlikely(!netif_running(priv->net_dev))) { |
| 7562 | priv->ieee->stats.rx_dropped++; |
| 7563 | priv->wstats.discard.misc++; |
| 7564 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 7565 | return; |
| 7566 | } |
| 7567 | |
| 7568 | /* Advance skb->data to the start of the actual payload */ |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 7569 | skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7570 | |
| 7571 | /* Set the size of the skb to the size of the frame */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7572 | skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7573 | |
| 7574 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); |
| 7575 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7576 | /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */ |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 7577 | hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data; |
| 7578 | if (priv->ieee->iw_mode != IW_MODE_MONITOR && |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 7579 | (is_multicast_ether_addr(hdr->addr1) ? |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 7580 | !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7581 | ipw_rebuild_decrypted_skb(priv, rxb->skb); |
| 7582 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7583 | if (!ieee80211_rx(priv->ieee, rxb->skb, stats)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7584 | priv->ieee->stats.rx_errors++; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7585 | else { /* ieee80211_rx succeeded, so it now owns the SKB */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7586 | rxb->skb = NULL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7587 | __ipw_led_activity_on(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7588 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7589 | } |
| 7590 | |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 7591 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7592 | static void ipw_handle_data_packet_monitor(struct ipw_priv *priv, |
| 7593 | struct ipw_rx_mem_buffer *rxb, |
| 7594 | struct ieee80211_rx_stats *stats) |
| 7595 | { |
| 7596 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7597 | struct ipw_rx_frame *frame = &pkt->u.frame; |
| 7598 | |
| 7599 | /* initial pull of some data */ |
| 7600 | u16 received_channel = frame->received_channel; |
| 7601 | u8 antennaAndPhy = frame->antennaAndPhy; |
| 7602 | s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */ |
| 7603 | u16 pktrate = frame->rate; |
| 7604 | |
| 7605 | /* Magic struct that slots into the radiotap header -- no reason |
| 7606 | * to build this manually element by element, we can write it much |
| 7607 | * more efficiently than we can parse it. ORDER MATTERS HERE */ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7608 | struct ipw_rt_hdr *ipw_rt; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7609 | |
| 7610 | short len = le16_to_cpu(pkt->u.frame.length); |
| 7611 | |
| 7612 | /* We received data from the HW, so stop the watchdog */ |
| 7613 | priv->net_dev->trans_start = jiffies; |
| 7614 | |
| 7615 | /* We only process data packets if the |
| 7616 | * interface is open */ |
| 7617 | if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) > |
| 7618 | skb_tailroom(rxb->skb))) { |
| 7619 | priv->ieee->stats.rx_errors++; |
| 7620 | priv->wstats.discard.misc++; |
| 7621 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 7622 | return; |
| 7623 | } else if (unlikely(!netif_running(priv->net_dev))) { |
| 7624 | priv->ieee->stats.rx_dropped++; |
| 7625 | priv->wstats.discard.misc++; |
| 7626 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 7627 | return; |
| 7628 | } |
| 7629 | |
| 7630 | /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use |
| 7631 | * that now */ |
| 7632 | if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) { |
| 7633 | /* FIXME: Should alloc bigger skb instead */ |
| 7634 | priv->ieee->stats.rx_dropped++; |
| 7635 | priv->wstats.discard.misc++; |
| 7636 | IPW_DEBUG_DROP("Dropping too large packet in monitor\n"); |
| 7637 | return; |
| 7638 | } |
| 7639 | |
| 7640 | /* copy the frame itself */ |
| 7641 | memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr), |
| 7642 | rxb->skb->data + IPW_RX_FRAME_SIZE, len); |
| 7643 | |
| 7644 | /* Zero the radiotap static buffer ... We only need to zero the bytes NOT |
| 7645 | * part of our real header, saves a little time. |
| 7646 | * |
| 7647 | * No longer necessary since we fill in all our data. Purge before merging |
| 7648 | * patch officially. |
| 7649 | * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0, |
| 7650 | * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr)); |
| 7651 | */ |
| 7652 | |
| 7653 | ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data; |
| 7654 | |
| 7655 | ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 7656 | ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ |
| 7657 | ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */ |
| 7658 | |
| 7659 | /* Big bitfield of all the fields we provide in radiotap */ |
| 7660 | ipw_rt->rt_hdr.it_present = |
| 7661 | ((1 << IEEE80211_RADIOTAP_FLAGS) | |
| 7662 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 7663 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 7664 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7665 | (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7666 | (1 << IEEE80211_RADIOTAP_ANTENNA)); |
| 7667 | |
| 7668 | /* Zero the flags, we'll add to them as we go */ |
| 7669 | ipw_rt->rt_flags = 0; |
Zhu Yi | 88a93df | 2006-08-21 11:38:08 +0800 | [diff] [blame] | 7670 | ipw_rt->rt_tsf = 0ULL; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7671 | |
| 7672 | /* Convert signal to DBM */ |
| 7673 | ipw_rt->rt_dbmsignal = antsignal; |
| 7674 | |
| 7675 | /* Convert the channel data and set the flags */ |
| 7676 | ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel)); |
| 7677 | if (received_channel > 14) { /* 802.11a */ |
| 7678 | ipw_rt->rt_chbitmask = |
| 7679 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); |
| 7680 | } else if (antennaAndPhy & 32) { /* 802.11b */ |
| 7681 | ipw_rt->rt_chbitmask = |
| 7682 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); |
| 7683 | } else { /* 802.11g */ |
| 7684 | ipw_rt->rt_chbitmask = |
| 7685 | (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ); |
| 7686 | } |
| 7687 | |
| 7688 | /* set the rate in multiples of 500k/s */ |
| 7689 | switch (pktrate) { |
| 7690 | case IPW_TX_RATE_1MB: |
| 7691 | ipw_rt->rt_rate = 2; |
| 7692 | break; |
| 7693 | case IPW_TX_RATE_2MB: |
| 7694 | ipw_rt->rt_rate = 4; |
| 7695 | break; |
| 7696 | case IPW_TX_RATE_5MB: |
| 7697 | ipw_rt->rt_rate = 10; |
| 7698 | break; |
| 7699 | case IPW_TX_RATE_6MB: |
| 7700 | ipw_rt->rt_rate = 12; |
| 7701 | break; |
| 7702 | case IPW_TX_RATE_9MB: |
| 7703 | ipw_rt->rt_rate = 18; |
| 7704 | break; |
| 7705 | case IPW_TX_RATE_11MB: |
| 7706 | ipw_rt->rt_rate = 22; |
| 7707 | break; |
| 7708 | case IPW_TX_RATE_12MB: |
| 7709 | ipw_rt->rt_rate = 24; |
| 7710 | break; |
| 7711 | case IPW_TX_RATE_18MB: |
| 7712 | ipw_rt->rt_rate = 36; |
| 7713 | break; |
| 7714 | case IPW_TX_RATE_24MB: |
| 7715 | ipw_rt->rt_rate = 48; |
| 7716 | break; |
| 7717 | case IPW_TX_RATE_36MB: |
| 7718 | ipw_rt->rt_rate = 72; |
| 7719 | break; |
| 7720 | case IPW_TX_RATE_48MB: |
| 7721 | ipw_rt->rt_rate = 96; |
| 7722 | break; |
| 7723 | case IPW_TX_RATE_54MB: |
| 7724 | ipw_rt->rt_rate = 108; |
| 7725 | break; |
| 7726 | default: |
| 7727 | ipw_rt->rt_rate = 0; |
| 7728 | break; |
| 7729 | } |
| 7730 | |
| 7731 | /* antenna number */ |
| 7732 | ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */ |
| 7733 | |
| 7734 | /* set the preamble flag if we have it */ |
| 7735 | if ((antennaAndPhy & 64)) |
| 7736 | ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; |
| 7737 | |
| 7738 | /* Set the size of the skb to the size of the frame */ |
| 7739 | skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7740 | |
| 7741 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); |
| 7742 | |
| 7743 | if (!ieee80211_rx(priv->ieee, rxb->skb, stats)) |
| 7744 | priv->ieee->stats.rx_errors++; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7745 | else { /* ieee80211_rx succeeded, so it now owns the SKB */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7746 | rxb->skb = NULL; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7747 | /* no LED during capture */ |
| 7748 | } |
| 7749 | } |
| 7750 | #endif |
| 7751 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7752 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 7753 | #define ieee80211_is_probe_response(fc) \ |
| 7754 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \ |
| 7755 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP ) |
| 7756 | |
| 7757 | #define ieee80211_is_management(fc) \ |
| 7758 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) |
| 7759 | |
| 7760 | #define ieee80211_is_control(fc) \ |
| 7761 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) |
| 7762 | |
| 7763 | #define ieee80211_is_data(fc) \ |
| 7764 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) |
| 7765 | |
| 7766 | #define ieee80211_is_assoc_request(fc) \ |
| 7767 | ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ) |
| 7768 | |
| 7769 | #define ieee80211_is_reassoc_request(fc) \ |
| 7770 | ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ) |
| 7771 | |
| 7772 | static void ipw_handle_promiscuous_rx(struct ipw_priv *priv, |
| 7773 | struct ipw_rx_mem_buffer *rxb, |
| 7774 | struct ieee80211_rx_stats *stats) |
| 7775 | { |
| 7776 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7777 | struct ipw_rx_frame *frame = &pkt->u.frame; |
| 7778 | struct ipw_rt_hdr *ipw_rt; |
| 7779 | |
| 7780 | /* First cache any information we need before we overwrite |
| 7781 | * the information provided in the skb from the hardware */ |
| 7782 | struct ieee80211_hdr *hdr; |
| 7783 | u16 channel = frame->received_channel; |
| 7784 | u8 phy_flags = frame->antennaAndPhy; |
| 7785 | s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM; |
| 7786 | s8 noise = frame->noise; |
| 7787 | u8 rate = frame->rate; |
| 7788 | short len = le16_to_cpu(pkt->u.frame.length); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7789 | struct sk_buff *skb; |
| 7790 | int hdr_only = 0; |
| 7791 | u16 filter = priv->prom_priv->filter; |
| 7792 | |
| 7793 | /* If the filter is set to not include Rx frames then return */ |
| 7794 | if (filter & IPW_PROM_NO_RX) |
| 7795 | return; |
| 7796 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7797 | /* We received data from the HW, so stop the watchdog */ |
| 7798 | priv->prom_net_dev->trans_start = jiffies; |
| 7799 | |
| 7800 | if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) { |
| 7801 | priv->prom_priv->ieee->stats.rx_errors++; |
| 7802 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 7803 | return; |
| 7804 | } |
| 7805 | |
| 7806 | /* We only process data packets if the interface is open */ |
| 7807 | if (unlikely(!netif_running(priv->prom_net_dev))) { |
| 7808 | priv->prom_priv->ieee->stats.rx_dropped++; |
| 7809 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 7810 | return; |
| 7811 | } |
| 7812 | |
| 7813 | /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use |
| 7814 | * that now */ |
| 7815 | if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) { |
| 7816 | /* FIXME: Should alloc bigger skb instead */ |
| 7817 | priv->prom_priv->ieee->stats.rx_dropped++; |
| 7818 | IPW_DEBUG_DROP("Dropping too large packet in monitor\n"); |
| 7819 | return; |
| 7820 | } |
| 7821 | |
| 7822 | hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE; |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 7823 | if (ieee80211_is_management(le16_to_cpu(hdr->frame_ctl))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7824 | if (filter & IPW_PROM_NO_MGMT) |
| 7825 | return; |
| 7826 | if (filter & IPW_PROM_MGMT_HEADER_ONLY) |
| 7827 | hdr_only = 1; |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 7828 | } else if (ieee80211_is_control(le16_to_cpu(hdr->frame_ctl))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7829 | if (filter & IPW_PROM_NO_CTL) |
| 7830 | return; |
| 7831 | if (filter & IPW_PROM_CTL_HEADER_ONLY) |
| 7832 | hdr_only = 1; |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 7833 | } else if (ieee80211_is_data(le16_to_cpu(hdr->frame_ctl))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7834 | if (filter & IPW_PROM_NO_DATA) |
| 7835 | return; |
| 7836 | if (filter & IPW_PROM_DATA_HEADER_ONLY) |
| 7837 | hdr_only = 1; |
| 7838 | } |
| 7839 | |
| 7840 | /* Copy the SKB since this is for the promiscuous side */ |
| 7841 | skb = skb_copy(rxb->skb, GFP_ATOMIC); |
| 7842 | if (skb == NULL) { |
| 7843 | IPW_ERROR("skb_clone failed for promiscuous copy.\n"); |
| 7844 | return; |
| 7845 | } |
| 7846 | |
| 7847 | /* copy the frame data to write after where the radiotap header goes */ |
| 7848 | ipw_rt = (void *)skb->data; |
| 7849 | |
| 7850 | if (hdr_only) |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 7851 | len = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7852 | |
| 7853 | memcpy(ipw_rt->payload, hdr, len); |
| 7854 | |
| 7855 | /* Zero the radiotap static buffer ... We only need to zero the bytes |
| 7856 | * NOT part of our real header, saves a little time. |
| 7857 | * |
| 7858 | * No longer necessary since we fill in all our data. Purge before |
| 7859 | * merging patch officially. |
| 7860 | * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0, |
| 7861 | * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr)); |
| 7862 | */ |
| 7863 | |
| 7864 | ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 7865 | ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ |
| 7866 | ipw_rt->rt_hdr.it_len = sizeof(*ipw_rt); /* total header+data */ |
| 7867 | |
| 7868 | /* Set the size of the skb to the size of the frame */ |
| 7869 | skb_put(skb, ipw_rt->rt_hdr.it_len + len); |
| 7870 | |
| 7871 | /* Big bitfield of all the fields we provide in radiotap */ |
| 7872 | ipw_rt->rt_hdr.it_present = |
| 7873 | ((1 << IEEE80211_RADIOTAP_FLAGS) | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7874 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 7875 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 7876 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | |
| 7877 | (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | |
| 7878 | (1 << IEEE80211_RADIOTAP_ANTENNA)); |
| 7879 | |
| 7880 | /* Zero the flags, we'll add to them as we go */ |
| 7881 | ipw_rt->rt_flags = 0; |
Zhu Yi | 88a93df | 2006-08-21 11:38:08 +0800 | [diff] [blame] | 7882 | ipw_rt->rt_tsf = 0ULL; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7883 | |
| 7884 | /* Convert to DBM */ |
| 7885 | ipw_rt->rt_dbmsignal = signal; |
| 7886 | ipw_rt->rt_dbmnoise = noise; |
| 7887 | |
| 7888 | /* Convert the channel data and set the flags */ |
| 7889 | ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel)); |
| 7890 | if (channel > 14) { /* 802.11a */ |
| 7891 | ipw_rt->rt_chbitmask = |
| 7892 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); |
| 7893 | } else if (phy_flags & (1 << 5)) { /* 802.11b */ |
| 7894 | ipw_rt->rt_chbitmask = |
| 7895 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); |
| 7896 | } else { /* 802.11g */ |
| 7897 | ipw_rt->rt_chbitmask = |
| 7898 | (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ); |
| 7899 | } |
| 7900 | |
| 7901 | /* set the rate in multiples of 500k/s */ |
| 7902 | switch (rate) { |
| 7903 | case IPW_TX_RATE_1MB: |
| 7904 | ipw_rt->rt_rate = 2; |
| 7905 | break; |
| 7906 | case IPW_TX_RATE_2MB: |
| 7907 | ipw_rt->rt_rate = 4; |
| 7908 | break; |
| 7909 | case IPW_TX_RATE_5MB: |
| 7910 | ipw_rt->rt_rate = 10; |
| 7911 | break; |
| 7912 | case IPW_TX_RATE_6MB: |
| 7913 | ipw_rt->rt_rate = 12; |
| 7914 | break; |
| 7915 | case IPW_TX_RATE_9MB: |
| 7916 | ipw_rt->rt_rate = 18; |
| 7917 | break; |
| 7918 | case IPW_TX_RATE_11MB: |
| 7919 | ipw_rt->rt_rate = 22; |
| 7920 | break; |
| 7921 | case IPW_TX_RATE_12MB: |
| 7922 | ipw_rt->rt_rate = 24; |
| 7923 | break; |
| 7924 | case IPW_TX_RATE_18MB: |
| 7925 | ipw_rt->rt_rate = 36; |
| 7926 | break; |
| 7927 | case IPW_TX_RATE_24MB: |
| 7928 | ipw_rt->rt_rate = 48; |
| 7929 | break; |
| 7930 | case IPW_TX_RATE_36MB: |
| 7931 | ipw_rt->rt_rate = 72; |
| 7932 | break; |
| 7933 | case IPW_TX_RATE_48MB: |
| 7934 | ipw_rt->rt_rate = 96; |
| 7935 | break; |
| 7936 | case IPW_TX_RATE_54MB: |
| 7937 | ipw_rt->rt_rate = 108; |
| 7938 | break; |
| 7939 | default: |
| 7940 | ipw_rt->rt_rate = 0; |
| 7941 | break; |
| 7942 | } |
| 7943 | |
| 7944 | /* antenna number */ |
| 7945 | ipw_rt->rt_antenna = (phy_flags & 3); |
| 7946 | |
| 7947 | /* set the preamble flag if we have it */ |
| 7948 | if (phy_flags & (1 << 6)) |
| 7949 | ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; |
| 7950 | |
| 7951 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len); |
| 7952 | |
| 7953 | if (!ieee80211_rx(priv->prom_priv->ieee, skb, stats)) { |
| 7954 | priv->prom_priv->ieee->stats.rx_errors++; |
| 7955 | dev_kfree_skb_any(skb); |
| 7956 | } |
| 7957 | } |
| 7958 | #endif |
| 7959 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 7960 | static int is_network_packet(struct ipw_priv *priv, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7961 | struct ieee80211_hdr_4addr *header) |
| 7962 | { |
| 7963 | /* Filter incoming packets to determine if they are targetted toward |
| 7964 | * this network, discarding packets coming from ourselves */ |
| 7965 | switch (priv->ieee->iw_mode) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7966 | case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7967 | /* packets from our adapter are dropped (echo) */ |
| 7968 | if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN)) |
| 7969 | return 0; |
| 7970 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 7971 | /* {broad,multi}cast packets to our BSSID go through */ |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 7972 | if (is_multicast_ether_addr(header->addr1)) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7973 | return !memcmp(header->addr3, priv->bssid, ETH_ALEN); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7974 | |
| 7975 | /* packets to our adapter go through */ |
| 7976 | return !memcmp(header->addr1, priv->net_dev->dev_addr, |
| 7977 | ETH_ALEN); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7978 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 7979 | case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7980 | /* packets from our adapter are dropped (echo) */ |
| 7981 | if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN)) |
| 7982 | return 0; |
| 7983 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 7984 | /* {broad,multi}cast packets to our BSS go through */ |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 7985 | if (is_multicast_ether_addr(header->addr1)) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7986 | return !memcmp(header->addr2, priv->bssid, ETH_ALEN); |
| 7987 | |
| 7988 | /* packets to our adapter go through */ |
| 7989 | return !memcmp(header->addr1, priv->net_dev->dev_addr, |
| 7990 | ETH_ALEN); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7991 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7992 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7993 | return 1; |
| 7994 | } |
| 7995 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7996 | #define IPW_PACKET_RETRY_TIME HZ |
| 7997 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 7998 | static int is_duplicate_packet(struct ipw_priv *priv, |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7999 | struct ieee80211_hdr_4addr *header) |
| 8000 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8001 | u16 sc = le16_to_cpu(header->seq_ctl); |
| 8002 | u16 seq = WLAN_GET_SEQ_SEQ(sc); |
| 8003 | u16 frag = WLAN_GET_SEQ_FRAG(sc); |
| 8004 | u16 *last_seq, *last_frag; |
| 8005 | unsigned long *last_time; |
| 8006 | |
| 8007 | switch (priv->ieee->iw_mode) { |
| 8008 | case IW_MODE_ADHOC: |
| 8009 | { |
| 8010 | struct list_head *p; |
| 8011 | struct ipw_ibss_seq *entry = NULL; |
| 8012 | u8 *mac = header->addr2; |
| 8013 | int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE; |
| 8014 | |
| 8015 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
| 8016 | entry = |
| 8017 | list_entry(p, struct ipw_ibss_seq, list); |
| 8018 | if (!memcmp(entry->mac, mac, ETH_ALEN)) |
| 8019 | break; |
| 8020 | } |
| 8021 | if (p == &priv->ibss_mac_hash[index]) { |
| 8022 | entry = kmalloc(sizeof(*entry), GFP_ATOMIC); |
| 8023 | if (!entry) { |
| 8024 | IPW_ERROR |
| 8025 | ("Cannot malloc new mac entry\n"); |
| 8026 | return 0; |
| 8027 | } |
| 8028 | memcpy(entry->mac, mac, ETH_ALEN); |
| 8029 | entry->seq_num = seq; |
| 8030 | entry->frag_num = frag; |
| 8031 | entry->packet_time = jiffies; |
| 8032 | list_add(&entry->list, |
| 8033 | &priv->ibss_mac_hash[index]); |
| 8034 | return 0; |
| 8035 | } |
| 8036 | last_seq = &entry->seq_num; |
| 8037 | last_frag = &entry->frag_num; |
| 8038 | last_time = &entry->packet_time; |
| 8039 | break; |
| 8040 | } |
| 8041 | case IW_MODE_INFRA: |
| 8042 | last_seq = &priv->last_seq_num; |
| 8043 | last_frag = &priv->last_frag_num; |
| 8044 | last_time = &priv->last_packet_time; |
| 8045 | break; |
| 8046 | default: |
| 8047 | return 0; |
| 8048 | } |
| 8049 | if ((*last_seq == seq) && |
| 8050 | time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) { |
| 8051 | if (*last_frag == frag) |
| 8052 | goto drop; |
| 8053 | if (*last_frag + 1 != frag) |
| 8054 | /* out-of-order fragment */ |
| 8055 | goto drop; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8056 | } else |
| 8057 | *last_seq = seq; |
| 8058 | |
Zhu Yi | f57ce7c | 2005-07-13 12:22:15 -0500 | [diff] [blame] | 8059 | *last_frag = frag; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8060 | *last_time = jiffies; |
| 8061 | return 0; |
| 8062 | |
| 8063 | drop: |
Zhu Yi | 87b016c | 2005-08-05 17:17:35 +0800 | [diff] [blame] | 8064 | /* Comment this line now since we observed the card receives |
| 8065 | * duplicate packets but the FCTL_RETRY bit is not set in the |
| 8066 | * IBSS mode with fragmentation enabled. |
| 8067 | BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8068 | return 1; |
| 8069 | } |
| 8070 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8071 | static void ipw_handle_mgmt_packet(struct ipw_priv *priv, |
| 8072 | struct ipw_rx_mem_buffer *rxb, |
| 8073 | struct ieee80211_rx_stats *stats) |
| 8074 | { |
| 8075 | struct sk_buff *skb = rxb->skb; |
| 8076 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data; |
| 8077 | struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *) |
| 8078 | (skb->data + IPW_RX_FRAME_SIZE); |
| 8079 | |
| 8080 | ieee80211_rx_mgt(priv->ieee, header, stats); |
| 8081 | |
| 8082 | if (priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 8083 | ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == |
| 8084 | IEEE80211_STYPE_PROBE_RESP) || |
| 8085 | (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == |
| 8086 | IEEE80211_STYPE_BEACON))) { |
| 8087 | if (!memcmp(header->addr3, priv->bssid, ETH_ALEN)) |
| 8088 | ipw_add_station(priv, header->addr2); |
| 8089 | } |
| 8090 | |
| 8091 | if (priv->config & CFG_NET_STATS) { |
| 8092 | IPW_DEBUG_HC("sending stat packet\n"); |
| 8093 | |
| 8094 | /* Set the size of the skb to the size of the full |
| 8095 | * ipw header and 802.11 frame */ |
| 8096 | skb_put(skb, le16_to_cpu(pkt->u.frame.length) + |
| 8097 | IPW_RX_FRAME_SIZE); |
| 8098 | |
| 8099 | /* Advance past the ipw packet header to the 802.11 frame */ |
| 8100 | skb_pull(skb, IPW_RX_FRAME_SIZE); |
| 8101 | |
| 8102 | /* Push the ieee80211_rx_stats before the 802.11 frame */ |
| 8103 | memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats)); |
| 8104 | |
| 8105 | skb->dev = priv->ieee->dev; |
| 8106 | |
| 8107 | /* Point raw at the ieee80211_stats */ |
| 8108 | skb->mac.raw = skb->data; |
| 8109 | |
| 8110 | skb->pkt_type = PACKET_OTHERHOST; |
| 8111 | skb->protocol = __constant_htons(ETH_P_80211_STATS); |
| 8112 | memset(skb->cb, 0, sizeof(rxb->skb->cb)); |
| 8113 | netif_rx(skb); |
| 8114 | rxb->skb = NULL; |
| 8115 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8116 | } |
| 8117 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8118 | /* |
| 8119 | * Main entry function for recieving a packet with 80211 headers. This |
| 8120 | * should be called when ever the FW has notified us that there is a new |
| 8121 | * skb in the recieve queue. |
| 8122 | */ |
| 8123 | static void ipw_rx(struct ipw_priv *priv) |
| 8124 | { |
| 8125 | struct ipw_rx_mem_buffer *rxb; |
| 8126 | struct ipw_rx_packet *pkt; |
James Ketrenos | 0dacca1 | 2005-09-21 12:23:41 -0500 | [diff] [blame] | 8127 | struct ieee80211_hdr_4addr *header; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8128 | u32 r, w, i; |
| 8129 | u8 network_packet; |
| 8130 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8131 | r = ipw_read32(priv, IPW_RX_READ_INDEX); |
| 8132 | w = ipw_read32(priv, IPW_RX_WRITE_INDEX); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8133 | i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE; |
| 8134 | |
| 8135 | while (i != r) { |
| 8136 | rxb = priv->rxq->queue[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8137 | if (unlikely(rxb == NULL)) { |
| 8138 | printk(KERN_CRIT "Queue not allocated!\n"); |
| 8139 | break; |
| 8140 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8141 | priv->rxq->queue[i] = NULL; |
| 8142 | |
| 8143 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8144 | IPW_RX_BUF_SIZE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8145 | PCI_DMA_FROMDEVICE); |
| 8146 | |
| 8147 | pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 8148 | IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n", |
| 8149 | pkt->header.message_type, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8150 | pkt->header.rx_seq_num, pkt->header.control_bits); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8151 | |
| 8152 | switch (pkt->header.message_type) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8153 | case RX_FRAME_TYPE: /* 802.11 frame */ { |
| 8154 | struct ieee80211_rx_stats stats = { |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 8155 | .rssi = pkt->u.frame.rssi_dbm - |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8156 | IPW_RSSI_TO_DBM, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8157 | .signal = |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 8158 | le16_to_cpu(pkt->u.frame.rssi_dbm) - |
| 8159 | IPW_RSSI_TO_DBM + 0x100, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8160 | .noise = |
| 8161 | le16_to_cpu(pkt->u.frame.noise), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8162 | .rate = pkt->u.frame.rate, |
| 8163 | .mac_time = jiffies, |
| 8164 | .received_channel = |
| 8165 | pkt->u.frame.received_channel, |
| 8166 | .freq = |
| 8167 | (pkt->u.frame. |
| 8168 | control & (1 << 0)) ? |
| 8169 | IEEE80211_24GHZ_BAND : |
| 8170 | IEEE80211_52GHZ_BAND, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8171 | .len = le16_to_cpu(pkt->u.frame.length), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8172 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8173 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8174 | if (stats.rssi != 0) |
| 8175 | stats.mask |= IEEE80211_STATMASK_RSSI; |
| 8176 | if (stats.signal != 0) |
| 8177 | stats.mask |= IEEE80211_STATMASK_SIGNAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8178 | if (stats.noise != 0) |
| 8179 | stats.mask |= IEEE80211_STATMASK_NOISE; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8180 | if (stats.rate != 0) |
| 8181 | stats.mask |= IEEE80211_STATMASK_RATE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8182 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8183 | priv->rx_packets++; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8184 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8185 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 8186 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) |
| 8187 | ipw_handle_promiscuous_rx(priv, rxb, &stats); |
| 8188 | #endif |
| 8189 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8190 | #ifdef CONFIG_IPW2200_MONITOR |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8191 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 8192 | #ifdef CONFIG_IPW2200_RADIOTAP |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8193 | |
| 8194 | ipw_handle_data_packet_monitor(priv, |
| 8195 | rxb, |
| 8196 | &stats); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8197 | #else |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8198 | ipw_handle_data_packet(priv, rxb, |
| 8199 | &stats); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8200 | #endif |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8201 | break; |
| 8202 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8203 | #endif |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8204 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8205 | header = |
James Ketrenos | 0dacca1 | 2005-09-21 12:23:41 -0500 | [diff] [blame] | 8206 | (struct ieee80211_hdr_4addr *)(rxb->skb-> |
| 8207 | data + |
| 8208 | IPW_RX_FRAME_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8209 | /* TODO: Check Ad-Hoc dest/source and make sure |
| 8210 | * that we are actually parsing these packets |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8211 | * correctly -- we should probably use the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8212 | * frame control of the packet and disregard |
| 8213 | * the current iw_mode */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8214 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8215 | network_packet = |
| 8216 | is_network_packet(priv, header); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8217 | if (network_packet && priv->assoc_network) { |
| 8218 | priv->assoc_network->stats.rssi = |
| 8219 | stats.rssi; |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 8220 | priv->exp_avg_rssi = |
| 8221 | exponential_average(priv->exp_avg_rssi, |
| 8222 | stats.rssi, DEPTH_RSSI); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8223 | } |
| 8224 | |
| 8225 | IPW_DEBUG_RX("Frame: len=%u\n", |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8226 | le16_to_cpu(pkt->u.frame.length)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8227 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8228 | if (le16_to_cpu(pkt->u.frame.length) < |
Zhu Yi | 9d0be03 | 2006-02-15 06:18:19 +0800 | [diff] [blame] | 8229 | ieee80211_get_hdrlen(le16_to_cpu( |
| 8230 | header->frame_ctl))) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8231 | IPW_DEBUG_DROP |
| 8232 | ("Received packet is too small. " |
| 8233 | "Dropping.\n"); |
| 8234 | priv->ieee->stats.rx_errors++; |
| 8235 | priv->wstats.discard.misc++; |
| 8236 | break; |
| 8237 | } |
| 8238 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8239 | switch (WLAN_FC_GET_TYPE |
| 8240 | (le16_to_cpu(header->frame_ctl))) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8241 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8242 | case IEEE80211_FTYPE_MGMT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8243 | ipw_handle_mgmt_packet(priv, rxb, |
| 8244 | &stats); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8245 | break; |
| 8246 | |
| 8247 | case IEEE80211_FTYPE_CTL: |
| 8248 | break; |
| 8249 | |
| 8250 | case IEEE80211_FTYPE_DATA: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8251 | if (unlikely(!network_packet || |
| 8252 | is_duplicate_packet(priv, |
| 8253 | header))) |
| 8254 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8255 | IPW_DEBUG_DROP("Dropping: " |
| 8256 | MAC_FMT ", " |
| 8257 | MAC_FMT ", " |
| 8258 | MAC_FMT "\n", |
| 8259 | MAC_ARG(header-> |
| 8260 | addr1), |
| 8261 | MAC_ARG(header-> |
| 8262 | addr2), |
| 8263 | MAC_ARG(header-> |
| 8264 | addr3)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8265 | break; |
| 8266 | } |
| 8267 | |
| 8268 | ipw_handle_data_packet(priv, rxb, |
| 8269 | &stats); |
| 8270 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8271 | break; |
| 8272 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8273 | break; |
| 8274 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8275 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8276 | case RX_HOST_NOTIFICATION_TYPE:{ |
| 8277 | IPW_DEBUG_RX |
| 8278 | ("Notification: subtype=%02X flags=%02X size=%d\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8279 | pkt->u.notification.subtype, |
| 8280 | pkt->u.notification.flags, |
| 8281 | pkt->u.notification.size); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8282 | ipw_rx_notification(priv, &pkt->u.notification); |
| 8283 | break; |
| 8284 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8285 | |
| 8286 | default: |
| 8287 | IPW_DEBUG_RX("Bad Rx packet of type %d\n", |
| 8288 | pkt->header.message_type); |
| 8289 | break; |
| 8290 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8291 | |
| 8292 | /* For now we just don't re-use anything. We can tweak this |
| 8293 | * later to try and re-use notification packets and SKBs that |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8294 | * fail to Rx correctly */ |
| 8295 | if (rxb->skb != NULL) { |
| 8296 | dev_kfree_skb_any(rxb->skb); |
| 8297 | rxb->skb = NULL; |
| 8298 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8299 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8300 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8301 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8302 | list_add_tail(&rxb->list, &priv->rxq->rx_used); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8303 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8304 | i = (i + 1) % RX_QUEUE_SIZE; |
| 8305 | } |
| 8306 | |
| 8307 | /* Backtrack one entry */ |
| 8308 | priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1; |
| 8309 | |
| 8310 | ipw_rx_queue_restock(priv); |
| 8311 | } |
| 8312 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8313 | #define DEFAULT_RTS_THRESHOLD 2304U |
| 8314 | #define MIN_RTS_THRESHOLD 1U |
| 8315 | #define MAX_RTS_THRESHOLD 2304U |
| 8316 | #define DEFAULT_BEACON_INTERVAL 100U |
| 8317 | #define DEFAULT_SHORT_RETRY_LIMIT 7U |
| 8318 | #define DEFAULT_LONG_RETRY_LIMIT 4U |
| 8319 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 8320 | /** |
| 8321 | * ipw_sw_reset |
| 8322 | * @option: options to control different reset behaviour |
| 8323 | * 0 = reset everything except the 'disable' module_param |
| 8324 | * 1 = reset everything and print out driver info (for probe only) |
| 8325 | * 2 = reset everything |
| 8326 | */ |
| 8327 | static int ipw_sw_reset(struct ipw_priv *priv, int option) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8328 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8329 | int band, modulation; |
| 8330 | int old_mode = priv->ieee->iw_mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8331 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8332 | /* Initialize module parameter values here */ |
| 8333 | priv->config = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8334 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8335 | /* We default to disabling the LED code as right now it causes |
| 8336 | * too many systems to lock up... */ |
| 8337 | if (!led) |
| 8338 | priv->config |= CFG_NO_LED; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8339 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8340 | if (associate) |
| 8341 | priv->config |= CFG_ASSOCIATE; |
| 8342 | else |
| 8343 | IPW_DEBUG_INFO("Auto associate disabled.\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8344 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8345 | if (auto_create) |
| 8346 | priv->config |= CFG_ADHOC_CREATE; |
| 8347 | else |
| 8348 | IPW_DEBUG_INFO("Auto adhoc creation disabled.\n"); |
| 8349 | |
Zhu Yi | 17ed081 | 2006-01-24 16:36:31 +0800 | [diff] [blame] | 8350 | priv->config &= ~CFG_STATIC_ESSID; |
| 8351 | priv->essid_len = 0; |
| 8352 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 8353 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 8354 | if (disable && option) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8355 | priv->status |= STATUS_RF_KILL_SW; |
| 8356 | IPW_DEBUG_INFO("Radio disabled.\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8357 | } |
| 8358 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8359 | if (channel != 0) { |
| 8360 | priv->config |= CFG_STATIC_CHANNEL; |
| 8361 | priv->channel = channel; |
| 8362 | IPW_DEBUG_INFO("Bind to static channel %d\n", channel); |
| 8363 | /* TODO: Validate that provided channel is in range */ |
| 8364 | } |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 8365 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8366 | ipw_qos_init(priv, qos_enable, qos_burst_enable, |
| 8367 | burst_duration_CCK, burst_duration_OFDM); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 8368 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8369 | |
| 8370 | switch (mode) { |
| 8371 | case 1: |
| 8372 | priv->ieee->iw_mode = IW_MODE_ADHOC; |
| 8373 | priv->net_dev->type = ARPHRD_ETHER; |
| 8374 | |
| 8375 | break; |
| 8376 | #ifdef CONFIG_IPW2200_MONITOR |
| 8377 | case 2: |
| 8378 | priv->ieee->iw_mode = IW_MODE_MONITOR; |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 8379 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8380 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 8381 | #else |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8382 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8383 | #endif |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8384 | break; |
| 8385 | #endif |
| 8386 | default: |
| 8387 | case 0: |
| 8388 | priv->net_dev->type = ARPHRD_ETHER; |
| 8389 | priv->ieee->iw_mode = IW_MODE_INFRA; |
| 8390 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8391 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8392 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8393 | if (hwcrypto) { |
| 8394 | priv->ieee->host_encrypt = 0; |
| 8395 | priv->ieee->host_encrypt_msdu = 0; |
| 8396 | priv->ieee->host_decrypt = 0; |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 8397 | priv->ieee->host_mc_decrypt = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8398 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8399 | IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8400 | |
Zhu Yi | e402c93 | 2005-08-05 17:20:40 +0800 | [diff] [blame] | 8401 | /* IPW2200/2915 is abled to do hardware fragmentation. */ |
| 8402 | priv->ieee->host_open_frag = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8403 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8404 | if ((priv->pci_dev->device == 0x4223) || |
| 8405 | (priv->pci_dev->device == 0x4224)) { |
Zhu Yi | e8c69e2 | 2006-02-17 08:25:12 +0800 | [diff] [blame] | 8406 | if (option == 1) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8407 | printk(KERN_INFO DRV_NAME |
| 8408 | ": Detected Intel PRO/Wireless 2915ABG Network " |
| 8409 | "Connection\n"); |
| 8410 | priv->ieee->abg_true = 1; |
| 8411 | band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND; |
| 8412 | modulation = IEEE80211_OFDM_MODULATION | |
| 8413 | IEEE80211_CCK_MODULATION; |
| 8414 | priv->adapter = IPW_2915ABG; |
| 8415 | priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8416 | } else { |
Zhu Yi | e8c69e2 | 2006-02-17 08:25:12 +0800 | [diff] [blame] | 8417 | if (option == 1) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8418 | printk(KERN_INFO DRV_NAME |
| 8419 | ": Detected Intel PRO/Wireless 2200BG Network " |
| 8420 | "Connection\n"); |
| 8421 | |
| 8422 | priv->ieee->abg_true = 0; |
| 8423 | band = IEEE80211_24GHZ_BAND; |
| 8424 | modulation = IEEE80211_OFDM_MODULATION | |
| 8425 | IEEE80211_CCK_MODULATION; |
| 8426 | priv->adapter = IPW_2200BG; |
| 8427 | priv->ieee->mode = IEEE_G | IEEE_B; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8428 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8429 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8430 | priv->ieee->freq_band = band; |
| 8431 | priv->ieee->modulation = modulation; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8432 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8433 | priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8434 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8435 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; |
| 8436 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8437 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8438 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
| 8439 | priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT; |
| 8440 | priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8441 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8442 | /* If power management is turned on, default to AC mode */ |
| 8443 | priv->power_mode = IPW_POWER_AC; |
| 8444 | priv->tx_power = IPW_TX_POWER_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8445 | |
Zhu Yi | 0ece35b | 2005-08-05 17:26:51 +0800 | [diff] [blame] | 8446 | return old_mode == priv->ieee->iw_mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8447 | } |
| 8448 | |
| 8449 | /* |
| 8450 | * This file defines the Wireless Extension handlers. It does not |
| 8451 | * define any methods of hardware manipulation and relies on the |
| 8452 | * functions defined in ipw_main to provide the HW interaction. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8453 | * |
| 8454 | * The exception to this is the use of the ipw_get_ordinal() |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8455 | * function used to poll the hardware vs. making unecessary calls. |
| 8456 | * |
| 8457 | */ |
| 8458 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8459 | static int ipw_wx_get_name(struct net_device *dev, |
| 8460 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8461 | union iwreq_data *wrqu, char *extra) |
| 8462 | { |
| 8463 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8464 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8465 | if (priv->status & STATUS_RF_KILL_MASK) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8466 | strcpy(wrqu->name, "radio off"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8467 | else if (!(priv->status & STATUS_ASSOCIATED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8468 | strcpy(wrqu->name, "unassociated"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8469 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8470 | snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c", |
| 8471 | ipw_modes[priv->assoc_request.ieee_mode]); |
| 8472 | IPW_DEBUG_WX("Name: %s\n", wrqu->name); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8473 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8474 | return 0; |
| 8475 | } |
| 8476 | |
| 8477 | static int ipw_set_channel(struct ipw_priv *priv, u8 channel) |
| 8478 | { |
| 8479 | if (channel == 0) { |
| 8480 | IPW_DEBUG_INFO("Setting channel to ANY (0)\n"); |
| 8481 | priv->config &= ~CFG_STATIC_CHANNEL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8482 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 8483 | "parameters.\n"); |
| 8484 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8485 | return 0; |
| 8486 | } |
| 8487 | |
| 8488 | priv->config |= CFG_STATIC_CHANNEL; |
| 8489 | |
| 8490 | if (priv->channel == channel) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8491 | IPW_DEBUG_INFO("Request to set channel to current value (%d)\n", |
| 8492 | channel); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8493 | return 0; |
| 8494 | } |
| 8495 | |
| 8496 | IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel); |
| 8497 | priv->channel = channel; |
| 8498 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8499 | #ifdef CONFIG_IPW2200_MONITOR |
| 8500 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8501 | int i; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8502 | if (priv->status & STATUS_SCANNING) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8503 | IPW_DEBUG_SCAN("Scan abort triggered due to " |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8504 | "channel change.\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8505 | ipw_abort_scan(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8506 | } |
| 8507 | |
| 8508 | for (i = 1000; i && (priv->status & STATUS_SCANNING); i--) |
| 8509 | udelay(10); |
| 8510 | |
| 8511 | if (priv->status & STATUS_SCANNING) |
| 8512 | IPW_DEBUG_SCAN("Still scanning...\n"); |
| 8513 | else |
| 8514 | IPW_DEBUG_SCAN("Took %dms to abort current scan\n", |
| 8515 | 1000 - i); |
| 8516 | |
| 8517 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8518 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8519 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 8520 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8521 | /* Network configuration changed -- force [re]association */ |
| 8522 | IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n"); |
| 8523 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8524 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8525 | |
| 8526 | return 0; |
| 8527 | } |
| 8528 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8529 | static int ipw_wx_set_freq(struct net_device *dev, |
| 8530 | struct iw_request_info *info, |
| 8531 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8532 | { |
| 8533 | struct ipw_priv *priv = ieee80211_priv(dev); |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 8534 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8535 | struct iw_freq *fwrq = &wrqu->freq; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8536 | int ret = 0, i; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8537 | u8 channel, flags; |
| 8538 | int band; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8539 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8540 | if (fwrq->m == 0) { |
| 8541 | IPW_DEBUG_WX("SET Freq/Channel -> any\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8542 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8543 | ret = ipw_set_channel(priv, 0); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8544 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8545 | return ret; |
| 8546 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8547 | /* if setting by freq convert to channel */ |
| 8548 | if (fwrq->e == 1) { |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 8549 | channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8550 | if (channel == 0) |
| 8551 | return -EINVAL; |
| 8552 | } else |
| 8553 | channel = fwrq->m; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8554 | |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 8555 | if (!(band = ieee80211_is_valid_channel(priv->ieee, channel))) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8556 | return -EINVAL; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8557 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8558 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 8559 | i = ieee80211_channel_to_index(priv->ieee, channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8560 | if (i == -1) |
| 8561 | return -EINVAL; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8562 | |
| 8563 | flags = (band == IEEE80211_24GHZ_BAND) ? |
| 8564 | geo->bg[i].flags : geo->a[i].flags; |
| 8565 | if (flags & IEEE80211_CH_PASSIVE_ONLY) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8566 | IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n"); |
| 8567 | return -EINVAL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8568 | } |
| 8569 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8570 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8571 | IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8572 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8573 | ret = ipw_set_channel(priv, channel); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8574 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8575 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8576 | } |
| 8577 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8578 | static int ipw_wx_get_freq(struct net_device *dev, |
| 8579 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8580 | union iwreq_data *wrqu, char *extra) |
| 8581 | { |
| 8582 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8583 | |
| 8584 | wrqu->freq.e = 0; |
| 8585 | |
| 8586 | /* If we are associated, trying to associate, or have a statically |
| 8587 | * configured CHANNEL then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8588 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8589 | if (priv->config & CFG_STATIC_CHANNEL || |
Zhu Yi | c580f67 | 2006-08-21 11:37:01 +0800 | [diff] [blame] | 8590 | priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) { |
| 8591 | int i; |
| 8592 | |
| 8593 | i = ieee80211_channel_to_index(priv->ieee, priv->channel); |
| 8594 | BUG_ON(i == -1); |
| 8595 | wrqu->freq.e = 1; |
| 8596 | |
| 8597 | switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) { |
| 8598 | case IEEE80211_52GHZ_BAND: |
| 8599 | wrqu->freq.m = priv->ieee->geo.a[i].freq * 100000; |
| 8600 | break; |
| 8601 | |
| 8602 | case IEEE80211_24GHZ_BAND: |
| 8603 | wrqu->freq.m = priv->ieee->geo.bg[i].freq * 100000; |
| 8604 | break; |
| 8605 | |
| 8606 | default: |
| 8607 | BUG(); |
| 8608 | } |
| 8609 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8610 | wrqu->freq.m = 0; |
| 8611 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8612 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8613 | IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel); |
| 8614 | return 0; |
| 8615 | } |
| 8616 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8617 | static int ipw_wx_set_mode(struct net_device *dev, |
| 8618 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8619 | union iwreq_data *wrqu, char *extra) |
| 8620 | { |
| 8621 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8622 | int err = 0; |
| 8623 | |
| 8624 | IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode); |
| 8625 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8626 | switch (wrqu->mode) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8627 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8628 | case IW_MODE_MONITOR: |
| 8629 | #endif |
| 8630 | case IW_MODE_ADHOC: |
| 8631 | case IW_MODE_INFRA: |
| 8632 | break; |
| 8633 | case IW_MODE_AUTO: |
| 8634 | wrqu->mode = IW_MODE_INFRA; |
| 8635 | break; |
| 8636 | default: |
| 8637 | return -EINVAL; |
| 8638 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8639 | if (wrqu->mode == priv->ieee->iw_mode) |
| 8640 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8641 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8642 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8643 | |
| 8644 | ipw_sw_reset(priv, 0); |
| 8645 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8646 | #ifdef CONFIG_IPW2200_MONITOR |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8647 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8648 | priv->net_dev->type = ARPHRD_ETHER; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8649 | |
| 8650 | if (wrqu->mode == IW_MODE_MONITOR) |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 8651 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8652 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 8653 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8654 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8655 | #endif |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8656 | #endif /* CONFIG_IPW2200_MONITOR */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8657 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8658 | /* Free the existing firmware and reset the fw_loaded |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8659 | * flag so ipw_load() will bring in the new firmawre */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8660 | free_firmware(); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8661 | |
| 8662 | priv->ieee->iw_mode = wrqu->mode; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8663 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8664 | queue_work(priv->workqueue, &priv->adapter_restart); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8665 | mutex_unlock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8666 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8667 | } |
| 8668 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8669 | static int ipw_wx_get_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8670 | struct iw_request_info *info, |
| 8671 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8672 | { |
| 8673 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8674 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8675 | wrqu->mode = priv->ieee->iw_mode; |
| 8676 | IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8677 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8678 | return 0; |
| 8679 | } |
| 8680 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8681 | /* Values are in microsecond */ |
| 8682 | static const s32 timeout_duration[] = { |
| 8683 | 350000, |
| 8684 | 250000, |
| 8685 | 75000, |
| 8686 | 37000, |
| 8687 | 25000, |
| 8688 | }; |
| 8689 | |
| 8690 | static const s32 period_duration[] = { |
| 8691 | 400000, |
| 8692 | 700000, |
| 8693 | 1000000, |
| 8694 | 1000000, |
| 8695 | 1000000 |
| 8696 | }; |
| 8697 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8698 | static int ipw_wx_get_range(struct net_device *dev, |
| 8699 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8700 | union iwreq_data *wrqu, char *extra) |
| 8701 | { |
| 8702 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8703 | struct iw_range *range = (struct iw_range *)extra; |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 8704 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8705 | int i = 0, j; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8706 | |
| 8707 | wrqu->data.length = sizeof(*range); |
| 8708 | memset(range, 0, sizeof(*range)); |
| 8709 | |
| 8710 | /* 54Mbs == ~27 Mb/s real (802.11g) */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8711 | range->throughput = 27 * 1000 * 1000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8712 | |
| 8713 | range->max_qual.qual = 100; |
| 8714 | /* TODO: Find real max RSSI and stick here */ |
| 8715 | range->max_qual.level = 0; |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 8716 | range->max_qual.noise = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8717 | range->max_qual.updated = 7; /* Updated all three */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8718 | |
| 8719 | range->avg_qual.qual = 70; |
| 8720 | /* TODO: Find real 'good' to 'bad' threshol value for RSSI */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8721 | range->avg_qual.level = 0; /* FIXME to real average level */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8722 | range->avg_qual.noise = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8723 | range->avg_qual.updated = 7; /* Updated all three */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8724 | mutex_lock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8725 | range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8726 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8727 | for (i = 0; i < range->num_bitrates; i++) |
| 8728 | range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) * |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8729 | 500000; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8730 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8731 | range->max_rts = DEFAULT_RTS_THRESHOLD; |
| 8732 | range->min_frag = MIN_FRAG_THRESHOLD; |
| 8733 | range->max_frag = MAX_FRAG_THRESHOLD; |
| 8734 | |
| 8735 | range->encoding_size[0] = 5; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8736 | range->encoding_size[1] = 13; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8737 | range->num_encoding_sizes = 2; |
| 8738 | range->max_encoding_tokens = WEP_KEYS; |
| 8739 | |
| 8740 | /* Set the Wireless Extension versions */ |
| 8741 | range->we_version_compiled = WIRELESS_EXT; |
Dan Williams | f1b5086 | 2006-01-30 13:58:56 -0500 | [diff] [blame] | 8742 | range->we_version_source = 18; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8743 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8744 | i = 0; |
| 8745 | if (priv->ieee->mode & (IEEE_B | IEEE_G)) { |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8746 | for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) { |
| 8747 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
| 8748 | (geo->bg[j].flags & IEEE80211_CH_PASSIVE_ONLY)) |
| 8749 | continue; |
| 8750 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8751 | range->freq[i].i = geo->bg[j].channel; |
| 8752 | range->freq[i].m = geo->bg[j].freq * 100000; |
| 8753 | range->freq[i].e = 1; |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8754 | i++; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8755 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8756 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8757 | |
| 8758 | if (priv->ieee->mode & IEEE_A) { |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8759 | for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) { |
| 8760 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
| 8761 | (geo->a[j].flags & IEEE80211_CH_PASSIVE_ONLY)) |
| 8762 | continue; |
| 8763 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8764 | range->freq[i].i = geo->a[j].channel; |
| 8765 | range->freq[i].m = geo->a[j].freq * 100000; |
| 8766 | range->freq[i].e = 1; |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8767 | i++; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8768 | } |
| 8769 | } |
| 8770 | |
| 8771 | range->num_channels = i; |
| 8772 | range->num_frequency = i; |
| 8773 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8774 | mutex_unlock(&priv->mutex); |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 8775 | |
| 8776 | /* Event capability (kernel + driver) */ |
| 8777 | range->event_capa[0] = (IW_EVENT_CAPA_K_0 | |
| 8778 | IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) | |
Zhu Yi | 07f02e4 | 2006-04-13 17:19:25 +0800 | [diff] [blame] | 8779 | IW_EVENT_CAPA_MASK(SIOCGIWAP) | |
| 8780 | IW_EVENT_CAPA_MASK(SIOCGIWSCAN)); |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 8781 | range->event_capa[1] = IW_EVENT_CAPA_K_1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8782 | |
Dan Williams | f1b5086 | 2006-01-30 13:58:56 -0500 | [diff] [blame] | 8783 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | |
| 8784 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; |
| 8785 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8786 | IPW_DEBUG_WX("GET Range\n"); |
| 8787 | return 0; |
| 8788 | } |
| 8789 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8790 | static int ipw_wx_set_wap(struct net_device *dev, |
| 8791 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8792 | union iwreq_data *wrqu, char *extra) |
| 8793 | { |
| 8794 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8795 | |
| 8796 | static const unsigned char any[] = { |
| 8797 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff |
| 8798 | }; |
| 8799 | static const unsigned char off[] = { |
| 8800 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 8801 | }; |
| 8802 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8803 | if (wrqu->ap_addr.sa_family != ARPHRD_ETHER) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8804 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8805 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8806 | if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) || |
| 8807 | !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) { |
| 8808 | /* we disable mandatory BSSID association */ |
| 8809 | IPW_DEBUG_WX("Setting AP BSSID to ANY\n"); |
| 8810 | priv->config &= ~CFG_STATIC_BSSID; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8811 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 8812 | "parameters.\n"); |
| 8813 | ipw_associate(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8814 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8815 | return 0; |
| 8816 | } |
| 8817 | |
| 8818 | priv->config |= CFG_STATIC_BSSID; |
| 8819 | if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) { |
| 8820 | IPW_DEBUG_WX("BSSID set to current BSSID.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8821 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8822 | return 0; |
| 8823 | } |
| 8824 | |
| 8825 | IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n", |
| 8826 | MAC_ARG(wrqu->ap_addr.sa_data)); |
| 8827 | |
| 8828 | memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN); |
| 8829 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8830 | /* Network configuration changed -- force [re]association */ |
| 8831 | IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n"); |
| 8832 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8833 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8834 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8835 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8836 | return 0; |
| 8837 | } |
| 8838 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8839 | static int ipw_wx_get_wap(struct net_device *dev, |
| 8840 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8841 | union iwreq_data *wrqu, char *extra) |
| 8842 | { |
| 8843 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8844 | /* If we are associated, trying to associate, or have a statically |
| 8845 | * configured BSSID then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8846 | mutex_lock(&priv->mutex); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8847 | if (priv->config & CFG_STATIC_BSSID || |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8848 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
| 8849 | wrqu->ap_addr.sa_family = ARPHRD_ETHER; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8850 | memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8851 | } else |
| 8852 | memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN); |
| 8853 | |
| 8854 | IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n", |
| 8855 | MAC_ARG(wrqu->ap_addr.sa_data)); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8856 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8857 | return 0; |
| 8858 | } |
| 8859 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8860 | static int ipw_wx_set_essid(struct net_device *dev, |
| 8861 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8862 | union iwreq_data *wrqu, char *extra) |
| 8863 | { |
| 8864 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | ab644b0 | 2006-08-21 11:37:13 +0800 | [diff] [blame] | 8865 | int length; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8866 | |
Zhu Yi | ab644b0 | 2006-08-21 11:37:13 +0800 | [diff] [blame] | 8867 | mutex_lock(&priv->mutex); |
| 8868 | |
| 8869 | if (!wrqu->essid.flags) |
| 8870 | { |
| 8871 | IPW_DEBUG_WX("Setting ESSID to ANY\n"); |
| 8872 | ipw_disassociate(priv); |
| 8873 | priv->config &= ~CFG_STATIC_ESSID; |
| 8874 | ipw_associate(priv); |
| 8875 | mutex_unlock(&priv->mutex); |
| 8876 | return 0; |
| 8877 | } |
| 8878 | |
Zhu Yi | a9f0d42 | 2006-08-21 11:37:26 +0800 | [diff] [blame] | 8879 | length = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE); |
| 8880 | if (!extra[length - 1]) |
| 8881 | length--; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8882 | |
| 8883 | priv->config |= CFG_STATIC_ESSID; |
| 8884 | |
Zhu Yi | a9f0d42 | 2006-08-21 11:37:26 +0800 | [diff] [blame] | 8885 | if (priv->essid_len == length && !memcmp(priv->essid, extra, length) |
| 8886 | && (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8887 | IPW_DEBUG_WX("ESSID set to current ESSID.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8888 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8889 | return 0; |
| 8890 | } |
| 8891 | |
Zhu Yi | ab644b0 | 2006-08-21 11:37:13 +0800 | [diff] [blame] | 8892 | IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(extra, length), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8893 | length); |
| 8894 | |
| 8895 | priv->essid_len = length; |
Zhu Yi | a9f0d42 | 2006-08-21 11:37:26 +0800 | [diff] [blame] | 8896 | memcpy(priv->essid, extra, priv->essid_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8897 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8898 | /* Network configuration changed -- force [re]association */ |
| 8899 | IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n"); |
| 8900 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8901 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8902 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8903 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8904 | return 0; |
| 8905 | } |
| 8906 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8907 | static int ipw_wx_get_essid(struct net_device *dev, |
| 8908 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8909 | union iwreq_data *wrqu, char *extra) |
| 8910 | { |
| 8911 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8912 | |
| 8913 | /* If we are associated, trying to associate, or have a statically |
| 8914 | * configured ESSID then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8915 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8916 | if (priv->config & CFG_STATIC_ESSID || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8917 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
| 8918 | IPW_DEBUG_WX("Getting essid: '%s'\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8919 | escape_essid(priv->essid, priv->essid_len)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8920 | memcpy(extra, priv->essid, priv->essid_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8921 | wrqu->essid.length = priv->essid_len; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8922 | wrqu->essid.flags = 1; /* active */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8923 | } else { |
| 8924 | IPW_DEBUG_WX("Getting essid: ANY\n"); |
| 8925 | wrqu->essid.length = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8926 | wrqu->essid.flags = 0; /* active */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8927 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8928 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8929 | return 0; |
| 8930 | } |
| 8931 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8932 | static int ipw_wx_set_nick(struct net_device *dev, |
| 8933 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8934 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8935 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8936 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8937 | |
| 8938 | IPW_DEBUG_WX("Setting nick to '%s'\n", extra); |
| 8939 | if (wrqu->data.length > IW_ESSID_MAX_SIZE) |
| 8940 | return -E2BIG; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8941 | mutex_lock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8942 | wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8943 | memset(priv->nick, 0, sizeof(priv->nick)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8944 | memcpy(priv->nick, extra, wrqu->data.length); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8945 | IPW_DEBUG_TRACE("<<\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8946 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8947 | return 0; |
| 8948 | |
| 8949 | } |
| 8950 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8951 | static int ipw_wx_get_nick(struct net_device *dev, |
| 8952 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8953 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8954 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8955 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8956 | IPW_DEBUG_WX("Getting nick\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8957 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8958 | wrqu->data.length = strlen(priv->nick) + 1; |
| 8959 | memcpy(extra, priv->nick, wrqu->data.length); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8960 | wrqu->data.flags = 1; /* active */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8961 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8962 | return 0; |
| 8963 | } |
| 8964 | |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame] | 8965 | static int ipw_wx_set_sens(struct net_device *dev, |
| 8966 | struct iw_request_info *info, |
| 8967 | union iwreq_data *wrqu, char *extra) |
| 8968 | { |
| 8969 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8970 | int err = 0; |
| 8971 | |
| 8972 | IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value); |
| 8973 | IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value); |
| 8974 | mutex_lock(&priv->mutex); |
| 8975 | |
| 8976 | if (wrqu->sens.fixed == 0) |
| 8977 | { |
| 8978 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; |
| 8979 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; |
| 8980 | goto out; |
| 8981 | } |
| 8982 | if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) || |
| 8983 | (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) { |
| 8984 | err = -EINVAL; |
| 8985 | goto out; |
| 8986 | } |
| 8987 | |
| 8988 | priv->roaming_threshold = wrqu->sens.value; |
| 8989 | priv->disassociate_threshold = 3*wrqu->sens.value; |
| 8990 | out: |
| 8991 | mutex_unlock(&priv->mutex); |
| 8992 | return err; |
| 8993 | } |
| 8994 | |
| 8995 | static int ipw_wx_get_sens(struct net_device *dev, |
| 8996 | struct iw_request_info *info, |
| 8997 | union iwreq_data *wrqu, char *extra) |
| 8998 | { |
| 8999 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9000 | mutex_lock(&priv->mutex); |
| 9001 | wrqu->sens.fixed = 1; |
| 9002 | wrqu->sens.value = priv->roaming_threshold; |
| 9003 | mutex_unlock(&priv->mutex); |
| 9004 | |
| 9005 | IPW_DEBUG_WX("GET roaming threshold -> %s %d \n", |
| 9006 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); |
| 9007 | |
| 9008 | return 0; |
| 9009 | } |
| 9010 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9011 | static int ipw_wx_set_rate(struct net_device *dev, |
| 9012 | struct iw_request_info *info, |
| 9013 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9014 | { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9015 | /* TODO: We should use semaphores or locks for access to priv */ |
| 9016 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9017 | u32 target_rate = wrqu->bitrate.value; |
| 9018 | u32 fixed, mask; |
| 9019 | |
| 9020 | /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */ |
| 9021 | /* value = X, fixed = 1 means only rate X */ |
| 9022 | /* value = X, fixed = 0 means all rates lower equal X */ |
| 9023 | |
| 9024 | if (target_rate == -1) { |
| 9025 | fixed = 0; |
| 9026 | mask = IEEE80211_DEFAULT_RATES_MASK; |
| 9027 | /* Now we should reassociate */ |
| 9028 | goto apply; |
| 9029 | } |
| 9030 | |
| 9031 | mask = 0; |
| 9032 | fixed = wrqu->bitrate.fixed; |
| 9033 | |
| 9034 | if (target_rate == 1000000 || !fixed) |
| 9035 | mask |= IEEE80211_CCK_RATE_1MB_MASK; |
| 9036 | if (target_rate == 1000000) |
| 9037 | goto apply; |
| 9038 | |
| 9039 | if (target_rate == 2000000 || !fixed) |
| 9040 | mask |= IEEE80211_CCK_RATE_2MB_MASK; |
| 9041 | if (target_rate == 2000000) |
| 9042 | goto apply; |
| 9043 | |
| 9044 | if (target_rate == 5500000 || !fixed) |
| 9045 | mask |= IEEE80211_CCK_RATE_5MB_MASK; |
| 9046 | if (target_rate == 5500000) |
| 9047 | goto apply; |
| 9048 | |
| 9049 | if (target_rate == 6000000 || !fixed) |
| 9050 | mask |= IEEE80211_OFDM_RATE_6MB_MASK; |
| 9051 | if (target_rate == 6000000) |
| 9052 | goto apply; |
| 9053 | |
| 9054 | if (target_rate == 9000000 || !fixed) |
| 9055 | mask |= IEEE80211_OFDM_RATE_9MB_MASK; |
| 9056 | if (target_rate == 9000000) |
| 9057 | goto apply; |
| 9058 | |
| 9059 | if (target_rate == 11000000 || !fixed) |
| 9060 | mask |= IEEE80211_CCK_RATE_11MB_MASK; |
| 9061 | if (target_rate == 11000000) |
| 9062 | goto apply; |
| 9063 | |
| 9064 | if (target_rate == 12000000 || !fixed) |
| 9065 | mask |= IEEE80211_OFDM_RATE_12MB_MASK; |
| 9066 | if (target_rate == 12000000) |
| 9067 | goto apply; |
| 9068 | |
| 9069 | if (target_rate == 18000000 || !fixed) |
| 9070 | mask |= IEEE80211_OFDM_RATE_18MB_MASK; |
| 9071 | if (target_rate == 18000000) |
| 9072 | goto apply; |
| 9073 | |
| 9074 | if (target_rate == 24000000 || !fixed) |
| 9075 | mask |= IEEE80211_OFDM_RATE_24MB_MASK; |
| 9076 | if (target_rate == 24000000) |
| 9077 | goto apply; |
| 9078 | |
| 9079 | if (target_rate == 36000000 || !fixed) |
| 9080 | mask |= IEEE80211_OFDM_RATE_36MB_MASK; |
| 9081 | if (target_rate == 36000000) |
| 9082 | goto apply; |
| 9083 | |
| 9084 | if (target_rate == 48000000 || !fixed) |
| 9085 | mask |= IEEE80211_OFDM_RATE_48MB_MASK; |
| 9086 | if (target_rate == 48000000) |
| 9087 | goto apply; |
| 9088 | |
| 9089 | if (target_rate == 54000000 || !fixed) |
| 9090 | mask |= IEEE80211_OFDM_RATE_54MB_MASK; |
| 9091 | if (target_rate == 54000000) |
| 9092 | goto apply; |
| 9093 | |
| 9094 | IPW_DEBUG_WX("invalid rate specified, returning error\n"); |
| 9095 | return -EINVAL; |
| 9096 | |
| 9097 | apply: |
| 9098 | IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n", |
| 9099 | mask, fixed ? "fixed" : "sub-rates"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9100 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9101 | if (mask == IEEE80211_DEFAULT_RATES_MASK) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9102 | priv->config &= ~CFG_FIXED_RATE; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9103 | ipw_set_fixed_rate(priv, priv->ieee->mode); |
| 9104 | } else |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9105 | priv->config |= CFG_FIXED_RATE; |
| 9106 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9107 | if (priv->rates_mask == mask) { |
| 9108 | IPW_DEBUG_WX("Mask set to current mask.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9109 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9110 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9111 | } |
| 9112 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9113 | priv->rates_mask = mask; |
| 9114 | |
| 9115 | /* Network configuration changed -- force [re]association */ |
| 9116 | IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n"); |
| 9117 | if (!ipw_disassociate(priv)) |
| 9118 | ipw_associate(priv); |
| 9119 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9120 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9121 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9122 | } |
| 9123 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9124 | static int ipw_wx_get_rate(struct net_device *dev, |
| 9125 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9126 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9127 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9128 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9129 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9130 | wrqu->bitrate.value = priv->last_rate; |
Zhu Yi | 455936c | 2006-04-13 17:20:05 +0800 | [diff] [blame] | 9131 | wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9132 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9133 | IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value); |
| 9134 | return 0; |
| 9135 | } |
| 9136 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9137 | static int ipw_wx_set_rts(struct net_device *dev, |
| 9138 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9139 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9140 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9141 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9142 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9143 | if (wrqu->rts.disabled) |
| 9144 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
| 9145 | else { |
| 9146 | if (wrqu->rts.value < MIN_RTS_THRESHOLD || |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9147 | wrqu->rts.value > MAX_RTS_THRESHOLD) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9148 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9149 | return -EINVAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9150 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9151 | priv->rts_threshold = wrqu->rts.value; |
| 9152 | } |
| 9153 | |
| 9154 | ipw_send_rts_threshold(priv, priv->rts_threshold); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9155 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9156 | IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold); |
| 9157 | return 0; |
| 9158 | } |
| 9159 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9160 | static int ipw_wx_get_rts(struct net_device *dev, |
| 9161 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9162 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9163 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9164 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9165 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9166 | wrqu->rts.value = priv->rts_threshold; |
| 9167 | wrqu->rts.fixed = 0; /* no auto select */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9168 | wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9169 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9170 | IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value); |
| 9171 | return 0; |
| 9172 | } |
| 9173 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9174 | static int ipw_wx_set_txpow(struct net_device *dev, |
| 9175 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9176 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9177 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9178 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9179 | int err = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9180 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9181 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9182 | if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9183 | err = -EINPROGRESS; |
| 9184 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9185 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9186 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9187 | if (!wrqu->power.fixed) |
| 9188 | wrqu->power.value = IPW_TX_POWER_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9189 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9190 | if (wrqu->power.flags != IW_TXPOW_DBM) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9191 | err = -EINVAL; |
| 9192 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9193 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9194 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9195 | if ((wrqu->power.value > IPW_TX_POWER_MAX) || |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9196 | (wrqu->power.value < IPW_TX_POWER_MIN)) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9197 | err = -EINVAL; |
| 9198 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9199 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9200 | |
| 9201 | priv->tx_power = wrqu->power.value; |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9202 | err = ipw_set_tx_power(priv); |
| 9203 | out: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9204 | mutex_unlock(&priv->mutex); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9205 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9206 | } |
| 9207 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9208 | static int ipw_wx_get_txpow(struct net_device *dev, |
| 9209 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9210 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9211 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9212 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9213 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9214 | wrqu->power.value = priv->tx_power; |
| 9215 | wrqu->power.fixed = 1; |
| 9216 | wrqu->power.flags = IW_TXPOW_DBM; |
| 9217 | wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9218 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9219 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9220 | IPW_DEBUG_WX("GET TX Power -> %s %d \n", |
Zhu Yi | 22501c8 | 2005-08-11 10:49:17 +0800 | [diff] [blame] | 9221 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9222 | |
| 9223 | return 0; |
| 9224 | } |
| 9225 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9226 | static int ipw_wx_set_frag(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9227 | struct iw_request_info *info, |
| 9228 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9229 | { |
| 9230 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9231 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9232 | if (wrqu->frag.disabled) |
| 9233 | priv->ieee->fts = DEFAULT_FTS; |
| 9234 | else { |
| 9235 | if (wrqu->frag.value < MIN_FRAG_THRESHOLD || |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9236 | wrqu->frag.value > MAX_FRAG_THRESHOLD) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9237 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9238 | return -EINVAL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9239 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9240 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9241 | priv->ieee->fts = wrqu->frag.value & ~0x1; |
| 9242 | } |
| 9243 | |
| 9244 | ipw_send_frag_threshold(priv, wrqu->frag.value); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9245 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9246 | IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value); |
| 9247 | return 0; |
| 9248 | } |
| 9249 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9250 | static int ipw_wx_get_frag(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9251 | struct iw_request_info *info, |
| 9252 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9253 | { |
| 9254 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9255 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9256 | wrqu->frag.value = priv->ieee->fts; |
| 9257 | wrqu->frag.fixed = 0; /* no auto select */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9258 | wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9259 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9260 | IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value); |
| 9261 | |
| 9262 | return 0; |
| 9263 | } |
| 9264 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9265 | static int ipw_wx_set_retry(struct net_device *dev, |
| 9266 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9267 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9268 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9269 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9270 | |
| 9271 | if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled) |
| 9272 | return -EINVAL; |
| 9273 | |
| 9274 | if (!(wrqu->retry.flags & IW_RETRY_LIMIT)) |
| 9275 | return 0; |
| 9276 | |
Zhu Yi | d5f7ac2 | 2006-08-21 11:38:17 +0800 | [diff] [blame] | 9277 | if (wrqu->retry.value < 0 || wrqu->retry.value >= 255) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9278 | return -EINVAL; |
| 9279 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9280 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9281 | if (wrqu->retry.flags & IW_RETRY_MIN) |
| 9282 | priv->short_retry_limit = (u8) wrqu->retry.value; |
| 9283 | else if (wrqu->retry.flags & IW_RETRY_MAX) |
| 9284 | priv->long_retry_limit = (u8) wrqu->retry.value; |
| 9285 | else { |
| 9286 | priv->short_retry_limit = (u8) wrqu->retry.value; |
| 9287 | priv->long_retry_limit = (u8) wrqu->retry.value; |
| 9288 | } |
| 9289 | |
| 9290 | ipw_send_retry_limit(priv, priv->short_retry_limit, |
| 9291 | priv->long_retry_limit); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9292 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9293 | IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n", |
| 9294 | priv->short_retry_limit, priv->long_retry_limit); |
| 9295 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9296 | } |
| 9297 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9298 | static int ipw_wx_get_retry(struct net_device *dev, |
| 9299 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9300 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9301 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9302 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9303 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9304 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9305 | wrqu->retry.disabled = 0; |
| 9306 | |
| 9307 | if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9308 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9309 | return -EINVAL; |
| 9310 | } |
| 9311 | |
| 9312 | if (wrqu->retry.flags & IW_RETRY_MAX) { |
| 9313 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX; |
| 9314 | wrqu->retry.value = priv->long_retry_limit; |
| 9315 | } else if (wrqu->retry.flags & IW_RETRY_MIN) { |
| 9316 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN; |
| 9317 | wrqu->retry.value = priv->short_retry_limit; |
| 9318 | } else { |
| 9319 | wrqu->retry.flags = IW_RETRY_LIMIT; |
| 9320 | wrqu->retry.value = priv->short_retry_limit; |
| 9321 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9322 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9323 | |
| 9324 | IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value); |
| 9325 | |
| 9326 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9327 | } |
| 9328 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9329 | static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid, |
| 9330 | int essid_len) |
| 9331 | { |
| 9332 | struct ipw_scan_request_ext scan; |
| 9333 | int err = 0, scan_type; |
| 9334 | |
Pekka Enberg | efb3442 | 2005-11-16 21:55:05 +0200 | [diff] [blame] | 9335 | if (!(priv->status & STATUS_INIT) || |
| 9336 | (priv->status & STATUS_EXIT_PENDING)) |
| 9337 | return 0; |
| 9338 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9339 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9340 | |
| 9341 | if (priv->status & STATUS_RF_KILL_MASK) { |
| 9342 | IPW_DEBUG_HC("Aborting scan due to RF kill activation\n"); |
| 9343 | priv->status |= STATUS_SCAN_PENDING; |
| 9344 | goto done; |
| 9345 | } |
| 9346 | |
| 9347 | IPW_DEBUG_HC("starting request direct scan!\n"); |
| 9348 | |
| 9349 | if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) { |
Olaf Kirch | d834a41 | 2006-01-09 17:00:37 +0100 | [diff] [blame] | 9350 | /* We should not sleep here; otherwise we will block most |
| 9351 | * of the system (for instance, we hold rtnl_lock when we |
| 9352 | * get here). |
| 9353 | */ |
| 9354 | err = -EAGAIN; |
| 9355 | goto done; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9356 | } |
| 9357 | memset(&scan, 0, sizeof(scan)); |
| 9358 | |
| 9359 | if (priv->config & CFG_SPEED_SCAN) |
| 9360 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
| 9361 | cpu_to_le16(30); |
| 9362 | else |
| 9363 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
| 9364 | cpu_to_le16(20); |
| 9365 | |
| 9366 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = |
| 9367 | cpu_to_le16(20); |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 9368 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9369 | scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20); |
| 9370 | |
| 9371 | scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee)); |
| 9372 | |
| 9373 | err = ipw_send_ssid(priv, essid, essid_len); |
| 9374 | if (err) { |
| 9375 | IPW_DEBUG_HC("Attempt to send SSID command failed\n"); |
| 9376 | goto done; |
| 9377 | } |
| 9378 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; |
| 9379 | |
| 9380 | ipw_add_scan_channels(priv, &scan, scan_type); |
| 9381 | |
| 9382 | err = ipw_send_scan_request_ext(priv, &scan); |
| 9383 | if (err) { |
| 9384 | IPW_DEBUG_HC("Sending scan command failed: %08X\n", err); |
| 9385 | goto done; |
| 9386 | } |
| 9387 | |
| 9388 | priv->status |= STATUS_SCANNING; |
| 9389 | |
| 9390 | done: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9391 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9392 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9393 | } |
| 9394 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9395 | static int ipw_wx_set_scan(struct net_device *dev, |
| 9396 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9397 | union iwreq_data *wrqu, char *extra) |
| 9398 | { |
| 9399 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 9400 | struct iw_scan_req *req = (struct iw_scan_req *)extra; |
| 9401 | |
| 9402 | if (wrqu->data.length == sizeof(struct iw_scan_req)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9403 | if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { |
| 9404 | ipw_request_direct_scan(priv, req->essid, |
| 9405 | req->essid_len); |
| 9406 | return 0; |
| 9407 | } |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 9408 | if (req->scan_type == IW_SCAN_TYPE_PASSIVE) { |
| 9409 | queue_work(priv->workqueue, |
| 9410 | &priv->request_passive_scan); |
| 9411 | return 0; |
| 9412 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9413 | } |
James Ketrenos | 8935f39 | 2005-10-05 15:59:08 -0500 | [diff] [blame] | 9414 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9415 | IPW_DEBUG_WX("Start scan\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9416 | |
| 9417 | queue_work(priv->workqueue, &priv->request_scan); |
| 9418 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9419 | return 0; |
| 9420 | } |
| 9421 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9422 | static int ipw_wx_get_scan(struct net_device *dev, |
| 9423 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9424 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9425 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9426 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9427 | return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra); |
| 9428 | } |
| 9429 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9430 | static int ipw_wx_set_encode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9431 | struct iw_request_info *info, |
| 9432 | union iwreq_data *wrqu, char *key) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9433 | { |
| 9434 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9435 | int ret; |
Hong Liu | caeff81 | 2005-08-05 17:25:50 +0800 | [diff] [blame] | 9436 | u32 cap = priv->capability; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9437 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9438 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9439 | ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9440 | |
Hong Liu | caeff81 | 2005-08-05 17:25:50 +0800 | [diff] [blame] | 9441 | /* In IBSS mode, we need to notify the firmware to update |
| 9442 | * the beacon info after we changed the capability. */ |
| 9443 | if (cap != priv->capability && |
| 9444 | priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 9445 | priv->status & STATUS_ASSOCIATED) |
| 9446 | ipw_disassociate(priv); |
| 9447 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9448 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9449 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9450 | } |
| 9451 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9452 | static int ipw_wx_get_encode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9453 | struct iw_request_info *info, |
| 9454 | union iwreq_data *wrqu, char *key) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9455 | { |
| 9456 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9457 | return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key); |
| 9458 | } |
| 9459 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9460 | static int ipw_wx_set_power(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9461 | struct iw_request_info *info, |
| 9462 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9463 | { |
| 9464 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9465 | int err; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9466 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9467 | if (wrqu->power.disabled) { |
| 9468 | priv->power_mode = IPW_POWER_LEVEL(priv->power_mode); |
| 9469 | err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM); |
| 9470 | if (err) { |
| 9471 | IPW_DEBUG_WX("failed setting power mode.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9472 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9473 | return err; |
| 9474 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9475 | IPW_DEBUG_WX("SET Power Management Mode -> off\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9476 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9477 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9478 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9479 | |
| 9480 | switch (wrqu->power.flags & IW_POWER_MODE) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9481 | case IW_POWER_ON: /* If not specified */ |
| 9482 | case IW_POWER_MODE: /* If set all mask */ |
| 9483 | case IW_POWER_ALL_R: /* If explicitely state all */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9484 | break; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9485 | default: /* Otherwise we don't support it */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9486 | IPW_DEBUG_WX("SET PM Mode: %X not supported.\n", |
| 9487 | wrqu->power.flags); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9488 | mutex_unlock(&priv->mutex); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9489 | return -EOPNOTSUPP; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9490 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9491 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9492 | /* If the user hasn't specified a power management mode yet, default |
| 9493 | * to BATTERY */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9494 | if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9495 | priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9496 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9497 | priv->power_mode = IPW_POWER_ENABLED | priv->power_mode; |
| 9498 | err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode)); |
| 9499 | if (err) { |
| 9500 | IPW_DEBUG_WX("failed setting power mode.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9501 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9502 | return err; |
| 9503 | } |
| 9504 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9505 | IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9506 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9507 | return 0; |
| 9508 | } |
| 9509 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9510 | static int ipw_wx_get_power(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9511 | struct iw_request_info *info, |
| 9512 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9513 | { |
| 9514 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9515 | mutex_lock(&priv->mutex); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9516 | if (!(priv->power_mode & IPW_POWER_ENABLED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9517 | wrqu->power.disabled = 1; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9518 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9519 | wrqu->power.disabled = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9520 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9521 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9522 | IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9523 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9524 | return 0; |
| 9525 | } |
| 9526 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9527 | static int ipw_wx_set_powermode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9528 | struct iw_request_info *info, |
| 9529 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9530 | { |
| 9531 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9532 | int mode = *(int *)extra; |
| 9533 | int err; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9534 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9535 | if ((mode < 1) || (mode > IPW_POWER_LIMIT)) { |
| 9536 | mode = IPW_POWER_AC; |
| 9537 | priv->power_mode = mode; |
| 9538 | } else { |
| 9539 | priv->power_mode = IPW_POWER_ENABLED | mode; |
| 9540 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9541 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9542 | if (priv->power_mode != mode) { |
| 9543 | err = ipw_send_power_mode(priv, mode); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9544 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9545 | if (err) { |
| 9546 | IPW_DEBUG_WX("failed setting power mode.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9547 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9548 | return err; |
| 9549 | } |
| 9550 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9551 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9552 | return 0; |
| 9553 | } |
| 9554 | |
| 9555 | #define MAX_WX_STRING 80 |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9556 | static int ipw_wx_get_powermode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9557 | struct iw_request_info *info, |
| 9558 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9559 | { |
| 9560 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9561 | int level = IPW_POWER_LEVEL(priv->power_mode); |
| 9562 | char *p = extra; |
| 9563 | |
| 9564 | p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level); |
| 9565 | |
| 9566 | switch (level) { |
| 9567 | case IPW_POWER_AC: |
| 9568 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)"); |
| 9569 | break; |
| 9570 | case IPW_POWER_BATTERY: |
| 9571 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)"); |
| 9572 | break; |
| 9573 | default: |
| 9574 | p += snprintf(p, MAX_WX_STRING - (p - extra), |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9575 | "(Timeout %dms, Period %dms)", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9576 | timeout_duration[level - 1] / 1000, |
| 9577 | period_duration[level - 1] / 1000); |
| 9578 | } |
| 9579 | |
| 9580 | if (!(priv->power_mode & IPW_POWER_ENABLED)) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9581 | p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9582 | |
| 9583 | wrqu->data.length = p - extra + 1; |
| 9584 | |
| 9585 | return 0; |
| 9586 | } |
| 9587 | |
| 9588 | static int ipw_wx_set_wireless_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9589 | struct iw_request_info *info, |
| 9590 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9591 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9592 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9593 | int mode = *(int *)extra; |
| 9594 | u8 band = 0, modulation = 0; |
| 9595 | |
| 9596 | if (mode == 0 || mode & ~IEEE_MODE_MASK) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9597 | IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9598 | return -EINVAL; |
| 9599 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9600 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9601 | if (priv->adapter == IPW_2915ABG) { |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9602 | priv->ieee->abg_true = 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9603 | if (mode & IEEE_A) { |
| 9604 | band |= IEEE80211_52GHZ_BAND; |
| 9605 | modulation |= IEEE80211_OFDM_MODULATION; |
| 9606 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9607 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9608 | } else { |
| 9609 | if (mode & IEEE_A) { |
| 9610 | IPW_WARNING("Attempt to set 2200BG into " |
| 9611 | "802.11a mode\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9612 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9613 | return -EINVAL; |
| 9614 | } |
| 9615 | |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9616 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9617 | } |
| 9618 | |
| 9619 | if (mode & IEEE_B) { |
| 9620 | band |= IEEE80211_24GHZ_BAND; |
| 9621 | modulation |= IEEE80211_CCK_MODULATION; |
| 9622 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9623 | priv->ieee->abg_true = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9624 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9625 | if (mode & IEEE_G) { |
| 9626 | band |= IEEE80211_24GHZ_BAND; |
| 9627 | modulation |= IEEE80211_OFDM_MODULATION; |
| 9628 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9629 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9630 | |
| 9631 | priv->ieee->mode = mode; |
| 9632 | priv->ieee->freq_band = band; |
| 9633 | priv->ieee->modulation = modulation; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9634 | init_supported_rates(priv, &priv->rates); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9635 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9636 | /* Network configuration changed -- force [re]association */ |
| 9637 | IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n"); |
| 9638 | if (!ipw_disassociate(priv)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9639 | ipw_send_supported_rates(priv, &priv->rates); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9640 | ipw_associate(priv); |
| 9641 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9642 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9643 | /* Update the band LEDs */ |
| 9644 | ipw_led_band_on(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9645 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9646 | IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9647 | mode & IEEE_A ? 'a' : '.', |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9648 | mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.'); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9649 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9650 | return 0; |
| 9651 | } |
| 9652 | |
| 9653 | static int ipw_wx_get_wireless_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9654 | struct iw_request_info *info, |
| 9655 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9656 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9657 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9658 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9659 | switch (priv->ieee->mode) { |
| 9660 | case IEEE_A: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9661 | strncpy(extra, "802.11a (1)", MAX_WX_STRING); |
| 9662 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9663 | case IEEE_B: |
| 9664 | strncpy(extra, "802.11b (2)", MAX_WX_STRING); |
| 9665 | break; |
| 9666 | case IEEE_A | IEEE_B: |
| 9667 | strncpy(extra, "802.11ab (3)", MAX_WX_STRING); |
| 9668 | break; |
| 9669 | case IEEE_G: |
| 9670 | strncpy(extra, "802.11g (4)", MAX_WX_STRING); |
| 9671 | break; |
| 9672 | case IEEE_A | IEEE_G: |
| 9673 | strncpy(extra, "802.11ag (5)", MAX_WX_STRING); |
| 9674 | break; |
| 9675 | case IEEE_B | IEEE_G: |
| 9676 | strncpy(extra, "802.11bg (6)", MAX_WX_STRING); |
| 9677 | break; |
| 9678 | case IEEE_A | IEEE_B | IEEE_G: |
| 9679 | strncpy(extra, "802.11abg (7)", MAX_WX_STRING); |
| 9680 | break; |
| 9681 | default: |
| 9682 | strncpy(extra, "unknown", MAX_WX_STRING); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9683 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9684 | } |
| 9685 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9686 | IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra); |
| 9687 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9688 | wrqu->data.length = strlen(extra) + 1; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9689 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9690 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9691 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9692 | } |
| 9693 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9694 | static int ipw_wx_set_preamble(struct net_device *dev, |
| 9695 | struct iw_request_info *info, |
| 9696 | union iwreq_data *wrqu, char *extra) |
| 9697 | { |
| 9698 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9699 | int mode = *(int *)extra; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9700 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9701 | /* Switching from SHORT -> LONG requires a disassociation */ |
| 9702 | if (mode == 1) { |
| 9703 | if (!(priv->config & CFG_PREAMBLE_LONG)) { |
| 9704 | priv->config |= CFG_PREAMBLE_LONG; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9705 | |
| 9706 | /* Network configuration changed -- force [re]association */ |
| 9707 | IPW_DEBUG_ASSOC |
| 9708 | ("[re]association triggered due to preamble change.\n"); |
| 9709 | if (!ipw_disassociate(priv)) |
| 9710 | ipw_associate(priv); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9711 | } |
| 9712 | goto done; |
| 9713 | } |
| 9714 | |
| 9715 | if (mode == 0) { |
| 9716 | priv->config &= ~CFG_PREAMBLE_LONG; |
| 9717 | goto done; |
| 9718 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9719 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9720 | return -EINVAL; |
| 9721 | |
| 9722 | done: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9723 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9724 | return 0; |
| 9725 | } |
| 9726 | |
| 9727 | static int ipw_wx_get_preamble(struct net_device *dev, |
| 9728 | struct iw_request_info *info, |
| 9729 | union iwreq_data *wrqu, char *extra) |
| 9730 | { |
| 9731 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9732 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9733 | if (priv->config & CFG_PREAMBLE_LONG) |
| 9734 | snprintf(wrqu->name, IFNAMSIZ, "long (1)"); |
| 9735 | else |
| 9736 | snprintf(wrqu->name, IFNAMSIZ, "auto (0)"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9737 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9738 | return 0; |
| 9739 | } |
| 9740 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9741 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9742 | static int ipw_wx_set_monitor(struct net_device *dev, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9743 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9744 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9745 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9746 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9747 | int *parms = (int *)extra; |
| 9748 | int enable = (parms[0] > 0); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9749 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9750 | IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9751 | if (enable) { |
| 9752 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 9753 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 9754 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 9755 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9756 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 9757 | #endif |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9758 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9759 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9760 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9761 | ipw_set_channel(priv, parms[1]); |
| 9762 | } else { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9763 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9764 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9765 | return 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9766 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9767 | priv->net_dev->type = ARPHRD_ETHER; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9768 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9769 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9770 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9771 | return 0; |
| 9772 | } |
| 9773 | |
Pavel Machek | 67fd6b4 | 2006-07-11 15:34:05 +0200 | [diff] [blame] | 9774 | #endif /* CONFIG_IPW2200_MONITOR */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9775 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9776 | static int ipw_wx_reset(struct net_device *dev, |
| 9777 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9778 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9779 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9780 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9781 | IPW_DEBUG_WX("RESET\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9782 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9783 | return 0; |
| 9784 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9785 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9786 | static int ipw_wx_sw_reset(struct net_device *dev, |
| 9787 | struct iw_request_info *info, |
| 9788 | union iwreq_data *wrqu, char *extra) |
| 9789 | { |
| 9790 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9791 | union iwreq_data wrqu_sec = { |
| 9792 | .encoding = { |
| 9793 | .flags = IW_ENCODE_DISABLED, |
| 9794 | }, |
| 9795 | }; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9796 | int ret; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9797 | |
| 9798 | IPW_DEBUG_WX("SW_RESET\n"); |
| 9799 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9800 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9801 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 9802 | ret = ipw_sw_reset(priv, 2); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9803 | if (!ret) { |
| 9804 | free_firmware(); |
| 9805 | ipw_adapter_restart(priv); |
| 9806 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9807 | |
| 9808 | /* The SW reset bit might have been toggled on by the 'disable' |
| 9809 | * module parameter, so take appropriate action */ |
| 9810 | ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW); |
| 9811 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9812 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9813 | ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9814 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9815 | |
| 9816 | if (!(priv->status & STATUS_RF_KILL_MASK)) { |
| 9817 | /* Configuration likely changed -- force [re]association */ |
| 9818 | IPW_DEBUG_ASSOC("[re]association triggered due to sw " |
| 9819 | "reset.\n"); |
| 9820 | if (!ipw_disassociate(priv)) |
| 9821 | ipw_associate(priv); |
| 9822 | } |
| 9823 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9824 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9825 | |
| 9826 | return 0; |
| 9827 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9828 | |
| 9829 | /* Rebase the WE IOCTLs to zero for the handler array */ |
| 9830 | #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT] |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9831 | static iw_handler ipw_wx_handlers[] = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9832 | IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name, |
| 9833 | IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq, |
| 9834 | IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq, |
| 9835 | IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode, |
| 9836 | IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode, |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame] | 9837 | IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens, |
| 9838 | IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9839 | IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range, |
| 9840 | IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap, |
| 9841 | IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap, |
| 9842 | IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan, |
| 9843 | IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan, |
| 9844 | IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid, |
| 9845 | IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid, |
| 9846 | IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick, |
| 9847 | IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick, |
| 9848 | IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate, |
| 9849 | IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate, |
| 9850 | IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts, |
| 9851 | IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts, |
| 9852 | IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag, |
| 9853 | IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag, |
| 9854 | IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow, |
| 9855 | IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow, |
| 9856 | IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry, |
| 9857 | IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry, |
| 9858 | IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode, |
| 9859 | IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode, |
| 9860 | IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power, |
| 9861 | IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9862 | IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy, |
| 9863 | IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy, |
| 9864 | IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy, |
| 9865 | IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy, |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9866 | IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie, |
| 9867 | IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie, |
| 9868 | IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme, |
| 9869 | IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth, |
| 9870 | IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth, |
| 9871 | IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext, |
| 9872 | IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9873 | }; |
| 9874 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9875 | enum { |
| 9876 | IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV, |
| 9877 | IPW_PRIV_GET_POWER, |
| 9878 | IPW_PRIV_SET_MODE, |
| 9879 | IPW_PRIV_GET_MODE, |
| 9880 | IPW_PRIV_SET_PREAMBLE, |
| 9881 | IPW_PRIV_GET_PREAMBLE, |
| 9882 | IPW_PRIV_RESET, |
| 9883 | IPW_PRIV_SW_RESET, |
| 9884 | #ifdef CONFIG_IPW2200_MONITOR |
| 9885 | IPW_PRIV_SET_MONITOR, |
| 9886 | #endif |
| 9887 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9888 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9889 | static struct iw_priv_args ipw_priv_args[] = { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9890 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9891 | .cmd = IPW_PRIV_SET_POWER, |
| 9892 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 9893 | .name = "set_power"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9894 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9895 | .cmd = IPW_PRIV_GET_POWER, |
| 9896 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, |
| 9897 | .name = "get_power"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9898 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9899 | .cmd = IPW_PRIV_SET_MODE, |
| 9900 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 9901 | .name = "set_mode"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9902 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9903 | .cmd = IPW_PRIV_GET_MODE, |
| 9904 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, |
| 9905 | .name = "get_mode"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9906 | { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9907 | .cmd = IPW_PRIV_SET_PREAMBLE, |
| 9908 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 9909 | .name = "set_preamble"}, |
| 9910 | { |
| 9911 | .cmd = IPW_PRIV_GET_PREAMBLE, |
| 9912 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, |
| 9913 | .name = "get_preamble"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9914 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9915 | IPW_PRIV_RESET, |
| 9916 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"}, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9917 | { |
| 9918 | IPW_PRIV_SW_RESET, |
| 9919 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"}, |
| 9920 | #ifdef CONFIG_IPW2200_MONITOR |
| 9921 | { |
| 9922 | IPW_PRIV_SET_MONITOR, |
| 9923 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"}, |
| 9924 | #endif /* CONFIG_IPW2200_MONITOR */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9925 | }; |
| 9926 | |
| 9927 | static iw_handler ipw_priv_handler[] = { |
| 9928 | ipw_wx_set_powermode, |
| 9929 | ipw_wx_get_powermode, |
| 9930 | ipw_wx_set_wireless_mode, |
| 9931 | ipw_wx_get_wireless_mode, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9932 | ipw_wx_set_preamble, |
| 9933 | ipw_wx_get_preamble, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9934 | ipw_wx_reset, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9935 | ipw_wx_sw_reset, |
| 9936 | #ifdef CONFIG_IPW2200_MONITOR |
| 9937 | ipw_wx_set_monitor, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9938 | #endif |
| 9939 | }; |
| 9940 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9941 | static struct iw_handler_def ipw_wx_handler_def = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9942 | .standard = ipw_wx_handlers, |
| 9943 | .num_standard = ARRAY_SIZE(ipw_wx_handlers), |
| 9944 | .num_private = ARRAY_SIZE(ipw_priv_handler), |
| 9945 | .num_private_args = ARRAY_SIZE(ipw_priv_args), |
| 9946 | .private = ipw_priv_handler, |
| 9947 | .private_args = ipw_priv_args, |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 9948 | .get_wireless_stats = ipw_get_wireless_stats, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9949 | }; |
| 9950 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9951 | /* |
| 9952 | * Get wireless statistics. |
| 9953 | * Called by /proc/net/wireless |
| 9954 | * Also called by SIOCGIWSTATS |
| 9955 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9956 | static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9957 | { |
| 9958 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9959 | struct iw_statistics *wstats; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9960 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9961 | wstats = &priv->wstats; |
| 9962 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9963 | /* if hw is disabled, then ipw_get_ordinal() can't be called. |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9964 | * netdev->get_wireless_stats seems to be called before fw is |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9965 | * initialized. STATUS_ASSOCIATED will only be set if the hw is up |
| 9966 | * and associated; if not associcated, the values are all meaningless |
| 9967 | * anyway, so set them all to NULL and INVALID */ |
| 9968 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 9969 | wstats->miss.beacon = 0; |
| 9970 | wstats->discard.retries = 0; |
| 9971 | wstats->qual.qual = 0; |
| 9972 | wstats->qual.level = 0; |
| 9973 | wstats->qual.noise = 0; |
| 9974 | wstats->qual.updated = 7; |
| 9975 | wstats->qual.updated |= IW_QUAL_NOISE_INVALID | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9976 | IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9977 | return wstats; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9978 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9979 | |
| 9980 | wstats->qual.qual = priv->quality; |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 9981 | wstats->qual.level = priv->exp_avg_rssi; |
| 9982 | wstats->qual.noise = priv->exp_avg_noise; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9983 | wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 9984 | IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9985 | |
| 9986 | wstats->miss.beacon = average_value(&priv->average_missed_beacons); |
| 9987 | wstats->discard.retries = priv->last_tx_failures; |
| 9988 | wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9989 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9990 | /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len)) |
| 9991 | goto fail_get_ordinal; |
| 9992 | wstats->discard.retries += tx_retry; */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9993 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9994 | return wstats; |
| 9995 | } |
| 9996 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9997 | /* net device stuff */ |
| 9998 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 9999 | static void init_sys_config(struct ipw_sys_config *sys_config) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10000 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10001 | memset(sys_config, 0, sizeof(struct ipw_sys_config)); |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10002 | sys_config->bt_coexistence = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10003 | sys_config->answer_broadcast_ssid_probe = 0; |
| 10004 | sys_config->accept_all_data_frames = 0; |
| 10005 | sys_config->accept_non_directed_frames = 1; |
| 10006 | sys_config->exclude_unicast_unencrypted = 0; |
| 10007 | sys_config->disable_unicast_decryption = 1; |
| 10008 | sys_config->exclude_multicast_unencrypted = 0; |
| 10009 | sys_config->disable_multicast_decryption = 1; |
Zhu Yi | d2b83e1 | 2006-04-13 17:19:36 +0800 | [diff] [blame] | 10010 | if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B) |
| 10011 | antenna = CFG_SYS_ANTENNA_BOTH; |
| 10012 | sys_config->antenna_diversity = antenna; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10013 | sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10014 | sys_config->dot11g_auto_detection = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10015 | sys_config->enable_cts_to_self = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10016 | sys_config->bt_coexist_collision_thr = 0; |
Pavel Machek | 67fd6b4 | 2006-07-11 15:34:05 +0200 | [diff] [blame] | 10017 | sys_config->pass_noise_stats_to_host = 1; /* 1 -- fix for 256 */ |
Cahill, Ben M | 1297715 | 2006-03-08 02:58:02 +0800 | [diff] [blame] | 10018 | sys_config->silence_threshold = 0x1e; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10019 | } |
| 10020 | |
| 10021 | static int ipw_net_open(struct net_device *dev) |
| 10022 | { |
| 10023 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 10024 | IPW_DEBUG_INFO("dev->open\n"); |
| 10025 | /* we should be verifying the device is ready to be opened */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10026 | mutex_lock(&priv->mutex); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10027 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
| 10028 | (priv->status & STATUS_ASSOCIATED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10029 | netif_start_queue(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10030 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10031 | return 0; |
| 10032 | } |
| 10033 | |
| 10034 | static int ipw_net_stop(struct net_device *dev) |
| 10035 | { |
| 10036 | IPW_DEBUG_INFO("dev->close\n"); |
| 10037 | netif_stop_queue(dev); |
| 10038 | return 0; |
| 10039 | } |
| 10040 | |
| 10041 | /* |
| 10042 | todo: |
| 10043 | |
| 10044 | modify to send one tfd per fragment instead of using chunking. otherwise |
| 10045 | we need to heavily modify the ieee80211_skb_to_txb. |
| 10046 | */ |
| 10047 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 10048 | static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb, |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10049 | int pri) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10050 | { |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 10051 | struct ieee80211_hdr_3addrqos *hdr = (struct ieee80211_hdr_3addrqos *) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10052 | txb->fragments[0]->data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10053 | int i = 0; |
| 10054 | struct tfd_frame *tfd; |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10055 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10056 | int tx_id = ipw_get_tx_queue_number(priv, pri); |
| 10057 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; |
| 10058 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10059 | struct clx2_tx_queue *txq = &priv->txq[0]; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10060 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10061 | struct clx2_queue *q = &txq->q; |
| 10062 | u8 id, hdr_len, unicast; |
| 10063 | u16 remaining_bytes; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10064 | int fc; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10065 | |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 10066 | hdr_len = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10067 | switch (priv->ieee->iw_mode) { |
| 10068 | case IW_MODE_ADHOC: |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 10069 | unicast = !is_multicast_ether_addr(hdr->addr1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10070 | id = ipw_find_station(priv, hdr->addr1); |
| 10071 | if (id == IPW_INVALID_STATION) { |
| 10072 | id = ipw_add_station(priv, hdr->addr1); |
| 10073 | if (id == IPW_INVALID_STATION) { |
| 10074 | IPW_WARNING("Attempt to send data to " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10075 | "invalid cell: " MAC_FMT "\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10076 | MAC_ARG(hdr->addr1)); |
| 10077 | goto drop; |
| 10078 | } |
| 10079 | } |
| 10080 | break; |
| 10081 | |
| 10082 | case IW_MODE_INFRA: |
| 10083 | default: |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 10084 | unicast = !is_multicast_ether_addr(hdr->addr3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10085 | id = 0; |
| 10086 | break; |
| 10087 | } |
| 10088 | |
| 10089 | tfd = &txq->bd[q->first_empty]; |
| 10090 | txq->txb[q->first_empty] = txb; |
| 10091 | memset(tfd, 0, sizeof(*tfd)); |
| 10092 | tfd->u.data.station_number = id; |
| 10093 | |
| 10094 | tfd->control_flags.message_type = TX_FRAME_TYPE; |
| 10095 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; |
| 10096 | |
| 10097 | tfd->u.data.cmd_id = DINO_CMD_TX; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10098 | tfd->u.data.len = cpu_to_le16(txb->payload_size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10099 | remaining_bytes = txb->payload_size; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10100 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10101 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10102 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10103 | else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10104 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10105 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10106 | if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE) |
| 10107 | tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10108 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10109 | fc = le16_to_cpu(hdr->frame_ctl); |
| 10110 | hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10111 | |
| 10112 | memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len); |
| 10113 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10114 | if (likely(unicast)) |
| 10115 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; |
| 10116 | |
| 10117 | if (txb->encrypted && !priv->ieee->host_encrypt) { |
| 10118 | switch (priv->ieee->sec.level) { |
| 10119 | case SEC_LEVEL_3: |
| 10120 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 10121 | cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10122 | /* XXX: ACK flag must be set for CCMP even if it |
| 10123 | * is a multicast/broadcast packet, because CCMP |
| 10124 | * group communication encrypted by GTK is |
| 10125 | * actually done by the AP. */ |
| 10126 | if (!unicast) |
| 10127 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; |
| 10128 | |
| 10129 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; |
| 10130 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM; |
| 10131 | tfd->u.data.key_index = 0; |
| 10132 | tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE; |
| 10133 | break; |
| 10134 | case SEC_LEVEL_2: |
| 10135 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 10136 | cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10137 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; |
| 10138 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP; |
| 10139 | tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE; |
| 10140 | break; |
| 10141 | case SEC_LEVEL_1: |
| 10142 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 10143 | cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10144 | tfd->u.data.key_index = priv->ieee->tx_keyidx; |
| 10145 | if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <= |
| 10146 | 40) |
| 10147 | tfd->u.data.key_index |= DCT_WEP_KEY_64Bit; |
| 10148 | else |
| 10149 | tfd->u.data.key_index |= DCT_WEP_KEY_128Bit; |
| 10150 | break; |
| 10151 | case SEC_LEVEL_0: |
| 10152 | break; |
| 10153 | default: |
| 10154 | printk(KERN_ERR "Unknow security level %d\n", |
| 10155 | priv->ieee->sec.level); |
| 10156 | break; |
| 10157 | } |
| 10158 | } else |
| 10159 | /* No hardware encryption */ |
| 10160 | tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP; |
| 10161 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10162 | #ifdef CONFIG_IPW2200_QOS |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 10163 | if (fc & IEEE80211_STYPE_QOS_DATA) |
| 10164 | ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data)); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10165 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10166 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10167 | /* payload */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10168 | tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2), |
| 10169 | txb->nr_frags)); |
| 10170 | IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n", |
| 10171 | txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks)); |
| 10172 | for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) { |
| 10173 | IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n", |
| 10174 | i, le32_to_cpu(tfd->u.data.num_chunks), |
| 10175 | txb->fragments[i]->len - hdr_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10176 | IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10177 | i, tfd->u.data.num_chunks, |
| 10178 | txb->fragments[i]->len - hdr_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10179 | printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10180 | txb->fragments[i]->len - hdr_len); |
| 10181 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10182 | tfd->u.data.chunk_ptr[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10183 | cpu_to_le32(pci_map_single |
| 10184 | (priv->pci_dev, |
| 10185 | txb->fragments[i]->data + hdr_len, |
| 10186 | txb->fragments[i]->len - hdr_len, |
| 10187 | PCI_DMA_TODEVICE)); |
| 10188 | tfd->u.data.chunk_len[i] = |
| 10189 | cpu_to_le16(txb->fragments[i]->len - hdr_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10190 | } |
| 10191 | |
| 10192 | if (i != txb->nr_frags) { |
| 10193 | struct sk_buff *skb; |
| 10194 | u16 remaining_bytes = 0; |
| 10195 | int j; |
| 10196 | |
| 10197 | for (j = i; j < txb->nr_frags; j++) |
| 10198 | remaining_bytes += txb->fragments[j]->len - hdr_len; |
| 10199 | |
| 10200 | printk(KERN_INFO "Trying to reallocate for %d bytes\n", |
| 10201 | remaining_bytes); |
| 10202 | skb = alloc_skb(remaining_bytes, GFP_ATOMIC); |
| 10203 | if (skb != NULL) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10204 | tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10205 | for (j = i; j < txb->nr_frags; j++) { |
| 10206 | int size = txb->fragments[j]->len - hdr_len; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10207 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10208 | printk(KERN_INFO "Adding frag %d %d...\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10209 | j, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10210 | memcpy(skb_put(skb, size), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10211 | txb->fragments[j]->data + hdr_len, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10212 | } |
| 10213 | dev_kfree_skb_any(txb->fragments[i]); |
| 10214 | txb->fragments[i] = skb; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10215 | tfd->u.data.chunk_ptr[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10216 | cpu_to_le32(pci_map_single |
| 10217 | (priv->pci_dev, skb->data, |
| 10218 | tfd->u.data.chunk_len[i], |
| 10219 | PCI_DMA_TODEVICE)); |
| 10220 | |
| 10221 | tfd->u.data.num_chunks = |
| 10222 | cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) + |
| 10223 | 1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10224 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10225 | } |
| 10226 | |
| 10227 | /* kick DMA */ |
| 10228 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); |
| 10229 | ipw_write32(priv, q->reg_w, q->first_empty); |
| 10230 | |
James Ketrenos | f697014 | 2006-02-14 09:10:51 +0800 | [diff] [blame] | 10231 | if (ipw_queue_space(q) < q->high_mark) |
| 10232 | netif_stop_queue(priv->net_dev); |
| 10233 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10234 | return NETDEV_TX_OK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10235 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10236 | drop: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10237 | IPW_DEBUG_DROP("Silently dropping Tx packet.\n"); |
| 10238 | ieee80211_txb_free(txb); |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10239 | return NETDEV_TX_OK; |
| 10240 | } |
| 10241 | |
| 10242 | static int ipw_net_is_queue_full(struct net_device *dev, int pri) |
| 10243 | { |
| 10244 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10245 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10246 | int tx_id = ipw_get_tx_queue_number(priv, pri); |
| 10247 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; |
| 10248 | #else |
| 10249 | struct clx2_tx_queue *txq = &priv->txq[0]; |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10250 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10251 | |
| 10252 | if (ipw_queue_space(&txq->q) < txq->q.high_mark) |
| 10253 | return 1; |
| 10254 | |
| 10255 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10256 | } |
| 10257 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10258 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 10259 | static void ipw_handle_promiscuous_tx(struct ipw_priv *priv, |
| 10260 | struct ieee80211_txb *txb) |
| 10261 | { |
| 10262 | struct ieee80211_rx_stats dummystats; |
| 10263 | struct ieee80211_hdr *hdr; |
| 10264 | u8 n; |
| 10265 | u16 filter = priv->prom_priv->filter; |
| 10266 | int hdr_only = 0; |
| 10267 | |
| 10268 | if (filter & IPW_PROM_NO_TX) |
| 10269 | return; |
| 10270 | |
| 10271 | memset(&dummystats, 0, sizeof(dummystats)); |
| 10272 | |
| 10273 | /* Filtering of fragment chains is done agains the first fragment */ |
| 10274 | hdr = (void *)txb->fragments[0]->data; |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 10275 | if (ieee80211_is_management(le16_to_cpu(hdr->frame_ctl))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10276 | if (filter & IPW_PROM_NO_MGMT) |
| 10277 | return; |
| 10278 | if (filter & IPW_PROM_MGMT_HEADER_ONLY) |
| 10279 | hdr_only = 1; |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 10280 | } else if (ieee80211_is_control(le16_to_cpu(hdr->frame_ctl))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10281 | if (filter & IPW_PROM_NO_CTL) |
| 10282 | return; |
| 10283 | if (filter & IPW_PROM_CTL_HEADER_ONLY) |
| 10284 | hdr_only = 1; |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 10285 | } else if (ieee80211_is_data(le16_to_cpu(hdr->frame_ctl))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10286 | if (filter & IPW_PROM_NO_DATA) |
| 10287 | return; |
| 10288 | if (filter & IPW_PROM_DATA_HEADER_ONLY) |
| 10289 | hdr_only = 1; |
| 10290 | } |
| 10291 | |
| 10292 | for(n=0; n<txb->nr_frags; ++n) { |
| 10293 | struct sk_buff *src = txb->fragments[n]; |
| 10294 | struct sk_buff *dst; |
| 10295 | struct ieee80211_radiotap_header *rt_hdr; |
| 10296 | int len; |
| 10297 | |
| 10298 | if (hdr_only) { |
| 10299 | hdr = (void *)src->data; |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 10300 | len = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10301 | } else |
| 10302 | len = src->len; |
| 10303 | |
| 10304 | dst = alloc_skb( |
| 10305 | len + IEEE80211_RADIOTAP_HDRLEN, GFP_ATOMIC); |
| 10306 | if (!dst) continue; |
| 10307 | |
| 10308 | rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr)); |
| 10309 | |
| 10310 | rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION; |
| 10311 | rt_hdr->it_pad = 0; |
| 10312 | rt_hdr->it_present = 0; /* after all, it's just an idea */ |
| 10313 | rt_hdr->it_present |= (1 << IEEE80211_RADIOTAP_CHANNEL); |
| 10314 | |
| 10315 | *(u16*)skb_put(dst, sizeof(u16)) = cpu_to_le16( |
| 10316 | ieee80211chan2mhz(priv->channel)); |
| 10317 | if (priv->channel > 14) /* 802.11a */ |
| 10318 | *(u16*)skb_put(dst, sizeof(u16)) = |
| 10319 | cpu_to_le16(IEEE80211_CHAN_OFDM | |
| 10320 | IEEE80211_CHAN_5GHZ); |
| 10321 | else if (priv->ieee->mode == IEEE_B) /* 802.11b */ |
| 10322 | *(u16*)skb_put(dst, sizeof(u16)) = |
| 10323 | cpu_to_le16(IEEE80211_CHAN_CCK | |
| 10324 | IEEE80211_CHAN_2GHZ); |
| 10325 | else /* 802.11g */ |
| 10326 | *(u16*)skb_put(dst, sizeof(u16)) = |
| 10327 | cpu_to_le16(IEEE80211_CHAN_OFDM | |
| 10328 | IEEE80211_CHAN_2GHZ); |
| 10329 | |
| 10330 | rt_hdr->it_len = dst->len; |
| 10331 | |
| 10332 | memcpy(skb_put(dst, len), src->data, len); |
| 10333 | |
| 10334 | if (!ieee80211_rx(priv->prom_priv->ieee, dst, &dummystats)) |
| 10335 | dev_kfree_skb_any(dst); |
| 10336 | } |
| 10337 | } |
| 10338 | #endif |
| 10339 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10340 | static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb, |
James Ketrenos | c8d42d1 | 2005-09-21 12:23:43 -0500 | [diff] [blame] | 10341 | struct net_device *dev, int pri) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10342 | { |
| 10343 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 10344 | unsigned long flags; |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10345 | int ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10346 | |
| 10347 | IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10348 | spin_lock_irqsave(&priv->lock, flags); |
| 10349 | |
| 10350 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 10351 | IPW_DEBUG_INFO("Tx attempt while not associated.\n"); |
| 10352 | priv->ieee->stats.tx_carrier_errors++; |
| 10353 | netif_stop_queue(dev); |
| 10354 | goto fail_unlock; |
| 10355 | } |
| 10356 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10357 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 10358 | if (rtap_iface && netif_running(priv->prom_net_dev)) |
| 10359 | ipw_handle_promiscuous_tx(priv, txb); |
| 10360 | #endif |
| 10361 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10362 | ret = ipw_tx_skb(priv, txb, pri); |
| 10363 | if (ret == NETDEV_TX_OK) |
| 10364 | __ipw_led_activity_on(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10365 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10366 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10367 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10368 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10369 | fail_unlock: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10370 | spin_unlock_irqrestore(&priv->lock, flags); |
| 10371 | return 1; |
| 10372 | } |
| 10373 | |
| 10374 | static struct net_device_stats *ipw_net_get_stats(struct net_device *dev) |
| 10375 | { |
| 10376 | struct ipw_priv *priv = ieee80211_priv(dev); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10377 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10378 | priv->ieee->stats.tx_packets = priv->tx_packets; |
| 10379 | priv->ieee->stats.rx_packets = priv->rx_packets; |
| 10380 | return &priv->ieee->stats; |
| 10381 | } |
| 10382 | |
| 10383 | static void ipw_net_set_multicast_list(struct net_device *dev) |
| 10384 | { |
| 10385 | |
| 10386 | } |
| 10387 | |
| 10388 | static int ipw_net_set_mac_address(struct net_device *dev, void *p) |
| 10389 | { |
| 10390 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 10391 | struct sockaddr *addr = p; |
| 10392 | if (!is_valid_ether_addr(addr->sa_data)) |
| 10393 | return -EADDRNOTAVAIL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10394 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10395 | priv->config |= CFG_CUSTOM_MAC; |
| 10396 | memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN); |
| 10397 | printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n", |
| 10398 | priv->net_dev->name, MAC_ARG(priv->mac_addr)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10399 | queue_work(priv->workqueue, &priv->adapter_restart); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10400 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10401 | return 0; |
| 10402 | } |
| 10403 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10404 | static void ipw_ethtool_get_drvinfo(struct net_device *dev, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10405 | struct ethtool_drvinfo *info) |
| 10406 | { |
| 10407 | struct ipw_priv *p = ieee80211_priv(dev); |
| 10408 | char vers[64]; |
| 10409 | char date[32]; |
| 10410 | u32 len; |
| 10411 | |
| 10412 | strcpy(info->driver, DRV_NAME); |
| 10413 | strcpy(info->version, DRV_VERSION); |
| 10414 | |
| 10415 | len = sizeof(vers); |
| 10416 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len); |
| 10417 | len = sizeof(date); |
| 10418 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len); |
| 10419 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10420 | snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10421 | vers, date); |
| 10422 | strcpy(info->bus_info, pci_name(p->pci_dev)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10423 | info->eedump_len = IPW_EEPROM_IMAGE_SIZE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10424 | } |
| 10425 | |
| 10426 | static u32 ipw_ethtool_get_link(struct net_device *dev) |
| 10427 | { |
| 10428 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 10429 | return (priv->status & STATUS_ASSOCIATED) != 0; |
| 10430 | } |
| 10431 | |
| 10432 | static int ipw_ethtool_get_eeprom_len(struct net_device *dev) |
| 10433 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10434 | return IPW_EEPROM_IMAGE_SIZE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10435 | } |
| 10436 | |
| 10437 | static int ipw_ethtool_get_eeprom(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10438 | struct ethtool_eeprom *eeprom, u8 * bytes) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10439 | { |
| 10440 | struct ipw_priv *p = ieee80211_priv(dev); |
| 10441 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10442 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10443 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10444 | mutex_lock(&p->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10445 | memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10446 | mutex_unlock(&p->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10447 | return 0; |
| 10448 | } |
| 10449 | |
| 10450 | static int ipw_ethtool_set_eeprom(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10451 | struct ethtool_eeprom *eeprom, u8 * bytes) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10452 | { |
| 10453 | struct ipw_priv *p = ieee80211_priv(dev); |
| 10454 | int i; |
| 10455 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10456 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10457 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10458 | mutex_lock(&p->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10459 | memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len); |
Adrian Bunk | 71e585f | 2006-03-11 04:42:58 +0100 | [diff] [blame] | 10460 | for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) |
| 10461 | ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10462 | mutex_unlock(&p->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10463 | return 0; |
| 10464 | } |
| 10465 | |
| 10466 | static struct ethtool_ops ipw_ethtool_ops = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10467 | .get_link = ipw_ethtool_get_link, |
| 10468 | .get_drvinfo = ipw_ethtool_get_drvinfo, |
| 10469 | .get_eeprom_len = ipw_ethtool_get_eeprom_len, |
| 10470 | .get_eeprom = ipw_ethtool_get_eeprom, |
| 10471 | .set_eeprom = ipw_ethtool_set_eeprom, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10472 | }; |
| 10473 | |
| 10474 | static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs) |
| 10475 | { |
| 10476 | struct ipw_priv *priv = data; |
| 10477 | u32 inta, inta_mask; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10478 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10479 | if (!priv) |
| 10480 | return IRQ_NONE; |
| 10481 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 10482 | spin_lock(&priv->irq_lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10483 | |
| 10484 | if (!(priv->status & STATUS_INT_ENABLED)) { |
| 10485 | /* Shared IRQ */ |
| 10486 | goto none; |
| 10487 | } |
| 10488 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10489 | inta = ipw_read32(priv, IPW_INTA_RW); |
| 10490 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10491 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10492 | if (inta == 0xFFFFFFFF) { |
| 10493 | /* Hardware disappeared */ |
| 10494 | IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n"); |
| 10495 | goto none; |
| 10496 | } |
| 10497 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10498 | if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10499 | /* Shared interrupt */ |
| 10500 | goto none; |
| 10501 | } |
| 10502 | |
| 10503 | /* tell the device to stop sending interrupts */ |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 10504 | __ipw_disable_interrupts(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10505 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10506 | /* ack current interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10507 | inta &= (IPW_INTA_MASK_ALL & inta_mask); |
| 10508 | ipw_write32(priv, IPW_INTA_RW, inta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10509 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10510 | /* Cache INTA value for our tasklet */ |
| 10511 | priv->isr_inta = inta; |
| 10512 | |
| 10513 | tasklet_schedule(&priv->irq_tasklet); |
| 10514 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 10515 | spin_unlock(&priv->irq_lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10516 | |
| 10517 | return IRQ_HANDLED; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10518 | none: |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 10519 | spin_unlock(&priv->irq_lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10520 | return IRQ_NONE; |
| 10521 | } |
| 10522 | |
| 10523 | static void ipw_rf_kill(void *adapter) |
| 10524 | { |
| 10525 | struct ipw_priv *priv = adapter; |
| 10526 | unsigned long flags; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10527 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10528 | spin_lock_irqsave(&priv->lock, flags); |
| 10529 | |
| 10530 | if (rf_kill_active(priv)) { |
| 10531 | IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n"); |
| 10532 | if (priv->workqueue) |
| 10533 | queue_delayed_work(priv->workqueue, |
| 10534 | &priv->rf_kill, 2 * HZ); |
| 10535 | goto exit_unlock; |
| 10536 | } |
| 10537 | |
| 10538 | /* RF Kill is now disabled, so bring the device back up */ |
| 10539 | |
| 10540 | if (!(priv->status & STATUS_RF_KILL_MASK)) { |
| 10541 | IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting " |
| 10542 | "device\n"); |
| 10543 | |
| 10544 | /* we can not do an adapter restart while inside an irq lock */ |
| 10545 | queue_work(priv->workqueue, &priv->adapter_restart); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10546 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10547 | IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still " |
| 10548 | "enabled\n"); |
| 10549 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10550 | exit_unlock: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10551 | spin_unlock_irqrestore(&priv->lock, flags); |
| 10552 | } |
| 10553 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10554 | static void ipw_bg_rf_kill(void *data) |
| 10555 | { |
| 10556 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10557 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10558 | ipw_rf_kill(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10559 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10560 | } |
| 10561 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 10562 | static void ipw_link_up(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10563 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10564 | priv->last_seq_num = -1; |
| 10565 | priv->last_frag_num = -1; |
| 10566 | priv->last_packet_time = 0; |
| 10567 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10568 | netif_carrier_on(priv->net_dev); |
| 10569 | if (netif_queue_stopped(priv->net_dev)) { |
| 10570 | IPW_DEBUG_NOTIF("waking queue\n"); |
| 10571 | netif_wake_queue(priv->net_dev); |
| 10572 | } else { |
| 10573 | IPW_DEBUG_NOTIF("starting queue\n"); |
| 10574 | netif_start_queue(priv->net_dev); |
| 10575 | } |
| 10576 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10577 | cancel_delayed_work(&priv->request_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10578 | ipw_reset_stats(priv); |
| 10579 | /* Ensure the rate is updated immediately */ |
| 10580 | priv->last_rate = ipw_get_current_rate(priv); |
| 10581 | ipw_gather_stats(priv); |
| 10582 | ipw_led_link_up(priv); |
| 10583 | notify_wx_assoc_event(priv); |
| 10584 | |
| 10585 | if (priv->config & CFG_BACKGROUND_SCAN) |
| 10586 | queue_delayed_work(priv->workqueue, &priv->request_scan, HZ); |
| 10587 | } |
| 10588 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10589 | static void ipw_bg_link_up(void *data) |
| 10590 | { |
| 10591 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10592 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10593 | ipw_link_up(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10594 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10595 | } |
| 10596 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 10597 | static void ipw_link_down(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10598 | { |
| 10599 | ipw_led_link_down(priv); |
| 10600 | netif_carrier_off(priv->net_dev); |
| 10601 | netif_stop_queue(priv->net_dev); |
| 10602 | notify_wx_assoc_event(priv); |
| 10603 | |
| 10604 | /* Cancel any queued work ... */ |
| 10605 | cancel_delayed_work(&priv->request_scan); |
| 10606 | cancel_delayed_work(&priv->adhoc_check); |
| 10607 | cancel_delayed_work(&priv->gather_stats); |
| 10608 | |
| 10609 | ipw_reset_stats(priv); |
| 10610 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10611 | if (!(priv->status & STATUS_EXIT_PENDING)) { |
| 10612 | /* Queue up another scan... */ |
| 10613 | queue_work(priv->workqueue, &priv->request_scan); |
| 10614 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10615 | } |
| 10616 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10617 | static void ipw_bg_link_down(void *data) |
| 10618 | { |
| 10619 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10620 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10621 | ipw_link_down(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10622 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10623 | } |
| 10624 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10625 | static int ipw_setup_deferred_work(struct ipw_priv *priv) |
| 10626 | { |
| 10627 | int ret = 0; |
| 10628 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10629 | priv->workqueue = create_workqueue(DRV_NAME); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10630 | init_waitqueue_head(&priv->wait_command_queue); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10631 | init_waitqueue_head(&priv->wait_state); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10632 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10633 | INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv); |
| 10634 | INIT_WORK(&priv->associate, ipw_bg_associate, priv); |
| 10635 | INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv); |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 10636 | INIT_WORK(&priv->system_config, ipw_system_config, priv); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10637 | INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv); |
| 10638 | INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv); |
| 10639 | INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv); |
| 10640 | INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv); |
| 10641 | INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10642 | INIT_WORK(&priv->request_scan, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10643 | (void (*)(void *))ipw_request_scan, priv); |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 10644 | INIT_WORK(&priv->request_passive_scan, |
| 10645 | (void (*)(void *))ipw_request_passive_scan, priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10646 | INIT_WORK(&priv->gather_stats, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10647 | (void (*)(void *))ipw_bg_gather_stats, priv); |
| 10648 | INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv); |
| 10649 | INIT_WORK(&priv->roam, ipw_bg_roam, priv); |
| 10650 | INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv); |
| 10651 | INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv); |
| 10652 | INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv); |
| 10653 | INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10654 | priv); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10655 | INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10656 | priv); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10657 | INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off, |
| 10658 | priv); |
| 10659 | INIT_WORK(&priv->merge_networks, |
| 10660 | (void (*)(void *))ipw_merge_adhoc_network, priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10661 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10662 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10663 | INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate, |
| 10664 | priv); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10665 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10666 | |
| 10667 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
| 10668 | ipw_irq_tasklet, (unsigned long)priv); |
| 10669 | |
| 10670 | return ret; |
| 10671 | } |
| 10672 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10673 | static void shim__set_security(struct net_device *dev, |
| 10674 | struct ieee80211_security *sec) |
| 10675 | { |
| 10676 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 10677 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10678 | for (i = 0; i < 4; i++) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10679 | if (sec->flags & (1 << i)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10680 | priv->ieee->sec.encode_alg[i] = sec->encode_alg[i]; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10681 | priv->ieee->sec.key_sizes[i] = sec->key_sizes[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10682 | if (sec->key_sizes[i] == 0) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10683 | priv->ieee->sec.flags &= ~(1 << i); |
| 10684 | else { |
| 10685 | memcpy(priv->ieee->sec.keys[i], sec->keys[i], |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10686 | sec->key_sizes[i]); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10687 | priv->ieee->sec.flags |= (1 << i); |
| 10688 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10689 | priv->status |= STATUS_SECURITY_UPDATED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10690 | } else if (sec->level != SEC_LEVEL_1) |
| 10691 | priv->ieee->sec.flags &= ~(1 << i); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10692 | } |
| 10693 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10694 | if (sec->flags & SEC_ACTIVE_KEY) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10695 | if (sec->active_key <= 3) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10696 | priv->ieee->sec.active_key = sec->active_key; |
| 10697 | priv->ieee->sec.flags |= SEC_ACTIVE_KEY; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10698 | } else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10699 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10700 | priv->status |= STATUS_SECURITY_UPDATED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10701 | } else |
| 10702 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10703 | |
| 10704 | if ((sec->flags & SEC_AUTH_MODE) && |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10705 | (priv->ieee->sec.auth_mode != sec->auth_mode)) { |
| 10706 | priv->ieee->sec.auth_mode = sec->auth_mode; |
| 10707 | priv->ieee->sec.flags |= SEC_AUTH_MODE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10708 | if (sec->auth_mode == WLAN_AUTH_SHARED_KEY) |
| 10709 | priv->capability |= CAP_SHARED_KEY; |
| 10710 | else |
| 10711 | priv->capability &= ~CAP_SHARED_KEY; |
| 10712 | priv->status |= STATUS_SECURITY_UPDATED; |
| 10713 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10714 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10715 | if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) { |
| 10716 | priv->ieee->sec.flags |= SEC_ENABLED; |
| 10717 | priv->ieee->sec.enabled = sec->enabled; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10718 | priv->status |= STATUS_SECURITY_UPDATED; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10719 | if (sec->enabled) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10720 | priv->capability |= CAP_PRIVACY_ON; |
| 10721 | else |
| 10722 | priv->capability &= ~CAP_PRIVACY_ON; |
| 10723 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10724 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10725 | if (sec->flags & SEC_ENCRYPT) |
| 10726 | priv->ieee->sec.encrypt = sec->encrypt; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10727 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10728 | if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) { |
| 10729 | priv->ieee->sec.level = sec->level; |
| 10730 | priv->ieee->sec.flags |= SEC_LEVEL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10731 | priv->status |= STATUS_SECURITY_UPDATED; |
| 10732 | } |
| 10733 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 10734 | if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT)) |
| 10735 | ipw_set_hwcrypto_keys(priv); |
| 10736 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10737 | /* To match current functionality of ipw2100 (which works well w/ |
| 10738 | * various supplicants, we don't force a disassociate if the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10739 | * privacy capability changes ... */ |
| 10740 | #if 0 |
| 10741 | if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) && |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10742 | (((priv->assoc_request.capability & |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10743 | WLAN_CAPABILITY_PRIVACY) && !sec->enabled) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10744 | (!(priv->assoc_request.capability & |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10745 | WLAN_CAPABILITY_PRIVACY) && sec->enabled))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10746 | IPW_DEBUG_ASSOC("Disassociating due to capability " |
| 10747 | "change.\n"); |
| 10748 | ipw_disassociate(priv); |
| 10749 | } |
| 10750 | #endif |
| 10751 | } |
| 10752 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10753 | static int init_supported_rates(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10754 | struct ipw_supported_rates *rates) |
| 10755 | { |
| 10756 | /* TODO: Mask out rates based on priv->rates_mask */ |
| 10757 | |
| 10758 | memset(rates, 0, sizeof(*rates)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10759 | /* configure supported rates */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10760 | switch (priv->ieee->freq_band) { |
| 10761 | case IEEE80211_52GHZ_BAND: |
| 10762 | rates->ieee_mode = IPW_A_MODE; |
| 10763 | rates->purpose = IPW_RATE_CAPABILITIES; |
| 10764 | ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION, |
| 10765 | IEEE80211_OFDM_DEFAULT_RATES_MASK); |
| 10766 | break; |
| 10767 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10768 | default: /* Mixed or 2.4Ghz */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10769 | rates->ieee_mode = IPW_G_MODE; |
| 10770 | rates->purpose = IPW_RATE_CAPABILITIES; |
| 10771 | ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION, |
| 10772 | IEEE80211_CCK_DEFAULT_RATES_MASK); |
| 10773 | if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) { |
| 10774 | ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION, |
| 10775 | IEEE80211_OFDM_DEFAULT_RATES_MASK); |
| 10776 | } |
| 10777 | break; |
| 10778 | } |
| 10779 | |
| 10780 | return 0; |
| 10781 | } |
| 10782 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10783 | static int ipw_config(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10784 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10785 | /* This is only called from ipw_up, which resets/reloads the firmware |
| 10786 | so, we don't need to first disable the card before we configure |
| 10787 | it */ |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 10788 | if (ipw_set_tx_power(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10789 | goto error; |
| 10790 | |
| 10791 | /* initialize adapter address */ |
| 10792 | if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr)) |
| 10793 | goto error; |
| 10794 | |
| 10795 | /* set basic system config settings */ |
| 10796 | init_sys_config(&priv->sys_config); |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10797 | |
| 10798 | /* Support Bluetooth if we have BT h/w on board, and user wants to. |
| 10799 | * Does not support BT priority yet (don't abort or defer our Tx) */ |
| 10800 | if (bt_coexist) { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10801 | unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY]; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10802 | |
| 10803 | if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG) |
| 10804 | priv->sys_config.bt_coexistence |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10805 | |= CFG_BT_COEXISTENCE_SIGNAL_CHNL; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10806 | if (bt_caps & EEPROM_SKU_CAP_BT_OOB) |
| 10807 | priv->sys_config.bt_coexistence |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10808 | |= CFG_BT_COEXISTENCE_OOB; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10809 | } |
| 10810 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10811 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 10812 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) { |
| 10813 | priv->sys_config.accept_all_data_frames = 1; |
| 10814 | priv->sys_config.accept_non_directed_frames = 1; |
| 10815 | priv->sys_config.accept_all_mgmt_bcpr = 1; |
| 10816 | priv->sys_config.accept_all_mgmt_frames = 1; |
| 10817 | } |
| 10818 | #endif |
| 10819 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10820 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 10821 | priv->sys_config.answer_broadcast_ssid_probe = 1; |
| 10822 | else |
| 10823 | priv->sys_config.answer_broadcast_ssid_probe = 0; |
| 10824 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10825 | if (ipw_send_system_config(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10826 | goto error; |
| 10827 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10828 | init_supported_rates(priv, &priv->rates); |
| 10829 | if (ipw_send_supported_rates(priv, &priv->rates)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10830 | goto error; |
| 10831 | |
| 10832 | /* Set request-to-send threshold */ |
| 10833 | if (priv->rts_threshold) { |
| 10834 | if (ipw_send_rts_threshold(priv, priv->rts_threshold)) |
| 10835 | goto error; |
| 10836 | } |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10837 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10838 | IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n"); |
| 10839 | ipw_qos_activate(priv, NULL); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10840 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10841 | |
| 10842 | if (ipw_set_random_seed(priv)) |
| 10843 | goto error; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10844 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10845 | /* final state transition to the RUN state */ |
| 10846 | if (ipw_send_host_complete(priv)) |
| 10847 | goto error; |
| 10848 | |
James Ketrenos | e666619 | 2005-08-12 09:17:04 -0500 | [diff] [blame] | 10849 | priv->status |= STATUS_INIT; |
| 10850 | |
| 10851 | ipw_led_init(priv); |
| 10852 | ipw_led_radio_on(priv); |
| 10853 | priv->notif_missed_beacons = 0; |
| 10854 | |
| 10855 | /* Set hardware WEP key if it is configured. */ |
| 10856 | if ((priv->capability & CAP_PRIVACY_ON) && |
| 10857 | (priv->ieee->sec.level == SEC_LEVEL_1) && |
| 10858 | !(priv->ieee->host_encrypt || priv->ieee->host_decrypt)) |
| 10859 | ipw_set_hwcrypto_keys(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10860 | |
| 10861 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10862 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10863 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10864 | return -EIO; |
| 10865 | } |
| 10866 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10867 | /* |
| 10868 | * NOTE: |
| 10869 | * |
| 10870 | * These tables have been tested in conjunction with the |
| 10871 | * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters. |
| 10872 | * |
| 10873 | * Altering this values, using it on other hardware, or in geographies |
| 10874 | * not intended for resale of the above mentioned Intel adapters has |
| 10875 | * not been tested. |
| 10876 | * |
Henrik Brix Andersen | 48a8477 | 2006-02-14 09:09:52 +0800 | [diff] [blame] | 10877 | * Remember to update the table in README.ipw2200 when changing this |
| 10878 | * table. |
| 10879 | * |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10880 | */ |
| 10881 | static const struct ieee80211_geo ipw_geos[] = { |
| 10882 | { /* Restricted */ |
| 10883 | "---", |
| 10884 | .bg_channels = 11, |
| 10885 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10886 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10887 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10888 | {2457, 10}, {2462, 11}}, |
| 10889 | }, |
| 10890 | |
| 10891 | { /* Custom US/Canada */ |
| 10892 | "ZZF", |
| 10893 | .bg_channels = 11, |
| 10894 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10895 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10896 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10897 | {2457, 10}, {2462, 11}}, |
| 10898 | .a_channels = 8, |
| 10899 | .a = {{5180, 36}, |
| 10900 | {5200, 40}, |
| 10901 | {5220, 44}, |
| 10902 | {5240, 48}, |
| 10903 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10904 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10905 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10906 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10907 | }, |
| 10908 | |
| 10909 | { /* Rest of World */ |
| 10910 | "ZZD", |
| 10911 | .bg_channels = 13, |
| 10912 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10913 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10914 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10915 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 10916 | {2472, 13}}, |
| 10917 | }, |
| 10918 | |
| 10919 | { /* Custom USA & Europe & High */ |
| 10920 | "ZZA", |
| 10921 | .bg_channels = 11, |
| 10922 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10923 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10924 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10925 | {2457, 10}, {2462, 11}}, |
| 10926 | .a_channels = 13, |
| 10927 | .a = {{5180, 36}, |
| 10928 | {5200, 40}, |
| 10929 | {5220, 44}, |
| 10930 | {5240, 48}, |
| 10931 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10932 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10933 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10934 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10935 | {5745, 149}, |
| 10936 | {5765, 153}, |
| 10937 | {5785, 157}, |
| 10938 | {5805, 161}, |
| 10939 | {5825, 165}}, |
| 10940 | }, |
| 10941 | |
| 10942 | { /* Custom NA & Europe */ |
| 10943 | "ZZB", |
| 10944 | .bg_channels = 11, |
| 10945 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10946 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10947 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10948 | {2457, 10}, {2462, 11}}, |
| 10949 | .a_channels = 13, |
| 10950 | .a = {{5180, 36}, |
| 10951 | {5200, 40}, |
| 10952 | {5220, 44}, |
| 10953 | {5240, 48}, |
| 10954 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10955 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10956 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10957 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10958 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, |
| 10959 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, |
| 10960 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, |
| 10961 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, |
| 10962 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10963 | }, |
| 10964 | |
| 10965 | { /* Custom Japan */ |
| 10966 | "ZZC", |
| 10967 | .bg_channels = 11, |
| 10968 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10969 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10970 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10971 | {2457, 10}, {2462, 11}}, |
| 10972 | .a_channels = 4, |
| 10973 | .a = {{5170, 34}, {5190, 38}, |
| 10974 | {5210, 42}, {5230, 46}}, |
| 10975 | }, |
| 10976 | |
| 10977 | { /* Custom */ |
| 10978 | "ZZM", |
| 10979 | .bg_channels = 11, |
| 10980 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10981 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10982 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10983 | {2457, 10}, {2462, 11}}, |
| 10984 | }, |
| 10985 | |
| 10986 | { /* Europe */ |
| 10987 | "ZZE", |
| 10988 | .bg_channels = 13, |
| 10989 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10990 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10991 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10992 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 10993 | {2472, 13}}, |
| 10994 | .a_channels = 19, |
| 10995 | .a = {{5180, 36}, |
| 10996 | {5200, 40}, |
| 10997 | {5220, 44}, |
| 10998 | {5240, 48}, |
| 10999 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 11000 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 11001 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 11002 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 11003 | {5500, 100, IEEE80211_CH_PASSIVE_ONLY}, |
| 11004 | {5520, 104, IEEE80211_CH_PASSIVE_ONLY}, |
| 11005 | {5540, 108, IEEE80211_CH_PASSIVE_ONLY}, |
| 11006 | {5560, 112, IEEE80211_CH_PASSIVE_ONLY}, |
| 11007 | {5580, 116, IEEE80211_CH_PASSIVE_ONLY}, |
| 11008 | {5600, 120, IEEE80211_CH_PASSIVE_ONLY}, |
| 11009 | {5620, 124, IEEE80211_CH_PASSIVE_ONLY}, |
| 11010 | {5640, 128, IEEE80211_CH_PASSIVE_ONLY}, |
| 11011 | {5660, 132, IEEE80211_CH_PASSIVE_ONLY}, |
| 11012 | {5680, 136, IEEE80211_CH_PASSIVE_ONLY}, |
| 11013 | {5700, 140, IEEE80211_CH_PASSIVE_ONLY}}, |
| 11014 | }, |
| 11015 | |
| 11016 | { /* Custom Japan */ |
| 11017 | "ZZJ", |
| 11018 | .bg_channels = 14, |
| 11019 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11020 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11021 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11022 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 11023 | {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}}, |
| 11024 | .a_channels = 4, |
| 11025 | .a = {{5170, 34}, {5190, 38}, |
| 11026 | {5210, 42}, {5230, 46}}, |
| 11027 | }, |
| 11028 | |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 11029 | { /* Rest of World */ |
| 11030 | "ZZR", |
| 11031 | .bg_channels = 14, |
| 11032 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11033 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11034 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11035 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 11036 | {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY | |
| 11037 | IEEE80211_CH_PASSIVE_ONLY}}, |
| 11038 | }, |
| 11039 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11040 | { /* High Band */ |
| 11041 | "ZZH", |
| 11042 | .bg_channels = 13, |
| 11043 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11044 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11045 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11046 | {2457, 10}, {2462, 11}, |
| 11047 | {2467, 12, IEEE80211_CH_PASSIVE_ONLY}, |
| 11048 | {2472, 13, IEEE80211_CH_PASSIVE_ONLY}}, |
| 11049 | .a_channels = 4, |
| 11050 | .a = {{5745, 149}, {5765, 153}, |
| 11051 | {5785, 157}, {5805, 161}}, |
| 11052 | }, |
| 11053 | |
| 11054 | { /* Custom Europe */ |
| 11055 | "ZZG", |
| 11056 | .bg_channels = 13, |
| 11057 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11058 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11059 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11060 | {2457, 10}, {2462, 11}, |
| 11061 | {2467, 12}, {2472, 13}}, |
| 11062 | .a_channels = 4, |
| 11063 | .a = {{5180, 36}, {5200, 40}, |
| 11064 | {5220, 44}, {5240, 48}}, |
| 11065 | }, |
| 11066 | |
| 11067 | { /* Europe */ |
| 11068 | "ZZK", |
| 11069 | .bg_channels = 13, |
| 11070 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11071 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11072 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11073 | {2457, 10}, {2462, 11}, |
| 11074 | {2467, 12, IEEE80211_CH_PASSIVE_ONLY}, |
| 11075 | {2472, 13, IEEE80211_CH_PASSIVE_ONLY}}, |
| 11076 | .a_channels = 24, |
| 11077 | .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY}, |
| 11078 | {5200, 40, IEEE80211_CH_PASSIVE_ONLY}, |
| 11079 | {5220, 44, IEEE80211_CH_PASSIVE_ONLY}, |
| 11080 | {5240, 48, IEEE80211_CH_PASSIVE_ONLY}, |
| 11081 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 11082 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 11083 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 11084 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 11085 | {5500, 100, IEEE80211_CH_PASSIVE_ONLY}, |
| 11086 | {5520, 104, IEEE80211_CH_PASSIVE_ONLY}, |
| 11087 | {5540, 108, IEEE80211_CH_PASSIVE_ONLY}, |
| 11088 | {5560, 112, IEEE80211_CH_PASSIVE_ONLY}, |
| 11089 | {5580, 116, IEEE80211_CH_PASSIVE_ONLY}, |
| 11090 | {5600, 120, IEEE80211_CH_PASSIVE_ONLY}, |
| 11091 | {5620, 124, IEEE80211_CH_PASSIVE_ONLY}, |
| 11092 | {5640, 128, IEEE80211_CH_PASSIVE_ONLY}, |
| 11093 | {5660, 132, IEEE80211_CH_PASSIVE_ONLY}, |
| 11094 | {5680, 136, IEEE80211_CH_PASSIVE_ONLY}, |
| 11095 | {5700, 140, IEEE80211_CH_PASSIVE_ONLY}, |
| 11096 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, |
| 11097 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, |
| 11098 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, |
| 11099 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, |
| 11100 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, |
| 11101 | }, |
| 11102 | |
| 11103 | { /* Europe */ |
| 11104 | "ZZL", |
| 11105 | .bg_channels = 11, |
| 11106 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11107 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11108 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11109 | {2457, 10}, {2462, 11}}, |
| 11110 | .a_channels = 13, |
| 11111 | .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY}, |
| 11112 | {5200, 40, IEEE80211_CH_PASSIVE_ONLY}, |
| 11113 | {5220, 44, IEEE80211_CH_PASSIVE_ONLY}, |
| 11114 | {5240, 48, IEEE80211_CH_PASSIVE_ONLY}, |
| 11115 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 11116 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 11117 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 11118 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 11119 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, |
| 11120 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, |
| 11121 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, |
| 11122 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, |
| 11123 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, |
| 11124 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11125 | }; |
| 11126 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11127 | #define MAX_HW_RESTARTS 5 |
| 11128 | static int ipw_up(struct ipw_priv *priv) |
| 11129 | { |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11130 | int rc, i, j; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11131 | |
| 11132 | if (priv->status & STATUS_EXIT_PENDING) |
| 11133 | return -EIO; |
| 11134 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11135 | if (cmdlog && !priv->cmdlog) { |
| 11136 | priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog, |
| 11137 | GFP_KERNEL); |
| 11138 | if (priv->cmdlog == NULL) { |
| 11139 | IPW_ERROR("Error allocating %d command log entries.\n", |
| 11140 | cmdlog); |
Zhu Yi | d0b526b | 2006-04-13 17:19:50 +0800 | [diff] [blame] | 11141 | return -ENOMEM; |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11142 | } else { |
| 11143 | memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog); |
| 11144 | priv->cmdlog_len = cmdlog; |
| 11145 | } |
| 11146 | } |
| 11147 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11148 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11149 | /* Load the microcode, firmware, and eeprom. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11150 | * Also start the clocks. */ |
| 11151 | rc = ipw_load(priv); |
| 11152 | if (rc) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 11153 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11154 | return rc; |
| 11155 | } |
| 11156 | |
| 11157 | ipw_init_ordinals(priv); |
| 11158 | if (!(priv->config & CFG_CUSTOM_MAC)) |
| 11159 | eeprom_parse_mac(priv, priv->mac_addr); |
| 11160 | memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN); |
| 11161 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11162 | for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) { |
| 11163 | if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE], |
| 11164 | ipw_geos[j].name, 3)) |
| 11165 | break; |
| 11166 | } |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 11167 | if (j == ARRAY_SIZE(ipw_geos)) { |
| 11168 | IPW_WARNING("SKU [%c%c%c] not recognized.\n", |
| 11169 | priv->eeprom[EEPROM_COUNTRY_CODE + 0], |
| 11170 | priv->eeprom[EEPROM_COUNTRY_CODE + 1], |
| 11171 | priv->eeprom[EEPROM_COUNTRY_CODE + 2]); |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11172 | j = 0; |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 11173 | } |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 11174 | if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) { |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11175 | IPW_WARNING("Could not set geography."); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11176 | return 0; |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11177 | } |
| 11178 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11179 | if (priv->status & STATUS_RF_KILL_SW) { |
| 11180 | IPW_WARNING("Radio disabled by module parameter.\n"); |
| 11181 | return 0; |
| 11182 | } else if (rf_kill_active(priv)) { |
| 11183 | IPW_WARNING("Radio Frequency Kill Switch is On:\n" |
| 11184 | "Kill switch must be turned off for " |
| 11185 | "wireless networking to work.\n"); |
| 11186 | queue_delayed_work(priv->workqueue, &priv->rf_kill, |
| 11187 | 2 * HZ); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11188 | return 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11189 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11190 | |
| 11191 | rc = ipw_config(priv); |
| 11192 | if (!rc) { |
| 11193 | IPW_DEBUG_INFO("Configured device on count %i\n", i); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11194 | |
James Ketrenos | e666619 | 2005-08-12 09:17:04 -0500 | [diff] [blame] | 11195 | /* If configure to try and auto-associate, kick |
| 11196 | * off a scan. */ |
| 11197 | queue_work(priv->workqueue, &priv->request_scan); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11198 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11199 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11200 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11201 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11202 | IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11203 | IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n", |
| 11204 | i, MAX_HW_RESTARTS); |
| 11205 | |
| 11206 | /* We had an error bringing up the hardware, so take it |
| 11207 | * all the way back down so we can try again */ |
| 11208 | ipw_down(priv); |
| 11209 | } |
| 11210 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11211 | /* tried to restart and config the device for as long as our |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11212 | * patience could withstand */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11213 | IPW_ERROR("Unable to initialize device after %d attempts.\n", i); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11214 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11215 | return -EIO; |
| 11216 | } |
| 11217 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11218 | static void ipw_bg_up(void *data) |
| 11219 | { |
| 11220 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11221 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11222 | ipw_up(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11223 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11224 | } |
| 11225 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11226 | static void ipw_deinit(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11227 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11228 | int i; |
| 11229 | |
| 11230 | if (priv->status & STATUS_SCANNING) { |
| 11231 | IPW_DEBUG_INFO("Aborting scan during shutdown.\n"); |
| 11232 | ipw_abort_scan(priv); |
| 11233 | } |
| 11234 | |
| 11235 | if (priv->status & STATUS_ASSOCIATED) { |
| 11236 | IPW_DEBUG_INFO("Disassociating during shutdown.\n"); |
| 11237 | ipw_disassociate(priv); |
| 11238 | } |
| 11239 | |
| 11240 | ipw_led_shutdown(priv); |
| 11241 | |
| 11242 | /* Wait up to 1s for status to change to not scanning and not |
| 11243 | * associated (disassociation can take a while for a ful 802.11 |
| 11244 | * exchange */ |
| 11245 | for (i = 1000; i && (priv->status & |
| 11246 | (STATUS_DISASSOCIATING | |
| 11247 | STATUS_ASSOCIATED | STATUS_SCANNING)); i--) |
| 11248 | udelay(10); |
| 11249 | |
| 11250 | if (priv->status & (STATUS_DISASSOCIATING | |
| 11251 | STATUS_ASSOCIATED | STATUS_SCANNING)) |
| 11252 | IPW_DEBUG_INFO("Still associated or scanning...\n"); |
| 11253 | else |
| 11254 | IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i); |
| 11255 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11256 | /* Attempt to disable the card */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11257 | ipw_send_card_disable(priv, 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11258 | |
| 11259 | priv->status &= ~STATUS_INIT; |
| 11260 | } |
| 11261 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11262 | static void ipw_down(struct ipw_priv *priv) |
| 11263 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11264 | int exit_pending = priv->status & STATUS_EXIT_PENDING; |
| 11265 | |
| 11266 | priv->status |= STATUS_EXIT_PENDING; |
| 11267 | |
| 11268 | if (ipw_is_init(priv)) |
| 11269 | ipw_deinit(priv); |
| 11270 | |
| 11271 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 11272 | * exiting the module */ |
| 11273 | if (!exit_pending) |
| 11274 | priv->status &= ~STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11275 | |
| 11276 | /* tell the device to stop sending interrupts */ |
| 11277 | ipw_disable_interrupts(priv); |
| 11278 | |
| 11279 | /* Clear all bits but the RF Kill */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11280 | priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11281 | netif_carrier_off(priv->net_dev); |
| 11282 | netif_stop_queue(priv->net_dev); |
| 11283 | |
| 11284 | ipw_stop_nic(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11285 | |
| 11286 | ipw_led_radio_off(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11287 | } |
| 11288 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11289 | static void ipw_bg_down(void *data) |
| 11290 | { |
| 11291 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11292 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11293 | ipw_down(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11294 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11295 | } |
| 11296 | |
| 11297 | /* Called by register_netdev() */ |
| 11298 | static int ipw_net_init(struct net_device *dev) |
| 11299 | { |
| 11300 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11301 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11302 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11303 | if (ipw_up(priv)) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11304 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11305 | return -EIO; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11306 | } |
| 11307 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11308 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11309 | return 0; |
| 11310 | } |
| 11311 | |
| 11312 | /* PCI driver stuff */ |
| 11313 | static struct pci_device_id card_ids[] = { |
| 11314 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0}, |
| 11315 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0}, |
| 11316 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0}, |
| 11317 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0}, |
| 11318 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0}, |
| 11319 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0}, |
| 11320 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0}, |
| 11321 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0}, |
| 11322 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0}, |
| 11323 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0}, |
| 11324 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0}, |
| 11325 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0}, |
| 11326 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0}, |
| 11327 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0}, |
| 11328 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0}, |
| 11329 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0}, |
| 11330 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0}, |
| 11331 | {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11332 | {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11333 | {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11334 | {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */ |
| 11335 | {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11336 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11337 | /* required last entry */ |
| 11338 | {0,} |
| 11339 | }; |
| 11340 | |
| 11341 | MODULE_DEVICE_TABLE(pci, card_ids); |
| 11342 | |
| 11343 | static struct attribute *ipw_sysfs_entries[] = { |
| 11344 | &dev_attr_rf_kill.attr, |
| 11345 | &dev_attr_direct_dword.attr, |
| 11346 | &dev_attr_indirect_byte.attr, |
| 11347 | &dev_attr_indirect_dword.attr, |
| 11348 | &dev_attr_mem_gpio_reg.attr, |
| 11349 | &dev_attr_command_event_reg.attr, |
| 11350 | &dev_attr_nic_type.attr, |
| 11351 | &dev_attr_status.attr, |
| 11352 | &dev_attr_cfg.attr, |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 11353 | &dev_attr_error.attr, |
| 11354 | &dev_attr_event_log.attr, |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11355 | &dev_attr_cmd_log.attr, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11356 | &dev_attr_eeprom_delay.attr, |
| 11357 | &dev_attr_ucode_version.attr, |
| 11358 | &dev_attr_rtc.attr, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11359 | &dev_attr_scan_age.attr, |
| 11360 | &dev_attr_led.attr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11361 | &dev_attr_speed_scan.attr, |
| 11362 | &dev_attr_net_stats.attr, |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11363 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11364 | &dev_attr_rtap_iface.attr, |
| 11365 | &dev_attr_rtap_filter.attr, |
| 11366 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11367 | NULL |
| 11368 | }; |
| 11369 | |
| 11370 | static struct attribute_group ipw_attribute_group = { |
| 11371 | .name = NULL, /* put in device directory */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11372 | .attrs = ipw_sysfs_entries, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11373 | }; |
| 11374 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11375 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11376 | static int ipw_prom_open(struct net_device *dev) |
| 11377 | { |
| 11378 | struct ipw_prom_priv *prom_priv = ieee80211_priv(dev); |
| 11379 | struct ipw_priv *priv = prom_priv->priv; |
| 11380 | |
| 11381 | IPW_DEBUG_INFO("prom dev->open\n"); |
| 11382 | netif_carrier_off(dev); |
| 11383 | netif_stop_queue(dev); |
| 11384 | |
| 11385 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
| 11386 | priv->sys_config.accept_all_data_frames = 1; |
| 11387 | priv->sys_config.accept_non_directed_frames = 1; |
| 11388 | priv->sys_config.accept_all_mgmt_bcpr = 1; |
| 11389 | priv->sys_config.accept_all_mgmt_frames = 1; |
| 11390 | |
| 11391 | ipw_send_system_config(priv); |
| 11392 | } |
| 11393 | |
| 11394 | return 0; |
| 11395 | } |
| 11396 | |
| 11397 | static int ipw_prom_stop(struct net_device *dev) |
| 11398 | { |
| 11399 | struct ipw_prom_priv *prom_priv = ieee80211_priv(dev); |
| 11400 | struct ipw_priv *priv = prom_priv->priv; |
| 11401 | |
| 11402 | IPW_DEBUG_INFO("prom dev->stop\n"); |
| 11403 | |
| 11404 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
| 11405 | priv->sys_config.accept_all_data_frames = 0; |
| 11406 | priv->sys_config.accept_non_directed_frames = 0; |
| 11407 | priv->sys_config.accept_all_mgmt_bcpr = 0; |
| 11408 | priv->sys_config.accept_all_mgmt_frames = 0; |
| 11409 | |
| 11410 | ipw_send_system_config(priv); |
| 11411 | } |
| 11412 | |
| 11413 | return 0; |
| 11414 | } |
| 11415 | |
| 11416 | static int ipw_prom_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 11417 | { |
| 11418 | IPW_DEBUG_INFO("prom dev->xmit\n"); |
| 11419 | netif_stop_queue(dev); |
| 11420 | return -EOPNOTSUPP; |
| 11421 | } |
| 11422 | |
| 11423 | static struct net_device_stats *ipw_prom_get_stats(struct net_device *dev) |
| 11424 | { |
| 11425 | struct ipw_prom_priv *prom_priv = ieee80211_priv(dev); |
| 11426 | return &prom_priv->ieee->stats; |
| 11427 | } |
| 11428 | |
| 11429 | static int ipw_prom_alloc(struct ipw_priv *priv) |
| 11430 | { |
| 11431 | int rc = 0; |
| 11432 | |
| 11433 | if (priv->prom_net_dev) |
| 11434 | return -EPERM; |
| 11435 | |
| 11436 | priv->prom_net_dev = alloc_ieee80211(sizeof(struct ipw_prom_priv)); |
| 11437 | if (priv->prom_net_dev == NULL) |
| 11438 | return -ENOMEM; |
| 11439 | |
| 11440 | priv->prom_priv = ieee80211_priv(priv->prom_net_dev); |
| 11441 | priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev); |
| 11442 | priv->prom_priv->priv = priv; |
| 11443 | |
| 11444 | strcpy(priv->prom_net_dev->name, "rtap%d"); |
| 11445 | |
| 11446 | priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 11447 | priv->prom_net_dev->open = ipw_prom_open; |
| 11448 | priv->prom_net_dev->stop = ipw_prom_stop; |
| 11449 | priv->prom_net_dev->get_stats = ipw_prom_get_stats; |
| 11450 | priv->prom_net_dev->hard_start_xmit = ipw_prom_hard_start_xmit; |
| 11451 | |
| 11452 | priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR; |
| 11453 | |
| 11454 | rc = register_netdev(priv->prom_net_dev); |
| 11455 | if (rc) { |
| 11456 | free_ieee80211(priv->prom_net_dev); |
| 11457 | priv->prom_net_dev = NULL; |
| 11458 | return rc; |
| 11459 | } |
| 11460 | |
| 11461 | return 0; |
| 11462 | } |
| 11463 | |
| 11464 | static void ipw_prom_free(struct ipw_priv *priv) |
| 11465 | { |
| 11466 | if (!priv->prom_net_dev) |
| 11467 | return; |
| 11468 | |
| 11469 | unregister_netdev(priv->prom_net_dev); |
| 11470 | free_ieee80211(priv->prom_net_dev); |
| 11471 | |
| 11472 | priv->prom_net_dev = NULL; |
| 11473 | } |
| 11474 | |
| 11475 | #endif |
| 11476 | |
| 11477 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11478 | static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11479 | { |
| 11480 | int err = 0; |
| 11481 | struct net_device *net_dev; |
| 11482 | void __iomem *base; |
| 11483 | u32 length, val; |
| 11484 | struct ipw_priv *priv; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11485 | int i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11486 | |
| 11487 | net_dev = alloc_ieee80211(sizeof(struct ipw_priv)); |
| 11488 | if (net_dev == NULL) { |
| 11489 | err = -ENOMEM; |
| 11490 | goto out; |
| 11491 | } |
| 11492 | |
| 11493 | priv = ieee80211_priv(net_dev); |
| 11494 | priv->ieee = netdev_priv(net_dev); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11495 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11496 | priv->net_dev = net_dev; |
| 11497 | priv->pci_dev = pdev; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11498 | ipw_debug_level = debug; |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 11499 | spin_lock_init(&priv->irq_lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11500 | spin_lock_init(&priv->lock); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11501 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) |
| 11502 | INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11503 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11504 | mutex_init(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11505 | if (pci_enable_device(pdev)) { |
| 11506 | err = -ENODEV; |
| 11507 | goto out_free_ieee80211; |
| 11508 | } |
| 11509 | |
| 11510 | pci_set_master(pdev); |
| 11511 | |
Tobias Klauser | 0e08b44 | 2005-06-20 14:28:41 -0700 | [diff] [blame] | 11512 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11513 | if (!err) |
Tobias Klauser | 0e08b44 | 2005-06-20 14:28:41 -0700 | [diff] [blame] | 11514 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11515 | if (err) { |
| 11516 | printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n"); |
| 11517 | goto out_pci_disable_device; |
| 11518 | } |
| 11519 | |
| 11520 | pci_set_drvdata(pdev, priv); |
| 11521 | |
| 11522 | err = pci_request_regions(pdev, DRV_NAME); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11523 | if (err) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11524 | goto out_pci_disable_device; |
| 11525 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11526 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11527 | * PCI Tx retries from interfering with C3 CPU state */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11528 | pci_read_config_dword(pdev, 0x40, &val); |
| 11529 | if ((val & 0x0000ff00) != 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11530 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11531 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11532 | length = pci_resource_len(pdev, 0); |
| 11533 | priv->hw_len = length; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11534 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11535 | base = ioremap_nocache(pci_resource_start(pdev, 0), length); |
| 11536 | if (!base) { |
| 11537 | err = -ENODEV; |
| 11538 | goto out_pci_release_regions; |
| 11539 | } |
| 11540 | |
| 11541 | priv->hw_base = base; |
| 11542 | IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length); |
| 11543 | IPW_DEBUG_INFO("pci_resource_base = %p\n", base); |
| 11544 | |
| 11545 | err = ipw_setup_deferred_work(priv); |
| 11546 | if (err) { |
| 11547 | IPW_ERROR("Unable to setup deferred work\n"); |
| 11548 | goto out_iounmap; |
| 11549 | } |
| 11550 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11551 | ipw_sw_reset(priv, 1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11552 | |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 11553 | err = request_irq(pdev->irq, ipw_isr, IRQF_SHARED, DRV_NAME, priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11554 | if (err) { |
| 11555 | IPW_ERROR("Error allocating IRQ %d\n", pdev->irq); |
| 11556 | goto out_destroy_workqueue; |
| 11557 | } |
| 11558 | |
| 11559 | SET_MODULE_OWNER(net_dev); |
| 11560 | SET_NETDEV_DEV(net_dev, &pdev->dev); |
| 11561 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11562 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11563 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11564 | priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit; |
| 11565 | priv->ieee->set_security = shim__set_security; |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 11566 | priv->ieee->is_queue_full = ipw_net_is_queue_full; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11567 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 11568 | #ifdef CONFIG_IPW2200_QOS |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 11569 | priv->ieee->is_qos_active = ipw_is_qos_active; |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 11570 | priv->ieee->handle_probe_response = ipw_handle_beacon; |
| 11571 | priv->ieee->handle_beacon = ipw_handle_probe_response; |
| 11572 | priv->ieee->handle_assoc_response = ipw_handle_assoc_response; |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 11573 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11574 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11575 | priv->ieee->perfect_rssi = -20; |
| 11576 | priv->ieee->worst_rssi = -85; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11577 | |
| 11578 | net_dev->open = ipw_net_open; |
| 11579 | net_dev->stop = ipw_net_stop; |
| 11580 | net_dev->init = ipw_net_init; |
| 11581 | net_dev->get_stats = ipw_net_get_stats; |
| 11582 | net_dev->set_multicast_list = ipw_net_set_multicast_list; |
| 11583 | net_dev->set_mac_address = ipw_net_set_mac_address; |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 11584 | priv->wireless_data.spy_data = &priv->ieee->spy_data; |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 11585 | net_dev->wireless_data = &priv->wireless_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11586 | net_dev->wireless_handlers = &ipw_wx_handler_def; |
| 11587 | net_dev->ethtool_ops = &ipw_ethtool_ops; |
| 11588 | net_dev->irq = pdev->irq; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11589 | net_dev->base_addr = (unsigned long)priv->hw_base; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11590 | net_dev->mem_start = pci_resource_start(pdev, 0); |
| 11591 | net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1; |
| 11592 | |
| 11593 | err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group); |
| 11594 | if (err) { |
| 11595 | IPW_ERROR("failed to create sysfs device attributes\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11596 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11597 | goto out_release_irq; |
| 11598 | } |
| 11599 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11600 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11601 | err = register_netdev(net_dev); |
| 11602 | if (err) { |
| 11603 | IPW_ERROR("failed to register network device\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11604 | goto out_remove_sysfs; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11605 | } |
Henrik Brix Andersen | 48a8477 | 2006-02-14 09:09:52 +0800 | [diff] [blame] | 11606 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11607 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11608 | if (rtap_iface) { |
| 11609 | err = ipw_prom_alloc(priv); |
| 11610 | if (err) { |
| 11611 | IPW_ERROR("Failed to register promiscuous network " |
| 11612 | "device (error %d).\n", err); |
| 11613 | unregister_netdev(priv->net_dev); |
| 11614 | goto out_remove_sysfs; |
| 11615 | } |
| 11616 | } |
| 11617 | #endif |
| 11618 | |
Henrik Brix Andersen | 48a8477 | 2006-02-14 09:09:52 +0800 | [diff] [blame] | 11619 | printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg " |
| 11620 | "channels, %d 802.11a channels)\n", |
| 11621 | priv->ieee->geo.name, priv->ieee->geo.bg_channels, |
| 11622 | priv->ieee->geo.a_channels); |
| 11623 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11624 | return 0; |
| 11625 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11626 | out_remove_sysfs: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11627 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11628 | out_release_irq: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11629 | free_irq(pdev->irq, priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11630 | out_destroy_workqueue: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11631 | destroy_workqueue(priv->workqueue); |
| 11632 | priv->workqueue = NULL; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11633 | out_iounmap: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11634 | iounmap(priv->hw_base); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11635 | out_pci_release_regions: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11636 | pci_release_regions(pdev); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11637 | out_pci_disable_device: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11638 | pci_disable_device(pdev); |
| 11639 | pci_set_drvdata(pdev, NULL); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11640 | out_free_ieee80211: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11641 | free_ieee80211(priv->net_dev); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11642 | out: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11643 | return err; |
| 11644 | } |
| 11645 | |
| 11646 | static void ipw_pci_remove(struct pci_dev *pdev) |
| 11647 | { |
| 11648 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11649 | struct list_head *p, *q; |
| 11650 | int i; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11651 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11652 | if (!priv) |
| 11653 | return; |
| 11654 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11655 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11656 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11657 | priv->status |= STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11658 | ipw_down(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11659 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
| 11660 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11661 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11662 | |
| 11663 | unregister_netdev(priv->net_dev); |
| 11664 | |
| 11665 | if (priv->rxq) { |
| 11666 | ipw_rx_queue_free(priv, priv->rxq); |
| 11667 | priv->rxq = NULL; |
| 11668 | } |
| 11669 | ipw_tx_queue_free(priv); |
| 11670 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11671 | if (priv->cmdlog) { |
| 11672 | kfree(priv->cmdlog); |
| 11673 | priv->cmdlog = NULL; |
| 11674 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11675 | /* ipw_down will ensure that there is no more pending work |
| 11676 | * in the workqueue's, so we can safely remove them now. */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11677 | cancel_delayed_work(&priv->adhoc_check); |
| 11678 | cancel_delayed_work(&priv->gather_stats); |
| 11679 | cancel_delayed_work(&priv->request_scan); |
| 11680 | cancel_delayed_work(&priv->rf_kill); |
| 11681 | cancel_delayed_work(&priv->scan_check); |
| 11682 | destroy_workqueue(priv->workqueue); |
| 11683 | priv->workqueue = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11684 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11685 | /* Free MAC hash list for ADHOC */ |
| 11686 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) { |
| 11687 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11688 | list_del(p); |
Zhu Yi | 489f445 | 2006-01-24 16:37:41 +0800 | [diff] [blame] | 11689 | kfree(list_entry(p, struct ipw_ibss_seq, list)); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11690 | } |
| 11691 | } |
| 11692 | |
Jesper Juhl | 8f76078 | 2006-06-27 02:55:06 -0700 | [diff] [blame] | 11693 | kfree(priv->error); |
| 11694 | priv->error = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11695 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11696 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11697 | ipw_prom_free(priv); |
| 11698 | #endif |
| 11699 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11700 | free_irq(pdev->irq, priv); |
| 11701 | iounmap(priv->hw_base); |
| 11702 | pci_release_regions(pdev); |
| 11703 | pci_disable_device(pdev); |
| 11704 | pci_set_drvdata(pdev, NULL); |
| 11705 | free_ieee80211(priv->net_dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11706 | free_firmware(); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11707 | } |
| 11708 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11709 | #ifdef CONFIG_PM |
Pavel Machek | 583a4e8 | 2005-09-03 15:56:58 -0700 | [diff] [blame] | 11710 | static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11711 | { |
| 11712 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 11713 | struct net_device *dev = priv->net_dev; |
| 11714 | |
| 11715 | printk(KERN_INFO "%s: Going into suspend...\n", dev->name); |
| 11716 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11717 | /* Take down the device; powers it off, etc. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11718 | ipw_down(priv); |
| 11719 | |
| 11720 | /* Remove the PRESENT state of the device */ |
| 11721 | netif_device_detach(dev); |
| 11722 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11723 | pci_save_state(pdev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11724 | pci_disable_device(pdev); |
Pavel Machek | 583a4e8 | 2005-09-03 15:56:58 -0700 | [diff] [blame] | 11725 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11726 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11727 | return 0; |
| 11728 | } |
| 11729 | |
| 11730 | static int ipw_pci_resume(struct pci_dev *pdev) |
| 11731 | { |
| 11732 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 11733 | struct net_device *dev = priv->net_dev; |
| 11734 | u32 val; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11735 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11736 | printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name); |
| 11737 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 11738 | pci_set_power_state(pdev, PCI_D0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11739 | pci_enable_device(pdev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11740 | pci_restore_state(pdev); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 11741 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11742 | /* |
| 11743 | * Suspend/Resume resets the PCI configuration space, so we have to |
| 11744 | * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries |
| 11745 | * from interfering with C3 CPU state. pci_restore_state won't help |
| 11746 | * here since it only restores the first 64 bytes pci config header. |
| 11747 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11748 | pci_read_config_dword(pdev, 0x40, &val); |
| 11749 | if ((val & 0x0000ff00) != 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11750 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
| 11751 | |
| 11752 | /* Set the device back into the PRESENT state; this will also wake |
| 11753 | * the queue of needed */ |
| 11754 | netif_device_attach(dev); |
| 11755 | |
| 11756 | /* Bring the device back up */ |
| 11757 | queue_work(priv->workqueue, &priv->up); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11758 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11759 | return 0; |
| 11760 | } |
| 11761 | #endif |
| 11762 | |
Zhu Yi | c8c22c9 | 2006-08-21 11:38:39 +0800 | [diff] [blame] | 11763 | static void ipw_pci_shutdown(struct pci_dev *pdev) |
| 11764 | { |
| 11765 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 11766 | |
| 11767 | /* Take down the device; powers it off, etc. */ |
| 11768 | ipw_down(priv); |
| 11769 | |
| 11770 | pci_disable_device(pdev); |
| 11771 | } |
| 11772 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11773 | /* driver initialization stuff */ |
| 11774 | static struct pci_driver ipw_driver = { |
| 11775 | .name = DRV_NAME, |
| 11776 | .id_table = card_ids, |
| 11777 | .probe = ipw_pci_probe, |
| 11778 | .remove = __devexit_p(ipw_pci_remove), |
| 11779 | #ifdef CONFIG_PM |
| 11780 | .suspend = ipw_pci_suspend, |
| 11781 | .resume = ipw_pci_resume, |
| 11782 | #endif |
Zhu Yi | c8c22c9 | 2006-08-21 11:38:39 +0800 | [diff] [blame] | 11783 | .shutdown = ipw_pci_shutdown, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11784 | }; |
| 11785 | |
| 11786 | static int __init ipw_init(void) |
| 11787 | { |
| 11788 | int ret; |
| 11789 | |
| 11790 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 11791 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
| 11792 | |
| 11793 | ret = pci_module_init(&ipw_driver); |
| 11794 | if (ret) { |
| 11795 | IPW_ERROR("Unable to initialize PCI module\n"); |
| 11796 | return ret; |
| 11797 | } |
| 11798 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11799 | ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11800 | if (ret) { |
| 11801 | IPW_ERROR("Unable to create driver sysfs file\n"); |
| 11802 | pci_unregister_driver(&ipw_driver); |
| 11803 | return ret; |
| 11804 | } |
| 11805 | |
| 11806 | return ret; |
| 11807 | } |
| 11808 | |
| 11809 | static void __exit ipw_exit(void) |
| 11810 | { |
| 11811 | driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level); |
| 11812 | pci_unregister_driver(&ipw_driver); |
| 11813 | } |
| 11814 | |
| 11815 | module_param(disable, int, 0444); |
| 11816 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
| 11817 | |
| 11818 | module_param(associate, int, 0444); |
| 11819 | MODULE_PARM_DESC(associate, "auto associate when scanning (default on)"); |
| 11820 | |
| 11821 | module_param(auto_create, int, 0444); |
| 11822 | MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)"); |
| 11823 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11824 | module_param(led, int, 0444); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11825 | MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11826 | |
Zhu Yi | 3e1555b | 2006-03-06 05:48:37 +0800 | [diff] [blame] | 11827 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11828 | module_param(debug, int, 0444); |
| 11829 | MODULE_PARM_DESC(debug, "debug output mask"); |
Zhu Yi | 3e1555b | 2006-03-06 05:48:37 +0800 | [diff] [blame] | 11830 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11831 | |
| 11832 | module_param(channel, int, 0444); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11833 | MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11834 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11835 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11836 | module_param(rtap_iface, int, 0444); |
| 11837 | MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)"); |
| 11838 | #endif |
| 11839 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 11840 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11841 | module_param(qos_enable, int, 0444); |
| 11842 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11843 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11844 | module_param(qos_burst_enable, int, 0444); |
| 11845 | MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode"); |
| 11846 | |
| 11847 | module_param(qos_no_ack_mask, int, 0444); |
| 11848 | MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack"); |
| 11849 | |
| 11850 | module_param(burst_duration_CCK, int, 0444); |
| 11851 | MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value"); |
| 11852 | |
| 11853 | module_param(burst_duration_OFDM, int, 0444); |
| 11854 | MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value"); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 11855 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11856 | |
| 11857 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11858 | module_param(mode, int, 0444); |
| 11859 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)"); |
| 11860 | #else |
| 11861 | module_param(mode, int, 0444); |
| 11862 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)"); |
| 11863 | #endif |
| 11864 | |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 11865 | module_param(bt_coexist, int, 0444); |
| 11866 | MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)"); |
| 11867 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11868 | module_param(hwcrypto, int, 0444); |
Zhu Yi | bde37d0 | 2006-01-24 16:38:08 +0800 | [diff] [blame] | 11869 | MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11870 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11871 | module_param(cmdlog, int, 0444); |
| 11872 | MODULE_PARM_DESC(cmdlog, |
| 11873 | "allocate a ring buffer for logging firmware commands"); |
| 11874 | |
Zhu Yi | 4bfdb91 | 2006-01-24 16:37:16 +0800 | [diff] [blame] | 11875 | module_param(roaming, int, 0444); |
| 11876 | MODULE_PARM_DESC(roaming, "enable roaming support (default on)"); |
| 11877 | |
Zhu Yi | d2b83e1 | 2006-04-13 17:19:36 +0800 | [diff] [blame] | 11878 | module_param(antenna, int, 0444); |
| 11879 | MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)"); |
| 11880 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11881 | module_exit(ipw_exit); |
| 11882 | module_init(ipw_init); |