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 | 555fd91 | 2006-04-13 17:20:40 +0800 | [diff] [blame] | 73 | #define IPW2200_VERSION "1.1.2" 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 | |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 570 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 571 | static char *ipw_error_desc(u32 val) |
| 572 | { |
| 573 | switch (val) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 574 | case IPW_FW_ERROR_OK: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 575 | return "ERROR_OK"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 576 | case IPW_FW_ERROR_FAIL: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 577 | return "ERROR_FAIL"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 578 | case IPW_FW_ERROR_MEMORY_UNDERFLOW: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 579 | return "MEMORY_UNDERFLOW"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 580 | case IPW_FW_ERROR_MEMORY_OVERFLOW: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 581 | return "MEMORY_OVERFLOW"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 582 | case IPW_FW_ERROR_BAD_PARAM: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 583 | return "BAD_PARAM"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 584 | case IPW_FW_ERROR_BAD_CHECKSUM: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 585 | return "BAD_CHECKSUM"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 586 | case IPW_FW_ERROR_NMI_INTERRUPT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 587 | return "NMI_INTERRUPT"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 588 | case IPW_FW_ERROR_BAD_DATABASE: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 589 | return "BAD_DATABASE"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 590 | case IPW_FW_ERROR_ALLOC_FAIL: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 591 | return "ALLOC_FAIL"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 592 | case IPW_FW_ERROR_DMA_UNDERRUN: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 593 | return "DMA_UNDERRUN"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 594 | case IPW_FW_ERROR_DMA_STATUS: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 595 | return "DMA_STATUS"; |
| 596 | case IPW_FW_ERROR_DINO_ERROR: |
| 597 | return "DINO_ERROR"; |
| 598 | case IPW_FW_ERROR_EEPROM_ERROR: |
| 599 | return "EEPROM_ERROR"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 600 | case IPW_FW_ERROR_SYSASSERT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 601 | return "SYSASSERT"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 602 | case IPW_FW_ERROR_FATAL_ERROR: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 603 | return "FATAL_ERROR"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 604 | default: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 605 | return "UNKNOWN_ERROR"; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 606 | } |
| 607 | } |
| 608 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 609 | static void ipw_dump_error_log(struct ipw_priv *priv, |
| 610 | struct ipw_fw_error *error) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 611 | { |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 612 | u32 i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 613 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 614 | if (!error) { |
| 615 | IPW_ERROR("Error allocating and capturing error log. " |
| 616 | "Nothing to dump.\n"); |
| 617 | return; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 618 | } |
| 619 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 620 | IPW_ERROR("Start IPW Error Log Dump:\n"); |
| 621 | IPW_ERROR("Status: 0x%08X, Config: %08X\n", |
| 622 | error->status, error->config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 623 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 624 | for (i = 0; i < error->elem_len; i++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 625 | 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] | 626 | ipw_error_desc(error->elem[i].desc), |
| 627 | error->elem[i].time, |
| 628 | error->elem[i].blink1, |
| 629 | error->elem[i].blink2, |
| 630 | error->elem[i].link1, |
| 631 | error->elem[i].link2, error->elem[i].data); |
| 632 | for (i = 0; i < error->log_len; i++) |
| 633 | IPW_ERROR("%i\t0x%08x\t%i\n", |
| 634 | error->log[i].time, |
James Ketrenos | 286568a | 2005-08-30 10:34:25 -0500 | [diff] [blame] | 635 | error->log[i].data, error->log[i].event); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 636 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 637 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 638 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 639 | static inline int ipw_is_init(struct ipw_priv *priv) |
| 640 | { |
| 641 | return (priv->status & STATUS_INIT) ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 642 | } |
| 643 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 644 | 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] | 645 | { |
| 646 | u32 addr, field_info, field_len, field_count, total_len; |
| 647 | |
| 648 | IPW_DEBUG_ORD("ordinal = %i\n", ord); |
| 649 | |
| 650 | if (!priv || !val || !len) { |
| 651 | IPW_DEBUG_ORD("Invalid argument\n"); |
| 652 | return -EINVAL; |
| 653 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 654 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 655 | /* verify device ordinal tables have been initialized */ |
| 656 | if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) { |
| 657 | IPW_DEBUG_ORD("Access ordinals before initialization\n"); |
| 658 | return -EINVAL; |
| 659 | } |
| 660 | |
| 661 | switch (IPW_ORD_TABLE_ID_MASK & ord) { |
| 662 | case IPW_ORD_TABLE_0_MASK: |
| 663 | /* |
| 664 | * TABLE 0: Direct access to a table of 32 bit values |
| 665 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 666 | * This is a very simple table with the data directly |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 667 | * read from the table |
| 668 | */ |
| 669 | |
| 670 | /* remove the table id from the ordinal */ |
| 671 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
| 672 | |
| 673 | /* boundary check */ |
| 674 | if (ord > priv->table0_len) { |
| 675 | IPW_DEBUG_ORD("ordinal value (%i) longer then " |
| 676 | "max (%i)\n", ord, priv->table0_len); |
| 677 | return -EINVAL; |
| 678 | } |
| 679 | |
| 680 | /* verify we have enough room to store the value */ |
| 681 | if (*len < sizeof(u32)) { |
| 682 | IPW_DEBUG_ORD("ordinal buffer length too small, " |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 683 | "need %zd\n", sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 684 | return -EINVAL; |
| 685 | } |
| 686 | |
| 687 | IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 688 | ord, priv->table0_addr + (ord << 2)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 689 | |
| 690 | *len = sizeof(u32); |
| 691 | ord <<= 2; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 692 | *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 693 | break; |
| 694 | |
| 695 | case IPW_ORD_TABLE_1_MASK: |
| 696 | /* |
| 697 | * TABLE 1: Indirect access to a table of 32 bit values |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 698 | * |
| 699 | * This is a fairly large table of u32 values each |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 700 | * representing starting addr for the data (which is |
| 701 | * also a u32) |
| 702 | */ |
| 703 | |
| 704 | /* remove the table id from the ordinal */ |
| 705 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 706 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 707 | /* boundary check */ |
| 708 | if (ord > priv->table1_len) { |
| 709 | IPW_DEBUG_ORD("ordinal value too long\n"); |
| 710 | return -EINVAL; |
| 711 | } |
| 712 | |
| 713 | /* verify we have enough room to store the value */ |
| 714 | if (*len < sizeof(u32)) { |
| 715 | IPW_DEBUG_ORD("ordinal buffer length too small, " |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 716 | "need %zd\n", sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 717 | return -EINVAL; |
| 718 | } |
| 719 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 720 | *((u32 *) val) = |
| 721 | ipw_read_reg32(priv, (priv->table1_addr + (ord << 2))); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 722 | *len = sizeof(u32); |
| 723 | break; |
| 724 | |
| 725 | case IPW_ORD_TABLE_2_MASK: |
| 726 | /* |
| 727 | * TABLE 2: Indirect access to a table of variable sized values |
| 728 | * |
| 729 | * This table consist of six values, each containing |
| 730 | * - dword containing the starting offset of the data |
| 731 | * - dword containing the lengh in the first 16bits |
| 732 | * and the count in the second 16bits |
| 733 | */ |
| 734 | |
| 735 | /* remove the table id from the ordinal */ |
| 736 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
| 737 | |
| 738 | /* boundary check */ |
| 739 | if (ord > priv->table2_len) { |
| 740 | IPW_DEBUG_ORD("ordinal value too long\n"); |
| 741 | return -EINVAL; |
| 742 | } |
| 743 | |
| 744 | /* get the address of statistic */ |
| 745 | addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 746 | |
| 747 | /* get the second DW of statistics ; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 748 | * two 16-bit words - first is length, second is count */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 749 | field_info = |
| 750 | ipw_read_reg32(priv, |
| 751 | priv->table2_addr + (ord << 3) + |
| 752 | sizeof(u32)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 753 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 754 | /* get each entry length */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 755 | field_len = *((u16 *) & field_info); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 756 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 757 | /* get number of entries */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 758 | field_count = *(((u16 *) & field_info) + 1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 759 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 760 | /* abort if not enought memory */ |
| 761 | total_len = field_len * field_count; |
| 762 | if (total_len > *len) { |
| 763 | *len = total_len; |
| 764 | return -EINVAL; |
| 765 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 766 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 767 | *len = total_len; |
| 768 | if (!total_len) |
| 769 | return 0; |
| 770 | |
| 771 | IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 772 | "field_info = 0x%08x\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 773 | addr, total_len, field_info); |
| 774 | ipw_read_indirect(priv, addr, val, total_len); |
| 775 | break; |
| 776 | |
| 777 | default: |
| 778 | IPW_DEBUG_ORD("Invalid ordinal!\n"); |
| 779 | return -EINVAL; |
| 780 | |
| 781 | } |
| 782 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 783 | return 0; |
| 784 | } |
| 785 | |
| 786 | static void ipw_init_ordinals(struct ipw_priv *priv) |
| 787 | { |
| 788 | priv->table0_addr = IPW_ORDINALS_TABLE_LOWER; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 789 | priv->table0_len = ipw_read32(priv, priv->table0_addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 790 | |
| 791 | IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n", |
| 792 | priv->table0_addr, priv->table0_len); |
| 793 | |
| 794 | priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1); |
| 795 | priv->table1_len = ipw_read_reg32(priv, priv->table1_addr); |
| 796 | |
| 797 | IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n", |
| 798 | priv->table1_addr, priv->table1_len); |
| 799 | |
| 800 | priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2); |
| 801 | priv->table2_len = ipw_read_reg32(priv, priv->table2_addr); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 802 | priv->table2_len &= 0x0000ffff; /* use first two bytes */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 803 | |
| 804 | IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n", |
| 805 | priv->table2_addr, priv->table2_len); |
| 806 | |
| 807 | } |
| 808 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 809 | static u32 ipw_register_toggle(u32 reg) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 810 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 811 | reg &= ~IPW_START_STANDBY; |
| 812 | if (reg & IPW_GATE_ODMA) |
| 813 | reg &= ~IPW_GATE_ODMA; |
| 814 | if (reg & IPW_GATE_IDMA) |
| 815 | reg &= ~IPW_GATE_IDMA; |
| 816 | if (reg & IPW_GATE_ADMA) |
| 817 | reg &= ~IPW_GATE_ADMA; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 818 | return reg; |
| 819 | } |
| 820 | |
| 821 | /* |
| 822 | * LED behavior: |
| 823 | * - On radio ON, turn on any LEDs that require to be on during start |
| 824 | * - On initialization, start unassociated blink |
| 825 | * - On association, disable unassociated blink |
| 826 | * - On disassociation, start unassociated blink |
| 827 | * - On radio OFF, turn off any LEDs started during radio on |
| 828 | * |
| 829 | */ |
Zhu Yi | ede6111 | 2006-01-24 16:37:10 +0800 | [diff] [blame] | 830 | #define LD_TIME_LINK_ON msecs_to_jiffies(300) |
| 831 | #define LD_TIME_LINK_OFF msecs_to_jiffies(2700) |
| 832 | #define LD_TIME_ACT_ON msecs_to_jiffies(250) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 833 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 834 | static void ipw_led_link_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 835 | { |
| 836 | unsigned long flags; |
| 837 | u32 led; |
| 838 | |
| 839 | /* If configured to not use LEDs, or nic_type is 1, |
| 840 | * then we don't toggle a LINK led */ |
| 841 | if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) |
| 842 | return; |
| 843 | |
| 844 | spin_lock_irqsave(&priv->lock, flags); |
| 845 | |
| 846 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
| 847 | !(priv->status & STATUS_LED_LINK_ON)) { |
| 848 | IPW_DEBUG_LED("Link LED On\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 849 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 850 | led |= priv->led_association_on; |
| 851 | |
| 852 | led = ipw_register_toggle(led); |
| 853 | |
| 854 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 855 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 856 | |
| 857 | priv->status |= STATUS_LED_LINK_ON; |
| 858 | |
| 859 | /* If we aren't associated, schedule turning the LED off */ |
| 860 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 861 | queue_delayed_work(priv->workqueue, |
| 862 | &priv->led_link_off, |
| 863 | LD_TIME_LINK_ON); |
| 864 | } |
| 865 | |
| 866 | spin_unlock_irqrestore(&priv->lock, flags); |
| 867 | } |
| 868 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 869 | static void ipw_bg_led_link_on(void *data) |
| 870 | { |
| 871 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 872 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 873 | ipw_led_link_on(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 874 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 875 | } |
| 876 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 877 | static void ipw_led_link_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 878 | { |
| 879 | unsigned long flags; |
| 880 | u32 led; |
| 881 | |
| 882 | /* If configured not to use LEDs, or nic type is 1, |
| 883 | * then we don't goggle the LINK led. */ |
| 884 | if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) |
| 885 | return; |
| 886 | |
| 887 | spin_lock_irqsave(&priv->lock, flags); |
| 888 | |
| 889 | if (priv->status & STATUS_LED_LINK_ON) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 890 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 891 | led &= priv->led_association_off; |
| 892 | led = ipw_register_toggle(led); |
| 893 | |
| 894 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 895 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 896 | |
| 897 | IPW_DEBUG_LED("Link LED Off\n"); |
| 898 | |
| 899 | priv->status &= ~STATUS_LED_LINK_ON; |
| 900 | |
| 901 | /* If we aren't associated and the radio is on, schedule |
| 902 | * turning the LED on (blink while unassociated) */ |
| 903 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
| 904 | !(priv->status & STATUS_ASSOCIATED)) |
| 905 | queue_delayed_work(priv->workqueue, &priv->led_link_on, |
| 906 | LD_TIME_LINK_OFF); |
| 907 | |
| 908 | } |
| 909 | |
| 910 | spin_unlock_irqrestore(&priv->lock, flags); |
| 911 | } |
| 912 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 913 | static void ipw_bg_led_link_off(void *data) |
| 914 | { |
| 915 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 916 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 917 | ipw_led_link_off(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 918 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 919 | } |
| 920 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 921 | static void __ipw_led_activity_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 922 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 923 | u32 led; |
| 924 | |
| 925 | if (priv->config & CFG_NO_LED) |
| 926 | return; |
| 927 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 928 | if (priv->status & STATUS_RF_KILL_MASK) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 929 | return; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 930 | |
| 931 | if (!(priv->status & STATUS_LED_ACT_ON)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 932 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 933 | led |= priv->led_activity_on; |
| 934 | |
| 935 | led = ipw_register_toggle(led); |
| 936 | |
| 937 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 938 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 939 | |
| 940 | IPW_DEBUG_LED("Activity LED On\n"); |
| 941 | |
| 942 | priv->status |= STATUS_LED_ACT_ON; |
| 943 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 944 | cancel_delayed_work(&priv->led_act_off); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 945 | queue_delayed_work(priv->workqueue, &priv->led_act_off, |
| 946 | LD_TIME_ACT_ON); |
| 947 | } else { |
| 948 | /* Reschedule LED off for full time period */ |
| 949 | cancel_delayed_work(&priv->led_act_off); |
| 950 | queue_delayed_work(priv->workqueue, &priv->led_act_off, |
| 951 | LD_TIME_ACT_ON); |
| 952 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 953 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 954 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 955 | #if 0 |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 956 | void ipw_led_activity_on(struct ipw_priv *priv) |
| 957 | { |
| 958 | unsigned long flags; |
| 959 | spin_lock_irqsave(&priv->lock, flags); |
| 960 | __ipw_led_activity_on(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 961 | spin_unlock_irqrestore(&priv->lock, flags); |
| 962 | } |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 963 | #endif /* 0 */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 964 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 965 | static void ipw_led_activity_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 966 | { |
| 967 | unsigned long flags; |
| 968 | u32 led; |
| 969 | |
| 970 | if (priv->config & CFG_NO_LED) |
| 971 | return; |
| 972 | |
| 973 | spin_lock_irqsave(&priv->lock, flags); |
| 974 | |
| 975 | if (priv->status & STATUS_LED_ACT_ON) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 976 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 977 | led &= priv->led_activity_off; |
| 978 | |
| 979 | led = ipw_register_toggle(led); |
| 980 | |
| 981 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 982 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 983 | |
| 984 | IPW_DEBUG_LED("Activity LED Off\n"); |
| 985 | |
| 986 | priv->status &= ~STATUS_LED_ACT_ON; |
| 987 | } |
| 988 | |
| 989 | spin_unlock_irqrestore(&priv->lock, flags); |
| 990 | } |
| 991 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 992 | static void ipw_bg_led_activity_off(void *data) |
| 993 | { |
| 994 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 995 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 996 | ipw_led_activity_off(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 997 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 998 | } |
| 999 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1000 | static void ipw_led_band_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1001 | { |
| 1002 | unsigned long flags; |
| 1003 | u32 led; |
| 1004 | |
| 1005 | /* Only nic type 1 supports mode LEDs */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 1006 | if (priv->config & CFG_NO_LED || |
| 1007 | priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1008 | return; |
| 1009 | |
| 1010 | spin_lock_irqsave(&priv->lock, flags); |
| 1011 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1012 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1013 | if (priv->assoc_network->mode == IEEE_A) { |
| 1014 | led |= priv->led_ofdm_on; |
| 1015 | led &= priv->led_association_off; |
| 1016 | IPW_DEBUG_LED("Mode LED On: 802.11a\n"); |
| 1017 | } else if (priv->assoc_network->mode == IEEE_G) { |
| 1018 | led |= priv->led_ofdm_on; |
| 1019 | led |= priv->led_association_on; |
| 1020 | IPW_DEBUG_LED("Mode LED On: 802.11g\n"); |
| 1021 | } else { |
| 1022 | led &= priv->led_ofdm_off; |
| 1023 | led |= priv->led_association_on; |
| 1024 | IPW_DEBUG_LED("Mode LED On: 802.11b\n"); |
| 1025 | } |
| 1026 | |
| 1027 | led = ipw_register_toggle(led); |
| 1028 | |
| 1029 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1030 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1031 | |
| 1032 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1033 | } |
| 1034 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1035 | static void ipw_led_band_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1036 | { |
| 1037 | unsigned long flags; |
| 1038 | u32 led; |
| 1039 | |
| 1040 | /* Only nic type 1 supports mode LEDs */ |
| 1041 | if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1) |
| 1042 | return; |
| 1043 | |
| 1044 | spin_lock_irqsave(&priv->lock, flags); |
| 1045 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1046 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1047 | led &= priv->led_ofdm_off; |
| 1048 | led &= priv->led_association_off; |
| 1049 | |
| 1050 | led = ipw_register_toggle(led); |
| 1051 | |
| 1052 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1053 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1054 | |
| 1055 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1056 | } |
| 1057 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1058 | static void ipw_led_radio_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1059 | { |
| 1060 | ipw_led_link_on(priv); |
| 1061 | } |
| 1062 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1063 | static void ipw_led_radio_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1064 | { |
| 1065 | ipw_led_activity_off(priv); |
| 1066 | ipw_led_link_off(priv); |
| 1067 | } |
| 1068 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1069 | static void ipw_led_link_up(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1070 | { |
| 1071 | /* Set the Link Led on for all nic types */ |
| 1072 | ipw_led_link_on(priv); |
| 1073 | } |
| 1074 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1075 | static void ipw_led_link_down(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1076 | { |
| 1077 | ipw_led_activity_off(priv); |
| 1078 | ipw_led_link_off(priv); |
| 1079 | |
| 1080 | if (priv->status & STATUS_RF_KILL_MASK) |
| 1081 | ipw_led_radio_off(priv); |
| 1082 | } |
| 1083 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1084 | static void ipw_led_init(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1085 | { |
| 1086 | priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE]; |
| 1087 | |
| 1088 | /* Set the default PINs for the link and activity leds */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1089 | priv->led_activity_on = IPW_ACTIVITY_LED; |
| 1090 | priv->led_activity_off = ~(IPW_ACTIVITY_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1091 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1092 | priv->led_association_on = IPW_ASSOCIATED_LED; |
| 1093 | priv->led_association_off = ~(IPW_ASSOCIATED_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1094 | |
| 1095 | /* Set the default PINs for the OFDM leds */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1096 | priv->led_ofdm_on = IPW_OFDM_LED; |
| 1097 | priv->led_ofdm_off = ~(IPW_OFDM_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1098 | |
| 1099 | switch (priv->nic_type) { |
| 1100 | case EEPROM_NIC_TYPE_1: |
| 1101 | /* In this NIC type, the LEDs are reversed.... */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1102 | priv->led_activity_on = IPW_ASSOCIATED_LED; |
| 1103 | priv->led_activity_off = ~(IPW_ASSOCIATED_LED); |
| 1104 | priv->led_association_on = IPW_ACTIVITY_LED; |
| 1105 | priv->led_association_off = ~(IPW_ACTIVITY_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1106 | |
| 1107 | if (!(priv->config & CFG_NO_LED)) |
| 1108 | ipw_led_band_on(priv); |
| 1109 | |
| 1110 | /* And we don't blink link LEDs for this nic, so |
| 1111 | * just return here */ |
| 1112 | return; |
| 1113 | |
| 1114 | case EEPROM_NIC_TYPE_3: |
| 1115 | case EEPROM_NIC_TYPE_2: |
| 1116 | case EEPROM_NIC_TYPE_4: |
| 1117 | case EEPROM_NIC_TYPE_0: |
| 1118 | break; |
| 1119 | |
| 1120 | default: |
| 1121 | IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n", |
| 1122 | priv->nic_type); |
| 1123 | priv->nic_type = EEPROM_NIC_TYPE_0; |
| 1124 | break; |
| 1125 | } |
| 1126 | |
| 1127 | if (!(priv->config & CFG_NO_LED)) { |
| 1128 | if (priv->status & STATUS_ASSOCIATED) |
| 1129 | ipw_led_link_on(priv); |
| 1130 | else |
| 1131 | ipw_led_link_off(priv); |
| 1132 | } |
| 1133 | } |
| 1134 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1135 | static void ipw_led_shutdown(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1136 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1137 | ipw_led_activity_off(priv); |
| 1138 | ipw_led_link_off(priv); |
| 1139 | ipw_led_band_off(priv); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1140 | cancel_delayed_work(&priv->led_link_on); |
| 1141 | cancel_delayed_work(&priv->led_link_off); |
| 1142 | cancel_delayed_work(&priv->led_act_off); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1143 | } |
| 1144 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1145 | /* |
| 1146 | * The following adds a new attribute to the sysfs representation |
| 1147 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/) |
| 1148 | * used for controling the debug level. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1149 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1150 | * See the level definitions in ipw for details. |
| 1151 | */ |
| 1152 | static ssize_t show_debug_level(struct device_driver *d, char *buf) |
| 1153 | { |
| 1154 | return sprintf(buf, "0x%08X\n", ipw_debug_level); |
| 1155 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1156 | |
| 1157 | static ssize_t store_debug_level(struct device_driver *d, const char *buf, |
| 1158 | size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1159 | { |
| 1160 | char *p = (char *)buf; |
| 1161 | u32 val; |
| 1162 | |
| 1163 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { |
| 1164 | p++; |
| 1165 | if (p[0] == 'x' || p[0] == 'X') |
| 1166 | p++; |
| 1167 | val = simple_strtoul(p, &p, 16); |
| 1168 | } else |
| 1169 | val = simple_strtoul(p, &p, 10); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1170 | if (p == buf) |
| 1171 | printk(KERN_INFO DRV_NAME |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1172 | ": %s is not in hex or decimal form.\n", buf); |
| 1173 | else |
| 1174 | ipw_debug_level = val; |
| 1175 | |
| 1176 | return strnlen(buf, count); |
| 1177 | } |
| 1178 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1179 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1180 | show_debug_level, store_debug_level); |
| 1181 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1182 | static inline u32 ipw_get_event_log_len(struct ipw_priv *priv) |
| 1183 | { |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 1184 | /* length = 1st dword in log */ |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1185 | return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG)); |
| 1186 | } |
| 1187 | |
| 1188 | static void ipw_capture_event_log(struct ipw_priv *priv, |
| 1189 | u32 log_len, struct ipw_event *log) |
| 1190 | { |
| 1191 | u32 base; |
| 1192 | |
| 1193 | if (log_len) { |
| 1194 | base = ipw_read32(priv, IPW_EVENT_LOG); |
| 1195 | ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32), |
| 1196 | (u8 *) log, sizeof(*log) * log_len); |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv) |
| 1201 | { |
| 1202 | struct ipw_fw_error *error; |
| 1203 | u32 log_len = ipw_get_event_log_len(priv); |
| 1204 | u32 base = ipw_read32(priv, IPW_ERROR_LOG); |
| 1205 | u32 elem_len = ipw_read_reg32(priv, base); |
| 1206 | |
| 1207 | error = kmalloc(sizeof(*error) + |
| 1208 | sizeof(*error->elem) * elem_len + |
| 1209 | sizeof(*error->log) * log_len, GFP_ATOMIC); |
| 1210 | if (!error) { |
| 1211 | IPW_ERROR("Memory allocation for firmware error log " |
| 1212 | "failed.\n"); |
| 1213 | return NULL; |
| 1214 | } |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1215 | error->jiffies = jiffies; |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1216 | error->status = priv->status; |
| 1217 | error->config = priv->config; |
| 1218 | error->elem_len = elem_len; |
| 1219 | error->log_len = log_len; |
| 1220 | error->elem = (struct ipw_error_elem *)error->payload; |
Zhu Yi | 3b26b11 | 2005-11-17 13:58:30 +0800 | [diff] [blame] | 1221 | error->log = (struct ipw_event *)(error->elem + elem_len); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1222 | |
| 1223 | ipw_capture_event_log(priv, log_len, error->log); |
| 1224 | |
| 1225 | if (elem_len) |
| 1226 | ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem, |
| 1227 | sizeof(*error->elem) * elem_len); |
| 1228 | |
| 1229 | return error; |
| 1230 | } |
| 1231 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1232 | static ssize_t show_event_log(struct device *d, |
| 1233 | struct device_attribute *attr, char *buf) |
| 1234 | { |
| 1235 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1236 | u32 log_len = ipw_get_event_log_len(priv); |
| 1237 | struct ipw_event log[log_len]; |
| 1238 | u32 len = 0, i; |
| 1239 | |
| 1240 | ipw_capture_event_log(priv, log_len, log); |
| 1241 | |
| 1242 | len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len); |
| 1243 | for (i = 0; i < log_len; i++) |
| 1244 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1245 | "\n%08X%08X%08X", |
| 1246 | log[i].time, log[i].event, log[i].data); |
| 1247 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1248 | return len; |
| 1249 | } |
| 1250 | |
| 1251 | static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL); |
| 1252 | |
| 1253 | static ssize_t show_error(struct device *d, |
| 1254 | struct device_attribute *attr, char *buf) |
| 1255 | { |
| 1256 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1257 | u32 len = 0, i; |
| 1258 | if (!priv->error) |
| 1259 | return 0; |
| 1260 | len += snprintf(buf + len, PAGE_SIZE - len, |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1261 | "%08lX%08X%08X%08X", |
| 1262 | priv->error->jiffies, |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1263 | priv->error->status, |
| 1264 | priv->error->config, priv->error->elem_len); |
| 1265 | for (i = 0; i < priv->error->elem_len; i++) |
| 1266 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1267 | "\n%08X%08X%08X%08X%08X%08X%08X", |
| 1268 | priv->error->elem[i].time, |
| 1269 | priv->error->elem[i].desc, |
| 1270 | priv->error->elem[i].blink1, |
| 1271 | priv->error->elem[i].blink2, |
| 1272 | priv->error->elem[i].link1, |
| 1273 | priv->error->elem[i].link2, |
| 1274 | priv->error->elem[i].data); |
| 1275 | |
| 1276 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1277 | "\n%08X", priv->error->log_len); |
| 1278 | for (i = 0; i < priv->error->log_len; i++) |
| 1279 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1280 | "\n%08X%08X%08X", |
| 1281 | priv->error->log[i].time, |
| 1282 | priv->error->log[i].event, |
| 1283 | priv->error->log[i].data); |
| 1284 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1285 | return len; |
| 1286 | } |
| 1287 | |
| 1288 | static ssize_t clear_error(struct device *d, |
| 1289 | struct device_attribute *attr, |
| 1290 | const char *buf, size_t count) |
| 1291 | { |
| 1292 | struct ipw_priv *priv = dev_get_drvdata(d); |
Jesper Juhl | 8f76078 | 2006-06-27 02:55:06 -0700 | [diff] [blame^] | 1293 | |
| 1294 | kfree(priv->error); |
| 1295 | priv->error = NULL; |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1296 | return count; |
| 1297 | } |
| 1298 | |
| 1299 | static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error); |
| 1300 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1301 | static ssize_t show_cmd_log(struct device *d, |
| 1302 | struct device_attribute *attr, char *buf) |
| 1303 | { |
| 1304 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1305 | u32 len = 0, i; |
| 1306 | if (!priv->cmdlog) |
| 1307 | return 0; |
| 1308 | for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len; |
| 1309 | (i != priv->cmdlog_pos) && (PAGE_SIZE - len); |
| 1310 | i = (i + 1) % priv->cmdlog_len) { |
| 1311 | len += |
| 1312 | snprintf(buf + len, PAGE_SIZE - len, |
| 1313 | "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies, |
| 1314 | priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd, |
| 1315 | priv->cmdlog[i].cmd.len); |
| 1316 | len += |
| 1317 | snprintk_buf(buf + len, PAGE_SIZE - len, |
| 1318 | (u8 *) priv->cmdlog[i].cmd.param, |
| 1319 | priv->cmdlog[i].cmd.len); |
| 1320 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1321 | } |
| 1322 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1323 | return len; |
| 1324 | } |
| 1325 | |
| 1326 | static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL); |
| 1327 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 1328 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 1329 | static void ipw_prom_free(struct ipw_priv *priv); |
| 1330 | static int ipw_prom_alloc(struct ipw_priv *priv); |
| 1331 | static ssize_t store_rtap_iface(struct device *d, |
| 1332 | struct device_attribute *attr, |
| 1333 | const char *buf, size_t count) |
| 1334 | { |
| 1335 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1336 | int rc = 0; |
| 1337 | |
| 1338 | if (count < 1) |
| 1339 | return -EINVAL; |
| 1340 | |
| 1341 | switch (buf[0]) { |
| 1342 | case '0': |
| 1343 | if (!rtap_iface) |
| 1344 | return count; |
| 1345 | |
| 1346 | if (netif_running(priv->prom_net_dev)) { |
| 1347 | IPW_WARNING("Interface is up. Cannot unregister.\n"); |
| 1348 | return count; |
| 1349 | } |
| 1350 | |
| 1351 | ipw_prom_free(priv); |
| 1352 | rtap_iface = 0; |
| 1353 | break; |
| 1354 | |
| 1355 | case '1': |
| 1356 | if (rtap_iface) |
| 1357 | return count; |
| 1358 | |
| 1359 | rc = ipw_prom_alloc(priv); |
| 1360 | if (!rc) |
| 1361 | rtap_iface = 1; |
| 1362 | break; |
| 1363 | |
| 1364 | default: |
| 1365 | return -EINVAL; |
| 1366 | } |
| 1367 | |
| 1368 | if (rc) { |
| 1369 | IPW_ERROR("Failed to register promiscuous network " |
| 1370 | "device (error %d).\n", rc); |
| 1371 | } |
| 1372 | |
| 1373 | return count; |
| 1374 | } |
| 1375 | |
| 1376 | static ssize_t show_rtap_iface(struct device *d, |
| 1377 | struct device_attribute *attr, |
| 1378 | char *buf) |
| 1379 | { |
| 1380 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1381 | if (rtap_iface) |
| 1382 | return sprintf(buf, "%s", priv->prom_net_dev->name); |
| 1383 | else { |
| 1384 | buf[0] = '-'; |
| 1385 | buf[1] = '1'; |
| 1386 | buf[2] = '\0'; |
| 1387 | return 3; |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface, |
| 1392 | store_rtap_iface); |
| 1393 | |
| 1394 | static ssize_t store_rtap_filter(struct device *d, |
| 1395 | struct device_attribute *attr, |
| 1396 | const char *buf, size_t count) |
| 1397 | { |
| 1398 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1399 | |
| 1400 | if (!priv->prom_priv) { |
| 1401 | IPW_ERROR("Attempting to set filter without " |
| 1402 | "rtap_iface enabled.\n"); |
| 1403 | return -EPERM; |
| 1404 | } |
| 1405 | |
| 1406 | priv->prom_priv->filter = simple_strtol(buf, NULL, 0); |
| 1407 | |
| 1408 | IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n", |
| 1409 | BIT_ARG16(priv->prom_priv->filter)); |
| 1410 | |
| 1411 | return count; |
| 1412 | } |
| 1413 | |
| 1414 | static ssize_t show_rtap_filter(struct device *d, |
| 1415 | struct device_attribute *attr, |
| 1416 | char *buf) |
| 1417 | { |
| 1418 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1419 | return sprintf(buf, "0x%04X", |
| 1420 | priv->prom_priv ? priv->prom_priv->filter : 0); |
| 1421 | } |
| 1422 | |
| 1423 | static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter, |
| 1424 | store_rtap_filter); |
| 1425 | #endif |
| 1426 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1427 | static ssize_t show_scan_age(struct device *d, struct device_attribute *attr, |
| 1428 | char *buf) |
| 1429 | { |
| 1430 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1431 | return sprintf(buf, "%d\n", priv->ieee->scan_age); |
| 1432 | } |
| 1433 | |
| 1434 | static ssize_t store_scan_age(struct device *d, struct device_attribute *attr, |
| 1435 | const char *buf, size_t count) |
| 1436 | { |
| 1437 | struct ipw_priv *priv = dev_get_drvdata(d); |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 1438 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1439 | struct net_device *dev = priv->net_dev; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 1440 | #endif |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1441 | char buffer[] = "00000000"; |
| 1442 | unsigned long len = |
| 1443 | (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1; |
| 1444 | unsigned long val; |
| 1445 | char *p = buffer; |
| 1446 | |
| 1447 | IPW_DEBUG_INFO("enter\n"); |
| 1448 | |
| 1449 | strncpy(buffer, buf, len); |
| 1450 | buffer[len] = 0; |
| 1451 | |
| 1452 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { |
| 1453 | p++; |
| 1454 | if (p[0] == 'x' || p[0] == 'X') |
| 1455 | p++; |
| 1456 | val = simple_strtoul(p, &p, 16); |
| 1457 | } else |
| 1458 | val = simple_strtoul(p, &p, 10); |
| 1459 | if (p == buffer) { |
| 1460 | IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name); |
| 1461 | } else { |
| 1462 | priv->ieee->scan_age = val; |
| 1463 | IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age); |
| 1464 | } |
| 1465 | |
| 1466 | IPW_DEBUG_INFO("exit\n"); |
| 1467 | return len; |
| 1468 | } |
| 1469 | |
| 1470 | static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age); |
| 1471 | |
| 1472 | static ssize_t show_led(struct device *d, struct device_attribute *attr, |
| 1473 | char *buf) |
| 1474 | { |
| 1475 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1476 | return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1); |
| 1477 | } |
| 1478 | |
| 1479 | static ssize_t store_led(struct device *d, struct device_attribute *attr, |
| 1480 | const char *buf, size_t count) |
| 1481 | { |
| 1482 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1483 | |
| 1484 | IPW_DEBUG_INFO("enter\n"); |
| 1485 | |
| 1486 | if (count == 0) |
| 1487 | return 0; |
| 1488 | |
| 1489 | if (*buf == 0) { |
| 1490 | IPW_DEBUG_LED("Disabling LED control.\n"); |
| 1491 | priv->config |= CFG_NO_LED; |
| 1492 | ipw_led_shutdown(priv); |
| 1493 | } else { |
| 1494 | IPW_DEBUG_LED("Enabling LED control.\n"); |
| 1495 | priv->config &= ~CFG_NO_LED; |
| 1496 | ipw_led_init(priv); |
| 1497 | } |
| 1498 | |
| 1499 | IPW_DEBUG_INFO("exit\n"); |
| 1500 | return count; |
| 1501 | } |
| 1502 | |
| 1503 | static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led); |
| 1504 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1505 | static ssize_t show_status(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1506 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1507 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1508 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1509 | return sprintf(buf, "0x%08x\n", (int)p->status); |
| 1510 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1511 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1512 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 1513 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1514 | static ssize_t show_cfg(struct device *d, struct device_attribute *attr, |
| 1515 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1516 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1517 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1518 | return sprintf(buf, "0x%08x\n", (int)p->config); |
| 1519 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1520 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1521 | static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL); |
| 1522 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1523 | static ssize_t show_nic_type(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1524 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1525 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1526 | struct ipw_priv *priv = d->driver_data; |
| 1527 | return sprintf(buf, "TYPE: %d\n", priv->nic_type); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1528 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1529 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1530 | static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL); |
| 1531 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1532 | static ssize_t show_ucode_version(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1533 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1534 | { |
| 1535 | u32 len = sizeof(u32), tmp = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1536 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1537 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1538 | if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1539 | return 0; |
| 1540 | |
| 1541 | return sprintf(buf, "0x%08x\n", tmp); |
| 1542 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1543 | |
| 1544 | 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] | 1545 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1546 | static ssize_t show_rtc(struct device *d, struct device_attribute *attr, |
| 1547 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1548 | { |
| 1549 | u32 len = sizeof(u32), tmp = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1550 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1551 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1552 | if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1553 | return 0; |
| 1554 | |
| 1555 | return sprintf(buf, "0x%08x\n", tmp); |
| 1556 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1557 | |
| 1558 | static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1559 | |
| 1560 | /* |
| 1561 | * Add a device attribute to view/control the delay between eeprom |
| 1562 | * operations. |
| 1563 | */ |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1564 | static ssize_t show_eeprom_delay(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1565 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1566 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1567 | int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1568 | return sprintf(buf, "%i\n", n); |
| 1569 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1570 | static ssize_t store_eeprom_delay(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1571 | struct device_attribute *attr, |
| 1572 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1573 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1574 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1575 | sscanf(buf, "%i", &p->eeprom_delay); |
| 1576 | return strnlen(buf, count); |
| 1577 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1578 | |
| 1579 | static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO, |
| 1580 | show_eeprom_delay, store_eeprom_delay); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1581 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1582 | static ssize_t show_command_event_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1583 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1584 | { |
| 1585 | u32 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1586 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1587 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1588 | reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1589 | return sprintf(buf, "0x%08x\n", reg); |
| 1590 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1591 | static ssize_t store_command_event_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1592 | struct device_attribute *attr, |
| 1593 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1594 | { |
| 1595 | u32 reg; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1596 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1597 | |
| 1598 | sscanf(buf, "%x", ®); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1599 | ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1600 | return strnlen(buf, count); |
| 1601 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1602 | |
| 1603 | static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO, |
| 1604 | show_command_event_reg, store_command_event_reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1605 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1606 | static ssize_t show_mem_gpio_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1607 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1608 | { |
| 1609 | u32 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1610 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1611 | |
| 1612 | reg = ipw_read_reg32(p, 0x301100); |
| 1613 | return sprintf(buf, "0x%08x\n", reg); |
| 1614 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1615 | static ssize_t store_mem_gpio_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1616 | struct device_attribute *attr, |
| 1617 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1618 | { |
| 1619 | u32 reg; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1620 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1621 | |
| 1622 | sscanf(buf, "%x", ®); |
| 1623 | ipw_write_reg32(p, 0x301100, reg); |
| 1624 | return strnlen(buf, count); |
| 1625 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1626 | |
| 1627 | static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO, |
| 1628 | show_mem_gpio_reg, store_mem_gpio_reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1629 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1630 | static ssize_t show_indirect_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1631 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1632 | { |
| 1633 | u32 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1634 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1635 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1636 | if (priv->status & STATUS_INDIRECT_DWORD) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1637 | reg = ipw_read_reg32(priv, priv->indirect_dword); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1638 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1639 | reg = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1640 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1641 | return sprintf(buf, "0x%08x\n", reg); |
| 1642 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1643 | static ssize_t store_indirect_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1644 | struct device_attribute *attr, |
| 1645 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1646 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1647 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1648 | |
| 1649 | sscanf(buf, "%x", &priv->indirect_dword); |
| 1650 | priv->status |= STATUS_INDIRECT_DWORD; |
| 1651 | return strnlen(buf, count); |
| 1652 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1653 | |
| 1654 | static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO, |
| 1655 | show_indirect_dword, store_indirect_dword); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1656 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1657 | static ssize_t show_indirect_byte(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1658 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1659 | { |
| 1660 | u8 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1661 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1662 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1663 | if (priv->status & STATUS_INDIRECT_BYTE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1664 | reg = ipw_read_reg8(priv, priv->indirect_byte); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1665 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1666 | reg = 0; |
| 1667 | |
| 1668 | return sprintf(buf, "0x%02x\n", reg); |
| 1669 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1670 | static ssize_t store_indirect_byte(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1671 | struct device_attribute *attr, |
| 1672 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1673 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1674 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1675 | |
| 1676 | sscanf(buf, "%x", &priv->indirect_byte); |
| 1677 | priv->status |= STATUS_INDIRECT_BYTE; |
| 1678 | return strnlen(buf, count); |
| 1679 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1680 | |
| 1681 | static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1682 | show_indirect_byte, store_indirect_byte); |
| 1683 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1684 | static ssize_t show_direct_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1685 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1686 | { |
| 1687 | u32 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1688 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1689 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1690 | if (priv->status & STATUS_DIRECT_DWORD) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1691 | reg = ipw_read32(priv, priv->direct_dword); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1692 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1693 | reg = 0; |
| 1694 | |
| 1695 | return sprintf(buf, "0x%08x\n", reg); |
| 1696 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1697 | static ssize_t store_direct_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1698 | struct device_attribute *attr, |
| 1699 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1700 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1701 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1702 | |
| 1703 | sscanf(buf, "%x", &priv->direct_dword); |
| 1704 | priv->status |= STATUS_DIRECT_DWORD; |
| 1705 | return strnlen(buf, count); |
| 1706 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1707 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1708 | static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO, |
| 1709 | show_direct_dword, store_direct_dword); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1710 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1711 | static int rf_kill_active(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1712 | { |
| 1713 | if (0 == (ipw_read32(priv, 0x30) & 0x10000)) |
| 1714 | priv->status |= STATUS_RF_KILL_HW; |
| 1715 | else |
| 1716 | priv->status &= ~STATUS_RF_KILL_HW; |
| 1717 | |
| 1718 | return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0; |
| 1719 | } |
| 1720 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1721 | 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] | 1722 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1723 | { |
| 1724 | /* 0 - RF kill not enabled |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1725 | 1 - SW based RF kill active (sysfs) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1726 | 2 - HW based RF kill active |
| 1727 | 3 - Both HW and SW baed RF kill active */ |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1728 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1729 | int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1730 | (rf_kill_active(priv) ? 0x2 : 0x0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1731 | return sprintf(buf, "%i\n", val); |
| 1732 | } |
| 1733 | |
| 1734 | static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio) |
| 1735 | { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1736 | if ((disable_radio ? 1 : 0) == |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 1737 | ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0)) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1738 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1739 | |
| 1740 | IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n", |
| 1741 | disable_radio ? "OFF" : "ON"); |
| 1742 | |
| 1743 | if (disable_radio) { |
| 1744 | priv->status |= STATUS_RF_KILL_SW; |
| 1745 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1746 | if (priv->workqueue) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1747 | cancel_delayed_work(&priv->request_scan); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1748 | queue_work(priv->workqueue, &priv->down); |
| 1749 | } else { |
| 1750 | priv->status &= ~STATUS_RF_KILL_SW; |
| 1751 | if (rf_kill_active(priv)) { |
| 1752 | IPW_DEBUG_RF_KILL("Can not turn radio back on - " |
| 1753 | "disabled by HW switch\n"); |
| 1754 | /* Make sure the RF_KILL check timer is running */ |
| 1755 | cancel_delayed_work(&priv->rf_kill); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1756 | queue_delayed_work(priv->workqueue, &priv->rf_kill, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1757 | 2 * HZ); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1758 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1759 | queue_work(priv->workqueue, &priv->up); |
| 1760 | } |
| 1761 | |
| 1762 | return 1; |
| 1763 | } |
| 1764 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1765 | static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr, |
| 1766 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1767 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1768 | struct ipw_priv *priv = d->driver_data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1769 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1770 | ipw_radio_kill_sw(priv, buf[0] == '1'); |
| 1771 | |
| 1772 | return count; |
| 1773 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1774 | |
| 1775 | 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] | 1776 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1777 | static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr, |
| 1778 | char *buf) |
| 1779 | { |
| 1780 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; |
| 1781 | int pos = 0, len = 0; |
| 1782 | if (priv->config & CFG_SPEED_SCAN) { |
| 1783 | while (priv->speed_scan[pos] != 0) |
| 1784 | len += sprintf(&buf[len], "%d ", |
| 1785 | priv->speed_scan[pos++]); |
| 1786 | return len + sprintf(&buf[len], "\n"); |
| 1787 | } |
| 1788 | |
| 1789 | return sprintf(buf, "0\n"); |
| 1790 | } |
| 1791 | |
| 1792 | static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr, |
| 1793 | const char *buf, size_t count) |
| 1794 | { |
| 1795 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; |
| 1796 | int channel, pos = 0; |
| 1797 | const char *p = buf; |
| 1798 | |
| 1799 | /* list of space separated channels to scan, optionally ending with 0 */ |
| 1800 | while ((channel = simple_strtol(p, NULL, 0))) { |
| 1801 | if (pos == MAX_SPEED_SCAN - 1) { |
| 1802 | priv->speed_scan[pos] = 0; |
| 1803 | break; |
| 1804 | } |
| 1805 | |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 1806 | if (ieee80211_is_valid_channel(priv->ieee, channel)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1807 | priv->speed_scan[pos++] = channel; |
| 1808 | else |
| 1809 | IPW_WARNING("Skipping invalid channel request: %d\n", |
| 1810 | channel); |
| 1811 | p = strchr(p, ' '); |
| 1812 | if (!p) |
| 1813 | break; |
| 1814 | while (*p == ' ' || *p == '\t') |
| 1815 | p++; |
| 1816 | } |
| 1817 | |
| 1818 | if (pos == 0) |
| 1819 | priv->config &= ~CFG_SPEED_SCAN; |
| 1820 | else { |
| 1821 | priv->speed_scan_pos = 0; |
| 1822 | priv->config |= CFG_SPEED_SCAN; |
| 1823 | } |
| 1824 | |
| 1825 | return count; |
| 1826 | } |
| 1827 | |
| 1828 | static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan, |
| 1829 | store_speed_scan); |
| 1830 | |
| 1831 | static ssize_t show_net_stats(struct device *d, struct device_attribute *attr, |
| 1832 | char *buf) |
| 1833 | { |
| 1834 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; |
| 1835 | return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0'); |
| 1836 | } |
| 1837 | |
| 1838 | static ssize_t store_net_stats(struct device *d, struct device_attribute *attr, |
| 1839 | const char *buf, size_t count) |
| 1840 | { |
| 1841 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; |
| 1842 | if (buf[0] == '1') |
| 1843 | priv->config |= CFG_NET_STATS; |
| 1844 | else |
| 1845 | priv->config &= ~CFG_NET_STATS; |
| 1846 | |
| 1847 | return count; |
| 1848 | } |
| 1849 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1850 | static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO, |
| 1851 | show_net_stats, store_net_stats); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1852 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 1853 | static void notify_wx_assoc_event(struct ipw_priv *priv) |
| 1854 | { |
| 1855 | union iwreq_data wrqu; |
| 1856 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 1857 | if (priv->status & STATUS_ASSOCIATED) |
| 1858 | memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN); |
| 1859 | else |
| 1860 | memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); |
| 1861 | wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL); |
| 1862 | } |
| 1863 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1864 | static void ipw_irq_tasklet(struct ipw_priv *priv) |
| 1865 | { |
| 1866 | u32 inta, inta_mask, handled = 0; |
| 1867 | unsigned long flags; |
| 1868 | int rc = 0; |
| 1869 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 1870 | spin_lock_irqsave(&priv->irq_lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1871 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1872 | inta = ipw_read32(priv, IPW_INTA_RW); |
| 1873 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); |
| 1874 | inta &= (IPW_INTA_MASK_ALL & inta_mask); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1875 | |
| 1876 | /* Add any cached INTA values that need to be handled */ |
| 1877 | inta |= priv->isr_inta; |
| 1878 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 1879 | spin_unlock_irqrestore(&priv->irq_lock, flags); |
| 1880 | |
| 1881 | spin_lock_irqsave(&priv->lock, flags); |
| 1882 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1883 | /* handle all the justifications for the interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1884 | if (inta & IPW_INTA_BIT_RX_TRANSFER) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1885 | ipw_rx(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1886 | handled |= IPW_INTA_BIT_RX_TRANSFER; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1887 | } |
| 1888 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1889 | if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1890 | IPW_DEBUG_HC("Command completed.\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1891 | rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1892 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 1893 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1894 | handled |= IPW_INTA_BIT_TX_CMD_QUEUE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1895 | } |
| 1896 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1897 | if (inta & IPW_INTA_BIT_TX_QUEUE_1) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1898 | IPW_DEBUG_TX("TX_QUEUE_1\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1899 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1900 | handled |= IPW_INTA_BIT_TX_QUEUE_1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1901 | } |
| 1902 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1903 | if (inta & IPW_INTA_BIT_TX_QUEUE_2) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1904 | IPW_DEBUG_TX("TX_QUEUE_2\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1905 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1906 | handled |= IPW_INTA_BIT_TX_QUEUE_2; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1907 | } |
| 1908 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1909 | if (inta & IPW_INTA_BIT_TX_QUEUE_3) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1910 | IPW_DEBUG_TX("TX_QUEUE_3\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1911 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1912 | handled |= IPW_INTA_BIT_TX_QUEUE_3; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1913 | } |
| 1914 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1915 | if (inta & IPW_INTA_BIT_TX_QUEUE_4) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1916 | IPW_DEBUG_TX("TX_QUEUE_4\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1917 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1918 | handled |= IPW_INTA_BIT_TX_QUEUE_4; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1919 | } |
| 1920 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1921 | if (inta & IPW_INTA_BIT_STATUS_CHANGE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1922 | IPW_WARNING("STATUS_CHANGE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1923 | handled |= IPW_INTA_BIT_STATUS_CHANGE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1924 | } |
| 1925 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1926 | if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1927 | IPW_WARNING("TX_PERIOD_EXPIRED\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1928 | handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1929 | } |
| 1930 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1931 | if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1932 | IPW_WARNING("HOST_CMD_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1933 | handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1934 | } |
| 1935 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1936 | if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1937 | IPW_WARNING("FW_INITIALIZATION_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1938 | handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1939 | } |
| 1940 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1941 | if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1942 | IPW_WARNING("PHY_OFF_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1943 | handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1944 | } |
| 1945 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1946 | if (inta & IPW_INTA_BIT_RF_KILL_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1947 | IPW_DEBUG_RF_KILL("RF_KILL_DONE\n"); |
| 1948 | priv->status |= STATUS_RF_KILL_HW; |
| 1949 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 1950 | priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1951 | cancel_delayed_work(&priv->request_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1952 | schedule_work(&priv->link_down); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1953 | queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1954 | handled |= IPW_INTA_BIT_RF_KILL_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1955 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1956 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1957 | if (inta & IPW_INTA_BIT_FATAL_ERROR) { |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 1958 | IPW_WARNING("Firmware error detected. Restarting.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1959 | if (priv->error) { |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 1960 | IPW_DEBUG_FW("Sysfs 'error' log already exists.\n"); |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 1961 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1962 | if (ipw_debug_level & IPW_DL_FW_ERRORS) { |
| 1963 | struct ipw_fw_error *error = |
| 1964 | ipw_alloc_error_log(priv); |
| 1965 | ipw_dump_error_log(priv, error); |
Jesper Juhl | 8f76078 | 2006-06-27 02:55:06 -0700 | [diff] [blame^] | 1966 | kfree(error); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1967 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1968 | #endif |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1969 | } else { |
| 1970 | priv->error = ipw_alloc_error_log(priv); |
| 1971 | if (priv->error) |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 1972 | IPW_DEBUG_FW("Sysfs 'error' log captured.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1973 | else |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 1974 | IPW_DEBUG_FW("Error allocating sysfs 'error' " |
| 1975 | "log.\n"); |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 1976 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1977 | if (ipw_debug_level & IPW_DL_FW_ERRORS) |
| 1978 | ipw_dump_error_log(priv, priv->error); |
| 1979 | #endif |
| 1980 | } |
| 1981 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1982 | /* XXX: If hardware encryption is for WPA/WPA2, |
| 1983 | * we have to notify the supplicant. */ |
| 1984 | if (priv->ieee->sec.encrypt) { |
| 1985 | priv->status &= ~STATUS_ASSOCIATED; |
| 1986 | notify_wx_assoc_event(priv); |
| 1987 | } |
| 1988 | |
| 1989 | /* Keep the restart process from trying to send host |
| 1990 | * commands by clearing the INIT status bit */ |
| 1991 | priv->status &= ~STATUS_INIT; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1992 | |
| 1993 | /* Cancel currently queued command. */ |
| 1994 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 1995 | wake_up_interruptible(&priv->wait_command_queue); |
| 1996 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1997 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1998 | handled |= IPW_INTA_BIT_FATAL_ERROR; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1999 | } |
| 2000 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2001 | if (inta & IPW_INTA_BIT_PARITY_ERROR) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2002 | IPW_ERROR("Parity error\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2003 | handled |= IPW_INTA_BIT_PARITY_ERROR; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | if (handled != inta) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2007 | IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2008 | } |
| 2009 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 2010 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2011 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2012 | /* enable all interrupts */ |
| 2013 | ipw_enable_interrupts(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2014 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2015 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2016 | #define IPW_CMD(x) case IPW_CMD_ ## x : return #x |
| 2017 | static char *get_cmd_string(u8 cmd) |
| 2018 | { |
| 2019 | switch (cmd) { |
| 2020 | IPW_CMD(HOST_COMPLETE); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2021 | IPW_CMD(POWER_DOWN); |
| 2022 | IPW_CMD(SYSTEM_CONFIG); |
| 2023 | IPW_CMD(MULTICAST_ADDRESS); |
| 2024 | IPW_CMD(SSID); |
| 2025 | IPW_CMD(ADAPTER_ADDRESS); |
| 2026 | IPW_CMD(PORT_TYPE); |
| 2027 | IPW_CMD(RTS_THRESHOLD); |
| 2028 | IPW_CMD(FRAG_THRESHOLD); |
| 2029 | IPW_CMD(POWER_MODE); |
| 2030 | IPW_CMD(WEP_KEY); |
| 2031 | IPW_CMD(TGI_TX_KEY); |
| 2032 | IPW_CMD(SCAN_REQUEST); |
| 2033 | IPW_CMD(SCAN_REQUEST_EXT); |
| 2034 | IPW_CMD(ASSOCIATE); |
| 2035 | IPW_CMD(SUPPORTED_RATES); |
| 2036 | IPW_CMD(SCAN_ABORT); |
| 2037 | IPW_CMD(TX_FLUSH); |
| 2038 | IPW_CMD(QOS_PARAMETERS); |
| 2039 | IPW_CMD(DINO_CONFIG); |
| 2040 | IPW_CMD(RSN_CAPABILITIES); |
| 2041 | IPW_CMD(RX_KEY); |
| 2042 | IPW_CMD(CARD_DISABLE); |
| 2043 | IPW_CMD(SEED_NUMBER); |
| 2044 | IPW_CMD(TX_POWER); |
| 2045 | IPW_CMD(COUNTRY_INFO); |
| 2046 | IPW_CMD(AIRONET_INFO); |
| 2047 | IPW_CMD(AP_TX_POWER); |
| 2048 | IPW_CMD(CCKM_INFO); |
| 2049 | IPW_CMD(CCX_VER_INFO); |
| 2050 | IPW_CMD(SET_CALIBRATION); |
| 2051 | IPW_CMD(SENSITIVITY_CALIB); |
| 2052 | IPW_CMD(RETRY_LIMIT); |
| 2053 | IPW_CMD(IPW_PRE_POWER_DOWN); |
| 2054 | IPW_CMD(VAP_BEACON_TEMPLATE); |
| 2055 | IPW_CMD(VAP_DTIM_PERIOD); |
| 2056 | IPW_CMD(EXT_SUPPORTED_RATES); |
| 2057 | IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT); |
| 2058 | IPW_CMD(VAP_QUIET_INTERVALS); |
| 2059 | IPW_CMD(VAP_CHANNEL_SWITCH); |
| 2060 | IPW_CMD(VAP_MANDATORY_CHANNELS); |
| 2061 | IPW_CMD(VAP_CELL_PWR_LIMIT); |
| 2062 | IPW_CMD(VAP_CF_PARAM_SET); |
| 2063 | IPW_CMD(VAP_SET_BEACONING_STATE); |
| 2064 | IPW_CMD(MEASUREMENT); |
| 2065 | IPW_CMD(POWER_CAPABILITY); |
| 2066 | IPW_CMD(SUPPORTED_CHANNELS); |
| 2067 | IPW_CMD(TPC_REPORT); |
| 2068 | IPW_CMD(WME_INFO); |
| 2069 | IPW_CMD(PRODUCTION_COMMAND); |
| 2070 | default: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2071 | return "UNKNOWN"; |
| 2072 | } |
| 2073 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2074 | |
| 2075 | #define HOST_COMPLETE_TIMEOUT HZ |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2076 | |
| 2077 | 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] | 2078 | { |
| 2079 | int rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2080 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2081 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2082 | spin_lock_irqsave(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2083 | if (priv->status & STATUS_HCMD_ACTIVE) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2084 | IPW_ERROR("Failed to send %s: Already sending a command.\n", |
| 2085 | get_cmd_string(cmd->cmd)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2086 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2087 | return -EAGAIN; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2088 | } |
| 2089 | |
| 2090 | priv->status |= STATUS_HCMD_ACTIVE; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2091 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2092 | if (priv->cmdlog) { |
| 2093 | priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies; |
| 2094 | priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd; |
| 2095 | priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len; |
| 2096 | memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param, |
| 2097 | cmd->len); |
| 2098 | priv->cmdlog[priv->cmdlog_pos].retcode = -1; |
| 2099 | } |
| 2100 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2101 | IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n", |
| 2102 | get_cmd_string(cmd->cmd), cmd->cmd, cmd->len, |
| 2103 | priv->status); |
Zhu Yi | f516dbc | 2006-01-24 16:36:44 +0800 | [diff] [blame] | 2104 | |
| 2105 | #ifndef DEBUG_CMD_WEP_KEY |
| 2106 | if (cmd->cmd == IPW_CMD_WEP_KEY) |
| 2107 | IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n"); |
| 2108 | else |
| 2109 | #endif |
| 2110 | printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len); |
| 2111 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2112 | 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] | 2113 | if (rc) { |
| 2114 | priv->status &= ~STATUS_HCMD_ACTIVE; |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2115 | IPW_ERROR("Failed to send %s: Reason %d\n", |
| 2116 | get_cmd_string(cmd->cmd), rc); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2117 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2118 | goto exit; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2119 | } |
| 2120 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2121 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2122 | rc = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 2123 | !(priv-> |
| 2124 | status & STATUS_HCMD_ACTIVE), |
| 2125 | HOST_COMPLETE_TIMEOUT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2126 | if (rc == 0) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2127 | spin_lock_irqsave(&priv->lock, flags); |
| 2128 | if (priv->status & STATUS_HCMD_ACTIVE) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2129 | IPW_ERROR("Failed to send %s: Command timed out.\n", |
| 2130 | get_cmd_string(cmd->cmd)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2131 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 2132 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2133 | rc = -EIO; |
| 2134 | goto exit; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2135 | } |
| 2136 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 2137 | } else |
| 2138 | rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2139 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2140 | if (priv->status & STATUS_RF_KILL_HW) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2141 | IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n", |
| 2142 | get_cmd_string(cmd->cmd)); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2143 | rc = -EIO; |
| 2144 | goto exit; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2145 | } |
| 2146 | |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2147 | exit: |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2148 | if (priv->cmdlog) { |
| 2149 | priv->cmdlog[priv->cmdlog_pos++].retcode = rc; |
| 2150 | priv->cmdlog_pos %= priv->cmdlog_len; |
| 2151 | } |
| 2152 | return rc; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2153 | } |
| 2154 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2155 | static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2156 | { |
| 2157 | struct host_cmd cmd = { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2158 | .cmd = command, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2159 | }; |
| 2160 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2161 | return __ipw_send_cmd(priv, &cmd); |
| 2162 | } |
| 2163 | |
| 2164 | static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len, |
| 2165 | void *data) |
| 2166 | { |
| 2167 | struct host_cmd cmd = { |
| 2168 | .cmd = command, |
| 2169 | .len = len, |
| 2170 | .param = data, |
| 2171 | }; |
| 2172 | |
| 2173 | return __ipw_send_cmd(priv, &cmd); |
| 2174 | } |
| 2175 | |
| 2176 | static int ipw_send_host_complete(struct ipw_priv *priv) |
| 2177 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2178 | if (!priv) { |
| 2179 | IPW_ERROR("Invalid args\n"); |
| 2180 | return -1; |
| 2181 | } |
| 2182 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2183 | return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2184 | } |
| 2185 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 2186 | static int ipw_send_system_config(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2187 | { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 2188 | return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG, |
| 2189 | sizeof(priv->sys_config), |
| 2190 | &priv->sys_config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2191 | } |
| 2192 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2193 | 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] | 2194 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2195 | if (!priv || !ssid) { |
| 2196 | IPW_ERROR("Invalid args\n"); |
| 2197 | return -1; |
| 2198 | } |
| 2199 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2200 | 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] | 2201 | ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2202 | } |
| 2203 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2204 | static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2205 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2206 | if (!priv || !mac) { |
| 2207 | IPW_ERROR("Invalid args\n"); |
| 2208 | return -1; |
| 2209 | } |
| 2210 | |
| 2211 | IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n", |
| 2212 | priv->net_dev->name, MAC_ARG(mac)); |
| 2213 | |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2214 | 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] | 2215 | } |
| 2216 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2217 | /* |
| 2218 | * NOTE: This must be executed from our workqueue as it results in udelay |
| 2219 | * being called which may corrupt the keyboard if executed on default |
| 2220 | * workqueue |
| 2221 | */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2222 | static void ipw_adapter_restart(void *adapter) |
| 2223 | { |
| 2224 | struct ipw_priv *priv = adapter; |
| 2225 | |
| 2226 | if (priv->status & STATUS_RF_KILL_MASK) |
| 2227 | return; |
| 2228 | |
| 2229 | ipw_down(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2230 | |
| 2231 | if (priv->assoc_network && |
| 2232 | (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS)) |
| 2233 | ipw_remove_current_network(priv); |
| 2234 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2235 | if (ipw_up(priv)) { |
| 2236 | IPW_ERROR("Failed to up device\n"); |
| 2237 | return; |
| 2238 | } |
| 2239 | } |
| 2240 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2241 | static void ipw_bg_adapter_restart(void *data) |
| 2242 | { |
| 2243 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2244 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2245 | ipw_adapter_restart(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2246 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2247 | } |
| 2248 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2249 | #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ) |
| 2250 | |
| 2251 | static void ipw_scan_check(void *data) |
| 2252 | { |
| 2253 | struct ipw_priv *priv = data; |
| 2254 | if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) { |
| 2255 | IPW_DEBUG_SCAN("Scan completion watchdog resetting " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2256 | "adapter after (%dms).\n", |
| 2257 | jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2258 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2259 | } |
| 2260 | } |
| 2261 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2262 | static void ipw_bg_scan_check(void *data) |
| 2263 | { |
| 2264 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2265 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2266 | ipw_scan_check(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2267 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2268 | } |
| 2269 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2270 | static int ipw_send_scan_request_ext(struct ipw_priv *priv, |
| 2271 | struct ipw_scan_request_ext *request) |
| 2272 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2273 | return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2274 | sizeof(*request), request); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | static int ipw_send_scan_abort(struct ipw_priv *priv) |
| 2278 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2279 | if (!priv) { |
| 2280 | IPW_ERROR("Invalid args\n"); |
| 2281 | return -1; |
| 2282 | } |
| 2283 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2284 | return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens) |
| 2288 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2289 | struct ipw_sensitivity_calib calib = { |
| 2290 | .beacon_rssi_raw = sens, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2291 | }; |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2292 | |
| 2293 | return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2294 | &calib); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2295 | } |
| 2296 | |
| 2297 | static int ipw_send_associate(struct ipw_priv *priv, |
| 2298 | struct ipw_associate *associate) |
| 2299 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2300 | struct ipw_associate tmp_associate; |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2301 | |
| 2302 | if (!priv || !associate) { |
| 2303 | IPW_ERROR("Invalid args\n"); |
| 2304 | return -1; |
| 2305 | } |
| 2306 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2307 | memcpy(&tmp_associate, associate, sizeof(*associate)); |
| 2308 | tmp_associate.policy_support = |
| 2309 | cpu_to_le16(tmp_associate.policy_support); |
| 2310 | tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw); |
| 2311 | tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw); |
| 2312 | tmp_associate.capability = cpu_to_le16(tmp_associate.capability); |
| 2313 | tmp_associate.listen_interval = |
| 2314 | cpu_to_le16(tmp_associate.listen_interval); |
| 2315 | tmp_associate.beacon_interval = |
| 2316 | cpu_to_le16(tmp_associate.beacon_interval); |
| 2317 | tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window); |
| 2318 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2319 | return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(tmp_associate), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2320 | &tmp_associate); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2321 | } |
| 2322 | |
| 2323 | static int ipw_send_supported_rates(struct ipw_priv *priv, |
| 2324 | struct ipw_supported_rates *rates) |
| 2325 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2326 | if (!priv || !rates) { |
| 2327 | IPW_ERROR("Invalid args\n"); |
| 2328 | return -1; |
| 2329 | } |
| 2330 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2331 | return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2332 | rates); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2333 | } |
| 2334 | |
| 2335 | static int ipw_set_random_seed(struct ipw_priv *priv) |
| 2336 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2337 | u32 val; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2338 | |
| 2339 | if (!priv) { |
| 2340 | IPW_ERROR("Invalid args\n"); |
| 2341 | return -1; |
| 2342 | } |
| 2343 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2344 | get_random_bytes(&val, sizeof(val)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2345 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2346 | 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] | 2347 | } |
| 2348 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2349 | static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off) |
| 2350 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2351 | if (!priv) { |
| 2352 | IPW_ERROR("Invalid args\n"); |
| 2353 | return -1; |
| 2354 | } |
| 2355 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2356 | 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] | 2357 | &phy_off); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2358 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2359 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2360 | 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] | 2361 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2362 | if (!priv || !power) { |
| 2363 | IPW_ERROR("Invalid args\n"); |
| 2364 | return -1; |
| 2365 | } |
| 2366 | |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2367 | 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] | 2368 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2369 | |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 2370 | static int ipw_set_tx_power(struct ipw_priv *priv) |
| 2371 | { |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 2372 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 2373 | struct ipw_tx_power tx_power; |
| 2374 | s8 max_power; |
| 2375 | int i; |
| 2376 | |
| 2377 | memset(&tx_power, 0, sizeof(tx_power)); |
| 2378 | |
| 2379 | /* configure device for 'G' band */ |
| 2380 | tx_power.ieee_mode = IPW_G_MODE; |
| 2381 | tx_power.num_channels = geo->bg_channels; |
| 2382 | for (i = 0; i < geo->bg_channels; i++) { |
| 2383 | max_power = geo->bg[i].max_power; |
| 2384 | tx_power.channels_tx_power[i].channel_number = |
| 2385 | geo->bg[i].channel; |
| 2386 | tx_power.channels_tx_power[i].tx_power = max_power ? |
| 2387 | min(max_power, priv->tx_power) : priv->tx_power; |
| 2388 | } |
| 2389 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2390 | return -EIO; |
| 2391 | |
| 2392 | /* configure device to also handle 'B' band */ |
| 2393 | tx_power.ieee_mode = IPW_B_MODE; |
| 2394 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2395 | return -EIO; |
| 2396 | |
| 2397 | /* configure device to also handle 'A' band */ |
| 2398 | if (priv->ieee->abg_true) { |
| 2399 | tx_power.ieee_mode = IPW_A_MODE; |
| 2400 | tx_power.num_channels = geo->a_channels; |
| 2401 | for (i = 0; i < tx_power.num_channels; i++) { |
| 2402 | max_power = geo->a[i].max_power; |
| 2403 | tx_power.channels_tx_power[i].channel_number = |
| 2404 | geo->a[i].channel; |
| 2405 | tx_power.channels_tx_power[i].tx_power = max_power ? |
| 2406 | min(max_power, priv->tx_power) : priv->tx_power; |
| 2407 | } |
| 2408 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2409 | return -EIO; |
| 2410 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2411 | return 0; |
| 2412 | } |
| 2413 | |
| 2414 | static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts) |
| 2415 | { |
| 2416 | struct ipw_rts_threshold rts_threshold = { |
| 2417 | .rts_threshold = rts, |
| 2418 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2419 | |
| 2420 | if (!priv) { |
| 2421 | IPW_ERROR("Invalid args\n"); |
| 2422 | return -1; |
| 2423 | } |
| 2424 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2425 | return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD, |
| 2426 | sizeof(rts_threshold), &rts_threshold); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2427 | } |
| 2428 | |
| 2429 | static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag) |
| 2430 | { |
| 2431 | struct ipw_frag_threshold frag_threshold = { |
| 2432 | .frag_threshold = frag, |
| 2433 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2434 | |
| 2435 | if (!priv) { |
| 2436 | IPW_ERROR("Invalid args\n"); |
| 2437 | return -1; |
| 2438 | } |
| 2439 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2440 | return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD, |
| 2441 | sizeof(frag_threshold), &frag_threshold); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2442 | } |
| 2443 | |
| 2444 | static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode) |
| 2445 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2446 | u32 param; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2447 | |
| 2448 | if (!priv) { |
| 2449 | IPW_ERROR("Invalid args\n"); |
| 2450 | return -1; |
| 2451 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2452 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2453 | /* If on battery, set to 3, if AC set to CAM, else user |
| 2454 | * level */ |
| 2455 | switch (mode) { |
| 2456 | case IPW_POWER_BATTERY: |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2457 | param = IPW_POWER_INDEX_3; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2458 | break; |
| 2459 | case IPW_POWER_AC: |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2460 | param = IPW_POWER_MODE_CAM; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2461 | break; |
| 2462 | default: |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2463 | param = mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2464 | break; |
| 2465 | } |
| 2466 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2467 | return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2468 | ¶m); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2469 | } |
| 2470 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2471 | static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit) |
| 2472 | { |
| 2473 | struct ipw_retry_limit retry_limit = { |
| 2474 | .short_retry_limit = slimit, |
| 2475 | .long_retry_limit = llimit |
| 2476 | }; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2477 | |
| 2478 | if (!priv) { |
| 2479 | IPW_ERROR("Invalid args\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2480 | return -1; |
| 2481 | } |
| 2482 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2483 | 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] | 2484 | &retry_limit); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2485 | } |
| 2486 | |
| 2487 | /* |
| 2488 | * The IPW device contains a Microwire compatible EEPROM that stores |
| 2489 | * various data like the MAC address. Usually the firmware has exclusive |
| 2490 | * access to the eeprom, but during device initialization (before the |
| 2491 | * device driver has sent the HostComplete command to the firmware) the |
| 2492 | * device driver has read access to the EEPROM by way of indirect addressing |
| 2493 | * through a couple of memory mapped registers. |
| 2494 | * |
| 2495 | * The following is a simplified implementation for pulling data out of the |
| 2496 | * the eeprom, along with some helper functions to find information in |
| 2497 | * the per device private data's copy of the eeprom. |
| 2498 | * |
| 2499 | * NOTE: To better understand how these functions work (i.e what is a chip |
| 2500 | * select and why do have to keep driving the eeprom clock?), read |
| 2501 | * just about any data sheet for a Microwire compatible EEPROM. |
| 2502 | */ |
| 2503 | |
| 2504 | /* write a 32 bit value into the indirect accessor register */ |
| 2505 | static inline void eeprom_write_reg(struct ipw_priv *p, u32 data) |
| 2506 | { |
| 2507 | ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2508 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2509 | /* the eeprom requires some time to complete the operation */ |
| 2510 | udelay(p->eeprom_delay); |
| 2511 | |
| 2512 | return; |
| 2513 | } |
| 2514 | |
| 2515 | /* perform a chip select operation */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2516 | static void eeprom_cs(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2517 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2518 | eeprom_write_reg(priv, 0); |
| 2519 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2520 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); |
| 2521 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2522 | } |
| 2523 | |
| 2524 | /* perform a chip select operation */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2525 | static void eeprom_disable_cs(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2526 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2527 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2528 | eeprom_write_reg(priv, 0); |
| 2529 | eeprom_write_reg(priv, EEPROM_BIT_SK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | /* push a single bit down to the eeprom */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2533 | static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2534 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2535 | int d = (bit ? EEPROM_BIT_DI : 0); |
| 2536 | eeprom_write_reg(p, EEPROM_BIT_CS | d); |
| 2537 | eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | /* push an opcode followed by an address down to the eeprom */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2541 | static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2542 | { |
| 2543 | int i; |
| 2544 | |
| 2545 | eeprom_cs(priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2546 | eeprom_write_bit(priv, 1); |
| 2547 | eeprom_write_bit(priv, op & 2); |
| 2548 | eeprom_write_bit(priv, op & 1); |
| 2549 | for (i = 7; i >= 0; i--) { |
| 2550 | eeprom_write_bit(priv, addr & (1 << i)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2551 | } |
| 2552 | } |
| 2553 | |
| 2554 | /* pull 16 bits off the eeprom, one bit at a time */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2555 | static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2556 | { |
| 2557 | int i; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2558 | u16 r = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2559 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2560 | /* Send READ Opcode */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2561 | eeprom_op(priv, EEPROM_CMD_READ, addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2562 | |
| 2563 | /* Send dummy bit */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2564 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2565 | |
| 2566 | /* Read the byte off the eeprom one bit at a time */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2567 | for (i = 0; i < 16; i++) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2568 | u32 data = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2569 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); |
| 2570 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2571 | data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS); |
| 2572 | r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2573 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2574 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2575 | /* Send another dummy bit */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2576 | eeprom_write_reg(priv, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2577 | eeprom_disable_cs(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2578 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2579 | return r; |
| 2580 | } |
| 2581 | |
| 2582 | /* helper function for pulling the mac address out of the private */ |
| 2583 | /* data's copy of the eeprom data */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2584 | static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2585 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2586 | memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2587 | } |
| 2588 | |
| 2589 | /* |
| 2590 | * Either the device driver (i.e. the host) or the firmware can |
| 2591 | * load eeprom data into the designated region in SRAM. If neither |
| 2592 | * happens then the FW will shutdown with a fatal error. |
| 2593 | * |
| 2594 | * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE |
| 2595 | * bit needs region of shared SRAM needs to be non-zero. |
| 2596 | */ |
| 2597 | static void ipw_eeprom_init_sram(struct ipw_priv *priv) |
| 2598 | { |
| 2599 | int i; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2600 | u16 *eeprom = (u16 *) priv->eeprom; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2601 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2602 | IPW_DEBUG_TRACE(">>\n"); |
| 2603 | |
| 2604 | /* read entire contents of eeprom into private buffer */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2605 | for (i = 0; i < 128; i++) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2606 | eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2607 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2608 | /* |
| 2609 | If the data looks correct, then copy it to our private |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2610 | copy. Otherwise let the firmware know to perform the operation |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2611 | on its own. |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2612 | */ |
Alexey Dobriyan | 386093e | 2006-02-01 03:04:57 -0800 | [diff] [blame] | 2613 | if (priv->eeprom[EEPROM_VERSION] != 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2614 | IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n"); |
| 2615 | |
| 2616 | /* write the eeprom data to sram */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2617 | for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2618 | ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2619 | |
| 2620 | /* Do not load eeprom data on fatal error or suspend */ |
| 2621 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); |
| 2622 | } else { |
| 2623 | IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n"); |
| 2624 | |
| 2625 | /* Load eeprom data on fatal error or suspend */ |
| 2626 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1); |
| 2627 | } |
| 2628 | |
| 2629 | IPW_DEBUG_TRACE("<<\n"); |
| 2630 | } |
| 2631 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2632 | 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] | 2633 | { |
| 2634 | count >>= 2; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2635 | if (!count) |
| 2636 | return; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2637 | _ipw_write32(priv, IPW_AUTOINC_ADDR, start); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2638 | while (count--) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2639 | _ipw_write32(priv, IPW_AUTOINC_DATA, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2640 | } |
| 2641 | |
| 2642 | static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv) |
| 2643 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2644 | ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2645 | CB_NUMBER_OF_ELEMENTS_SMALL * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2646 | sizeof(struct command_block)); |
| 2647 | } |
| 2648 | |
| 2649 | static int ipw_fw_dma_enable(struct ipw_priv *priv) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2650 | { /* start dma engine but no transfers yet */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2651 | |
| 2652 | IPW_DEBUG_FW(">> : \n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2653 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2654 | /* Start the dma */ |
| 2655 | ipw_fw_dma_reset_command_blocks(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2656 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2657 | /* Write CB base address */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2658 | 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] | 2659 | |
| 2660 | IPW_DEBUG_FW("<< : \n"); |
| 2661 | return 0; |
| 2662 | } |
| 2663 | |
| 2664 | static void ipw_fw_dma_abort(struct ipw_priv *priv) |
| 2665 | { |
| 2666 | u32 control = 0; |
| 2667 | |
| 2668 | IPW_DEBUG_FW(">> :\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2669 | |
| 2670 | //set the Stop and Abort bit |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2671 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2672 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2673 | priv->sram_desc.last_cb_index = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2674 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2675 | IPW_DEBUG_FW("<< \n"); |
| 2676 | } |
| 2677 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2678 | static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index, |
| 2679 | struct command_block *cb) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2680 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2681 | u32 address = |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2682 | IPW_SHARED_SRAM_DMA_CONTROL + |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2683 | (sizeof(struct command_block) * index); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2684 | IPW_DEBUG_FW(">> :\n"); |
| 2685 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2686 | ipw_write_indirect(priv, address, (u8 *) cb, |
| 2687 | (int)sizeof(struct command_block)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2688 | |
| 2689 | IPW_DEBUG_FW("<< :\n"); |
| 2690 | return 0; |
| 2691 | |
| 2692 | } |
| 2693 | |
| 2694 | static int ipw_fw_dma_kick(struct ipw_priv *priv) |
| 2695 | { |
| 2696 | u32 control = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2697 | u32 index = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2698 | |
| 2699 | IPW_DEBUG_FW(">> :\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2700 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2701 | for (index = 0; index < priv->sram_desc.last_cb_index; index++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2702 | ipw_fw_dma_write_command_block(priv, index, |
| 2703 | &priv->sram_desc.cb_list[index]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2704 | |
| 2705 | /* Enable the DMA in the CSR register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2706 | ipw_clear_bit(priv, IPW_RESET_REG, |
| 2707 | IPW_RESET_REG_MASTER_DISABLED | |
| 2708 | IPW_RESET_REG_STOP_MASTER); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2709 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2710 | /* Set the Start bit. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2711 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2712 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2713 | |
| 2714 | IPW_DEBUG_FW("<< :\n"); |
| 2715 | return 0; |
| 2716 | } |
| 2717 | |
| 2718 | static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv) |
| 2719 | { |
| 2720 | u32 address; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2721 | u32 register_value = 0; |
| 2722 | u32 cb_fields_address = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2723 | |
| 2724 | IPW_DEBUG_FW(">> :\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2725 | address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2726 | IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2727 | |
| 2728 | /* Read the DMA Controlor register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2729 | register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL); |
| 2730 | 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] | 2731 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2732 | /* Print the CB values */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2733 | cb_fields_address = address; |
| 2734 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2735 | 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] | 2736 | |
| 2737 | cb_fields_address += sizeof(u32); |
| 2738 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2739 | 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] | 2740 | |
| 2741 | cb_fields_address += sizeof(u32); |
| 2742 | register_value = ipw_read_reg32(priv, cb_fields_address); |
| 2743 | IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n", |
| 2744 | register_value); |
| 2745 | |
| 2746 | cb_fields_address += sizeof(u32); |
| 2747 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2748 | 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] | 2749 | |
| 2750 | IPW_DEBUG_FW(">> :\n"); |
| 2751 | } |
| 2752 | |
| 2753 | static int ipw_fw_dma_command_block_index(struct ipw_priv *priv) |
| 2754 | { |
| 2755 | u32 current_cb_address = 0; |
| 2756 | u32 current_cb_index = 0; |
| 2757 | |
| 2758 | IPW_DEBUG_FW("<< :\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2759 | current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2760 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2761 | current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2762 | sizeof(struct command_block); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2763 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2764 | 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] | 2765 | current_cb_index, current_cb_address); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2766 | |
| 2767 | IPW_DEBUG_FW(">> :\n"); |
| 2768 | return current_cb_index; |
| 2769 | |
| 2770 | } |
| 2771 | |
| 2772 | static int ipw_fw_dma_add_command_block(struct ipw_priv *priv, |
| 2773 | u32 src_address, |
| 2774 | u32 dest_address, |
| 2775 | u32 length, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2776 | int interrupt_enabled, int is_last) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2777 | { |
| 2778 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2779 | 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] | 2780 | CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG | |
| 2781 | CB_DEST_SIZE_LONG; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2782 | struct command_block *cb; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2783 | u32 last_cb_element = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2784 | |
| 2785 | IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n", |
| 2786 | src_address, dest_address, length); |
| 2787 | |
| 2788 | if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL) |
| 2789 | return -1; |
| 2790 | |
| 2791 | last_cb_element = priv->sram_desc.last_cb_index; |
| 2792 | cb = &priv->sram_desc.cb_list[last_cb_element]; |
| 2793 | priv->sram_desc.last_cb_index++; |
| 2794 | |
| 2795 | /* Calculate the new CB control word */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2796 | if (interrupt_enabled) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2797 | control |= CB_INT_ENABLED; |
| 2798 | |
| 2799 | if (is_last) |
| 2800 | control |= CB_LAST_VALID; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2801 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2802 | control |= length; |
| 2803 | |
| 2804 | /* Calculate the CB Element's checksum value */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2805 | cb->status = control ^ src_address ^ dest_address; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2806 | |
| 2807 | /* Copy the Source and Destination addresses */ |
| 2808 | cb->dest_addr = dest_address; |
| 2809 | cb->source_addr = src_address; |
| 2810 | |
| 2811 | /* Copy the Control Word last */ |
| 2812 | cb->control = control; |
| 2813 | |
| 2814 | return 0; |
| 2815 | } |
| 2816 | |
| 2817 | static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2818 | u32 src_phys, u32 dest_address, u32 length) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2819 | { |
| 2820 | u32 bytes_left = length; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2821 | u32 src_offset = 0; |
| 2822 | u32 dest_offset = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2823 | int status = 0; |
| 2824 | IPW_DEBUG_FW(">> \n"); |
| 2825 | IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n", |
| 2826 | src_phys, dest_address, length); |
| 2827 | while (bytes_left > CB_MAX_LENGTH) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2828 | status = ipw_fw_dma_add_command_block(priv, |
| 2829 | src_phys + src_offset, |
| 2830 | dest_address + |
| 2831 | dest_offset, |
| 2832 | CB_MAX_LENGTH, 0, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2833 | if (status) { |
| 2834 | IPW_DEBUG_FW_INFO(": Failed\n"); |
| 2835 | return -1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2836 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2837 | IPW_DEBUG_FW_INFO(": Added new cb\n"); |
| 2838 | |
| 2839 | src_offset += CB_MAX_LENGTH; |
| 2840 | dest_offset += CB_MAX_LENGTH; |
| 2841 | bytes_left -= CB_MAX_LENGTH; |
| 2842 | } |
| 2843 | |
| 2844 | /* add the buffer tail */ |
| 2845 | if (bytes_left > 0) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2846 | status = |
| 2847 | ipw_fw_dma_add_command_block(priv, src_phys + src_offset, |
| 2848 | dest_address + dest_offset, |
| 2849 | bytes_left, 0, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2850 | if (status) { |
| 2851 | IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n"); |
| 2852 | return -1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2853 | } else |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2854 | IPW_DEBUG_FW_INFO |
| 2855 | (": Adding new cb - the buffer tail\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2856 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2857 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2858 | IPW_DEBUG_FW("<< \n"); |
| 2859 | return 0; |
| 2860 | } |
| 2861 | |
| 2862 | static int ipw_fw_dma_wait(struct ipw_priv *priv) |
| 2863 | { |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2864 | u32 current_index = 0, previous_index; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2865 | u32 watchdog = 0; |
| 2866 | |
| 2867 | IPW_DEBUG_FW(">> : \n"); |
| 2868 | |
| 2869 | current_index = ipw_fw_dma_command_block_index(priv); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2870 | IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2871 | (int)priv->sram_desc.last_cb_index); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2872 | |
| 2873 | while (current_index < priv->sram_desc.last_cb_index) { |
| 2874 | udelay(50); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2875 | previous_index = current_index; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2876 | current_index = ipw_fw_dma_command_block_index(priv); |
| 2877 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2878 | if (previous_index < current_index) { |
| 2879 | watchdog = 0; |
| 2880 | continue; |
| 2881 | } |
| 2882 | if (++watchdog > 400) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2883 | IPW_DEBUG_FW_INFO("Timeout\n"); |
| 2884 | ipw_fw_dma_dump_command_block(priv); |
| 2885 | ipw_fw_dma_abort(priv); |
| 2886 | return -1; |
| 2887 | } |
| 2888 | } |
| 2889 | |
| 2890 | ipw_fw_dma_abort(priv); |
| 2891 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2892 | /*Disable the DMA in the CSR register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2893 | ipw_set_bit(priv, IPW_RESET_REG, |
| 2894 | IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2895 | |
| 2896 | IPW_DEBUG_FW("<< dmaWaitSync \n"); |
| 2897 | return 0; |
| 2898 | } |
| 2899 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2900 | static void ipw_remove_current_network(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2901 | { |
| 2902 | struct list_head *element, *safe; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2903 | struct ieee80211_network *network = NULL; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2904 | unsigned long flags; |
| 2905 | |
| 2906 | spin_lock_irqsave(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2907 | list_for_each_safe(element, safe, &priv->ieee->network_list) { |
| 2908 | network = list_entry(element, struct ieee80211_network, list); |
| 2909 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
| 2910 | list_del(element); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2911 | list_add_tail(&network->list, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2912 | &priv->ieee->network_free_list); |
| 2913 | } |
| 2914 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2915 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2916 | } |
| 2917 | |
| 2918 | /** |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2919 | * Check that card is still alive. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2920 | * Reads debug register from domain0. |
| 2921 | * If card is present, pre-defined value should |
| 2922 | * be found there. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2923 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2924 | * @param priv |
| 2925 | * @return 1 if card is present, 0 otherwise |
| 2926 | */ |
| 2927 | static inline int ipw_alive(struct ipw_priv *priv) |
| 2928 | { |
| 2929 | return ipw_read32(priv, 0x90) == 0xd55555d5; |
| 2930 | } |
| 2931 | |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2932 | /* timeout in msec, attempted in 10-msec quanta */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2933 | 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] | 2934 | int timeout) |
| 2935 | { |
| 2936 | int i = 0; |
| 2937 | |
| 2938 | do { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2939 | if ((ipw_read32(priv, addr) & mask) == mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2940 | return i; |
| 2941 | mdelay(10); |
| 2942 | i += 10; |
| 2943 | } while (i < timeout); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2944 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2945 | return -ETIME; |
| 2946 | } |
| 2947 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2948 | /* These functions load the firmware and micro code for the operation of |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2949 | * the ipw hardware. It assumes the buffer has all the bits for the |
| 2950 | * image and the caller is handling the memory allocation and clean up. |
| 2951 | */ |
| 2952 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2953 | static int ipw_stop_master(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2954 | { |
| 2955 | int rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2956 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2957 | IPW_DEBUG_TRACE(">> \n"); |
| 2958 | /* stop master. typical delay - 0 */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2959 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2960 | |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2961 | /* timeout is in msec, polled in 10-msec quanta */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2962 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
| 2963 | IPW_RESET_REG_MASTER_DISABLED, 100); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2964 | if (rc < 0) { |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2965 | IPW_ERROR("wait for stop master failed after 100ms\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2966 | return -1; |
| 2967 | } |
| 2968 | |
| 2969 | IPW_DEBUG_INFO("stop master %dms\n", rc); |
| 2970 | |
| 2971 | return rc; |
| 2972 | } |
| 2973 | |
| 2974 | static void ipw_arc_release(struct ipw_priv *priv) |
| 2975 | { |
| 2976 | IPW_DEBUG_TRACE(">> \n"); |
| 2977 | mdelay(5); |
| 2978 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2979 | ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2980 | |
| 2981 | /* no one knows timing, for safety add some delay */ |
| 2982 | mdelay(5); |
| 2983 | } |
| 2984 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2985 | struct fw_chunk { |
| 2986 | u32 address; |
| 2987 | u32 length; |
| 2988 | }; |
| 2989 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2990 | 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] | 2991 | { |
| 2992 | int rc = 0, i, addr; |
| 2993 | u8 cr = 0; |
| 2994 | u16 *image; |
| 2995 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2996 | image = (u16 *) data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2997 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2998 | IPW_DEBUG_TRACE(">> \n"); |
| 2999 | |
| 3000 | rc = ipw_stop_master(priv); |
| 3001 | |
| 3002 | if (rc < 0) |
| 3003 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3004 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3005 | // spin_lock_irqsave(&priv->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3006 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3007 | for (addr = IPW_SHARED_LOWER_BOUND; |
| 3008 | addr < IPW_REGISTER_DOMAIN1_END; addr += 4) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3009 | ipw_write32(priv, addr, 0); |
| 3010 | } |
| 3011 | |
| 3012 | /* no ucode (yet) */ |
| 3013 | memset(&priv->dino_alive, 0, sizeof(priv->dino_alive)); |
| 3014 | /* destroy DMA queues */ |
| 3015 | /* reset sequence */ |
| 3016 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3017 | 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] | 3018 | ipw_arc_release(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3019 | 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] | 3020 | mdelay(1); |
| 3021 | |
| 3022 | /* reset PHY */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3023 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3024 | mdelay(1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3025 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3026 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3027 | mdelay(1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3028 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3029 | /* enable ucode store */ |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 3030 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0); |
| 3031 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3032 | mdelay(1); |
| 3033 | |
| 3034 | /* write ucode */ |
| 3035 | /** |
| 3036 | * @bug |
| 3037 | * Do NOT set indirect address register once and then |
| 3038 | * store data to indirect data register in the loop. |
| 3039 | * It seems very reasonable, but in this case DINO do not |
| 3040 | * accept ucode. It is essential to set address each time. |
| 3041 | */ |
| 3042 | /* load new ipw uCode */ |
| 3043 | for (i = 0; i < len / 2; i++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3044 | ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3045 | cpu_to_le16(image[i])); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3046 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3047 | /* enable DINO */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3048 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
| 3049 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3050 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3051 | /* this is where the igx / win driver deveates from the VAP driver. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3052 | |
| 3053 | /* wait for alive response */ |
| 3054 | for (i = 0; i < 100; i++) { |
| 3055 | /* poll for incoming data */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3056 | cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3057 | if (cr & DINO_RXFIFO_DATA) |
| 3058 | break; |
| 3059 | mdelay(1); |
| 3060 | } |
| 3061 | |
| 3062 | if (cr & DINO_RXFIFO_DATA) { |
| 3063 | /* alive_command_responce size is NOT multiple of 4 */ |
| 3064 | u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4]; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3065 | |
| 3066 | for (i = 0; i < ARRAY_SIZE(response_buffer); i++) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3067 | response_buffer[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3068 | le32_to_cpu(ipw_read_reg32(priv, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3069 | IPW_BASEBAND_RX_FIFO_READ)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3070 | memcpy(&priv->dino_alive, response_buffer, |
| 3071 | sizeof(priv->dino_alive)); |
| 3072 | if (priv->dino_alive.alive_command == 1 |
| 3073 | && priv->dino_alive.ucode_valid == 1) { |
| 3074 | rc = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3075 | IPW_DEBUG_INFO |
| 3076 | ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) " |
| 3077 | "of %02d/%02d/%02d %02d:%02d\n", |
| 3078 | priv->dino_alive.software_revision, |
| 3079 | priv->dino_alive.software_revision, |
| 3080 | priv->dino_alive.device_identifier, |
| 3081 | priv->dino_alive.device_identifier, |
| 3082 | priv->dino_alive.time_stamp[0], |
| 3083 | priv->dino_alive.time_stamp[1], |
| 3084 | priv->dino_alive.time_stamp[2], |
| 3085 | priv->dino_alive.time_stamp[3], |
| 3086 | priv->dino_alive.time_stamp[4]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3087 | } else { |
| 3088 | IPW_DEBUG_INFO("Microcode is not alive\n"); |
| 3089 | rc = -EINVAL; |
| 3090 | } |
| 3091 | } else { |
| 3092 | IPW_DEBUG_INFO("No alive response from DINO\n"); |
| 3093 | rc = -ETIME; |
| 3094 | } |
| 3095 | |
| 3096 | /* disable DINO, otherwise for some reason |
| 3097 | firmware have problem getting alive resp. */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3098 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3099 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3100 | // spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3101 | |
| 3102 | return rc; |
| 3103 | } |
| 3104 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3105 | 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] | 3106 | { |
| 3107 | int rc = -1; |
| 3108 | int offset = 0; |
| 3109 | struct fw_chunk *chunk; |
| 3110 | dma_addr_t shared_phys; |
| 3111 | u8 *shared_virt; |
| 3112 | |
| 3113 | IPW_DEBUG_TRACE("<< : \n"); |
| 3114 | shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys); |
| 3115 | |
| 3116 | if (!shared_virt) |
| 3117 | return -ENOMEM; |
| 3118 | |
| 3119 | memmove(shared_virt, data, len); |
| 3120 | |
| 3121 | /* Start the Dma */ |
| 3122 | rc = ipw_fw_dma_enable(priv); |
| 3123 | |
| 3124 | if (priv->sram_desc.last_cb_index > 0) { |
| 3125 | /* the DMA is already ready this would be a bug. */ |
| 3126 | BUG(); |
| 3127 | goto out; |
| 3128 | } |
| 3129 | |
| 3130 | do { |
| 3131 | chunk = (struct fw_chunk *)(data + offset); |
| 3132 | offset += sizeof(struct fw_chunk); |
| 3133 | /* build DMA packet and queue up for sending */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3134 | /* dma to chunk->address, the chunk->length bytes from data + |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3135 | * offeset*/ |
| 3136 | /* Dma loading */ |
| 3137 | rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3138 | le32_to_cpu(chunk->address), |
| 3139 | le32_to_cpu(chunk->length)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3140 | if (rc) { |
| 3141 | IPW_DEBUG_INFO("dmaAddBuffer Failed\n"); |
| 3142 | goto out; |
| 3143 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3144 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3145 | offset += le32_to_cpu(chunk->length); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3146 | } while (offset < len); |
| 3147 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3148 | /* Run the DMA and wait for the answer */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3149 | rc = ipw_fw_dma_kick(priv); |
| 3150 | if (rc) { |
| 3151 | IPW_ERROR("dmaKick Failed\n"); |
| 3152 | goto out; |
| 3153 | } |
| 3154 | |
| 3155 | rc = ipw_fw_dma_wait(priv); |
| 3156 | if (rc) { |
| 3157 | IPW_ERROR("dmaWaitSync Failed\n"); |
| 3158 | goto out; |
| 3159 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3160 | out: |
| 3161 | pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3162 | return rc; |
| 3163 | } |
| 3164 | |
| 3165 | /* stop nic */ |
| 3166 | static int ipw_stop_nic(struct ipw_priv *priv) |
| 3167 | { |
| 3168 | int rc = 0; |
| 3169 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3170 | /* stop */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3171 | ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3172 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3173 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
| 3174 | IPW_RESET_REG_MASTER_DISABLED, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3175 | if (rc < 0) { |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3176 | IPW_ERROR("wait for reg master disabled failed after 500ms\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3177 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3178 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3179 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3180 | ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3181 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3182 | return rc; |
| 3183 | } |
| 3184 | |
| 3185 | static void ipw_start_nic(struct ipw_priv *priv) |
| 3186 | { |
| 3187 | IPW_DEBUG_TRACE(">>\n"); |
| 3188 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3189 | /* prvHwStartNic release ARC */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3190 | ipw_clear_bit(priv, IPW_RESET_REG, |
| 3191 | IPW_RESET_REG_MASTER_DISABLED | |
| 3192 | IPW_RESET_REG_STOP_MASTER | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3193 | CBD_RESET_REG_PRINCETON_RESET); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3194 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3195 | /* enable power management */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3196 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, |
| 3197 | IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3198 | |
| 3199 | IPW_DEBUG_TRACE("<<\n"); |
| 3200 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3201 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3202 | static int ipw_init_nic(struct ipw_priv *priv) |
| 3203 | { |
| 3204 | int rc; |
| 3205 | |
| 3206 | IPW_DEBUG_TRACE(">>\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3207 | /* reset */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3208 | /*prvHwInitNic */ |
| 3209 | /* set "initialization complete" bit to move adapter to D0 state */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3210 | 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] | 3211 | |
| 3212 | /* low-level PLL activation */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3213 | ipw_write32(priv, IPW_READ_INT_REGISTER, |
| 3214 | IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3215 | |
| 3216 | /* wait for clock stabilization */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3217 | rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW, |
| 3218 | IPW_GP_CNTRL_BIT_CLOCK_READY, 250); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3219 | if (rc < 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3220 | IPW_DEBUG_INFO("FAILED wait for clock stablization\n"); |
| 3221 | |
| 3222 | /* assert SW reset */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3223 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3224 | |
| 3225 | udelay(10); |
| 3226 | |
| 3227 | /* set "initialization complete" bit to move adapter to D0 state */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3228 | 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] | 3229 | |
| 3230 | IPW_DEBUG_TRACE(">>\n"); |
| 3231 | return 0; |
| 3232 | } |
| 3233 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3234 | /* Call this function from process context, it will sleep in request_firmware. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3235 | * Probe is an ok place to call this from. |
| 3236 | */ |
| 3237 | static int ipw_reset_nic(struct ipw_priv *priv) |
| 3238 | { |
| 3239 | int rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3240 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3241 | |
| 3242 | IPW_DEBUG_TRACE(">>\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3243 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3244 | rc = ipw_init_nic(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3245 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3246 | spin_lock_irqsave(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3247 | /* Clear the 'host command active' bit... */ |
| 3248 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 3249 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3250 | priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); |
| 3251 | wake_up_interruptible(&priv->wait_state); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3252 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3253 | |
| 3254 | IPW_DEBUG_TRACE("<<\n"); |
| 3255 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3256 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3257 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3258 | |
| 3259 | struct ipw_fw { |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3260 | __le32 ver; |
| 3261 | __le32 boot_size; |
| 3262 | __le32 ucode_size; |
| 3263 | __le32 fw_size; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3264 | u8 data[0]; |
| 3265 | }; |
| 3266 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3267 | static int ipw_get_fw(struct ipw_priv *priv, |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3268 | const struct firmware **raw, const char *name) |
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 | struct ipw_fw *fw; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3271 | int rc; |
| 3272 | |
| 3273 | /* ask firmware_class module to get the boot firmware off disk */ |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3274 | rc = request_firmware(raw, name, &priv->pci_dev->dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3275 | if (rc < 0) { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3276 | IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3277 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3278 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3279 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3280 | if ((*raw)->size < sizeof(*fw)) { |
| 3281 | IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3282 | return -EINVAL; |
| 3283 | } |
| 3284 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3285 | fw = (void *)(*raw)->data; |
| 3286 | |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3287 | if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) + |
| 3288 | le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3289 | IPW_ERROR("%s is too small or corrupt (%zd)\n", |
| 3290 | name, (*raw)->size); |
| 3291 | return -EINVAL; |
| 3292 | } |
| 3293 | |
| 3294 | 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] | 3295 | name, |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3296 | le32_to_cpu(fw->ver) >> 16, |
| 3297 | le32_to_cpu(fw->ver) & 0xff, |
| 3298 | (*raw)->size - sizeof(*fw)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3299 | return 0; |
| 3300 | } |
| 3301 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3302 | #define IPW_RX_BUF_SIZE (3000) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3303 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3304 | static void ipw_rx_queue_reset(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3305 | struct ipw_rx_queue *rxq) |
| 3306 | { |
| 3307 | unsigned long flags; |
| 3308 | int i; |
| 3309 | |
| 3310 | spin_lock_irqsave(&rxq->lock, flags); |
| 3311 | |
| 3312 | INIT_LIST_HEAD(&rxq->rx_free); |
| 3313 | INIT_LIST_HEAD(&rxq->rx_used); |
| 3314 | |
| 3315 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 3316 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { |
| 3317 | /* In the reset function, these buffers may have been allocated |
| 3318 | * to an SKB, so we need to unmap and free potential storage */ |
| 3319 | if (rxq->pool[i].skb != NULL) { |
| 3320 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3321 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3322 | dev_kfree_skb(rxq->pool[i].skb); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3323 | rxq->pool[i].skb = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3324 | } |
| 3325 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 3326 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3327 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3328 | /* Set us so that we have processed and used all buffers, but have |
| 3329 | * not restocked the Rx queue with fresh buffers */ |
| 3330 | rxq->read = rxq->write = 0; |
| 3331 | rxq->processed = RX_QUEUE_SIZE - 1; |
| 3332 | rxq->free_count = 0; |
| 3333 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3334 | } |
| 3335 | |
| 3336 | #ifdef CONFIG_PM |
| 3337 | static int fw_loaded = 0; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3338 | static const struct firmware *raw = NULL; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3339 | |
| 3340 | static void free_firmware(void) |
| 3341 | { |
| 3342 | if (fw_loaded) { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3343 | release_firmware(raw); |
| 3344 | raw = NULL; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3345 | fw_loaded = 0; |
| 3346 | } |
| 3347 | } |
| 3348 | #else |
| 3349 | #define free_firmware() do {} while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3350 | #endif |
| 3351 | |
| 3352 | static int ipw_load(struct ipw_priv *priv) |
| 3353 | { |
| 3354 | #ifndef CONFIG_PM |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3355 | const struct firmware *raw = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3356 | #endif |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3357 | struct ipw_fw *fw; |
| 3358 | u8 *boot_img, *ucode_img, *fw_img; |
| 3359 | u8 *name = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3360 | int rc = 0, retries = 3; |
| 3361 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3362 | switch (priv->ieee->iw_mode) { |
| 3363 | case IW_MODE_ADHOC: |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3364 | name = "ipw2200-ibss.fw"; |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3365 | break; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3366 | #ifdef CONFIG_IPW2200_MONITOR |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3367 | case IW_MODE_MONITOR: |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3368 | name = "ipw2200-sniffer.fw"; |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3369 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3370 | #endif |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3371 | case IW_MODE_INFRA: |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3372 | name = "ipw2200-bss.fw"; |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3373 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3374 | } |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3375 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3376 | if (!name) { |
| 3377 | rc = -EINVAL; |
| 3378 | goto error; |
| 3379 | } |
| 3380 | |
| 3381 | #ifdef CONFIG_PM |
| 3382 | if (!fw_loaded) { |
| 3383 | #endif |
| 3384 | rc = ipw_get_fw(priv, &raw, name); |
| 3385 | if (rc < 0) |
| 3386 | goto error; |
| 3387 | #ifdef CONFIG_PM |
| 3388 | } |
| 3389 | #endif |
| 3390 | |
| 3391 | fw = (void *)raw->data; |
| 3392 | boot_img = &fw->data[0]; |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3393 | ucode_img = &fw->data[le32_to_cpu(fw->boot_size)]; |
| 3394 | fw_img = &fw->data[le32_to_cpu(fw->boot_size) + |
| 3395 | le32_to_cpu(fw->ucode_size)]; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3396 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3397 | if (rc < 0) |
| 3398 | goto error; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3399 | |
| 3400 | if (!priv->rxq) |
| 3401 | priv->rxq = ipw_rx_queue_alloc(priv); |
| 3402 | else |
| 3403 | ipw_rx_queue_reset(priv, priv->rxq); |
| 3404 | if (!priv->rxq) { |
| 3405 | IPW_ERROR("Unable to initialize Rx queue\n"); |
| 3406 | goto error; |
| 3407 | } |
| 3408 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3409 | retry: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3410 | /* Ensure interrupts are disabled */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3411 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3412 | priv->status &= ~STATUS_INT_ENABLED; |
| 3413 | |
| 3414 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3415 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3416 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3417 | ipw_stop_nic(priv); |
| 3418 | |
| 3419 | rc = ipw_reset_nic(priv); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3420 | if (rc < 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3421 | IPW_ERROR("Unable to reset NIC\n"); |
| 3422 | goto error; |
| 3423 | } |
| 3424 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3425 | ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND, |
| 3426 | IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3427 | |
| 3428 | /* DMA the initial boot firmware into the device */ |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3429 | 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] | 3430 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3431 | IPW_ERROR("Unable to load boot firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3432 | goto error; |
| 3433 | } |
| 3434 | |
| 3435 | /* kick start the device */ |
| 3436 | ipw_start_nic(priv); |
| 3437 | |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3438 | /* wait for the device to finish its initial startup sequence */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3439 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
| 3440 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3441 | if (rc < 0) { |
| 3442 | IPW_ERROR("device failed to boot initial fw image\n"); |
| 3443 | goto error; |
| 3444 | } |
| 3445 | IPW_DEBUG_INFO("initial device response after %dms\n", rc); |
| 3446 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3447 | /* ack fw init done interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3448 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3449 | |
| 3450 | /* DMA the ucode into the device */ |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3451 | 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] | 3452 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3453 | IPW_ERROR("Unable to load ucode: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3454 | goto error; |
| 3455 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3456 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3457 | /* stop nic */ |
| 3458 | ipw_stop_nic(priv); |
| 3459 | |
| 3460 | /* DMA bss firmware into the device */ |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3461 | 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] | 3462 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3463 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3464 | goto error; |
| 3465 | } |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3466 | #ifdef CONFIG_PM |
| 3467 | fw_loaded = 1; |
| 3468 | #endif |
| 3469 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3470 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); |
| 3471 | |
| 3472 | rc = ipw_queue_reset(priv); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3473 | if (rc < 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3474 | IPW_ERROR("Unable to initialize queues\n"); |
| 3475 | goto error; |
| 3476 | } |
| 3477 | |
| 3478 | /* Ensure interrupts are disabled */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3479 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3480 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3481 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3482 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3483 | /* kick start the device */ |
| 3484 | ipw_start_nic(priv); |
| 3485 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3486 | if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3487 | if (retries > 0) { |
| 3488 | IPW_WARNING("Parity error. Retrying init.\n"); |
| 3489 | retries--; |
| 3490 | goto retry; |
| 3491 | } |
| 3492 | |
| 3493 | IPW_ERROR("TODO: Handle parity error -- schedule restart?\n"); |
| 3494 | rc = -EIO; |
| 3495 | goto error; |
| 3496 | } |
| 3497 | |
| 3498 | /* wait for the device */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3499 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
| 3500 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3501 | if (rc < 0) { |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3502 | IPW_ERROR("device failed to start within 500ms\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3503 | goto error; |
| 3504 | } |
| 3505 | IPW_DEBUG_INFO("device response after %dms\n", rc); |
| 3506 | |
| 3507 | /* ack fw init done interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3508 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3509 | |
| 3510 | /* read eeprom data and initialize the eeprom region of sram */ |
| 3511 | priv->eeprom_delay = 1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3512 | ipw_eeprom_init_sram(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3513 | |
| 3514 | /* enable interrupts */ |
| 3515 | ipw_enable_interrupts(priv); |
| 3516 | |
| 3517 | /* Ensure our queue has valid packets */ |
| 3518 | ipw_rx_queue_replenish(priv); |
| 3519 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3520 | ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3521 | |
| 3522 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3523 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3524 | |
| 3525 | #ifndef CONFIG_PM |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3526 | release_firmware(raw); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3527 | #endif |
| 3528 | return 0; |
| 3529 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3530 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3531 | if (priv->rxq) { |
| 3532 | ipw_rx_queue_free(priv, priv->rxq); |
| 3533 | priv->rxq = NULL; |
| 3534 | } |
| 3535 | ipw_tx_queue_free(priv); |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3536 | if (raw) |
| 3537 | release_firmware(raw); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3538 | #ifdef CONFIG_PM |
| 3539 | fw_loaded = 0; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3540 | raw = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3541 | #endif |
| 3542 | |
| 3543 | return rc; |
| 3544 | } |
| 3545 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3546 | /** |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3547 | * DMA services |
| 3548 | * |
| 3549 | * Theory of operation |
| 3550 | * |
| 3551 | * A queue is a circular buffers with 'Read' and 'Write' pointers. |
| 3552 | * 2 empty entries always kept in the buffer to protect from overflow. |
| 3553 | * |
| 3554 | * 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] | 3555 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 3556 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3557 | * Tx queue resumed. |
| 3558 | * |
| 3559 | * The IPW operates with six queues, one receive queue in the device's |
| 3560 | * sram, one transmit queue for sending commands to the device firmware, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3561 | * and four transmit queues for data. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3562 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3563 | * The four transmit queues allow for performing quality of service (qos) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3564 | * transmissions as per the 802.11 protocol. Currently Linux does not |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3565 | * provide a mechanism to the user for utilizing prioritized queues, so |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3566 | * we only utilize the first data transmit queue (queue1). |
| 3567 | */ |
| 3568 | |
| 3569 | /** |
| 3570 | * Driver allocates buffers of this size for Rx |
| 3571 | */ |
| 3572 | |
| 3573 | static inline int ipw_queue_space(const struct clx2_queue *q) |
| 3574 | { |
| 3575 | int s = q->last_used - q->first_empty; |
| 3576 | if (s <= 0) |
| 3577 | s += q->n_bd; |
| 3578 | s -= 2; /* keep some reserve to not confuse empty and full situations */ |
| 3579 | if (s < 0) |
| 3580 | s = 0; |
| 3581 | return s; |
| 3582 | } |
| 3583 | |
| 3584 | static inline int ipw_queue_inc_wrap(int index, int n_bd) |
| 3585 | { |
| 3586 | return (++index == n_bd) ? 0 : index; |
| 3587 | } |
| 3588 | |
| 3589 | /** |
| 3590 | * Initialize common DMA queue structure |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3591 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3592 | * @param q queue to init |
| 3593 | * @param count Number of BD's to allocate. Should be power of 2 |
| 3594 | * @param read_register Address for 'read' register |
| 3595 | * (not offset within BAR, full address) |
| 3596 | * @param write_register Address for 'write' register |
| 3597 | * (not offset within BAR, full address) |
| 3598 | * @param base_register Address for 'base' register |
| 3599 | * (not offset within BAR, full address) |
| 3600 | * @param size Address for 'size' register |
| 3601 | * (not offset within BAR, full address) |
| 3602 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3603 | 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] | 3604 | int count, u32 read, u32 write, u32 base, u32 size) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3605 | { |
| 3606 | q->n_bd = count; |
| 3607 | |
| 3608 | q->low_mark = q->n_bd / 4; |
| 3609 | if (q->low_mark < 4) |
| 3610 | q->low_mark = 4; |
| 3611 | |
| 3612 | q->high_mark = q->n_bd / 8; |
| 3613 | if (q->high_mark < 2) |
| 3614 | q->high_mark = 2; |
| 3615 | |
| 3616 | q->first_empty = q->last_used = 0; |
| 3617 | q->reg_r = read; |
| 3618 | q->reg_w = write; |
| 3619 | |
| 3620 | ipw_write32(priv, base, q->dma_addr); |
| 3621 | ipw_write32(priv, size, count); |
| 3622 | ipw_write32(priv, read, 0); |
| 3623 | ipw_write32(priv, write, 0); |
| 3624 | |
| 3625 | _ipw_read32(priv, 0x90); |
| 3626 | } |
| 3627 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3628 | static int ipw_queue_tx_init(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3629 | struct clx2_tx_queue *q, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3630 | int count, u32 read, u32 write, u32 base, u32 size) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3631 | { |
| 3632 | struct pci_dev *dev = priv->pci_dev; |
| 3633 | |
| 3634 | q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL); |
| 3635 | if (!q->txb) { |
| 3636 | IPW_ERROR("vmalloc for auxilary BD structures failed\n"); |
| 3637 | return -ENOMEM; |
| 3638 | } |
| 3639 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3640 | q->bd = |
| 3641 | 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] | 3642 | if (!q->bd) { |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 3643 | IPW_ERROR("pci_alloc_consistent(%zd) failed\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3644 | sizeof(q->bd[0]) * count); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3645 | kfree(q->txb); |
| 3646 | q->txb = NULL; |
| 3647 | return -ENOMEM; |
| 3648 | } |
| 3649 | |
| 3650 | ipw_queue_init(priv, &q->q, count, read, write, base, size); |
| 3651 | return 0; |
| 3652 | } |
| 3653 | |
| 3654 | /** |
| 3655 | * Free one TFD, those at index [txq->q.last_used]. |
| 3656 | * Do NOT advance any indexes |
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 | * @param dev |
| 3659 | * @param txq |
| 3660 | */ |
| 3661 | static void ipw_queue_tx_free_tfd(struct ipw_priv *priv, |
| 3662 | struct clx2_tx_queue *txq) |
| 3663 | { |
| 3664 | struct tfd_frame *bd = &txq->bd[txq->q.last_used]; |
| 3665 | struct pci_dev *dev = priv->pci_dev; |
| 3666 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3667 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3668 | /* classify bd */ |
| 3669 | if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE) |
| 3670 | /* nothing to cleanup after for host commands */ |
| 3671 | return; |
| 3672 | |
| 3673 | /* sanity check */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3674 | if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) { |
| 3675 | IPW_ERROR("Too many chunks: %i\n", |
| 3676 | le32_to_cpu(bd->u.data.num_chunks)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3677 | /** @todo issue fatal error, it is quite serious situation */ |
| 3678 | return; |
| 3679 | } |
| 3680 | |
| 3681 | /* unmap chunks if any */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3682 | for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) { |
| 3683 | pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]), |
| 3684 | le16_to_cpu(bd->u.data.chunk_len[i]), |
| 3685 | PCI_DMA_TODEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3686 | if (txq->txb[txq->q.last_used]) { |
| 3687 | ieee80211_txb_free(txq->txb[txq->q.last_used]); |
| 3688 | txq->txb[txq->q.last_used] = NULL; |
| 3689 | } |
| 3690 | } |
| 3691 | } |
| 3692 | |
| 3693 | /** |
| 3694 | * Deallocate DMA queue. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3695 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3696 | * Empty queue by removing and destroying all BD's. |
| 3697 | * Free all buffers. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3698 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3699 | * @param dev |
| 3700 | * @param q |
| 3701 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3702 | 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] | 3703 | { |
| 3704 | struct clx2_queue *q = &txq->q; |
| 3705 | struct pci_dev *dev = priv->pci_dev; |
| 3706 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3707 | if (q->n_bd == 0) |
| 3708 | return; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3709 | |
| 3710 | /* first, empty all BD's */ |
| 3711 | for (; q->first_empty != q->last_used; |
| 3712 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { |
| 3713 | ipw_queue_tx_free_tfd(priv, txq); |
| 3714 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3715 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3716 | /* free buffers belonging to queue itself */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3717 | 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] | 3718 | q->dma_addr); |
| 3719 | kfree(txq->txb); |
| 3720 | |
| 3721 | /* 0 fill whole structure */ |
| 3722 | memset(txq, 0, sizeof(*txq)); |
| 3723 | } |
| 3724 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3725 | /** |
| 3726 | * Destroy all DMA queues and structures |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3727 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3728 | * @param priv |
| 3729 | */ |
| 3730 | static void ipw_tx_queue_free(struct ipw_priv *priv) |
| 3731 | { |
| 3732 | /* Tx CMD queue */ |
| 3733 | ipw_queue_tx_free(priv, &priv->txq_cmd); |
| 3734 | |
| 3735 | /* Tx queues */ |
| 3736 | ipw_queue_tx_free(priv, &priv->txq[0]); |
| 3737 | ipw_queue_tx_free(priv, &priv->txq[1]); |
| 3738 | ipw_queue_tx_free(priv, &priv->txq[2]); |
| 3739 | ipw_queue_tx_free(priv, &priv->txq[3]); |
| 3740 | } |
| 3741 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3742 | static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3743 | { |
| 3744 | /* First 3 bytes are manufacturer */ |
| 3745 | bssid[0] = priv->mac_addr[0]; |
| 3746 | bssid[1] = priv->mac_addr[1]; |
| 3747 | bssid[2] = priv->mac_addr[2]; |
| 3748 | |
| 3749 | /* Last bytes are random */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3750 | get_random_bytes(&bssid[3], ETH_ALEN - 3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3751 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3752 | bssid[0] &= 0xfe; /* clear multicast bit */ |
| 3753 | bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3754 | } |
| 3755 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3756 | static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3757 | { |
| 3758 | struct ipw_station_entry entry; |
| 3759 | int i; |
| 3760 | |
| 3761 | for (i = 0; i < priv->num_stations; i++) { |
| 3762 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) { |
| 3763 | /* Another node is active in network */ |
| 3764 | priv->missed_adhoc_beacons = 0; |
| 3765 | if (!(priv->config & CFG_STATIC_CHANNEL)) |
| 3766 | /* when other nodes drop out, we drop out */ |
| 3767 | priv->config &= ~CFG_ADHOC_PERSIST; |
| 3768 | |
| 3769 | return i; |
| 3770 | } |
| 3771 | } |
| 3772 | |
| 3773 | if (i == MAX_STATIONS) |
| 3774 | return IPW_INVALID_STATION; |
| 3775 | |
| 3776 | IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid)); |
| 3777 | |
| 3778 | entry.reserved = 0; |
| 3779 | entry.support_mode = 0; |
| 3780 | memcpy(entry.mac_addr, bssid, ETH_ALEN); |
| 3781 | memcpy(priv->stations[i], bssid, ETH_ALEN); |
| 3782 | ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3783 | &entry, sizeof(entry)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3784 | priv->num_stations++; |
| 3785 | |
| 3786 | return i; |
| 3787 | } |
| 3788 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3789 | static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3790 | { |
| 3791 | int i; |
| 3792 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3793 | for (i = 0; i < priv->num_stations; i++) |
| 3794 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3795 | return i; |
| 3796 | |
| 3797 | return IPW_INVALID_STATION; |
| 3798 | } |
| 3799 | |
| 3800 | static void ipw_send_disassociate(struct ipw_priv *priv, int quiet) |
| 3801 | { |
| 3802 | int err; |
| 3803 | |
Hong Liu | 7b99659 | 2005-08-25 17:36:13 +0800 | [diff] [blame] | 3804 | if (priv->status & STATUS_ASSOCIATING) { |
| 3805 | IPW_DEBUG_ASSOC("Disassociating while associating.\n"); |
| 3806 | queue_work(priv->workqueue, &priv->disassociate); |
| 3807 | return; |
| 3808 | } |
| 3809 | |
| 3810 | if (!(priv->status & STATUS_ASSOCIATED)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3811 | IPW_DEBUG_ASSOC("Disassociating while not associated.\n"); |
| 3812 | return; |
| 3813 | } |
| 3814 | |
| 3815 | IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " " |
| 3816 | "on channel %d.\n", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3817 | MAC_ARG(priv->assoc_request.bssid), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3818 | priv->assoc_request.channel); |
| 3819 | |
| 3820 | priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED); |
| 3821 | priv->status |= STATUS_DISASSOCIATING; |
| 3822 | |
| 3823 | if (quiet) |
| 3824 | priv->assoc_request.assoc_type = HC_DISASSOC_QUIET; |
| 3825 | else |
| 3826 | priv->assoc_request.assoc_type = HC_DISASSOCIATE; |
Hong Liu | e632472 | 2005-09-14 21:04:15 -0500 | [diff] [blame] | 3827 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3828 | err = ipw_send_associate(priv, &priv->assoc_request); |
| 3829 | if (err) { |
| 3830 | IPW_DEBUG_HC("Attempt to send [dis]associate command " |
| 3831 | "failed.\n"); |
| 3832 | return; |
| 3833 | } |
| 3834 | |
| 3835 | } |
| 3836 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3837 | static int ipw_disassociate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3838 | { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3839 | struct ipw_priv *priv = data; |
| 3840 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) |
| 3841 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3842 | ipw_send_disassociate(data, 0); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3843 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3844 | } |
| 3845 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3846 | static void ipw_bg_disassociate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3847 | { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3848 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 3849 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3850 | ipw_disassociate(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 3851 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3852 | } |
| 3853 | |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 3854 | static void ipw_system_config(void *data) |
| 3855 | { |
| 3856 | struct ipw_priv *priv = data; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 3857 | |
| 3858 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 3859 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) { |
| 3860 | priv->sys_config.accept_all_data_frames = 1; |
| 3861 | priv->sys_config.accept_non_directed_frames = 1; |
| 3862 | priv->sys_config.accept_all_mgmt_bcpr = 1; |
| 3863 | priv->sys_config.accept_all_mgmt_frames = 1; |
| 3864 | } |
| 3865 | #endif |
| 3866 | |
| 3867 | ipw_send_system_config(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3868 | } |
| 3869 | |
| 3870 | struct ipw_status_code { |
| 3871 | u16 status; |
| 3872 | const char *reason; |
| 3873 | }; |
| 3874 | |
| 3875 | static const struct ipw_status_code ipw_status_codes[] = { |
| 3876 | {0x00, "Successful"}, |
| 3877 | {0x01, "Unspecified failure"}, |
| 3878 | {0x0A, "Cannot support all requested capabilities in the " |
| 3879 | "Capability information field"}, |
| 3880 | {0x0B, "Reassociation denied due to inability to confirm that " |
| 3881 | "association exists"}, |
| 3882 | {0x0C, "Association denied due to reason outside the scope of this " |
| 3883 | "standard"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3884 | {0x0D, |
| 3885 | "Responding station does not support the specified authentication " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3886 | "algorithm"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3887 | {0x0E, |
| 3888 | "Received an Authentication frame with authentication sequence " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3889 | "transaction sequence number out of expected sequence"}, |
| 3890 | {0x0F, "Authentication rejected because of challenge failure"}, |
| 3891 | {0x10, "Authentication rejected due to timeout waiting for next " |
| 3892 | "frame in sequence"}, |
| 3893 | {0x11, "Association denied because AP is unable to handle additional " |
| 3894 | "associated stations"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3895 | {0x12, |
| 3896 | "Association denied due to requesting station not supporting all " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3897 | "of the datarates in the BSSBasicServiceSet Parameter"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3898 | {0x13, |
| 3899 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3900 | "short preamble operation"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3901 | {0x14, |
| 3902 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3903 | "PBCC encoding"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3904 | {0x15, |
| 3905 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3906 | "channel agility"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3907 | {0x19, |
| 3908 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3909 | "short slot operation"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3910 | {0x1A, |
| 3911 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3912 | "DSSS-OFDM operation"}, |
| 3913 | {0x28, "Invalid Information Element"}, |
| 3914 | {0x29, "Group Cipher is not valid"}, |
| 3915 | {0x2A, "Pairwise Cipher is not valid"}, |
| 3916 | {0x2B, "AKMP is not valid"}, |
| 3917 | {0x2C, "Unsupported RSN IE version"}, |
| 3918 | {0x2D, "Invalid RSN IE Capabilities"}, |
| 3919 | {0x2E, "Cipher suite is rejected per security policy"}, |
| 3920 | }; |
| 3921 | |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 3922 | #ifdef CONFIG_IPW2200_DEBUG |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3923 | static const char *ipw_get_status_code(u16 status) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3924 | { |
| 3925 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3926 | for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 3927 | if (ipw_status_codes[i].status == (status & 0xff)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3928 | return ipw_status_codes[i].reason; |
| 3929 | return "Unknown status value."; |
| 3930 | } |
| 3931 | #endif |
| 3932 | |
| 3933 | static void inline average_init(struct average *avg) |
| 3934 | { |
| 3935 | memset(avg, 0, sizeof(*avg)); |
| 3936 | } |
| 3937 | |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 3938 | #define DEPTH_RSSI 8 |
| 3939 | #define DEPTH_NOISE 16 |
| 3940 | static s16 exponential_average(s16 prev_avg, s16 val, u8 depth) |
| 3941 | { |
| 3942 | return ((depth-1)*prev_avg + val)/depth; |
| 3943 | } |
| 3944 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3945 | static void average_add(struct average *avg, s16 val) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3946 | { |
| 3947 | avg->sum -= avg->entries[avg->pos]; |
| 3948 | avg->sum += val; |
| 3949 | avg->entries[avg->pos++] = val; |
| 3950 | if (unlikely(avg->pos == AVG_ENTRIES)) { |
| 3951 | avg->init = 1; |
| 3952 | avg->pos = 0; |
| 3953 | } |
| 3954 | } |
| 3955 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3956 | static s16 average_value(struct average *avg) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3957 | { |
| 3958 | if (!unlikely(avg->init)) { |
| 3959 | if (avg->pos) |
| 3960 | return avg->sum / avg->pos; |
| 3961 | return 0; |
| 3962 | } |
| 3963 | |
| 3964 | return avg->sum / AVG_ENTRIES; |
| 3965 | } |
| 3966 | |
| 3967 | static void ipw_reset_stats(struct ipw_priv *priv) |
| 3968 | { |
| 3969 | u32 len = sizeof(u32); |
| 3970 | |
| 3971 | priv->quality = 0; |
| 3972 | |
| 3973 | average_init(&priv->average_missed_beacons); |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 3974 | priv->exp_avg_rssi = -60; |
| 3975 | priv->exp_avg_noise = -85 + 0x100; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3976 | |
| 3977 | priv->last_rate = 0; |
| 3978 | priv->last_missed_beacons = 0; |
| 3979 | priv->last_rx_packets = 0; |
| 3980 | priv->last_tx_packets = 0; |
| 3981 | priv->last_tx_failures = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3982 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3983 | /* Firmware managed, reset only when NIC is restarted, so we have to |
| 3984 | * normalize on the current value */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3985 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3986 | &priv->last_rx_err, &len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3987 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3988 | &priv->last_tx_failures, &len); |
| 3989 | |
| 3990 | /* Driver managed, reset with each association */ |
| 3991 | priv->missed_adhoc_beacons = 0; |
| 3992 | priv->missed_beacons = 0; |
| 3993 | priv->tx_packets = 0; |
| 3994 | priv->rx_packets = 0; |
| 3995 | |
| 3996 | } |
| 3997 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3998 | static u32 ipw_get_max_rate(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3999 | { |
| 4000 | u32 i = 0x80000000; |
| 4001 | u32 mask = priv->rates_mask; |
| 4002 | /* If currently associated in B mode, restrict the maximum |
| 4003 | * rate match to B rates */ |
| 4004 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) |
| 4005 | mask &= IEEE80211_CCK_RATES_MASK; |
| 4006 | |
| 4007 | /* TODO: Verify that the rate is supported by the current rates |
| 4008 | * list. */ |
| 4009 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4010 | while (i && !(mask & i)) |
| 4011 | i >>= 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4012 | switch (i) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4013 | case IEEE80211_CCK_RATE_1MB_MASK: |
| 4014 | return 1000000; |
| 4015 | case IEEE80211_CCK_RATE_2MB_MASK: |
| 4016 | return 2000000; |
| 4017 | case IEEE80211_CCK_RATE_5MB_MASK: |
| 4018 | return 5500000; |
| 4019 | case IEEE80211_OFDM_RATE_6MB_MASK: |
| 4020 | return 6000000; |
| 4021 | case IEEE80211_OFDM_RATE_9MB_MASK: |
| 4022 | return 9000000; |
| 4023 | case IEEE80211_CCK_RATE_11MB_MASK: |
| 4024 | return 11000000; |
| 4025 | case IEEE80211_OFDM_RATE_12MB_MASK: |
| 4026 | return 12000000; |
| 4027 | case IEEE80211_OFDM_RATE_18MB_MASK: |
| 4028 | return 18000000; |
| 4029 | case IEEE80211_OFDM_RATE_24MB_MASK: |
| 4030 | return 24000000; |
| 4031 | case IEEE80211_OFDM_RATE_36MB_MASK: |
| 4032 | return 36000000; |
| 4033 | case IEEE80211_OFDM_RATE_48MB_MASK: |
| 4034 | return 48000000; |
| 4035 | case IEEE80211_OFDM_RATE_54MB_MASK: |
| 4036 | return 54000000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4037 | } |
| 4038 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4039 | if (priv->ieee->mode == IEEE_B) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4040 | return 11000000; |
| 4041 | else |
| 4042 | return 54000000; |
| 4043 | } |
| 4044 | |
| 4045 | static u32 ipw_get_current_rate(struct ipw_priv *priv) |
| 4046 | { |
| 4047 | u32 rate, len = sizeof(rate); |
| 4048 | int err; |
| 4049 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4050 | if (!(priv->status & STATUS_ASSOCIATED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4051 | return 0; |
| 4052 | |
| 4053 | if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4054 | err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4055 | &len); |
| 4056 | if (err) { |
| 4057 | IPW_DEBUG_INFO("failed querying ordinals.\n"); |
| 4058 | return 0; |
| 4059 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4060 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4061 | return ipw_get_max_rate(priv); |
| 4062 | |
| 4063 | switch (rate) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4064 | case IPW_TX_RATE_1MB: |
| 4065 | return 1000000; |
| 4066 | case IPW_TX_RATE_2MB: |
| 4067 | return 2000000; |
| 4068 | case IPW_TX_RATE_5MB: |
| 4069 | return 5500000; |
| 4070 | case IPW_TX_RATE_6MB: |
| 4071 | return 6000000; |
| 4072 | case IPW_TX_RATE_9MB: |
| 4073 | return 9000000; |
| 4074 | case IPW_TX_RATE_11MB: |
| 4075 | return 11000000; |
| 4076 | case IPW_TX_RATE_12MB: |
| 4077 | return 12000000; |
| 4078 | case IPW_TX_RATE_18MB: |
| 4079 | return 18000000; |
| 4080 | case IPW_TX_RATE_24MB: |
| 4081 | return 24000000; |
| 4082 | case IPW_TX_RATE_36MB: |
| 4083 | return 36000000; |
| 4084 | case IPW_TX_RATE_48MB: |
| 4085 | return 48000000; |
| 4086 | case IPW_TX_RATE_54MB: |
| 4087 | return 54000000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4088 | } |
| 4089 | |
| 4090 | return 0; |
| 4091 | } |
| 4092 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4093 | #define IPW_STATS_INTERVAL (2 * HZ) |
| 4094 | static void ipw_gather_stats(struct ipw_priv *priv) |
| 4095 | { |
| 4096 | u32 rx_err, rx_err_delta, rx_packets_delta; |
| 4097 | u32 tx_failures, tx_failures_delta, tx_packets_delta; |
| 4098 | u32 missed_beacons_percent, missed_beacons_delta; |
| 4099 | u32 quality = 0; |
| 4100 | u32 len = sizeof(u32); |
| 4101 | s16 rssi; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4102 | u32 beacon_quality, signal_quality, tx_quality, rx_quality, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4103 | rate_quality; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4104 | u32 max_rate; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4105 | |
| 4106 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 4107 | priv->quality = 0; |
| 4108 | return; |
| 4109 | } |
| 4110 | |
| 4111 | /* Update the statistics */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4112 | ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4113 | &priv->missed_beacons, &len); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4114 | missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4115 | priv->last_missed_beacons = priv->missed_beacons; |
| 4116 | if (priv->assoc_request.beacon_interval) { |
| 4117 | missed_beacons_percent = missed_beacons_delta * |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4118 | (HZ * priv->assoc_request.beacon_interval) / |
| 4119 | (IPW_STATS_INTERVAL * 10); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4120 | } else { |
| 4121 | missed_beacons_percent = 0; |
| 4122 | } |
| 4123 | average_add(&priv->average_missed_beacons, missed_beacons_percent); |
| 4124 | |
| 4125 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len); |
| 4126 | rx_err_delta = rx_err - priv->last_rx_err; |
| 4127 | priv->last_rx_err = rx_err; |
| 4128 | |
| 4129 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len); |
| 4130 | tx_failures_delta = tx_failures - priv->last_tx_failures; |
| 4131 | priv->last_tx_failures = tx_failures; |
| 4132 | |
| 4133 | rx_packets_delta = priv->rx_packets - priv->last_rx_packets; |
| 4134 | priv->last_rx_packets = priv->rx_packets; |
| 4135 | |
| 4136 | tx_packets_delta = priv->tx_packets - priv->last_tx_packets; |
| 4137 | priv->last_tx_packets = priv->tx_packets; |
| 4138 | |
| 4139 | /* Calculate quality based on the following: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4140 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4141 | * Missed beacon: 100% = 0, 0% = 70% missed |
| 4142 | * Rate: 60% = 1Mbs, 100% = Max |
| 4143 | * Rx and Tx errors represent a straight % of total Rx/Tx |
| 4144 | * RSSI: 100% = > -50, 0% = < -80 |
| 4145 | * Rx errors: 100% = 0, 0% = 50% missed |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4146 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4147 | * The lowest computed quality is used. |
| 4148 | * |
| 4149 | */ |
| 4150 | #define BEACON_THRESHOLD 5 |
| 4151 | beacon_quality = 100 - missed_beacons_percent; |
| 4152 | if (beacon_quality < BEACON_THRESHOLD) |
| 4153 | beacon_quality = 0; |
| 4154 | else |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4155 | beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4156 | (100 - BEACON_THRESHOLD); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4157 | IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4158 | beacon_quality, missed_beacons_percent); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4159 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4160 | priv->last_rate = ipw_get_current_rate(priv); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4161 | max_rate = ipw_get_max_rate(priv); |
| 4162 | rate_quality = priv->last_rate * 40 / max_rate + 60; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4163 | IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n", |
| 4164 | rate_quality, priv->last_rate / 1000000); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4165 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4166 | if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4167 | rx_quality = 100 - (rx_err_delta * 100) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4168 | (rx_packets_delta + rx_err_delta); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4169 | else |
| 4170 | rx_quality = 100; |
| 4171 | IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n", |
| 4172 | rx_quality, rx_err_delta, rx_packets_delta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4173 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4174 | if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4175 | tx_quality = 100 - (tx_failures_delta * 100) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4176 | (tx_packets_delta + tx_failures_delta); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4177 | else |
| 4178 | tx_quality = 100; |
| 4179 | IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n", |
| 4180 | tx_quality, tx_failures_delta, tx_packets_delta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4181 | |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 4182 | rssi = priv->exp_avg_rssi; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4183 | signal_quality = |
| 4184 | (100 * |
| 4185 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * |
| 4186 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) - |
| 4187 | (priv->ieee->perfect_rssi - rssi) * |
| 4188 | (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) + |
| 4189 | 62 * (priv->ieee->perfect_rssi - rssi))) / |
| 4190 | ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * |
| 4191 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi)); |
| 4192 | if (signal_quality > 100) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4193 | signal_quality = 100; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4194 | else if (signal_quality < 1) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4195 | signal_quality = 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4196 | |
Zhu Yi | 61fb9ed | 2006-04-13 17:19:55 +0800 | [diff] [blame] | 4197 | IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4198 | signal_quality, rssi); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4199 | |
| 4200 | quality = min(beacon_quality, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4201 | min(rate_quality, |
| 4202 | min(tx_quality, min(rx_quality, signal_quality)))); |
| 4203 | if (quality == beacon_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4204 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n", |
| 4205 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4206 | if (quality == rate_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4207 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n", |
| 4208 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4209 | if (quality == tx_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4210 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n", |
| 4211 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4212 | if (quality == rx_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4213 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n", |
| 4214 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4215 | if (quality == signal_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4216 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n", |
| 4217 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4218 | |
| 4219 | priv->quality = quality; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4220 | |
| 4221 | queue_delayed_work(priv->workqueue, &priv->gather_stats, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4222 | IPW_STATS_INTERVAL); |
| 4223 | } |
| 4224 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4225 | static void ipw_bg_gather_stats(void *data) |
| 4226 | { |
| 4227 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 4228 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4229 | ipw_gather_stats(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 4230 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4231 | } |
| 4232 | |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4233 | /* Missed beacon behavior: |
| 4234 | * 1st missed -> roaming_threshold, just wait, don't do any scan/roam. |
| 4235 | * roaming_threshold -> disassociate_threshold, scan and roam for better signal. |
| 4236 | * Above disassociate threshold, give up and stop scanning. |
| 4237 | * Roaming is disabled if disassociate_threshold <= roaming_threshold */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4238 | static void ipw_handle_missed_beacon(struct ipw_priv *priv, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4239 | int missed_count) |
| 4240 | { |
| 4241 | priv->notif_missed_beacons = missed_count; |
| 4242 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4243 | if (missed_count > priv->disassociate_threshold && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4244 | priv->status & STATUS_ASSOCIATED) { |
| 4245 | /* If associated and we've hit the missed |
| 4246 | * beacon threshold, disassociate, turn |
| 4247 | * off roaming, and abort any active scans */ |
| 4248 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4249 | IPW_DL_STATE | IPW_DL_ASSOC, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4250 | "Missed beacon: %d - disassociate\n", missed_count); |
| 4251 | priv->status &= ~STATUS_ROAMING; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4252 | if (priv->status & STATUS_SCANNING) { |
| 4253 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
| 4254 | IPW_DL_STATE, |
| 4255 | "Aborting scan with missed beacon.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4256 | queue_work(priv->workqueue, &priv->abort_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4257 | } |
| 4258 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4259 | queue_work(priv->workqueue, &priv->disassociate); |
| 4260 | return; |
| 4261 | } |
| 4262 | |
| 4263 | if (priv->status & STATUS_ROAMING) { |
| 4264 | /* If we are currently roaming, then just |
| 4265 | * print a debug statement... */ |
| 4266 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4267 | "Missed beacon: %d - roam in progress\n", |
| 4268 | missed_count); |
| 4269 | return; |
| 4270 | } |
| 4271 | |
Zhu Yi | 4bfdb91 | 2006-01-24 16:37:16 +0800 | [diff] [blame] | 4272 | if (roaming && |
| 4273 | (missed_count > priv->roaming_threshold && |
| 4274 | missed_count <= priv->disassociate_threshold)) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4275 | /* If we are not already roaming, set the ROAM |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4276 | * bit in the status and kick off a scan. |
| 4277 | * This can happen several times before we reach |
| 4278 | * disassociate_threshold. */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4279 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4280 | "Missed beacon: %d - initiate " |
| 4281 | "roaming\n", missed_count); |
| 4282 | if (!(priv->status & STATUS_ROAMING)) { |
| 4283 | priv->status |= STATUS_ROAMING; |
| 4284 | if (!(priv->status & STATUS_SCANNING)) |
| 4285 | queue_work(priv->workqueue, |
| 4286 | &priv->request_scan); |
| 4287 | } |
| 4288 | return; |
| 4289 | } |
| 4290 | |
| 4291 | if (priv->status & STATUS_SCANNING) { |
| 4292 | /* Stop scan to keep fw from getting |
| 4293 | * stuck (only if we aren't roaming -- |
| 4294 | * otherwise we'll never scan more than 2 or 3 |
| 4295 | * channels..) */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4296 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE, |
| 4297 | "Aborting scan with missed beacon.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4298 | queue_work(priv->workqueue, &priv->abort_scan); |
| 4299 | } |
| 4300 | |
| 4301 | IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4302 | } |
| 4303 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4304 | /** |
| 4305 | * Handle host notification packet. |
| 4306 | * Called from interrupt routine |
| 4307 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4308 | static void ipw_rx_notification(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4309 | struct ipw_rx_notification *notif) |
| 4310 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4311 | notif->size = le16_to_cpu(notif->size); |
| 4312 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4313 | IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4314 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4315 | switch (notif->subtype) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4316 | case HOST_NOTIFICATION_STATUS_ASSOCIATED:{ |
| 4317 | struct notif_association *assoc = ¬if->u.assoc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4318 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4319 | switch (assoc->state) { |
| 4320 | case CMAS_ASSOCIATED:{ |
| 4321 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4322 | IPW_DL_ASSOC, |
| 4323 | "associated: '%s' " MAC_FMT |
| 4324 | " \n", |
| 4325 | escape_essid(priv->essid, |
| 4326 | priv->essid_len), |
| 4327 | MAC_ARG(priv->bssid)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4328 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4329 | switch (priv->ieee->iw_mode) { |
| 4330 | case IW_MODE_INFRA: |
| 4331 | memcpy(priv->ieee->bssid, |
| 4332 | priv->bssid, ETH_ALEN); |
| 4333 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4334 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4335 | case IW_MODE_ADHOC: |
| 4336 | memcpy(priv->ieee->bssid, |
| 4337 | priv->bssid, ETH_ALEN); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4338 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4339 | /* clear out the station table */ |
| 4340 | priv->num_stations = 0; |
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 | IPW_DEBUG_ASSOC |
| 4343 | ("queueing adhoc check\n"); |
| 4344 | queue_delayed_work(priv-> |
| 4345 | workqueue, |
| 4346 | &priv-> |
| 4347 | adhoc_check, |
| 4348 | priv-> |
| 4349 | assoc_request. |
| 4350 | beacon_interval); |
| 4351 | break; |
| 4352 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4353 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4354 | priv->status &= ~STATUS_ASSOCIATING; |
| 4355 | priv->status |= STATUS_ASSOCIATED; |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 4356 | queue_work(priv->workqueue, |
| 4357 | &priv->system_config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4358 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 4359 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4360 | #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \ |
| 4361 | le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl)) |
| 4362 | if ((priv->status & STATUS_AUTH) && |
| 4363 | (IPW_GET_PACKET_STYPE(¬if->u.raw) |
| 4364 | == IEEE80211_STYPE_ASSOC_RESP)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4365 | if ((sizeof |
| 4366 | (struct |
James Ketrenos | 2b184d5 | 2005-08-03 20:33:14 -0500 | [diff] [blame] | 4367 | ieee80211_assoc_response) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4368 | <= notif->size) |
| 4369 | && (notif->size <= 2314)) { |
| 4370 | struct |
| 4371 | ieee80211_rx_stats |
| 4372 | stats = { |
| 4373 | .len = |
| 4374 | notif-> |
| 4375 | size - 1, |
| 4376 | }; |
| 4377 | |
| 4378 | IPW_DEBUG_QOS |
| 4379 | ("QoS Associate " |
| 4380 | "size %d\n", |
| 4381 | notif->size); |
| 4382 | ieee80211_rx_mgt(priv-> |
| 4383 | ieee, |
| 4384 | (struct |
James Ketrenos | 2b184d5 | 2005-08-03 20:33:14 -0500 | [diff] [blame] | 4385 | ieee80211_hdr_4addr |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4386 | *) |
| 4387 | ¬if->u.raw, &stats); |
| 4388 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4389 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4390 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4391 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4392 | schedule_work(&priv->link_up); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4393 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4394 | break; |
| 4395 | } |
| 4396 | |
| 4397 | case CMAS_AUTHENTICATED:{ |
| 4398 | if (priv-> |
| 4399 | status & (STATUS_ASSOCIATED | |
| 4400 | STATUS_AUTH)) { |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 4401 | #ifdef CONFIG_IPW2200_DEBUG |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4402 | struct notif_authenticate *auth |
| 4403 | = ¬if->u.auth; |
| 4404 | IPW_DEBUG(IPW_DL_NOTIF | |
| 4405 | IPW_DL_STATE | |
| 4406 | IPW_DL_ASSOC, |
| 4407 | "deauthenticated: '%s' " |
| 4408 | MAC_FMT |
| 4409 | ": (0x%04X) - %s \n", |
| 4410 | escape_essid(priv-> |
| 4411 | essid, |
| 4412 | priv-> |
| 4413 | essid_len), |
| 4414 | MAC_ARG(priv->bssid), |
| 4415 | ntohs(auth->status), |
| 4416 | ipw_get_status_code |
| 4417 | (ntohs |
| 4418 | (auth->status))); |
| 4419 | #endif |
| 4420 | |
| 4421 | priv->status &= |
| 4422 | ~(STATUS_ASSOCIATING | |
| 4423 | STATUS_AUTH | |
| 4424 | STATUS_ASSOCIATED); |
| 4425 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4426 | schedule_work(&priv->link_down); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4427 | break; |
| 4428 | } |
| 4429 | |
| 4430 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4431 | IPW_DL_ASSOC, |
| 4432 | "authenticated: '%s' " MAC_FMT |
| 4433 | "\n", |
| 4434 | escape_essid(priv->essid, |
| 4435 | priv->essid_len), |
| 4436 | MAC_ARG(priv->bssid)); |
| 4437 | break; |
| 4438 | } |
| 4439 | |
| 4440 | case CMAS_INIT:{ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4441 | if (priv->status & STATUS_AUTH) { |
| 4442 | struct |
| 4443 | ieee80211_assoc_response |
| 4444 | *resp; |
| 4445 | resp = |
| 4446 | (struct |
| 4447 | ieee80211_assoc_response |
| 4448 | *)¬if->u.raw; |
| 4449 | IPW_DEBUG(IPW_DL_NOTIF | |
| 4450 | IPW_DL_STATE | |
| 4451 | IPW_DL_ASSOC, |
| 4452 | "association failed (0x%04X): %s\n", |
| 4453 | ntohs(resp->status), |
| 4454 | ipw_get_status_code |
| 4455 | (ntohs |
| 4456 | (resp->status))); |
| 4457 | } |
| 4458 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4459 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4460 | IPW_DL_ASSOC, |
| 4461 | "disassociated: '%s' " MAC_FMT |
| 4462 | " \n", |
| 4463 | escape_essid(priv->essid, |
| 4464 | priv->essid_len), |
| 4465 | MAC_ARG(priv->bssid)); |
| 4466 | |
| 4467 | priv->status &= |
| 4468 | ~(STATUS_DISASSOCIATING | |
| 4469 | STATUS_ASSOCIATING | |
| 4470 | STATUS_ASSOCIATED | STATUS_AUTH); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4471 | if (priv->assoc_network |
| 4472 | && (priv->assoc_network-> |
| 4473 | capability & |
| 4474 | WLAN_CAPABILITY_IBSS)) |
| 4475 | ipw_remove_current_network |
| 4476 | (priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4477 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4478 | schedule_work(&priv->link_down); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4479 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4480 | break; |
| 4481 | } |
| 4482 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4483 | case CMAS_RX_ASSOC_RESP: |
| 4484 | break; |
| 4485 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4486 | default: |
| 4487 | IPW_ERROR("assoc: unknown (%d)\n", |
| 4488 | assoc->state); |
| 4489 | break; |
| 4490 | } |
| 4491 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4492 | break; |
| 4493 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4494 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4495 | case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{ |
| 4496 | struct notif_authenticate *auth = ¬if->u.auth; |
| 4497 | switch (auth->state) { |
| 4498 | case CMAS_AUTHENTICATED: |
| 4499 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4500 | "authenticated: '%s' " MAC_FMT " \n", |
| 4501 | escape_essid(priv->essid, |
| 4502 | priv->essid_len), |
| 4503 | MAC_ARG(priv->bssid)); |
| 4504 | priv->status |= STATUS_AUTH; |
| 4505 | break; |
| 4506 | |
| 4507 | case CMAS_INIT: |
| 4508 | if (priv->status & STATUS_AUTH) { |
| 4509 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4510 | IPW_DL_ASSOC, |
| 4511 | "authentication failed (0x%04X): %s\n", |
| 4512 | ntohs(auth->status), |
| 4513 | ipw_get_status_code(ntohs |
| 4514 | (auth-> |
| 4515 | status))); |
| 4516 | } |
| 4517 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4518 | IPW_DL_ASSOC, |
| 4519 | "deauthenticated: '%s' " MAC_FMT "\n", |
| 4520 | escape_essid(priv->essid, |
| 4521 | priv->essid_len), |
| 4522 | MAC_ARG(priv->bssid)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4523 | |
| 4524 | priv->status &= ~(STATUS_ASSOCIATING | |
| 4525 | STATUS_AUTH | |
| 4526 | STATUS_ASSOCIATED); |
| 4527 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4528 | schedule_work(&priv->link_down); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4529 | break; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4530 | |
| 4531 | case CMAS_TX_AUTH_SEQ_1: |
| 4532 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4533 | IPW_DL_ASSOC, "AUTH_SEQ_1\n"); |
| 4534 | break; |
| 4535 | case CMAS_RX_AUTH_SEQ_2: |
| 4536 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4537 | IPW_DL_ASSOC, "AUTH_SEQ_2\n"); |
| 4538 | break; |
| 4539 | case CMAS_AUTH_SEQ_1_PASS: |
| 4540 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4541 | IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n"); |
| 4542 | break; |
| 4543 | case CMAS_AUTH_SEQ_1_FAIL: |
| 4544 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4545 | IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n"); |
| 4546 | break; |
| 4547 | case CMAS_TX_AUTH_SEQ_3: |
| 4548 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4549 | IPW_DL_ASSOC, "AUTH_SEQ_3\n"); |
| 4550 | break; |
| 4551 | case CMAS_RX_AUTH_SEQ_4: |
| 4552 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4553 | IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n"); |
| 4554 | break; |
| 4555 | case CMAS_AUTH_SEQ_2_PASS: |
| 4556 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4557 | IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n"); |
| 4558 | break; |
| 4559 | case CMAS_AUTH_SEQ_2_FAIL: |
| 4560 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4561 | IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n"); |
| 4562 | break; |
| 4563 | case CMAS_TX_ASSOC: |
| 4564 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4565 | IPW_DL_ASSOC, "TX_ASSOC\n"); |
| 4566 | break; |
| 4567 | case CMAS_RX_ASSOC_RESP: |
| 4568 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4569 | IPW_DL_ASSOC, "RX_ASSOC_RESP\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4570 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4571 | break; |
| 4572 | case CMAS_ASSOCIATED: |
| 4573 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4574 | IPW_DL_ASSOC, "ASSOCIATED\n"); |
| 4575 | break; |
| 4576 | default: |
| 4577 | IPW_DEBUG_NOTIF("auth: failure - %d\n", |
| 4578 | auth->state); |
| 4579 | break; |
| 4580 | } |
| 4581 | break; |
| 4582 | } |
| 4583 | |
| 4584 | case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{ |
| 4585 | struct notif_channel_result *x = |
| 4586 | ¬if->u.channel_result; |
| 4587 | |
| 4588 | if (notif->size == sizeof(*x)) { |
| 4589 | IPW_DEBUG_SCAN("Scan result for channel %d\n", |
| 4590 | x->channel_num); |
| 4591 | } else { |
| 4592 | IPW_DEBUG_SCAN("Scan result of wrong size %d " |
| 4593 | "(should be %zd)\n", |
| 4594 | notif->size, sizeof(*x)); |
| 4595 | } |
| 4596 | break; |
| 4597 | } |
| 4598 | |
| 4599 | case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{ |
| 4600 | struct notif_scan_complete *x = ¬if->u.scan_complete; |
| 4601 | if (notif->size == sizeof(*x)) { |
| 4602 | IPW_DEBUG_SCAN |
| 4603 | ("Scan completed: type %d, %d channels, " |
| 4604 | "%d status\n", x->scan_type, |
| 4605 | x->num_channels, x->status); |
| 4606 | } else { |
| 4607 | IPW_ERROR("Scan completed of wrong size %d " |
| 4608 | "(should be %zd)\n", |
| 4609 | notif->size, sizeof(*x)); |
| 4610 | } |
| 4611 | |
| 4612 | priv->status &= |
| 4613 | ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); |
| 4614 | |
James Ketrenos | a0e04ab | 2005-08-25 00:49:43 -0500 | [diff] [blame] | 4615 | wake_up_interruptible(&priv->wait_state); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4616 | cancel_delayed_work(&priv->scan_check); |
| 4617 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4618 | if (priv->status & STATUS_EXIT_PENDING) |
| 4619 | break; |
| 4620 | |
| 4621 | priv->ieee->scans++; |
| 4622 | |
| 4623 | #ifdef CONFIG_IPW2200_MONITOR |
| 4624 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4625 | priv->status |= STATUS_SCAN_FORCED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4626 | queue_work(priv->workqueue, |
| 4627 | &priv->request_scan); |
| 4628 | break; |
| 4629 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4630 | priv->status &= ~STATUS_SCAN_FORCED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4631 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 4632 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4633 | if (!(priv->status & (STATUS_ASSOCIATED | |
| 4634 | STATUS_ASSOCIATING | |
| 4635 | STATUS_ROAMING | |
| 4636 | STATUS_DISASSOCIATING))) |
| 4637 | queue_work(priv->workqueue, &priv->associate); |
| 4638 | else if (priv->status & STATUS_ROAMING) { |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4639 | if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) |
| 4640 | /* If a scan completed and we are in roam mode, then |
| 4641 | * the scan that completed was the one requested as a |
| 4642 | * result of entering roam... so, schedule the |
| 4643 | * roam work */ |
| 4644 | queue_work(priv->workqueue, |
| 4645 | &priv->roam); |
| 4646 | else |
| 4647 | /* Don't schedule if we aborted the scan */ |
| 4648 | priv->status &= ~STATUS_ROAMING; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4649 | } else if (priv->status & STATUS_SCAN_PENDING) |
| 4650 | queue_work(priv->workqueue, |
| 4651 | &priv->request_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4652 | else if (priv->config & CFG_BACKGROUND_SCAN |
| 4653 | && priv->status & STATUS_ASSOCIATED) |
| 4654 | queue_delayed_work(priv->workqueue, |
| 4655 | &priv->request_scan, HZ); |
Zhu Yi | 07f02e4 | 2006-04-13 17:19:25 +0800 | [diff] [blame] | 4656 | |
| 4657 | /* Send an empty event to user space. |
| 4658 | * We don't send the received data on the event because |
| 4659 | * it would require us to do complex transcoding, and |
| 4660 | * we want to minimise the work done in the irq handler |
| 4661 | * Use a request to extract the data. |
| 4662 | * Also, we generate this even for any scan, regardless |
| 4663 | * on how the scan was initiated. User space can just |
| 4664 | * sync on periodic scan to get fresh data... |
| 4665 | * Jean II */ |
| 4666 | if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) { |
| 4667 | union iwreq_data wrqu; |
| 4668 | |
| 4669 | wrqu.data.length = 0; |
| 4670 | wrqu.data.flags = 0; |
| 4671 | wireless_send_event(priv->net_dev, SIOCGIWSCAN, |
| 4672 | &wrqu, NULL); |
| 4673 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4674 | break; |
| 4675 | } |
| 4676 | |
| 4677 | case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{ |
| 4678 | struct notif_frag_length *x = ¬if->u.frag_len; |
| 4679 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4680 | if (notif->size == sizeof(*x)) |
| 4681 | IPW_ERROR("Frag length: %d\n", |
| 4682 | le16_to_cpu(x->frag_length)); |
| 4683 | else |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4684 | IPW_ERROR("Frag length of wrong size %d " |
| 4685 | "(should be %zd)\n", |
| 4686 | notif->size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4687 | break; |
| 4688 | } |
| 4689 | |
| 4690 | case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{ |
| 4691 | struct notif_link_deterioration *x = |
| 4692 | ¬if->u.link_deterioration; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4693 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4694 | if (notif->size == sizeof(*x)) { |
| 4695 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
Cahill, Ben M | 1297715 | 2006-03-08 02:58:02 +0800 | [diff] [blame] | 4696 | "link deterioration: type %d, cnt %d\n", |
| 4697 | x->silence_notification_type, |
| 4698 | x->silence_count); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4699 | memcpy(&priv->last_link_deterioration, x, |
| 4700 | sizeof(*x)); |
| 4701 | } else { |
| 4702 | IPW_ERROR("Link Deterioration of wrong size %d " |
| 4703 | "(should be %zd)\n", |
| 4704 | notif->size, sizeof(*x)); |
| 4705 | } |
| 4706 | break; |
| 4707 | } |
| 4708 | |
| 4709 | case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{ |
| 4710 | IPW_ERROR("Dino config\n"); |
| 4711 | if (priv->hcmd |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4712 | && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4713 | IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4714 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4715 | break; |
| 4716 | } |
| 4717 | |
| 4718 | case HOST_NOTIFICATION_STATUS_BEACON_STATE:{ |
| 4719 | struct notif_beacon_state *x = ¬if->u.beacon_state; |
| 4720 | if (notif->size != sizeof(*x)) { |
| 4721 | IPW_ERROR |
| 4722 | ("Beacon state of wrong size %d (should " |
| 4723 | "be %zd)\n", notif->size, sizeof(*x)); |
| 4724 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4725 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4726 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4727 | if (le32_to_cpu(x->state) == |
| 4728 | HOST_NOTIFICATION_STATUS_BEACON_MISSING) |
| 4729 | ipw_handle_missed_beacon(priv, |
| 4730 | le32_to_cpu(x-> |
| 4731 | number)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4732 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4733 | break; |
| 4734 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4735 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4736 | case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{ |
| 4737 | struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key; |
| 4738 | if (notif->size == sizeof(*x)) { |
| 4739 | IPW_ERROR("TGi Tx Key: state 0x%02x sec type " |
| 4740 | "0x%02x station %d\n", |
| 4741 | x->key_state, x->security_type, |
| 4742 | x->station_index); |
| 4743 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4744 | } |
| 4745 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4746 | IPW_ERROR |
| 4747 | ("TGi Tx Key of wrong size %d (should be %zd)\n", |
| 4748 | notif->size, sizeof(*x)); |
| 4749 | break; |
| 4750 | } |
| 4751 | |
| 4752 | case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{ |
| 4753 | struct notif_calibration *x = ¬if->u.calibration; |
| 4754 | |
| 4755 | if (notif->size == sizeof(*x)) { |
| 4756 | memcpy(&priv->calib, x, sizeof(*x)); |
| 4757 | IPW_DEBUG_INFO("TODO: Calibration\n"); |
| 4758 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4759 | } |
| 4760 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4761 | IPW_ERROR |
| 4762 | ("Calibration of wrong size %d (should be %zd)\n", |
| 4763 | notif->size, sizeof(*x)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4764 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4765 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4766 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4767 | case HOST_NOTIFICATION_NOISE_STATS:{ |
| 4768 | if (notif->size == sizeof(u32)) { |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 4769 | priv->exp_avg_noise = |
| 4770 | exponential_average(priv->exp_avg_noise, |
| 4771 | (u8) (le32_to_cpu(notif->u.noise.value) & 0xff), |
| 4772 | DEPTH_NOISE); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4773 | break; |
| 4774 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4775 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4776 | IPW_ERROR |
| 4777 | ("Noise stat is wrong size %d (should be %zd)\n", |
| 4778 | notif->size, sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4779 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4780 | } |
| 4781 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4782 | default: |
Zhu Yi | 1dd31b6 | 2006-02-20 18:28:09 -0800 | [diff] [blame] | 4783 | IPW_DEBUG_NOTIF("Unknown notification: " |
| 4784 | "subtype=%d,flags=0x%2x,size=%d\n", |
| 4785 | notif->subtype, notif->flags, notif->size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4786 | } |
| 4787 | } |
| 4788 | |
| 4789 | /** |
| 4790 | * Destroys all DMA structures and initialise them again |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4791 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4792 | * @param priv |
| 4793 | * @return error code |
| 4794 | */ |
| 4795 | static int ipw_queue_reset(struct ipw_priv *priv) |
| 4796 | { |
| 4797 | int rc = 0; |
| 4798 | /** @todo customize queue sizes */ |
| 4799 | int nTx = 64, nTxCmd = 8; |
| 4800 | ipw_tx_queue_free(priv); |
| 4801 | /* Tx CMD queue */ |
| 4802 | rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4803 | IPW_TX_CMD_QUEUE_READ_INDEX, |
| 4804 | IPW_TX_CMD_QUEUE_WRITE_INDEX, |
| 4805 | IPW_TX_CMD_QUEUE_BD_BASE, |
| 4806 | IPW_TX_CMD_QUEUE_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4807 | if (rc) { |
| 4808 | IPW_ERROR("Tx Cmd queue init failed\n"); |
| 4809 | goto error; |
| 4810 | } |
| 4811 | /* Tx queue(s) */ |
| 4812 | rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4813 | IPW_TX_QUEUE_0_READ_INDEX, |
| 4814 | IPW_TX_QUEUE_0_WRITE_INDEX, |
| 4815 | IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4816 | if (rc) { |
| 4817 | IPW_ERROR("Tx 0 queue init failed\n"); |
| 4818 | goto error; |
| 4819 | } |
| 4820 | rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4821 | IPW_TX_QUEUE_1_READ_INDEX, |
| 4822 | IPW_TX_QUEUE_1_WRITE_INDEX, |
| 4823 | IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4824 | if (rc) { |
| 4825 | IPW_ERROR("Tx 1 queue init failed\n"); |
| 4826 | goto error; |
| 4827 | } |
| 4828 | rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4829 | IPW_TX_QUEUE_2_READ_INDEX, |
| 4830 | IPW_TX_QUEUE_2_WRITE_INDEX, |
| 4831 | IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4832 | if (rc) { |
| 4833 | IPW_ERROR("Tx 2 queue init failed\n"); |
| 4834 | goto error; |
| 4835 | } |
| 4836 | rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4837 | IPW_TX_QUEUE_3_READ_INDEX, |
| 4838 | IPW_TX_QUEUE_3_WRITE_INDEX, |
| 4839 | IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4840 | if (rc) { |
| 4841 | IPW_ERROR("Tx 3 queue init failed\n"); |
| 4842 | goto error; |
| 4843 | } |
| 4844 | /* statistics */ |
| 4845 | priv->rx_bufs_min = 0; |
| 4846 | priv->rx_pend_max = 0; |
| 4847 | return rc; |
| 4848 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4849 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4850 | ipw_tx_queue_free(priv); |
| 4851 | return rc; |
| 4852 | } |
| 4853 | |
| 4854 | /** |
| 4855 | * Reclaim Tx queue entries no more used by NIC. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4856 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4857 | * When FW adwances 'R' index, all entries between old and |
| 4858 | * new 'R' index need to be reclaimed. As result, some free space |
| 4859 | * forms. If there is enough free space (> low mark), wake Tx queue. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4860 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4861 | * @note Need to protect against garbage in 'R' index |
| 4862 | * @param priv |
| 4863 | * @param txq |
| 4864 | * @param qindex |
| 4865 | * @return Number of used entries remains in the queue |
| 4866 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4867 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4868 | struct clx2_tx_queue *txq, int qindex) |
| 4869 | { |
| 4870 | u32 hw_tail; |
| 4871 | int used; |
| 4872 | struct clx2_queue *q = &txq->q; |
| 4873 | |
| 4874 | hw_tail = ipw_read32(priv, q->reg_r); |
| 4875 | if (hw_tail >= q->n_bd) { |
| 4876 | IPW_ERROR |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4877 | ("Read index for DMA queue (%d) is out of range [0-%d)\n", |
| 4878 | hw_tail, q->n_bd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4879 | goto done; |
| 4880 | } |
| 4881 | for (; q->last_used != hw_tail; |
| 4882 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { |
| 4883 | ipw_queue_tx_free_tfd(priv, txq); |
| 4884 | priv->tx_packets++; |
| 4885 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4886 | done: |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 4887 | if ((ipw_queue_space(q) > q->low_mark) && |
| 4888 | (qindex >= 0) && |
| 4889 | (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev)) |
| 4890 | netif_wake_queue(priv->net_dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4891 | used = q->first_empty - q->last_used; |
| 4892 | if (used < 0) |
| 4893 | used += q->n_bd; |
| 4894 | |
| 4895 | return used; |
| 4896 | } |
| 4897 | |
| 4898 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, |
| 4899 | int len, int sync) |
| 4900 | { |
| 4901 | struct clx2_tx_queue *txq = &priv->txq_cmd; |
| 4902 | struct clx2_queue *q = &txq->q; |
| 4903 | struct tfd_frame *tfd; |
| 4904 | |
| 4905 | if (ipw_queue_space(q) < (sync ? 1 : 2)) { |
| 4906 | IPW_ERROR("No space for Tx\n"); |
| 4907 | return -EBUSY; |
| 4908 | } |
| 4909 | |
| 4910 | tfd = &txq->bd[q->first_empty]; |
| 4911 | txq->txb[q->first_empty] = NULL; |
| 4912 | |
| 4913 | memset(tfd, 0, sizeof(*tfd)); |
| 4914 | tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE; |
| 4915 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; |
| 4916 | priv->hcmd_seq++; |
| 4917 | tfd->u.cmd.index = hcmd; |
| 4918 | tfd->u.cmd.length = len; |
| 4919 | memcpy(tfd->u.cmd.payload, buf, len); |
| 4920 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); |
| 4921 | ipw_write32(priv, q->reg_w, q->first_empty); |
| 4922 | _ipw_read32(priv, 0x90); |
| 4923 | |
| 4924 | return 0; |
| 4925 | } |
| 4926 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4927 | /* |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4928 | * Rx theory of operation |
| 4929 | * |
| 4930 | * The host allocates 32 DMA target addresses and passes the host address |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4931 | * 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] | 4932 | * 0 to 31 |
| 4933 | * |
| 4934 | * Rx Queue Indexes |
| 4935 | * The host/firmware share two index registers for managing the Rx buffers. |
| 4936 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4937 | * The READ index maps to the first position that the firmware may be writing |
| 4938 | * to -- the driver can read up to (but not including) this position and get |
| 4939 | * good data. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4940 | * The READ index is managed by the firmware once the card is enabled. |
| 4941 | * |
| 4942 | * The WRITE index maps to the last position the driver has read from -- the |
| 4943 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 4944 | * |
| 4945 | * 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] | 4946 | * WRITE = READ. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4947 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4948 | * 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] | 4949 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 4950 | * |
| 4951 | * When the firmware places a packet in a buffer it will advance the READ index |
| 4952 | * and fire the RX interrupt. The driver can then query the READ index and |
| 4953 | * process as many packets as possible, moving the WRITE index forward as it |
| 4954 | * resets the Rx queue buffers with new memory. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4955 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4956 | * The management in the driver is as follows: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4957 | * + 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] | 4958 | * 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] | 4959 | * to replensish the ipw->rxq->rx_free. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4960 | * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the |
| 4961 | * ipw->rxq is replenished and the READ INDEX is updated (updating the |
| 4962 | * 'processed' and 'read' driver indexes as well) |
| 4963 | * + A received packet is processed and handed to the kernel network stack, |
| 4964 | * detached from the ipw->rxq. The driver 'processed' index is updated. |
| 4965 | * + 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] | 4966 | * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ |
| 4967 | * 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] | 4968 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 4969 | * |
| 4970 | * |
| 4971 | * Driver sequence: |
| 4972 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4973 | * ipw_rx_queue_alloc() Allocates rx_free |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4974 | * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls |
| 4975 | * ipw_rx_queue_restock |
| 4976 | * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx |
| 4977 | * queue, updates firmware pointers, and updates |
| 4978 | * the WRITE index. If insufficient rx_free buffers |
| 4979 | * are available, schedules ipw_rx_queue_replenish |
| 4980 | * |
| 4981 | * -- enable interrupts -- |
| 4982 | * 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] | 4983 | * READ INDEX, detaching the SKB from the pool. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4984 | * Moves the packet buffer from queue to rx_used. |
| 4985 | * Calls ipw_rx_queue_restock to refill any empty |
| 4986 | * slots. |
| 4987 | * ... |
| 4988 | * |
| 4989 | */ |
| 4990 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4991 | /* |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4992 | * If there are slots in the RX queue that need to be restocked, |
| 4993 | * and we have free pre-allocated buffers, fill the ranks as much |
| 4994 | * as we can pulling from rx_free. |
| 4995 | * |
| 4996 | * This moves the 'write' index forward to catch up with 'processed', and |
| 4997 | * also updates the memory address in the firmware to reference the new |
| 4998 | * target buffer. |
| 4999 | */ |
| 5000 | static void ipw_rx_queue_restock(struct ipw_priv *priv) |
| 5001 | { |
| 5002 | struct ipw_rx_queue *rxq = priv->rxq; |
| 5003 | struct list_head *element; |
| 5004 | struct ipw_rx_mem_buffer *rxb; |
| 5005 | unsigned long flags; |
| 5006 | int write; |
| 5007 | |
| 5008 | spin_lock_irqsave(&rxq->lock, flags); |
| 5009 | write = rxq->write; |
| 5010 | while ((rxq->write != rxq->processed) && (rxq->free_count)) { |
| 5011 | element = rxq->rx_free.next; |
| 5012 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); |
| 5013 | list_del(element); |
| 5014 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5015 | ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5016 | rxb->dma_addr); |
| 5017 | rxq->queue[rxq->write] = rxb; |
| 5018 | rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE; |
| 5019 | rxq->free_count--; |
| 5020 | } |
| 5021 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 5022 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5023 | /* If the pre-allocated buffer pool is dropping low, schedule to |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5024 | * refill it */ |
| 5025 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 5026 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 5027 | |
| 5028 | /* 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] | 5029 | if (write != rxq->write) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5030 | ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5031 | } |
| 5032 | |
| 5033 | /* |
| 5034 | * 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] | 5035 | * Also restock the Rx queue via ipw_rx_queue_restock. |
| 5036 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5037 | * This is called as a scheduled work item (except for during intialization) |
| 5038 | */ |
| 5039 | static void ipw_rx_queue_replenish(void *data) |
| 5040 | { |
| 5041 | struct ipw_priv *priv = data; |
| 5042 | struct ipw_rx_queue *rxq = priv->rxq; |
| 5043 | struct list_head *element; |
| 5044 | struct ipw_rx_mem_buffer *rxb; |
| 5045 | unsigned long flags; |
| 5046 | |
| 5047 | spin_lock_irqsave(&rxq->lock, flags); |
| 5048 | while (!list_empty(&rxq->rx_used)) { |
| 5049 | element = rxq->rx_used.next; |
| 5050 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5051 | rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5052 | if (!rxb->skb) { |
| 5053 | printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n", |
| 5054 | priv->net_dev->name); |
| 5055 | /* We don't reschedule replenish work here -- we will |
| 5056 | * call the restock method and if it still needs |
| 5057 | * more buffers it will schedule replenish */ |
| 5058 | break; |
| 5059 | } |
| 5060 | list_del(element); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5061 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5062 | rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5063 | rxb->dma_addr = |
| 5064 | pci_map_single(priv->pci_dev, rxb->skb->data, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5065 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5066 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5067 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 5068 | rxq->free_count++; |
| 5069 | } |
| 5070 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 5071 | |
| 5072 | ipw_rx_queue_restock(priv); |
| 5073 | } |
| 5074 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5075 | static void ipw_bg_rx_queue_replenish(void *data) |
| 5076 | { |
| 5077 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5078 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5079 | ipw_rx_queue_replenish(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5080 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5081 | } |
| 5082 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5083 | /* 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] | 5084 | * 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] | 5085 | * 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] | 5086 | * non NULL it is unmapped and freed |
| 5087 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5088 | 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] | 5089 | { |
| 5090 | int i; |
| 5091 | |
| 5092 | if (!rxq) |
| 5093 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5094 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5095 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
| 5096 | if (rxq->pool[i].skb != NULL) { |
| 5097 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5098 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5099 | dev_kfree_skb(rxq->pool[i].skb); |
| 5100 | } |
| 5101 | } |
| 5102 | |
| 5103 | kfree(rxq); |
| 5104 | } |
| 5105 | |
| 5106 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv) |
| 5107 | { |
| 5108 | struct ipw_rx_queue *rxq; |
| 5109 | int i; |
| 5110 | |
Takis | c75f474 | 2005-12-01 01:41:45 -0800 | [diff] [blame] | 5111 | rxq = kzalloc(sizeof(*rxq), GFP_KERNEL); |
Panagiotis Issaris | ad18b0e | 2005-09-05 04:14:10 +0200 | [diff] [blame] | 5112 | if (unlikely(!rxq)) { |
| 5113 | IPW_ERROR("memory allocation failed\n"); |
| 5114 | return NULL; |
| 5115 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5116 | spin_lock_init(&rxq->lock); |
| 5117 | INIT_LIST_HEAD(&rxq->rx_free); |
| 5118 | INIT_LIST_HEAD(&rxq->rx_used); |
| 5119 | |
| 5120 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5121 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5122 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 5123 | |
| 5124 | /* Set us so that we have processed and used all buffers, but have |
| 5125 | * not restocked the Rx queue with fresh buffers */ |
| 5126 | rxq->read = rxq->write = 0; |
| 5127 | rxq->processed = RX_QUEUE_SIZE - 1; |
| 5128 | rxq->free_count = 0; |
| 5129 | |
| 5130 | return rxq; |
| 5131 | } |
| 5132 | |
| 5133 | static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate) |
| 5134 | { |
| 5135 | rate &= ~IEEE80211_BASIC_RATE_MASK; |
| 5136 | if (ieee_mode == IEEE_A) { |
| 5137 | switch (rate) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5138 | case IEEE80211_OFDM_RATE_6MB: |
| 5139 | return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5140 | 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5141 | case IEEE80211_OFDM_RATE_9MB: |
| 5142 | return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5143 | 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5144 | case IEEE80211_OFDM_RATE_12MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5145 | return priv-> |
| 5146 | rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5147 | case IEEE80211_OFDM_RATE_18MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5148 | return priv-> |
| 5149 | rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5150 | case IEEE80211_OFDM_RATE_24MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5151 | return priv-> |
| 5152 | rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5153 | case IEEE80211_OFDM_RATE_36MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5154 | return priv-> |
| 5155 | rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5156 | case IEEE80211_OFDM_RATE_48MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5157 | return priv-> |
| 5158 | rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5159 | case IEEE80211_OFDM_RATE_54MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5160 | return priv-> |
| 5161 | rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5162 | default: |
| 5163 | return 0; |
| 5164 | } |
| 5165 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5166 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5167 | /* B and G mixed */ |
| 5168 | switch (rate) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5169 | case IEEE80211_CCK_RATE_1MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5170 | return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5171 | case IEEE80211_CCK_RATE_2MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5172 | return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5173 | case IEEE80211_CCK_RATE_5MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5174 | return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5175 | case IEEE80211_CCK_RATE_11MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5176 | return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0; |
| 5177 | } |
| 5178 | |
| 5179 | /* If we are limited to B modulations, bail at this point */ |
| 5180 | if (ieee_mode == IEEE_B) |
| 5181 | return 0; |
| 5182 | |
| 5183 | /* G */ |
| 5184 | switch (rate) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5185 | case IEEE80211_OFDM_RATE_6MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5186 | return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5187 | case IEEE80211_OFDM_RATE_9MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5188 | return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5189 | case IEEE80211_OFDM_RATE_12MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5190 | return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5191 | case IEEE80211_OFDM_RATE_18MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5192 | return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5193 | case IEEE80211_OFDM_RATE_24MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5194 | return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5195 | case IEEE80211_OFDM_RATE_36MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5196 | return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5197 | case IEEE80211_OFDM_RATE_48MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5198 | return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5199 | case IEEE80211_OFDM_RATE_54MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5200 | return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0; |
| 5201 | } |
| 5202 | |
| 5203 | return 0; |
| 5204 | } |
| 5205 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5206 | static int ipw_compatible_rates(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5207 | const struct ieee80211_network *network, |
| 5208 | struct ipw_supported_rates *rates) |
| 5209 | { |
| 5210 | int num_rates, i; |
| 5211 | |
| 5212 | memset(rates, 0, sizeof(*rates)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5213 | num_rates = min(network->rates_len, (u8) IPW_MAX_RATES); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5214 | rates->num_rates = 0; |
| 5215 | for (i = 0; i < num_rates; i++) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5216 | if (!ipw_is_rate_in_mask(priv, network->mode, |
| 5217 | network->rates[i])) { |
| 5218 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5219 | if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5220 | IPW_DEBUG_SCAN("Adding masked mandatory " |
| 5221 | "rate %02X\n", |
| 5222 | network->rates[i]); |
| 5223 | rates->supported_rates[rates->num_rates++] = |
| 5224 | network->rates[i]; |
| 5225 | continue; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5226 | } |
| 5227 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5228 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
| 5229 | network->rates[i], priv->rates_mask); |
| 5230 | continue; |
| 5231 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5232 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5233 | rates->supported_rates[rates->num_rates++] = network->rates[i]; |
| 5234 | } |
| 5235 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5236 | num_rates = min(network->rates_ex_len, |
| 5237 | (u8) (IPW_MAX_RATES - num_rates)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5238 | for (i = 0; i < num_rates; i++) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5239 | if (!ipw_is_rate_in_mask(priv, network->mode, |
| 5240 | network->rates_ex[i])) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5241 | if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5242 | IPW_DEBUG_SCAN("Adding masked mandatory " |
| 5243 | "rate %02X\n", |
| 5244 | network->rates_ex[i]); |
| 5245 | rates->supported_rates[rates->num_rates++] = |
| 5246 | network->rates[i]; |
| 5247 | continue; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5248 | } |
| 5249 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5250 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
| 5251 | network->rates_ex[i], priv->rates_mask); |
| 5252 | continue; |
| 5253 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5254 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5255 | rates->supported_rates[rates->num_rates++] = |
| 5256 | network->rates_ex[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5257 | } |
| 5258 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5259 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5260 | } |
| 5261 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 5262 | static void ipw_copy_rates(struct ipw_supported_rates *dest, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5263 | const struct ipw_supported_rates *src) |
| 5264 | { |
| 5265 | u8 i; |
| 5266 | for (i = 0; i < src->num_rates; i++) |
| 5267 | dest->supported_rates[i] = src->supported_rates[i]; |
| 5268 | dest->num_rates = src->num_rates; |
| 5269 | } |
| 5270 | |
| 5271 | /* TODO: Look at sniffed packets in the air to determine if the basic rate |
| 5272 | * mask should ever be used -- right now all callers to add the scan rates are |
| 5273 | * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */ |
| 5274 | static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5275 | u8 modulation, u32 rate_mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5276 | { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5277 | u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5278 | IEEE80211_BASIC_RATE_MASK : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5279 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5280 | if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5281 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5282 | IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5283 | |
| 5284 | if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5285 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5286 | IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5287 | |
| 5288 | if (rate_mask & IEEE80211_CCK_RATE_5MB_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_CCK_RATE_5MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5291 | |
| 5292 | if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5293 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5294 | IEEE80211_CCK_RATE_11MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5295 | } |
| 5296 | |
| 5297 | static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5298 | u8 modulation, u32 rate_mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5299 | { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5300 | u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5301 | IEEE80211_BASIC_RATE_MASK : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5302 | |
| 5303 | if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5304 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5305 | IEEE80211_OFDM_RATE_6MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5306 | |
| 5307 | if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5308 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5309 | IEEE80211_OFDM_RATE_9MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5310 | |
| 5311 | if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5312 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5313 | IEEE80211_OFDM_RATE_12MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5314 | |
| 5315 | if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5316 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5317 | IEEE80211_OFDM_RATE_18MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5318 | |
| 5319 | if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5320 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5321 | IEEE80211_OFDM_RATE_24MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5322 | |
| 5323 | if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5324 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5325 | IEEE80211_OFDM_RATE_36MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5326 | |
| 5327 | if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5328 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5329 | IEEE80211_OFDM_RATE_48MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5330 | |
| 5331 | if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5332 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5333 | IEEE80211_OFDM_RATE_54MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5334 | } |
| 5335 | |
| 5336 | struct ipw_network_match { |
| 5337 | struct ieee80211_network *network; |
| 5338 | struct ipw_supported_rates rates; |
| 5339 | }; |
| 5340 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5341 | static int ipw_find_adhoc_network(struct ipw_priv *priv, |
| 5342 | struct ipw_network_match *match, |
| 5343 | struct ieee80211_network *network, |
| 5344 | int roaming) |
| 5345 | { |
| 5346 | struct ipw_supported_rates rates; |
| 5347 | |
| 5348 | /* Verify that this network's capability is compatible with the |
| 5349 | * current mode (AdHoc or Infrastructure) */ |
| 5350 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 5351 | !(network->capability & WLAN_CAPABILITY_IBSS))) { |
| 5352 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to " |
| 5353 | "capability mismatch.\n", |
| 5354 | escape_essid(network->ssid, network->ssid_len), |
| 5355 | MAC_ARG(network->bssid)); |
| 5356 | return 0; |
| 5357 | } |
| 5358 | |
| 5359 | /* If we do not have an ESSID for this AP, we can not associate with |
| 5360 | * it */ |
| 5361 | if (network->flags & NETWORK_EMPTY_ESSID) { |
| 5362 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5363 | "because of hidden ESSID.\n", |
| 5364 | escape_essid(network->ssid, network->ssid_len), |
| 5365 | MAC_ARG(network->bssid)); |
| 5366 | return 0; |
| 5367 | } |
| 5368 | |
| 5369 | if (unlikely(roaming)) { |
| 5370 | /* If we are roaming, then ensure check if this is a valid |
| 5371 | * network to try and roam to */ |
| 5372 | if ((network->ssid_len != match->network->ssid_len) || |
| 5373 | memcmp(network->ssid, match->network->ssid, |
| 5374 | network->ssid_len)) { |
| 5375 | IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded " |
| 5376 | "because of non-network ESSID.\n", |
| 5377 | escape_essid(network->ssid, |
| 5378 | network->ssid_len), |
| 5379 | MAC_ARG(network->bssid)); |
| 5380 | return 0; |
| 5381 | } |
| 5382 | } else { |
| 5383 | /* If an ESSID has been configured then compare the broadcast |
| 5384 | * ESSID to ours */ |
| 5385 | if ((priv->config & CFG_STATIC_ESSID) && |
| 5386 | ((network->ssid_len != priv->essid_len) || |
| 5387 | memcmp(network->ssid, priv->essid, |
| 5388 | min(network->ssid_len, priv->essid_len)))) { |
| 5389 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5390 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5391 | strncpy(escaped, |
| 5392 | escape_essid(network->ssid, network->ssid_len), |
| 5393 | sizeof(escaped)); |
| 5394 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5395 | "because of ESSID mismatch: '%s'.\n", |
| 5396 | escaped, MAC_ARG(network->bssid), |
| 5397 | escape_essid(priv->essid, |
| 5398 | priv->essid_len)); |
| 5399 | return 0; |
| 5400 | } |
| 5401 | } |
| 5402 | |
| 5403 | /* If the old network rate is better than this one, don't bother |
| 5404 | * testing everything else. */ |
| 5405 | |
| 5406 | if (network->time_stamp[0] < match->network->time_stamp[0]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5407 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
| 5408 | "current network.\n", |
| 5409 | escape_essid(match->network->ssid, |
| 5410 | match->network->ssid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5411 | return 0; |
| 5412 | } else if (network->time_stamp[1] < match->network->time_stamp[1]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5413 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
| 5414 | "current network.\n", |
| 5415 | escape_essid(match->network->ssid, |
| 5416 | match->network->ssid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5417 | return 0; |
| 5418 | } |
| 5419 | |
| 5420 | /* Now go through and see if the requested network is valid... */ |
| 5421 | if (priv->ieee->scan_age != 0 && |
| 5422 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
| 5423 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5424 | "because of age: %ums.\n", |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5425 | escape_essid(network->ssid, network->ssid_len), |
| 5426 | MAC_ARG(network->bssid), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5427 | jiffies_to_msecs(jiffies - |
| 5428 | network->last_scanned)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5429 | return 0; |
| 5430 | } |
| 5431 | |
| 5432 | if ((priv->config & CFG_STATIC_CHANNEL) && |
| 5433 | (network->channel != priv->channel)) { |
| 5434 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5435 | "because of channel mismatch: %d != %d.\n", |
| 5436 | escape_essid(network->ssid, network->ssid_len), |
| 5437 | MAC_ARG(network->bssid), |
| 5438 | network->channel, priv->channel); |
| 5439 | return 0; |
| 5440 | } |
| 5441 | |
| 5442 | /* Verify privacy compatability */ |
| 5443 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
| 5444 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
| 5445 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5446 | "because of privacy mismatch: %s != %s.\n", |
| 5447 | escape_essid(network->ssid, network->ssid_len), |
| 5448 | MAC_ARG(network->bssid), |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5449 | priv-> |
| 5450 | capability & CAP_PRIVACY_ON ? "on" : "off", |
| 5451 | network-> |
| 5452 | capability & WLAN_CAPABILITY_PRIVACY ? "on" : |
| 5453 | "off"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5454 | return 0; |
| 5455 | } |
| 5456 | |
| 5457 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
| 5458 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5459 | "because of the same BSSID match: " MAC_FMT |
| 5460 | ".\n", escape_essid(network->ssid, |
| 5461 | network->ssid_len), |
| 5462 | MAC_ARG(network->bssid), MAC_ARG(priv->bssid)); |
| 5463 | return 0; |
| 5464 | } |
| 5465 | |
| 5466 | /* Filter out any incompatible freq / mode combinations */ |
| 5467 | if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) { |
| 5468 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5469 | "because of invalid frequency/mode " |
| 5470 | "combination.\n", |
| 5471 | escape_essid(network->ssid, network->ssid_len), |
| 5472 | MAC_ARG(network->bssid)); |
| 5473 | return 0; |
| 5474 | } |
| 5475 | |
| 5476 | /* Ensure that the rates supported by the driver are compatible with |
| 5477 | * this AP, including verification of basic rates (mandatory) */ |
| 5478 | if (!ipw_compatible_rates(priv, network, &rates)) { |
| 5479 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5480 | "because configured rate mask excludes " |
| 5481 | "AP mandatory rate.\n", |
| 5482 | escape_essid(network->ssid, network->ssid_len), |
| 5483 | MAC_ARG(network->bssid)); |
| 5484 | return 0; |
| 5485 | } |
| 5486 | |
| 5487 | if (rates.num_rates == 0) { |
| 5488 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5489 | "because of no compatible rates.\n", |
| 5490 | escape_essid(network->ssid, network->ssid_len), |
| 5491 | MAC_ARG(network->bssid)); |
| 5492 | return 0; |
| 5493 | } |
| 5494 | |
| 5495 | /* TODO: Perform any further minimal comparititive tests. We do not |
| 5496 | * want to put too much policy logic here; intelligent scan selection |
| 5497 | * should occur within a generic IEEE 802.11 user space tool. */ |
| 5498 | |
| 5499 | /* Set up 'new' AP to this network */ |
| 5500 | ipw_copy_rates(&match->rates, &rates); |
| 5501 | match->network = network; |
| 5502 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n", |
| 5503 | escape_essid(network->ssid, network->ssid_len), |
| 5504 | MAC_ARG(network->bssid)); |
| 5505 | |
| 5506 | return 1; |
| 5507 | } |
| 5508 | |
| 5509 | static void ipw_merge_adhoc_network(void *data) |
| 5510 | { |
| 5511 | struct ipw_priv *priv = data; |
| 5512 | struct ieee80211_network *network = NULL; |
| 5513 | struct ipw_network_match match = { |
| 5514 | .network = priv->assoc_network |
| 5515 | }; |
| 5516 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5517 | if ((priv->status & STATUS_ASSOCIATED) && |
| 5518 | (priv->ieee->iw_mode == IW_MODE_ADHOC)) { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5519 | /* First pass through ROAM process -- look for a better |
| 5520 | * network */ |
| 5521 | unsigned long flags; |
| 5522 | |
| 5523 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 5524 | list_for_each_entry(network, &priv->ieee->network_list, list) { |
| 5525 | if (network != priv->assoc_network) |
| 5526 | ipw_find_adhoc_network(priv, &match, network, |
| 5527 | 1); |
| 5528 | } |
| 5529 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 5530 | |
| 5531 | if (match.network == priv->assoc_network) { |
| 5532 | IPW_DEBUG_MERGE("No better ADHOC in this network to " |
| 5533 | "merge to.\n"); |
| 5534 | return; |
| 5535 | } |
| 5536 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5537 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5538 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) { |
| 5539 | IPW_DEBUG_MERGE("remove network %s\n", |
| 5540 | escape_essid(priv->essid, |
| 5541 | priv->essid_len)); |
| 5542 | ipw_remove_current_network(priv); |
| 5543 | } |
| 5544 | |
| 5545 | ipw_disassociate(priv); |
| 5546 | priv->assoc_network = match.network; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5547 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5548 | return; |
| 5549 | } |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5550 | } |
| 5551 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5552 | static int ipw_best_network(struct ipw_priv *priv, |
| 5553 | struct ipw_network_match *match, |
| 5554 | struct ieee80211_network *network, int roaming) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5555 | { |
| 5556 | struct ipw_supported_rates rates; |
| 5557 | |
| 5558 | /* Verify that this network's capability is compatible with the |
| 5559 | * current mode (AdHoc or Infrastructure) */ |
| 5560 | if ((priv->ieee->iw_mode == IW_MODE_INFRA && |
Jouni Malinen | 2474385 | 2005-08-14 20:59:59 -0700 | [diff] [blame] | 5561 | !(network->capability & WLAN_CAPABILITY_ESS)) || |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5562 | (priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 5563 | !(network->capability & WLAN_CAPABILITY_IBSS))) { |
| 5564 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5565 | "capability mismatch.\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5566 | escape_essid(network->ssid, network->ssid_len), |
| 5567 | MAC_ARG(network->bssid)); |
| 5568 | return 0; |
| 5569 | } |
| 5570 | |
| 5571 | /* If we do not have an ESSID for this AP, we can not associate with |
| 5572 | * it */ |
| 5573 | if (network->flags & NETWORK_EMPTY_ESSID) { |
| 5574 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5575 | "because of hidden ESSID.\n", |
| 5576 | escape_essid(network->ssid, network->ssid_len), |
| 5577 | MAC_ARG(network->bssid)); |
| 5578 | return 0; |
| 5579 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5580 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5581 | if (unlikely(roaming)) { |
| 5582 | /* If we are roaming, then ensure check if this is a valid |
| 5583 | * network to try and roam to */ |
| 5584 | if ((network->ssid_len != match->network->ssid_len) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5585 | memcmp(network->ssid, match->network->ssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5586 | network->ssid_len)) { |
| 5587 | IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded " |
| 5588 | "because of non-network ESSID.\n", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5589 | escape_essid(network->ssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5590 | network->ssid_len), |
| 5591 | MAC_ARG(network->bssid)); |
| 5592 | return 0; |
| 5593 | } |
| 5594 | } else { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5595 | /* If an ESSID has been configured then compare the broadcast |
| 5596 | * ESSID to ours */ |
| 5597 | if ((priv->config & CFG_STATIC_ESSID) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5598 | ((network->ssid_len != priv->essid_len) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5599 | memcmp(network->ssid, priv->essid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5600 | min(network->ssid_len, priv->essid_len)))) { |
| 5601 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5602 | strncpy(escaped, |
| 5603 | escape_essid(network->ssid, network->ssid_len), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5604 | sizeof(escaped)); |
| 5605 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5606 | "because of ESSID mismatch: '%s'.\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5607 | escaped, MAC_ARG(network->bssid), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5608 | escape_essid(priv->essid, |
| 5609 | priv->essid_len)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5610 | return 0; |
| 5611 | } |
| 5612 | } |
| 5613 | |
| 5614 | /* If the old network rate is better than this one, don't bother |
| 5615 | * testing everything else. */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5616 | if (match->network && match->network->stats.rssi > network->stats.rssi) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5617 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5618 | strncpy(escaped, |
| 5619 | escape_essid(network->ssid, network->ssid_len), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5620 | sizeof(escaped)); |
| 5621 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because " |
| 5622 | "'%s (" MAC_FMT ")' has a stronger signal.\n", |
| 5623 | escaped, MAC_ARG(network->bssid), |
| 5624 | escape_essid(match->network->ssid, |
| 5625 | match->network->ssid_len), |
| 5626 | MAC_ARG(match->network->bssid)); |
| 5627 | return 0; |
| 5628 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5629 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5630 | /* If this network has already had an association attempt within the |
| 5631 | * last 3 seconds, do not try and associate again... */ |
| 5632 | if (network->last_associate && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5633 | time_after(network->last_associate + (HZ * 3UL), jiffies)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5634 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5635 | "because of storming (%ums since last " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5636 | "assoc attempt).\n", |
| 5637 | escape_essid(network->ssid, network->ssid_len), |
| 5638 | MAC_ARG(network->bssid), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5639 | jiffies_to_msecs(jiffies - |
| 5640 | network->last_associate)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5641 | return 0; |
| 5642 | } |
| 5643 | |
| 5644 | /* Now go through and see if the requested network is valid... */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5645 | if (priv->ieee->scan_age != 0 && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5646 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5647 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5648 | "because of age: %ums.\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5649 | escape_essid(network->ssid, network->ssid_len), |
| 5650 | MAC_ARG(network->bssid), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5651 | jiffies_to_msecs(jiffies - |
| 5652 | network->last_scanned)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5653 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5654 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5655 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5656 | if ((priv->config & CFG_STATIC_CHANNEL) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5657 | (network->channel != priv->channel)) { |
| 5658 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5659 | "because of channel mismatch: %d != %d.\n", |
| 5660 | escape_essid(network->ssid, network->ssid_len), |
| 5661 | MAC_ARG(network->bssid), |
| 5662 | network->channel, priv->channel); |
| 5663 | return 0; |
| 5664 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5665 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5666 | /* Verify privacy compatability */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5667 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5668 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
| 5669 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5670 | "because of privacy mismatch: %s != %s.\n", |
| 5671 | escape_essid(network->ssid, network->ssid_len), |
| 5672 | MAC_ARG(network->bssid), |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5673 | priv->capability & CAP_PRIVACY_ON ? "on" : |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5674 | "off", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5675 | network->capability & |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5676 | WLAN_CAPABILITY_PRIVACY ? "on" : "off"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5677 | return 0; |
| 5678 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5679 | |
| 5680 | if ((priv->config & CFG_STATIC_BSSID) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5681 | memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
| 5682 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5683 | "because of BSSID mismatch: " MAC_FMT ".\n", |
| 5684 | escape_essid(network->ssid, network->ssid_len), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5685 | MAC_ARG(network->bssid), MAC_ARG(priv->bssid)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5686 | return 0; |
| 5687 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5688 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5689 | /* Filter out any incompatible freq / mode combinations */ |
| 5690 | if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) { |
| 5691 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5692 | "because of invalid frequency/mode " |
| 5693 | "combination.\n", |
| 5694 | escape_essid(network->ssid, network->ssid_len), |
| 5695 | MAC_ARG(network->bssid)); |
| 5696 | return 0; |
| 5697 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5698 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5699 | /* Filter out invalid channel in current GEO */ |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 5700 | if (!ieee80211_is_valid_channel(priv->ieee, network->channel)) { |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5701 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5702 | "because of invalid channel in current GEO\n", |
| 5703 | escape_essid(network->ssid, network->ssid_len), |
| 5704 | MAC_ARG(network->bssid)); |
| 5705 | return 0; |
| 5706 | } |
| 5707 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5708 | /* Ensure that the rates supported by the driver are compatible with |
| 5709 | * this AP, including verification of basic rates (mandatory) */ |
| 5710 | if (!ipw_compatible_rates(priv, network, &rates)) { |
| 5711 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5712 | "because configured rate mask excludes " |
| 5713 | "AP mandatory rate.\n", |
| 5714 | escape_essid(network->ssid, network->ssid_len), |
| 5715 | MAC_ARG(network->bssid)); |
| 5716 | return 0; |
| 5717 | } |
| 5718 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5719 | if (rates.num_rates == 0) { |
| 5720 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5721 | "because of no compatible rates.\n", |
| 5722 | escape_essid(network->ssid, network->ssid_len), |
| 5723 | MAC_ARG(network->bssid)); |
| 5724 | return 0; |
| 5725 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5726 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5727 | /* TODO: Perform any further minimal comparititive tests. We do not |
| 5728 | * want to put too much policy logic here; intelligent scan selection |
| 5729 | * should occur within a generic IEEE 802.11 user space tool. */ |
| 5730 | |
| 5731 | /* Set up 'new' AP to this network */ |
| 5732 | ipw_copy_rates(&match->rates, &rates); |
| 5733 | match->network = network; |
| 5734 | |
| 5735 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n", |
| 5736 | escape_essid(network->ssid, network->ssid_len), |
| 5737 | MAC_ARG(network->bssid)); |
| 5738 | |
| 5739 | return 1; |
| 5740 | } |
| 5741 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5742 | static void ipw_adhoc_create(struct ipw_priv *priv, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5743 | struct ieee80211_network *network) |
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 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5746 | int i; |
| 5747 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5748 | /* |
| 5749 | * For the purposes of scanning, we can set our wireless mode |
| 5750 | * to trigger scans across combinations of bands, but when it |
| 5751 | * comes to creating a new ad-hoc network, we have tell the FW |
| 5752 | * exactly which band to use. |
| 5753 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5754 | * We also have the possibility of an invalid channel for the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5755 | * chossen band. Attempting to create a new ad-hoc network |
| 5756 | * with an invalid channel for wireless mode will trigger a |
| 5757 | * FW fatal error. |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5758 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5759 | */ |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 5760 | switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5761 | case IEEE80211_52GHZ_BAND: |
| 5762 | network->mode = IEEE_A; |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 5763 | i = ieee80211_channel_to_index(priv->ieee, priv->channel); |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 5764 | BUG_ON(i == -1); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5765 | if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) { |
| 5766 | IPW_WARNING("Overriding invalid channel\n"); |
| 5767 | priv->channel = geo->a[0].channel; |
| 5768 | } |
| 5769 | break; |
| 5770 | |
| 5771 | case IEEE80211_24GHZ_BAND: |
| 5772 | if (priv->ieee->mode & IEEE_G) |
| 5773 | network->mode = IEEE_G; |
| 5774 | else |
| 5775 | network->mode = IEEE_B; |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 5776 | i = ieee80211_channel_to_index(priv->ieee, priv->channel); |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 5777 | BUG_ON(i == -1); |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5778 | if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) { |
| 5779 | IPW_WARNING("Overriding invalid channel\n"); |
| 5780 | priv->channel = geo->bg[0].channel; |
| 5781 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5782 | break; |
| 5783 | |
| 5784 | default: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5785 | IPW_WARNING("Overriding invalid channel\n"); |
| 5786 | if (priv->ieee->mode & IEEE_A) { |
| 5787 | network->mode = IEEE_A; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5788 | priv->channel = geo->a[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5789 | } else if (priv->ieee->mode & IEEE_G) { |
| 5790 | network->mode = IEEE_G; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5791 | priv->channel = geo->bg[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5792 | } else { |
| 5793 | network->mode = IEEE_B; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5794 | priv->channel = geo->bg[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5795 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5796 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5797 | } |
| 5798 | |
| 5799 | network->channel = priv->channel; |
| 5800 | priv->config |= CFG_ADHOC_PERSIST; |
| 5801 | ipw_create_bssid(priv, network->bssid); |
| 5802 | network->ssid_len = priv->essid_len; |
| 5803 | memcpy(network->ssid, priv->essid, priv->essid_len); |
| 5804 | memset(&network->stats, 0, sizeof(network->stats)); |
| 5805 | network->capability = WLAN_CAPABILITY_IBSS; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5806 | if (!(priv->config & CFG_PREAMBLE_LONG)) |
| 5807 | network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5808 | if (priv->capability & CAP_PRIVACY_ON) |
| 5809 | network->capability |= WLAN_CAPABILITY_PRIVACY; |
| 5810 | network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5811 | memcpy(network->rates, priv->rates.supported_rates, network->rates_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5812 | network->rates_ex_len = priv->rates.num_rates - network->rates_len; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5813 | memcpy(network->rates_ex, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5814 | &priv->rates.supported_rates[network->rates_len], |
| 5815 | network->rates_ex_len); |
| 5816 | network->last_scanned = 0; |
| 5817 | network->flags = 0; |
| 5818 | network->last_associate = 0; |
| 5819 | network->time_stamp[0] = 0; |
| 5820 | network->time_stamp[1] = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5821 | network->beacon_interval = 100; /* Default */ |
| 5822 | network->listen_interval = 10; /* Default */ |
| 5823 | network->atim_window = 0; /* Default */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5824 | network->wpa_ie_len = 0; |
| 5825 | network->rsn_ie_len = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5826 | } |
| 5827 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5828 | static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index) |
| 5829 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5830 | struct ipw_tgi_tx_key key; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5831 | |
| 5832 | if (!(priv->ieee->sec.flags & (1 << index))) |
| 5833 | return; |
| 5834 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5835 | key.key_id = index; |
| 5836 | memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH); |
| 5837 | key.security_type = type; |
| 5838 | key.station_index = 0; /* always 0 for BSS */ |
| 5839 | key.flags = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5840 | /* 0 for new key; previous value of counter (after fatal error) */ |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5841 | key.tx_counter[0] = 0; |
| 5842 | key.tx_counter[1] = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5843 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5844 | 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] | 5845 | } |
| 5846 | |
| 5847 | static void ipw_send_wep_keys(struct ipw_priv *priv, int type) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5848 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5849 | struct ipw_wep_key key; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5850 | int i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5851 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5852 | key.cmd_id = DINO_CMD_WEP_KEY; |
| 5853 | key.seq_num = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5854 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5855 | /* Note: AES keys cannot be set for multiple times. |
| 5856 | * Only set it at the first time. */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5857 | for (i = 0; i < 4; i++) { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5858 | key.key_index = i | type; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5859 | if (!(priv->ieee->sec.flags & (1 << i))) { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5860 | key.key_size = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5861 | continue; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5862 | } |
| 5863 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5864 | key.key_size = priv->ieee->sec.key_sizes[i]; |
| 5865 | memcpy(key.key, priv->ieee->sec.keys[i], key.key_size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5866 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5867 | ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5868 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5869 | } |
| 5870 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 5871 | static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level) |
| 5872 | { |
| 5873 | if (priv->ieee->host_encrypt) |
| 5874 | return; |
| 5875 | |
| 5876 | switch (level) { |
| 5877 | case SEC_LEVEL_3: |
| 5878 | priv->sys_config.disable_unicast_decryption = 0; |
| 5879 | priv->ieee->host_decrypt = 0; |
| 5880 | break; |
| 5881 | case SEC_LEVEL_2: |
| 5882 | priv->sys_config.disable_unicast_decryption = 1; |
| 5883 | priv->ieee->host_decrypt = 1; |
| 5884 | break; |
| 5885 | case SEC_LEVEL_1: |
| 5886 | priv->sys_config.disable_unicast_decryption = 0; |
| 5887 | priv->ieee->host_decrypt = 0; |
| 5888 | break; |
| 5889 | case SEC_LEVEL_0: |
| 5890 | priv->sys_config.disable_unicast_decryption = 1; |
| 5891 | break; |
| 5892 | default: |
| 5893 | break; |
| 5894 | } |
| 5895 | } |
| 5896 | |
| 5897 | static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level) |
| 5898 | { |
| 5899 | if (priv->ieee->host_encrypt) |
| 5900 | return; |
| 5901 | |
| 5902 | switch (level) { |
| 5903 | case SEC_LEVEL_3: |
| 5904 | priv->sys_config.disable_multicast_decryption = 0; |
| 5905 | break; |
| 5906 | case SEC_LEVEL_2: |
| 5907 | priv->sys_config.disable_multicast_decryption = 1; |
| 5908 | break; |
| 5909 | case SEC_LEVEL_1: |
| 5910 | priv->sys_config.disable_multicast_decryption = 0; |
| 5911 | break; |
| 5912 | case SEC_LEVEL_0: |
| 5913 | priv->sys_config.disable_multicast_decryption = 1; |
| 5914 | break; |
| 5915 | default: |
| 5916 | break; |
| 5917 | } |
| 5918 | } |
| 5919 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5920 | static void ipw_set_hwcrypto_keys(struct ipw_priv *priv) |
| 5921 | { |
| 5922 | switch (priv->ieee->sec.level) { |
| 5923 | case SEC_LEVEL_3: |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 5924 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
| 5925 | ipw_send_tgi_tx_key(priv, |
| 5926 | DCT_FLAG_EXT_SECURITY_CCM, |
| 5927 | priv->ieee->sec.active_key); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5928 | |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 5929 | if (!priv->ieee->host_mc_decrypt) |
| 5930 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5931 | break; |
| 5932 | case SEC_LEVEL_2: |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 5933 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
| 5934 | ipw_send_tgi_tx_key(priv, |
| 5935 | DCT_FLAG_EXT_SECURITY_TKIP, |
| 5936 | priv->ieee->sec.active_key); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5937 | break; |
| 5938 | case SEC_LEVEL_1: |
| 5939 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); |
Hong Liu | 29cb843 | 2005-09-12 10:43:33 -0500 | [diff] [blame] | 5940 | ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level); |
| 5941 | ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5942 | break; |
| 5943 | case SEC_LEVEL_0: |
| 5944 | default: |
| 5945 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5946 | } |
| 5947 | } |
| 5948 | |
| 5949 | static void ipw_adhoc_check(void *data) |
| 5950 | { |
| 5951 | struct ipw_priv *priv = data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5952 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5953 | if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5954 | !(priv->config & CFG_ADHOC_PERSIST)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5955 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
| 5956 | IPW_DL_STATE | IPW_DL_ASSOC, |
| 5957 | "Missed beacon: %d - disassociate\n", |
| 5958 | priv->missed_adhoc_beacons); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5959 | ipw_remove_current_network(priv); |
| 5960 | ipw_disassociate(priv); |
| 5961 | return; |
| 5962 | } |
| 5963 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5964 | queue_delayed_work(priv->workqueue, &priv->adhoc_check, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5965 | priv->assoc_request.beacon_interval); |
| 5966 | } |
| 5967 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5968 | static void ipw_bg_adhoc_check(void *data) |
| 5969 | { |
| 5970 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5971 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5972 | ipw_adhoc_check(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5973 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5974 | } |
| 5975 | |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 5976 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5977 | static void ipw_debug_config(struct ipw_priv *priv) |
| 5978 | { |
| 5979 | IPW_DEBUG_INFO("Scan completed, no valid APs matched " |
| 5980 | "[CFG 0x%08X]\n", priv->config); |
| 5981 | if (priv->config & CFG_STATIC_CHANNEL) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5982 | IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5983 | else |
| 5984 | IPW_DEBUG_INFO("Channel unlocked.\n"); |
| 5985 | if (priv->config & CFG_STATIC_ESSID) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5986 | IPW_DEBUG_INFO("ESSID locked to '%s'\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5987 | escape_essid(priv->essid, priv->essid_len)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5988 | else |
| 5989 | IPW_DEBUG_INFO("ESSID unlocked.\n"); |
| 5990 | if (priv->config & CFG_STATIC_BSSID) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5991 | IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n", |
| 5992 | MAC_ARG(priv->bssid)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5993 | else |
| 5994 | IPW_DEBUG_INFO("BSSID unlocked.\n"); |
| 5995 | if (priv->capability & CAP_PRIVACY_ON) |
| 5996 | IPW_DEBUG_INFO("PRIVACY on\n"); |
| 5997 | else |
| 5998 | IPW_DEBUG_INFO("PRIVACY off\n"); |
| 5999 | IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask); |
| 6000 | } |
| 6001 | #else |
Jiri Benc | 8d45ff7 | 2005-08-25 20:09:39 -0400 | [diff] [blame] | 6002 | #define ipw_debug_config(x) do {} while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6003 | #endif |
| 6004 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 6005 | static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6006 | { |
| 6007 | /* TODO: Verify that this works... */ |
| 6008 | struct ipw_fixed_rate fr = { |
| 6009 | .tx_rates = priv->rates_mask |
| 6010 | }; |
| 6011 | u32 reg; |
| 6012 | u16 mask = 0; |
| 6013 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6014 | /* Identify 'current FW band' and match it with the fixed |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6015 | * Tx rates */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6016 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6017 | switch (priv->ieee->freq_band) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 6018 | case IEEE80211_52GHZ_BAND: /* A only */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6019 | /* IEEE_A */ |
| 6020 | if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) { |
| 6021 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6022 | IPW_DEBUG_WX |
| 6023 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6024 | fr.tx_rates = 0; |
| 6025 | break; |
| 6026 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6027 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6028 | fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A; |
| 6029 | break; |
| 6030 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 6031 | default: /* 2.4Ghz or Mixed */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6032 | /* IEEE_B */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6033 | if (mode == IEEE_B) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6034 | if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) { |
| 6035 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6036 | IPW_DEBUG_WX |
| 6037 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6038 | fr.tx_rates = 0; |
| 6039 | } |
| 6040 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6041 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6042 | |
| 6043 | /* IEEE_G */ |
| 6044 | if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK | |
| 6045 | IEEE80211_OFDM_RATES_MASK)) { |
| 6046 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6047 | IPW_DEBUG_WX |
| 6048 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6049 | fr.tx_rates = 0; |
| 6050 | break; |
| 6051 | } |
| 6052 | |
| 6053 | if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) { |
| 6054 | mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1); |
| 6055 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK; |
| 6056 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6057 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6058 | if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) { |
| 6059 | mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1); |
| 6060 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK; |
| 6061 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6062 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6063 | if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) { |
| 6064 | mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1); |
| 6065 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK; |
| 6066 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6067 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6068 | fr.tx_rates |= mask; |
| 6069 | break; |
| 6070 | } |
| 6071 | |
| 6072 | reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 6073 | ipw_write_reg32(priv, reg, *(u32 *) & fr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6074 | } |
| 6075 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6076 | static void ipw_abort_scan(struct ipw_priv *priv) |
| 6077 | { |
| 6078 | int err; |
| 6079 | |
| 6080 | if (priv->status & STATUS_SCAN_ABORTING) { |
| 6081 | IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n"); |
| 6082 | return; |
| 6083 | } |
| 6084 | priv->status |= STATUS_SCAN_ABORTING; |
| 6085 | |
| 6086 | err = ipw_send_scan_abort(priv); |
| 6087 | if (err) |
| 6088 | IPW_DEBUG_HC("Request to abort scan failed.\n"); |
| 6089 | } |
| 6090 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6091 | static void ipw_add_scan_channels(struct ipw_priv *priv, |
| 6092 | struct ipw_scan_request_ext *scan, |
| 6093 | int scan_type) |
| 6094 | { |
| 6095 | int channel_index = 0; |
| 6096 | const struct ieee80211_geo *geo; |
| 6097 | int i; |
| 6098 | |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 6099 | geo = ieee80211_get_geo(priv->ieee); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6100 | |
| 6101 | if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) { |
| 6102 | int start = channel_index; |
| 6103 | for (i = 0; i < geo->a_channels; i++) { |
| 6104 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6105 | geo->a[i].channel == priv->channel) |
| 6106 | continue; |
| 6107 | channel_index++; |
| 6108 | scan->channels_list[channel_index] = geo->a[i].channel; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6109 | ipw_set_scan_type(scan, channel_index, |
| 6110 | geo->a[i]. |
| 6111 | flags & IEEE80211_CH_PASSIVE_ONLY ? |
| 6112 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN : |
| 6113 | scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6114 | } |
| 6115 | |
| 6116 | if (start != channel_index) { |
| 6117 | scan->channels_list[start] = (u8) (IPW_A_MODE << 6) | |
| 6118 | (channel_index - start); |
| 6119 | channel_index++; |
| 6120 | } |
| 6121 | } |
| 6122 | |
| 6123 | if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) { |
| 6124 | int start = channel_index; |
| 6125 | if (priv->config & CFG_SPEED_SCAN) { |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6126 | int index; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6127 | u8 channels[IEEE80211_24GHZ_CHANNELS] = { |
| 6128 | /* nop out the list */ |
| 6129 | [0] = 0 |
| 6130 | }; |
| 6131 | |
| 6132 | u8 channel; |
| 6133 | while (channel_index < IPW_SCAN_CHANNELS) { |
| 6134 | channel = |
| 6135 | priv->speed_scan[priv->speed_scan_pos]; |
| 6136 | if (channel == 0) { |
| 6137 | priv->speed_scan_pos = 0; |
| 6138 | channel = priv->speed_scan[0]; |
| 6139 | } |
| 6140 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6141 | channel == priv->channel) { |
| 6142 | priv->speed_scan_pos++; |
| 6143 | continue; |
| 6144 | } |
| 6145 | |
| 6146 | /* If this channel has already been |
| 6147 | * added in scan, break from loop |
| 6148 | * and this will be the first channel |
| 6149 | * in the next scan. |
| 6150 | */ |
| 6151 | if (channels[channel - 1] != 0) |
| 6152 | break; |
| 6153 | |
| 6154 | channels[channel - 1] = 1; |
| 6155 | priv->speed_scan_pos++; |
| 6156 | channel_index++; |
| 6157 | scan->channels_list[channel_index] = channel; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6158 | index = |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 6159 | ieee80211_channel_to_index(priv->ieee, channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6160 | ipw_set_scan_type(scan, channel_index, |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6161 | geo->bg[index]. |
| 6162 | flags & |
| 6163 | IEEE80211_CH_PASSIVE_ONLY ? |
| 6164 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN |
| 6165 | : scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6166 | } |
| 6167 | } else { |
| 6168 | for (i = 0; i < geo->bg_channels; i++) { |
| 6169 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6170 | geo->bg[i].channel == priv->channel) |
| 6171 | continue; |
| 6172 | channel_index++; |
| 6173 | scan->channels_list[channel_index] = |
| 6174 | geo->bg[i].channel; |
| 6175 | ipw_set_scan_type(scan, channel_index, |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6176 | geo->bg[i]. |
| 6177 | flags & |
| 6178 | IEEE80211_CH_PASSIVE_ONLY ? |
| 6179 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN |
| 6180 | : scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6181 | } |
| 6182 | } |
| 6183 | |
| 6184 | if (start != channel_index) { |
| 6185 | scan->channels_list[start] = (u8) (IPW_B_MODE << 6) | |
| 6186 | (channel_index - start); |
| 6187 | } |
| 6188 | } |
| 6189 | } |
| 6190 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6191 | static int ipw_request_scan(struct ipw_priv *priv) |
| 6192 | { |
| 6193 | struct ipw_scan_request_ext scan; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6194 | int err = 0, scan_type; |
| 6195 | |
| 6196 | if (!(priv->status & STATUS_INIT) || |
| 6197 | (priv->status & STATUS_EXIT_PENDING)) |
| 6198 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6199 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6200 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6201 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6202 | if (priv->status & STATUS_SCANNING) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6203 | IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6204 | priv->status |= STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6205 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6206 | } |
| 6207 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6208 | if (!(priv->status & STATUS_SCAN_FORCED) && |
| 6209 | priv->status & STATUS_SCAN_ABORTING) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6210 | IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 6211 | priv->status |= STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6212 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6213 | } |
| 6214 | |
| 6215 | if (priv->status & STATUS_RF_KILL_MASK) { |
| 6216 | IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 6217 | priv->status |= STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6218 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6219 | } |
| 6220 | |
| 6221 | memset(&scan, 0, sizeof(scan)); |
| 6222 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6223 | if (priv->config & CFG_SPEED_SCAN) |
| 6224 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
| 6225 | cpu_to_le16(30); |
| 6226 | else |
| 6227 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
| 6228 | cpu_to_le16(20); |
| 6229 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6230 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = |
| 6231 | cpu_to_le16(20); |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6232 | 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] | 6233 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6234 | scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee)); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6235 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6236 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6237 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6238 | u8 channel; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6239 | u8 band = 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6240 | |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 6241 | switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6242 | case IEEE80211_52GHZ_BAND: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6243 | band = (u8) (IPW_A_MODE << 6) | 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6244 | channel = priv->channel; |
| 6245 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6246 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6247 | case IEEE80211_24GHZ_BAND: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6248 | band = (u8) (IPW_B_MODE << 6) | 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6249 | channel = priv->channel; |
| 6250 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6251 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6252 | default: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6253 | band = (u8) (IPW_B_MODE << 6) | 1; |
| 6254 | channel = 9; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6255 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6256 | } |
| 6257 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6258 | scan.channels_list[0] = band; |
| 6259 | scan.channels_list[1] = channel; |
| 6260 | ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6261 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6262 | /* NOTE: The card will sit on this channel for this time |
| 6263 | * period. Scan aborts are timing sensitive and frequently |
| 6264 | * result in firmware restarts. As such, it is best to |
| 6265 | * set a small dwell_time here and just keep re-issuing |
| 6266 | * scans. Otherwise fast channel hopping will not actually |
| 6267 | * hop channels. |
| 6268 | * |
| 6269 | * TODO: Move SPEED SCAN support to all modes and bands */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6270 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
| 6271 | cpu_to_le16(2000); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6272 | } else { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6273 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 6274 | /* If we are roaming, then make this a directed scan for the |
| 6275 | * current network. Otherwise, ensure that every other scan |
| 6276 | * is a fast channel hop scan */ |
| 6277 | if ((priv->status & STATUS_ROAMING) |
| 6278 | || (!(priv->status & STATUS_ASSOCIATED) |
| 6279 | && (priv->config & CFG_STATIC_ESSID) |
| 6280 | && (le32_to_cpu(scan.full_scan_index) % 2))) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6281 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
| 6282 | if (err) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6283 | IPW_DEBUG_HC("Attempt to send SSID command " |
| 6284 | "failed.\n"); |
| 6285 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6286 | } |
| 6287 | |
| 6288 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6289 | } else |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6290 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6291 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6292 | ipw_add_scan_channels(priv, &scan, scan_type); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6293 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6294 | } |
| 6295 | #endif |
| 6296 | |
| 6297 | err = ipw_send_scan_request_ext(priv, &scan); |
| 6298 | if (err) { |
| 6299 | IPW_DEBUG_HC("Sending scan command failed: %08X\n", err); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6300 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6301 | } |
| 6302 | |
| 6303 | priv->status |= STATUS_SCANNING; |
| 6304 | priv->status &= ~STATUS_SCAN_PENDING; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6305 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 6306 | IPW_SCAN_CHECK_WATCHDOG); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6307 | done: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6308 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6309 | return err; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6310 | } |
| 6311 | |
| 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 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6390 | //mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6391 | |
| 6392 | //if (!ieee->wpa_enabled) { |
| 6393 | // err = -EOPNOTSUPP; |
| 6394 | // goto out; |
| 6395 | //} |
| 6396 | |
| 6397 | if (wrqu->data.length) { |
| 6398 | buf = kmalloc(wrqu->data.length, GFP_KERNEL); |
| 6399 | if (buf == NULL) { |
| 6400 | err = -ENOMEM; |
| 6401 | goto out; |
| 6402 | } |
| 6403 | |
| 6404 | memcpy(buf, extra, wrqu->data.length); |
| 6405 | kfree(ieee->wpa_ie); |
| 6406 | ieee->wpa_ie = buf; |
| 6407 | ieee->wpa_ie_len = wrqu->data.length; |
| 6408 | } else { |
| 6409 | kfree(ieee->wpa_ie); |
| 6410 | ieee->wpa_ie = NULL; |
| 6411 | ieee->wpa_ie_len = 0; |
| 6412 | } |
| 6413 | |
| 6414 | ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len); |
| 6415 | out: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6416 | //mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6417 | return err; |
| 6418 | } |
| 6419 | |
| 6420 | /* SIOCGIWGENIE */ |
| 6421 | static int ipw_wx_get_genie(struct net_device *dev, |
| 6422 | struct iw_request_info *info, |
| 6423 | union iwreq_data *wrqu, char *extra) |
| 6424 | { |
| 6425 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6426 | struct ieee80211_device *ieee = priv->ieee; |
| 6427 | int err = 0; |
| 6428 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6429 | //mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6430 | |
| 6431 | //if (!ieee->wpa_enabled) { |
| 6432 | // err = -EOPNOTSUPP; |
| 6433 | // goto out; |
| 6434 | //} |
| 6435 | |
| 6436 | if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) { |
| 6437 | wrqu->data.length = 0; |
| 6438 | goto out; |
| 6439 | } |
| 6440 | |
| 6441 | if (wrqu->data.length < ieee->wpa_ie_len) { |
| 6442 | err = -E2BIG; |
| 6443 | goto out; |
| 6444 | } |
| 6445 | |
| 6446 | wrqu->data.length = ieee->wpa_ie_len; |
| 6447 | memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len); |
| 6448 | |
| 6449 | out: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6450 | //mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6451 | return err; |
| 6452 | } |
| 6453 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6454 | static int wext_cipher2level(int cipher) |
| 6455 | { |
| 6456 | switch (cipher) { |
| 6457 | case IW_AUTH_CIPHER_NONE: |
| 6458 | return SEC_LEVEL_0; |
| 6459 | case IW_AUTH_CIPHER_WEP40: |
| 6460 | case IW_AUTH_CIPHER_WEP104: |
| 6461 | return SEC_LEVEL_1; |
| 6462 | case IW_AUTH_CIPHER_TKIP: |
| 6463 | return SEC_LEVEL_2; |
| 6464 | case IW_AUTH_CIPHER_CCMP: |
| 6465 | return SEC_LEVEL_3; |
| 6466 | default: |
| 6467 | return -1; |
| 6468 | } |
| 6469 | } |
| 6470 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6471 | /* SIOCSIWAUTH */ |
| 6472 | static int ipw_wx_set_auth(struct net_device *dev, |
| 6473 | struct iw_request_info *info, |
| 6474 | union iwreq_data *wrqu, char *extra) |
| 6475 | { |
| 6476 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6477 | struct ieee80211_device *ieee = priv->ieee; |
| 6478 | struct iw_param *param = &wrqu->param; |
| 6479 | struct ieee80211_crypt_data *crypt; |
| 6480 | unsigned long flags; |
| 6481 | int ret = 0; |
| 6482 | |
| 6483 | switch (param->flags & IW_AUTH_INDEX) { |
| 6484 | case IW_AUTH_WPA_VERSION: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6485 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6486 | case IW_AUTH_CIPHER_PAIRWISE: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6487 | ipw_set_hw_decrypt_unicast(priv, |
| 6488 | wext_cipher2level(param->value)); |
| 6489 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6490 | case IW_AUTH_CIPHER_GROUP: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6491 | ipw_set_hw_decrypt_multicast(priv, |
| 6492 | wext_cipher2level(param->value)); |
| 6493 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6494 | case IW_AUTH_KEY_MGMT: |
| 6495 | /* |
| 6496 | * ipw2200 does not use these parameters |
| 6497 | */ |
| 6498 | break; |
| 6499 | |
| 6500 | case IW_AUTH_TKIP_COUNTERMEASURES: |
| 6501 | crypt = priv->ieee->crypt[priv->ieee->tx_keyidx]; |
James Ketrenos | 991d1cc | 2005-10-13 09:26:48 +0000 | [diff] [blame] | 6502 | if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6503 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6504 | |
| 6505 | flags = crypt->ops->get_flags(crypt->priv); |
| 6506 | |
| 6507 | if (param->value) |
| 6508 | flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; |
| 6509 | else |
| 6510 | flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; |
| 6511 | |
| 6512 | crypt->ops->set_flags(flags, crypt->priv); |
| 6513 | |
| 6514 | break; |
| 6515 | |
| 6516 | case IW_AUTH_DROP_UNENCRYPTED:{ |
| 6517 | /* HACK: |
| 6518 | * |
| 6519 | * wpa_supplicant calls set_wpa_enabled when the driver |
| 6520 | * is loaded and unloaded, regardless of if WPA is being |
| 6521 | * used. No other calls are made which can be used to |
| 6522 | * determine if encryption will be used or not prior to |
| 6523 | * association being expected. If encryption is not being |
| 6524 | * used, drop_unencrypted is set to false, else true -- we |
| 6525 | * can use this to determine if the CAP_PRIVACY_ON bit should |
| 6526 | * be set. |
| 6527 | */ |
| 6528 | struct ieee80211_security sec = { |
| 6529 | .flags = SEC_ENABLED, |
| 6530 | .enabled = param->value, |
| 6531 | }; |
| 6532 | priv->ieee->drop_unencrypted = param->value; |
| 6533 | /* We only change SEC_LEVEL for open mode. Others |
| 6534 | * are set by ipw_wpa_set_encryption. |
| 6535 | */ |
| 6536 | if (!param->value) { |
| 6537 | sec.flags |= SEC_LEVEL; |
| 6538 | sec.level = SEC_LEVEL_0; |
| 6539 | } else { |
| 6540 | sec.flags |= SEC_LEVEL; |
| 6541 | sec.level = SEC_LEVEL_1; |
| 6542 | } |
| 6543 | if (priv->ieee->set_security) |
| 6544 | priv->ieee->set_security(priv->ieee->dev, &sec); |
| 6545 | break; |
| 6546 | } |
| 6547 | |
| 6548 | case IW_AUTH_80211_AUTH_ALG: |
| 6549 | ret = ipw_wpa_set_auth_algs(priv, param->value); |
| 6550 | break; |
| 6551 | |
| 6552 | case IW_AUTH_WPA_ENABLED: |
| 6553 | ret = ipw_wpa_enable(priv, param->value); |
Zhu Yi | e3c5a64 | 2006-04-13 17:21:13 +0800 | [diff] [blame] | 6554 | ipw_disassociate(priv); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6555 | break; |
| 6556 | |
| 6557 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 6558 | ieee->ieee802_1x = param->value; |
| 6559 | break; |
| 6560 | |
| 6561 | //case IW_AUTH_ROAMING_CONTROL: |
| 6562 | case IW_AUTH_PRIVACY_INVOKED: |
| 6563 | ieee->privacy_invoked = param->value; |
| 6564 | break; |
| 6565 | |
| 6566 | default: |
| 6567 | return -EOPNOTSUPP; |
| 6568 | } |
| 6569 | return ret; |
| 6570 | } |
| 6571 | |
| 6572 | /* SIOCGIWAUTH */ |
| 6573 | static int ipw_wx_get_auth(struct net_device *dev, |
| 6574 | struct iw_request_info *info, |
| 6575 | union iwreq_data *wrqu, char *extra) |
| 6576 | { |
| 6577 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6578 | struct ieee80211_device *ieee = priv->ieee; |
| 6579 | struct ieee80211_crypt_data *crypt; |
| 6580 | struct iw_param *param = &wrqu->param; |
| 6581 | int ret = 0; |
| 6582 | |
| 6583 | switch (param->flags & IW_AUTH_INDEX) { |
| 6584 | case IW_AUTH_WPA_VERSION: |
| 6585 | case IW_AUTH_CIPHER_PAIRWISE: |
| 6586 | case IW_AUTH_CIPHER_GROUP: |
| 6587 | case IW_AUTH_KEY_MGMT: |
| 6588 | /* |
| 6589 | * wpa_supplicant will control these internally |
| 6590 | */ |
| 6591 | ret = -EOPNOTSUPP; |
| 6592 | break; |
| 6593 | |
| 6594 | case IW_AUTH_TKIP_COUNTERMEASURES: |
| 6595 | crypt = priv->ieee->crypt[priv->ieee->tx_keyidx]; |
James Ketrenos | 991d1cc | 2005-10-13 09:26:48 +0000 | [diff] [blame] | 6596 | if (!crypt || !crypt->ops->get_flags) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6597 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6598 | |
| 6599 | param->value = (crypt->ops->get_flags(crypt->priv) & |
| 6600 | IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0; |
| 6601 | |
| 6602 | break; |
| 6603 | |
| 6604 | case IW_AUTH_DROP_UNENCRYPTED: |
| 6605 | param->value = ieee->drop_unencrypted; |
| 6606 | break; |
| 6607 | |
| 6608 | case IW_AUTH_80211_AUTH_ALG: |
| 6609 | param->value = ieee->sec.auth_mode; |
| 6610 | break; |
| 6611 | |
| 6612 | case IW_AUTH_WPA_ENABLED: |
| 6613 | param->value = ieee->wpa_enabled; |
| 6614 | break; |
| 6615 | |
| 6616 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 6617 | param->value = ieee->ieee802_1x; |
| 6618 | break; |
| 6619 | |
| 6620 | case IW_AUTH_ROAMING_CONTROL: |
| 6621 | case IW_AUTH_PRIVACY_INVOKED: |
| 6622 | param->value = ieee->privacy_invoked; |
| 6623 | break; |
| 6624 | |
| 6625 | default: |
| 6626 | return -EOPNOTSUPP; |
| 6627 | } |
| 6628 | return 0; |
| 6629 | } |
| 6630 | |
| 6631 | /* SIOCSIWENCODEEXT */ |
| 6632 | static int ipw_wx_set_encodeext(struct net_device *dev, |
| 6633 | struct iw_request_info *info, |
| 6634 | union iwreq_data *wrqu, char *extra) |
| 6635 | { |
| 6636 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6637 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; |
| 6638 | |
| 6639 | if (hwcrypto) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6640 | if (ext->alg == IW_ENCODE_ALG_TKIP) { |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 6641 | /* IPW HW can't build TKIP MIC, |
| 6642 | host decryption still needed */ |
| 6643 | if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) |
| 6644 | priv->ieee->host_mc_decrypt = 1; |
| 6645 | else { |
| 6646 | priv->ieee->host_encrypt = 0; |
| 6647 | priv->ieee->host_encrypt_msdu = 1; |
| 6648 | priv->ieee->host_decrypt = 1; |
| 6649 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6650 | } else { |
| 6651 | priv->ieee->host_encrypt = 0; |
| 6652 | priv->ieee->host_encrypt_msdu = 0; |
| 6653 | priv->ieee->host_decrypt = 0; |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 6654 | priv->ieee->host_mc_decrypt = 0; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6655 | } |
| 6656 | } |
| 6657 | |
| 6658 | return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra); |
| 6659 | } |
| 6660 | |
| 6661 | /* SIOCGIWENCODEEXT */ |
| 6662 | static int ipw_wx_get_encodeext(struct net_device *dev, |
| 6663 | struct iw_request_info *info, |
| 6664 | union iwreq_data *wrqu, char *extra) |
| 6665 | { |
| 6666 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6667 | return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra); |
| 6668 | } |
| 6669 | |
| 6670 | /* SIOCSIWMLME */ |
| 6671 | static int ipw_wx_set_mlme(struct net_device *dev, |
| 6672 | struct iw_request_info *info, |
| 6673 | union iwreq_data *wrqu, char *extra) |
| 6674 | { |
| 6675 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6676 | struct iw_mlme *mlme = (struct iw_mlme *)extra; |
| 6677 | u16 reason; |
| 6678 | |
| 6679 | reason = cpu_to_le16(mlme->reason_code); |
| 6680 | |
| 6681 | switch (mlme->cmd) { |
| 6682 | case IW_MLME_DEAUTH: |
| 6683 | // silently ignore |
| 6684 | break; |
| 6685 | |
| 6686 | case IW_MLME_DISASSOC: |
| 6687 | ipw_disassociate(priv); |
| 6688 | break; |
| 6689 | |
| 6690 | default: |
| 6691 | return -EOPNOTSUPP; |
| 6692 | } |
| 6693 | return 0; |
| 6694 | } |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6695 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 6696 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6697 | |
| 6698 | /* QoS */ |
| 6699 | /* |
| 6700 | * get the modulation type of the current network or |
| 6701 | * the card current mode |
| 6702 | */ |
Adrian Bunk | 53d0bcf | 2006-03-04 13:14:31 +0100 | [diff] [blame] | 6703 | static u8 ipw_qos_current_mode(struct ipw_priv * priv) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6704 | { |
| 6705 | u8 mode = 0; |
| 6706 | |
| 6707 | if (priv->status & STATUS_ASSOCIATED) { |
| 6708 | unsigned long flags; |
| 6709 | |
| 6710 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 6711 | mode = priv->assoc_network->mode; |
| 6712 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 6713 | } else { |
| 6714 | mode = priv->ieee->mode; |
| 6715 | } |
| 6716 | IPW_DEBUG_QOS("QoS network/card mode %d \n", mode); |
| 6717 | return mode; |
| 6718 | } |
| 6719 | |
| 6720 | /* |
| 6721 | * Handle management frame beacon and probe response |
| 6722 | */ |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 6723 | static int ipw_qos_handle_probe_response(struct ipw_priv *priv, |
| 6724 | int active_network, |
| 6725 | struct ieee80211_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6726 | { |
| 6727 | u32 size = sizeof(struct ieee80211_qos_parameters); |
| 6728 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6729 | if (network->capability & WLAN_CAPABILITY_IBSS) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6730 | network->qos_data.active = network->qos_data.supported; |
| 6731 | |
| 6732 | if (network->flags & NETWORK_HAS_QOS_MASK) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6733 | if (active_network && |
| 6734 | (network->flags & NETWORK_HAS_QOS_PARAMETERS)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6735 | network->qos_data.active = network->qos_data.supported; |
| 6736 | |
| 6737 | if ((network->qos_data.active == 1) && (active_network == 1) && |
| 6738 | (network->flags & NETWORK_HAS_QOS_PARAMETERS) && |
| 6739 | (network->qos_data.old_param_count != |
| 6740 | network->qos_data.param_count)) { |
| 6741 | network->qos_data.old_param_count = |
| 6742 | network->qos_data.param_count; |
| 6743 | schedule_work(&priv->qos_activate); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6744 | IPW_DEBUG_QOS("QoS parameters change call " |
| 6745 | "qos_activate\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6746 | } |
| 6747 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6748 | if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B)) |
| 6749 | memcpy(&network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6750 | &def_parameters_CCK, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6751 | else |
| 6752 | memcpy(&network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6753 | &def_parameters_OFDM, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6754 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6755 | if ((network->qos_data.active == 1) && (active_network == 1)) { |
| 6756 | IPW_DEBUG_QOS("QoS was disabled call qos_activate \n"); |
| 6757 | schedule_work(&priv->qos_activate); |
| 6758 | } |
| 6759 | |
| 6760 | network->qos_data.active = 0; |
| 6761 | network->qos_data.supported = 0; |
| 6762 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6763 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6764 | (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) { |
| 6765 | if (memcmp(network->bssid, priv->bssid, ETH_ALEN)) |
| 6766 | if ((network->capability & WLAN_CAPABILITY_IBSS) && |
| 6767 | !(network->flags & NETWORK_EMPTY_ESSID)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6768 | if ((network->ssid_len == |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6769 | priv->assoc_network->ssid_len) && |
| 6770 | !memcmp(network->ssid, |
| 6771 | priv->assoc_network->ssid, |
| 6772 | network->ssid_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6773 | queue_work(priv->workqueue, |
| 6774 | &priv->merge_networks); |
| 6775 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6776 | } |
| 6777 | |
| 6778 | return 0; |
| 6779 | } |
| 6780 | |
| 6781 | /* |
| 6782 | * This function set up the firmware to support QoS. It sends |
| 6783 | * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO |
| 6784 | */ |
| 6785 | static int ipw_qos_activate(struct ipw_priv *priv, |
| 6786 | struct ieee80211_qos_data *qos_network_data) |
| 6787 | { |
| 6788 | int err; |
| 6789 | struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS]; |
| 6790 | struct ieee80211_qos_parameters *active_one = NULL; |
| 6791 | u32 size = sizeof(struct ieee80211_qos_parameters); |
| 6792 | u32 burst_duration; |
| 6793 | int i; |
| 6794 | u8 type; |
| 6795 | |
| 6796 | type = ipw_qos_current_mode(priv); |
| 6797 | |
| 6798 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]); |
| 6799 | memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size); |
| 6800 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]); |
| 6801 | memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size); |
| 6802 | |
| 6803 | if (qos_network_data == NULL) { |
| 6804 | if (type == IEEE_B) { |
| 6805 | IPW_DEBUG_QOS("QoS activate network mode %d\n", type); |
| 6806 | active_one = &def_parameters_CCK; |
| 6807 | } else |
| 6808 | active_one = &def_parameters_OFDM; |
| 6809 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6810 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6811 | burst_duration = ipw_qos_get_burst_duration(priv); |
| 6812 | for (i = 0; i < QOS_QUEUE_NUM; i++) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6813 | qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] = |
| 6814 | (u16) burst_duration; |
| 6815 | } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6816 | if (type == IEEE_B) { |
| 6817 | IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n", |
| 6818 | type); |
| 6819 | if (priv->qos_data.qos_enable == 0) |
| 6820 | active_one = &def_parameters_CCK; |
| 6821 | else |
| 6822 | active_one = priv->qos_data.def_qos_parm_CCK; |
| 6823 | } else { |
| 6824 | if (priv->qos_data.qos_enable == 0) |
| 6825 | active_one = &def_parameters_OFDM; |
| 6826 | else |
| 6827 | active_one = priv->qos_data.def_qos_parm_OFDM; |
| 6828 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6829 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6830 | } else { |
| 6831 | unsigned long flags; |
| 6832 | int active; |
| 6833 | |
| 6834 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 6835 | active_one = &(qos_network_data->parameters); |
| 6836 | qos_network_data->old_param_count = |
| 6837 | qos_network_data->param_count; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6838 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6839 | active = qos_network_data->supported; |
| 6840 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 6841 | |
| 6842 | if (active == 0) { |
| 6843 | burst_duration = ipw_qos_get_burst_duration(priv); |
| 6844 | for (i = 0; i < QOS_QUEUE_NUM; i++) |
| 6845 | qos_parameters[QOS_PARAM_SET_ACTIVE]. |
| 6846 | tx_op_limit[i] = (u16) burst_duration; |
| 6847 | } |
| 6848 | } |
| 6849 | |
| 6850 | IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6851 | err = ipw_send_qos_params_command(priv, |
| 6852 | (struct ieee80211_qos_parameters *) |
| 6853 | &(qos_parameters[0])); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6854 | if (err) |
| 6855 | IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n"); |
| 6856 | |
| 6857 | return err; |
| 6858 | } |
| 6859 | |
| 6860 | /* |
| 6861 | * send IPW_CMD_WME_INFO to the firmware |
| 6862 | */ |
| 6863 | static int ipw_qos_set_info_element(struct ipw_priv *priv) |
| 6864 | { |
| 6865 | int ret = 0; |
| 6866 | struct ieee80211_qos_information_element qos_info; |
| 6867 | |
| 6868 | if (priv == NULL) |
| 6869 | return -1; |
| 6870 | |
| 6871 | qos_info.elementID = QOS_ELEMENT_ID; |
| 6872 | qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2; |
| 6873 | |
| 6874 | qos_info.version = QOS_VERSION_1; |
| 6875 | qos_info.ac_info = 0; |
| 6876 | |
| 6877 | memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN); |
| 6878 | qos_info.qui_type = QOS_OUI_TYPE; |
| 6879 | qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE; |
| 6880 | |
| 6881 | ret = ipw_send_qos_info_command(priv, &qos_info); |
| 6882 | if (ret != 0) { |
| 6883 | IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n"); |
| 6884 | } |
| 6885 | return ret; |
| 6886 | } |
| 6887 | |
| 6888 | /* |
| 6889 | * Set the QoS parameter with the association request structure |
| 6890 | */ |
| 6891 | static int ipw_qos_association(struct ipw_priv *priv, |
| 6892 | struct ieee80211_network *network) |
| 6893 | { |
| 6894 | int err = 0; |
| 6895 | struct ieee80211_qos_data *qos_data = NULL; |
| 6896 | struct ieee80211_qos_data ibss_data = { |
| 6897 | .supported = 1, |
| 6898 | .active = 1, |
| 6899 | }; |
| 6900 | |
| 6901 | switch (priv->ieee->iw_mode) { |
| 6902 | case IW_MODE_ADHOC: |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 6903 | BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6904 | |
| 6905 | qos_data = &ibss_data; |
| 6906 | break; |
| 6907 | |
| 6908 | case IW_MODE_INFRA: |
| 6909 | qos_data = &network->qos_data; |
| 6910 | break; |
| 6911 | |
| 6912 | default: |
| 6913 | BUG(); |
| 6914 | break; |
| 6915 | } |
| 6916 | |
| 6917 | err = ipw_qos_activate(priv, qos_data); |
| 6918 | if (err) { |
| 6919 | priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC; |
| 6920 | return err; |
| 6921 | } |
| 6922 | |
| 6923 | if (priv->qos_data.qos_enable && qos_data->supported) { |
| 6924 | IPW_DEBUG_QOS("QoS will be enabled for this association\n"); |
| 6925 | priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC; |
| 6926 | return ipw_qos_set_info_element(priv); |
| 6927 | } |
| 6928 | |
| 6929 | return 0; |
| 6930 | } |
| 6931 | |
| 6932 | /* |
| 6933 | * handling the beaconing responces. if we get different QoS setting |
| 6934 | * of the network from the the associated setting adjust the QoS |
| 6935 | * setting |
| 6936 | */ |
| 6937 | static int ipw_qos_association_resp(struct ipw_priv *priv, |
| 6938 | struct ieee80211_network *network) |
| 6939 | { |
| 6940 | int ret = 0; |
| 6941 | unsigned long flags; |
| 6942 | u32 size = sizeof(struct ieee80211_qos_parameters); |
| 6943 | int set_qos_param = 0; |
| 6944 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6945 | if ((priv == NULL) || (network == NULL) || |
| 6946 | (priv->assoc_network == NULL)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6947 | return ret; |
| 6948 | |
| 6949 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 6950 | return ret; |
| 6951 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6952 | if ((priv->ieee->iw_mode != IW_MODE_INFRA)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6953 | return ret; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6954 | |
| 6955 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 6956 | if (network->flags & NETWORK_HAS_QOS_PARAMETERS) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6957 | memcpy(&priv->assoc_network->qos_data, &network->qos_data, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6958 | sizeof(struct ieee80211_qos_data)); |
| 6959 | priv->assoc_network->qos_data.active = 1; |
| 6960 | if ((network->qos_data.old_param_count != |
| 6961 | network->qos_data.param_count)) { |
| 6962 | set_qos_param = 1; |
| 6963 | network->qos_data.old_param_count = |
| 6964 | network->qos_data.param_count; |
| 6965 | } |
| 6966 | |
| 6967 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6968 | if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B)) |
| 6969 | memcpy(&priv->assoc_network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6970 | &def_parameters_CCK, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6971 | else |
| 6972 | memcpy(&priv->assoc_network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6973 | &def_parameters_OFDM, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6974 | priv->assoc_network->qos_data.active = 0; |
| 6975 | priv->assoc_network->qos_data.supported = 0; |
| 6976 | set_qos_param = 1; |
| 6977 | } |
| 6978 | |
| 6979 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 6980 | |
| 6981 | if (set_qos_param == 1) |
| 6982 | schedule_work(&priv->qos_activate); |
| 6983 | |
| 6984 | return ret; |
| 6985 | } |
| 6986 | |
| 6987 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv) |
| 6988 | { |
| 6989 | u32 ret = 0; |
| 6990 | |
| 6991 | if ((priv == NULL)) |
| 6992 | return 0; |
| 6993 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6994 | if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6995 | ret = priv->qos_data.burst_duration_CCK; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6996 | else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6997 | ret = priv->qos_data.burst_duration_OFDM; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6998 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6999 | return ret; |
| 7000 | } |
| 7001 | |
| 7002 | /* |
| 7003 | * Initialize the setting of QoS global |
| 7004 | */ |
| 7005 | static void ipw_qos_init(struct ipw_priv *priv, int enable, |
| 7006 | int burst_enable, u32 burst_duration_CCK, |
| 7007 | u32 burst_duration_OFDM) |
| 7008 | { |
| 7009 | priv->qos_data.qos_enable = enable; |
| 7010 | |
| 7011 | if (priv->qos_data.qos_enable) { |
| 7012 | priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK; |
| 7013 | priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM; |
| 7014 | IPW_DEBUG_QOS("QoS is enabled\n"); |
| 7015 | } else { |
| 7016 | priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK; |
| 7017 | priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM; |
| 7018 | IPW_DEBUG_QOS("QoS is not enabled\n"); |
| 7019 | } |
| 7020 | |
| 7021 | priv->qos_data.burst_enable = burst_enable; |
| 7022 | |
| 7023 | if (burst_enable) { |
| 7024 | priv->qos_data.burst_duration_CCK = burst_duration_CCK; |
| 7025 | priv->qos_data.burst_duration_OFDM = burst_duration_OFDM; |
| 7026 | } else { |
| 7027 | priv->qos_data.burst_duration_CCK = 0; |
| 7028 | priv->qos_data.burst_duration_OFDM = 0; |
| 7029 | } |
| 7030 | } |
| 7031 | |
| 7032 | /* |
| 7033 | * map the packet priority to the right TX Queue |
| 7034 | */ |
| 7035 | static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority) |
| 7036 | { |
| 7037 | if (priority > 7 || !priv->qos_data.qos_enable) |
| 7038 | priority = 0; |
| 7039 | |
| 7040 | return from_priority_to_tx_queue[priority] - 1; |
| 7041 | } |
| 7042 | |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7043 | static int ipw_is_qos_active(struct net_device *dev, |
| 7044 | struct sk_buff *skb) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7045 | { |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7046 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7047 | struct ieee80211_qos_data *qos_data = NULL; |
| 7048 | int active, supported; |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7049 | u8 *daddr = skb->data + ETH_ALEN; |
| 7050 | int unicast = !is_multicast_ether_addr(daddr); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7051 | |
| 7052 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 7053 | return 0; |
| 7054 | |
| 7055 | qos_data = &priv->assoc_network->qos_data; |
| 7056 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7057 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
| 7058 | if (unicast == 0) |
| 7059 | qos_data->active = 0; |
| 7060 | else |
| 7061 | qos_data->active = qos_data->supported; |
| 7062 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7063 | active = qos_data->active; |
| 7064 | supported = qos_data->supported; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7065 | IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d " |
| 7066 | "unicast %d\n", |
| 7067 | priv->qos_data.qos_enable, active, supported, unicast); |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7068 | if (active && priv->qos_data.qos_enable) |
| 7069 | return 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7070 | |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7071 | return 0; |
| 7072 | |
| 7073 | } |
| 7074 | /* |
| 7075 | * add QoS parameter to the TX command |
| 7076 | */ |
| 7077 | static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv, |
| 7078 | u16 priority, |
| 7079 | struct tfd_data *tfd) |
| 7080 | { |
| 7081 | int tx_queue_id = 0; |
| 7082 | |
| 7083 | |
| 7084 | tx_queue_id = from_priority_to_tx_queue[priority] - 1; |
| 7085 | tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED; |
| 7086 | |
| 7087 | if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) { |
| 7088 | tfd->tx_flags &= ~DCT_FLAG_ACK_REQD; |
| 7089 | tfd->tfd.tfd_26.mchdr.qos_ctrl |= CTRL_QOS_NO_ACK; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7090 | } |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7091 | return 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7092 | } |
| 7093 | |
| 7094 | /* |
| 7095 | * background support to run QoS activate functionality |
| 7096 | */ |
| 7097 | static void ipw_bg_qos_activate(void *data) |
| 7098 | { |
| 7099 | struct ipw_priv *priv = data; |
| 7100 | |
| 7101 | if (priv == NULL) |
| 7102 | return; |
| 7103 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7104 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7105 | |
| 7106 | if (priv->status & STATUS_ASSOCIATED) |
| 7107 | ipw_qos_activate(priv, &(priv->assoc_network->qos_data)); |
| 7108 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7109 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7110 | } |
| 7111 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7112 | static int ipw_handle_probe_response(struct net_device *dev, |
| 7113 | struct ieee80211_probe_response *resp, |
| 7114 | struct ieee80211_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7115 | { |
| 7116 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7117 | int active_network = ((priv->status & STATUS_ASSOCIATED) && |
| 7118 | (network == priv->assoc_network)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7119 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7120 | ipw_qos_handle_probe_response(priv, active_network, network); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7121 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7122 | return 0; |
| 7123 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7124 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7125 | static int ipw_handle_beacon(struct net_device *dev, |
| 7126 | struct ieee80211_beacon *resp, |
| 7127 | struct ieee80211_network *network) |
| 7128 | { |
| 7129 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 7130 | int active_network = ((priv->status & STATUS_ASSOCIATED) && |
| 7131 | (network == priv->assoc_network)); |
| 7132 | |
| 7133 | ipw_qos_handle_probe_response(priv, active_network, network); |
| 7134 | |
| 7135 | return 0; |
| 7136 | } |
| 7137 | |
| 7138 | static int ipw_handle_assoc_response(struct net_device *dev, |
| 7139 | struct ieee80211_assoc_response *resp, |
| 7140 | struct ieee80211_network *network) |
| 7141 | { |
| 7142 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 7143 | ipw_qos_association_resp(priv, network); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7144 | return 0; |
| 7145 | } |
| 7146 | |
| 7147 | static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters |
| 7148 | *qos_param) |
| 7149 | { |
Zhu Yi | 4e22699 | 2006-01-24 16:37:36 +0800 | [diff] [blame] | 7150 | return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS, |
| 7151 | sizeof(*qos_param) * 3, qos_param); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7152 | } |
| 7153 | |
| 7154 | static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element |
| 7155 | *qos_param) |
| 7156 | { |
Zhu Yi | 4e22699 | 2006-01-24 16:37:36 +0800 | [diff] [blame] | 7157 | return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param), |
| 7158 | qos_param); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7159 | } |
| 7160 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 7161 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7162 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7163 | static int ipw_associate_network(struct ipw_priv *priv, |
| 7164 | struct ieee80211_network *network, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7165 | struct ipw_supported_rates *rates, int roaming) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7166 | { |
| 7167 | int err; |
| 7168 | |
| 7169 | if (priv->config & CFG_FIXED_RATE) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7170 | ipw_set_fixed_rate(priv, network->mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7171 | |
| 7172 | if (!(priv->config & CFG_STATIC_ESSID)) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7173 | priv->essid_len = min(network->ssid_len, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7174 | (u8) IW_ESSID_MAX_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7175 | memcpy(priv->essid, network->ssid, priv->essid_len); |
| 7176 | } |
| 7177 | |
| 7178 | network->last_associate = jiffies; |
| 7179 | |
| 7180 | memset(&priv->assoc_request, 0, sizeof(priv->assoc_request)); |
| 7181 | priv->assoc_request.channel = network->channel; |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7182 | priv->assoc_request.auth_key = 0; |
| 7183 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7184 | if ((priv->capability & CAP_PRIVACY_ON) && |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7185 | (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7186 | priv->assoc_request.auth_type = AUTH_SHARED_KEY; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7187 | priv->assoc_request.auth_key = priv->ieee->sec.active_key; |
| 7188 | |
Zhu Yi | 1ba61e0 | 2006-02-15 13:00:55 +0800 | [diff] [blame] | 7189 | if (priv->ieee->sec.level == SEC_LEVEL_1) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7190 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7191 | |
| 7192 | } else if ((priv->capability & CAP_PRIVACY_ON) && |
| 7193 | (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP)) |
| 7194 | priv->assoc_request.auth_type = AUTH_LEAP; |
| 7195 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7196 | priv->assoc_request.auth_type = AUTH_OPEN; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7197 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7198 | if (priv->ieee->wpa_ie_len) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7199 | priv->assoc_request.policy_support = 0x02; /* RSN active */ |
| 7200 | ipw_set_rsn_capa(priv, priv->ieee->wpa_ie, |
| 7201 | priv->ieee->wpa_ie_len); |
| 7202 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7203 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7204 | /* |
| 7205 | * It is valid for our ieee device to support multiple modes, but |
| 7206 | * 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] | 7207 | * just one mode. |
| 7208 | */ |
| 7209 | if (network->mode & priv->ieee->mode & IEEE_A) |
| 7210 | priv->assoc_request.ieee_mode = IPW_A_MODE; |
| 7211 | else if (network->mode & priv->ieee->mode & IEEE_G) |
| 7212 | priv->assoc_request.ieee_mode = IPW_G_MODE; |
| 7213 | else if (network->mode & priv->ieee->mode & IEEE_B) |
| 7214 | priv->assoc_request.ieee_mode = IPW_B_MODE; |
| 7215 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7216 | priv->assoc_request.capability = network->capability; |
| 7217 | if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 7218 | && !(priv->config & CFG_PREAMBLE_LONG)) { |
| 7219 | priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE; |
| 7220 | } else { |
| 7221 | priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE; |
| 7222 | |
| 7223 | /* Clear the short preamble if we won't be supporting it */ |
| 7224 | priv->assoc_request.capability &= |
| 7225 | ~WLAN_CAPABILITY_SHORT_PREAMBLE; |
| 7226 | } |
| 7227 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7228 | /* Clear capability bits that aren't used in Ad Hoc */ |
| 7229 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 7230 | priv->assoc_request.capability &= |
| 7231 | ~WLAN_CAPABILITY_SHORT_SLOT_TIME; |
| 7232 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7233 | IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, " |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7234 | "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] | 7235 | roaming ? "Rea" : "A", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7236 | escape_essid(priv->essid, priv->essid_len), |
| 7237 | network->channel, |
| 7238 | ipw_modes[priv->assoc_request.ieee_mode], |
| 7239 | rates->num_rates, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7240 | (priv->assoc_request.preamble_length == |
| 7241 | DCT_FLAG_LONG_PREAMBLE) ? "long" : "short", |
| 7242 | network->capability & |
| 7243 | WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7244 | priv->capability & CAP_PRIVACY_ON ? "on " : "off", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7245 | priv->capability & CAP_PRIVACY_ON ? |
| 7246 | (priv->capability & CAP_SHARED_KEY ? "(shared)" : |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7247 | "(open)") : "", |
| 7248 | priv->capability & CAP_PRIVACY_ON ? " key=" : "", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7249 | priv->capability & CAP_PRIVACY_ON ? |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7250 | '1' + priv->ieee->sec.active_key : '.', |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7251 | priv->capability & CAP_PRIVACY_ON ? '.' : ' '); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7252 | |
| 7253 | priv->assoc_request.beacon_interval = network->beacon_interval; |
| 7254 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7255 | (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7256 | priv->assoc_request.assoc_type = HC_IBSS_START; |
| 7257 | priv->assoc_request.assoc_tsf_msw = 0; |
| 7258 | priv->assoc_request.assoc_tsf_lsw = 0; |
| 7259 | } else { |
| 7260 | if (unlikely(roaming)) |
| 7261 | priv->assoc_request.assoc_type = HC_REASSOCIATE; |
| 7262 | else |
| 7263 | priv->assoc_request.assoc_type = HC_ASSOCIATE; |
| 7264 | priv->assoc_request.assoc_tsf_msw = network->time_stamp[1]; |
| 7265 | priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0]; |
| 7266 | } |
| 7267 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7268 | memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7269 | |
| 7270 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
| 7271 | memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN); |
| 7272 | priv->assoc_request.atim_window = network->atim_window; |
| 7273 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7274 | memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7275 | priv->assoc_request.atim_window = 0; |
| 7276 | } |
| 7277 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7278 | priv->assoc_request.listen_interval = network->listen_interval; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7279 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7280 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
| 7281 | if (err) { |
| 7282 | IPW_DEBUG_HC("Attempt to send SSID command failed.\n"); |
| 7283 | return err; |
| 7284 | } |
| 7285 | |
| 7286 | rates->ieee_mode = priv->assoc_request.ieee_mode; |
| 7287 | rates->purpose = IPW_RATE_CONNECT; |
| 7288 | ipw_send_supported_rates(priv, rates); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7289 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7290 | if (priv->assoc_request.ieee_mode == IPW_G_MODE) |
| 7291 | priv->sys_config.dot11g_auto_detection = 1; |
| 7292 | else |
| 7293 | priv->sys_config.dot11g_auto_detection = 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7294 | |
| 7295 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 7296 | priv->sys_config.answer_broadcast_ssid_probe = 1; |
| 7297 | else |
| 7298 | priv->sys_config.answer_broadcast_ssid_probe = 0; |
| 7299 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7300 | err = ipw_send_system_config(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7301 | if (err) { |
| 7302 | IPW_DEBUG_HC("Attempt to send sys config command failed.\n"); |
| 7303 | return err; |
| 7304 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7305 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7306 | IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7307 | err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7308 | if (err) { |
| 7309 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); |
| 7310 | return err; |
| 7311 | } |
| 7312 | |
| 7313 | /* |
| 7314 | * If preemption is enabled, it is possible for the association |
| 7315 | * to complete before we return from ipw_send_associate. Therefore |
| 7316 | * we have to be sure and update our priviate data first. |
| 7317 | */ |
| 7318 | priv->channel = network->channel; |
| 7319 | memcpy(priv->bssid, network->bssid, ETH_ALEN); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7320 | priv->status |= STATUS_ASSOCIATING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7321 | priv->status &= ~STATUS_SECURITY_UPDATED; |
| 7322 | |
| 7323 | priv->assoc_network = network; |
| 7324 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 7325 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7326 | ipw_qos_association(priv, network); |
| 7327 | #endif |
| 7328 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7329 | err = ipw_send_associate(priv, &priv->assoc_request); |
| 7330 | if (err) { |
| 7331 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); |
| 7332 | return err; |
| 7333 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7334 | |
| 7335 | IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7336 | escape_essid(priv->essid, priv->essid_len), |
| 7337 | MAC_ARG(priv->bssid)); |
| 7338 | |
| 7339 | return 0; |
| 7340 | } |
| 7341 | |
| 7342 | static void ipw_roam(void *data) |
| 7343 | { |
| 7344 | struct ipw_priv *priv = data; |
| 7345 | struct ieee80211_network *network = NULL; |
| 7346 | struct ipw_network_match match = { |
| 7347 | .network = priv->assoc_network |
| 7348 | }; |
| 7349 | |
| 7350 | /* The roaming process is as follows: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7351 | * |
| 7352 | * 1. Missed beacon threshold triggers the roaming process by |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7353 | * setting the status ROAM bit and requesting a scan. |
| 7354 | * 2. When the scan completes, it schedules the ROAM work |
| 7355 | * 3. The ROAM work looks at all of the known networks for one that |
| 7356 | * is a better network than the currently associated. If none |
| 7357 | * found, the ROAM process is over (ROAM bit cleared) |
| 7358 | * 4. If a better network is found, a disassociation request is |
| 7359 | * sent. |
| 7360 | * 5. When the disassociation completes, the roam work is again |
| 7361 | * scheduled. The second time through, the driver is no longer |
| 7362 | * associated, and the newly selected network is sent an |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7363 | * association request. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7364 | * 6. At this point ,the roaming process is complete and the ROAM |
| 7365 | * status bit is cleared. |
| 7366 | */ |
| 7367 | |
| 7368 | /* If we are no longer associated, and the roaming bit is no longer |
| 7369 | * set, then we are not actively roaming, so just return */ |
| 7370 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING))) |
| 7371 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7372 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7373 | if (priv->status & STATUS_ASSOCIATED) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7374 | /* First pass through ROAM process -- look for a better |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7375 | * network */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7376 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7377 | u8 rssi = priv->assoc_network->stats.rssi; |
| 7378 | priv->assoc_network->stats.rssi = -128; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7379 | spin_lock_irqsave(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7380 | list_for_each_entry(network, &priv->ieee->network_list, list) { |
| 7381 | if (network != priv->assoc_network) |
| 7382 | ipw_best_network(priv, &match, network, 1); |
| 7383 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7384 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7385 | priv->assoc_network->stats.rssi = rssi; |
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 | if (match.network == priv->assoc_network) { |
| 7388 | IPW_DEBUG_ASSOC("No better APs in this network to " |
| 7389 | "roam to.\n"); |
| 7390 | priv->status &= ~STATUS_ROAMING; |
| 7391 | ipw_debug_config(priv); |
| 7392 | return; |
| 7393 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7394 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7395 | ipw_send_disassociate(priv, 1); |
| 7396 | priv->assoc_network = match.network; |
| 7397 | |
| 7398 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7399 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7400 | |
| 7401 | /* Second pass through ROAM process -- request association */ |
| 7402 | ipw_compatible_rates(priv, priv->assoc_network, &match.rates); |
| 7403 | ipw_associate_network(priv, priv->assoc_network, &match.rates, 1); |
| 7404 | priv->status &= ~STATUS_ROAMING; |
| 7405 | } |
| 7406 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7407 | static void ipw_bg_roam(void *data) |
| 7408 | { |
| 7409 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7410 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7411 | ipw_roam(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7412 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7413 | } |
| 7414 | |
| 7415 | static int ipw_associate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7416 | { |
| 7417 | struct ipw_priv *priv = data; |
| 7418 | |
| 7419 | struct ieee80211_network *network = NULL; |
| 7420 | struct ipw_network_match match = { |
| 7421 | .network = NULL |
| 7422 | }; |
| 7423 | struct ipw_supported_rates *rates; |
| 7424 | struct list_head *element; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7425 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7426 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7427 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
| 7428 | IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n"); |
| 7429 | return 0; |
| 7430 | } |
| 7431 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7432 | if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7433 | IPW_DEBUG_ASSOC("Not attempting association (already in " |
| 7434 | "progress)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7435 | return 0; |
| 7436 | } |
| 7437 | |
Hong Liu | e632472 | 2005-09-14 21:04:15 -0500 | [diff] [blame] | 7438 | if (priv->status & STATUS_DISASSOCIATING) { |
| 7439 | IPW_DEBUG_ASSOC("Not attempting association (in " |
| 7440 | "disassociating)\n "); |
| 7441 | queue_work(priv->workqueue, &priv->associate); |
| 7442 | return 0; |
| 7443 | } |
| 7444 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7445 | if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7446 | IPW_DEBUG_ASSOC("Not attempting association (scanning or not " |
| 7447 | "initialized)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7448 | return 0; |
| 7449 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7450 | |
| 7451 | if (!(priv->config & CFG_ASSOCIATE) && |
| 7452 | !(priv->config & (CFG_STATIC_ESSID | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7453 | CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7454 | IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7455 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7456 | } |
| 7457 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7458 | /* Protect our use of the network_list */ |
| 7459 | spin_lock_irqsave(&priv->ieee->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7460 | list_for_each_entry(network, &priv->ieee->network_list, list) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7461 | ipw_best_network(priv, &match, network, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7462 | |
| 7463 | network = match.network; |
| 7464 | rates = &match.rates; |
| 7465 | |
| 7466 | if (network == NULL && |
| 7467 | priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 7468 | priv->config & CFG_ADHOC_CREATE && |
| 7469 | priv->config & CFG_STATIC_ESSID && |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7470 | priv->config & CFG_STATIC_CHANNEL && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7471 | !list_empty(&priv->ieee->network_free_list)) { |
| 7472 | element = priv->ieee->network_free_list.next; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7473 | network = list_entry(element, struct ieee80211_network, list); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7474 | ipw_adhoc_create(priv, network); |
| 7475 | rates = &priv->rates; |
| 7476 | list_del(element); |
| 7477 | list_add_tail(&network->list, &priv->ieee->network_list); |
| 7478 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7479 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7480 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7481 | /* If we reached the end of the list, then we don't have any valid |
| 7482 | * matching APs */ |
| 7483 | if (!network) { |
| 7484 | ipw_debug_config(priv); |
| 7485 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7486 | if (!(priv->status & STATUS_SCANNING)) { |
| 7487 | if (!(priv->config & CFG_SPEED_SCAN)) |
| 7488 | queue_delayed_work(priv->workqueue, |
| 7489 | &priv->request_scan, |
| 7490 | SCAN_INTERVAL); |
| 7491 | else |
| 7492 | queue_work(priv->workqueue, |
| 7493 | &priv->request_scan); |
| 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 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7497 | } |
| 7498 | |
| 7499 | ipw_associate_network(priv, network, rates, 0); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7500 | |
| 7501 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7502 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7503 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7504 | static void ipw_bg_associate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7505 | { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7506 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7507 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7508 | ipw_associate(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7509 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7510 | } |
| 7511 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7512 | static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv, |
| 7513 | struct sk_buff *skb) |
| 7514 | { |
| 7515 | struct ieee80211_hdr *hdr; |
| 7516 | u16 fc; |
| 7517 | |
| 7518 | hdr = (struct ieee80211_hdr *)skb->data; |
| 7519 | fc = le16_to_cpu(hdr->frame_ctl); |
| 7520 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 7521 | return; |
| 7522 | |
| 7523 | fc &= ~IEEE80211_FCTL_PROTECTED; |
| 7524 | hdr->frame_ctl = cpu_to_le16(fc); |
| 7525 | switch (priv->ieee->sec.level) { |
| 7526 | case SEC_LEVEL_3: |
| 7527 | /* Remove CCMP HDR */ |
| 7528 | memmove(skb->data + IEEE80211_3ADDR_LEN, |
| 7529 | skb->data + IEEE80211_3ADDR_LEN + 8, |
| 7530 | skb->len - IEEE80211_3ADDR_LEN - 8); |
Zhu Yi | f4ff497 | 2005-09-12 10:48:48 -0500 | [diff] [blame] | 7531 | skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7532 | break; |
| 7533 | case SEC_LEVEL_2: |
| 7534 | break; |
| 7535 | case SEC_LEVEL_1: |
| 7536 | /* Remove IV */ |
| 7537 | memmove(skb->data + IEEE80211_3ADDR_LEN, |
| 7538 | skb->data + IEEE80211_3ADDR_LEN + 4, |
| 7539 | skb->len - IEEE80211_3ADDR_LEN - 4); |
Zhu Yi | f4ff497 | 2005-09-12 10:48:48 -0500 | [diff] [blame] | 7540 | skb_trim(skb, skb->len - 8); /* IV + ICV */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7541 | break; |
| 7542 | case SEC_LEVEL_0: |
| 7543 | break; |
| 7544 | default: |
| 7545 | printk(KERN_ERR "Unknow security level %d\n", |
| 7546 | priv->ieee->sec.level); |
| 7547 | break; |
| 7548 | } |
| 7549 | } |
| 7550 | |
| 7551 | static void ipw_handle_data_packet(struct ipw_priv *priv, |
| 7552 | struct ipw_rx_mem_buffer *rxb, |
| 7553 | struct ieee80211_rx_stats *stats) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7554 | { |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 7555 | struct ieee80211_hdr_4addr *hdr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7556 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7557 | |
| 7558 | /* We received data from the HW, so stop the watchdog */ |
| 7559 | priv->net_dev->trans_start = jiffies; |
| 7560 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7561 | /* We only process data packets if the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7562 | * interface is open */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7563 | 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] | 7564 | skb_tailroom(rxb->skb))) { |
| 7565 | priv->ieee->stats.rx_errors++; |
| 7566 | priv->wstats.discard.misc++; |
| 7567 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 7568 | return; |
| 7569 | } else if (unlikely(!netif_running(priv->net_dev))) { |
| 7570 | priv->ieee->stats.rx_dropped++; |
| 7571 | priv->wstats.discard.misc++; |
| 7572 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 7573 | return; |
| 7574 | } |
| 7575 | |
| 7576 | /* Advance skb->data to the start of the actual payload */ |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 7577 | skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7578 | |
| 7579 | /* Set the size of the skb to the size of the frame */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7580 | skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7581 | |
| 7582 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); |
| 7583 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7584 | /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */ |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 7585 | hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data; |
| 7586 | if (priv->ieee->iw_mode != IW_MODE_MONITOR && |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 7587 | (is_multicast_ether_addr(hdr->addr1) ? |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 7588 | !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7589 | ipw_rebuild_decrypted_skb(priv, rxb->skb); |
| 7590 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7591 | if (!ieee80211_rx(priv->ieee, rxb->skb, stats)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7592 | priv->ieee->stats.rx_errors++; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7593 | else { /* ieee80211_rx succeeded, so it now owns the SKB */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7594 | rxb->skb = NULL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7595 | __ipw_led_activity_on(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7596 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7597 | } |
| 7598 | |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 7599 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7600 | static void ipw_handle_data_packet_monitor(struct ipw_priv *priv, |
| 7601 | struct ipw_rx_mem_buffer *rxb, |
| 7602 | struct ieee80211_rx_stats *stats) |
| 7603 | { |
| 7604 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7605 | struct ipw_rx_frame *frame = &pkt->u.frame; |
| 7606 | |
| 7607 | /* initial pull of some data */ |
| 7608 | u16 received_channel = frame->received_channel; |
| 7609 | u8 antennaAndPhy = frame->antennaAndPhy; |
| 7610 | s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */ |
| 7611 | u16 pktrate = frame->rate; |
| 7612 | |
| 7613 | /* Magic struct that slots into the radiotap header -- no reason |
| 7614 | * to build this manually element by element, we can write it much |
| 7615 | * more efficiently than we can parse it. ORDER MATTERS HERE */ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7616 | struct ipw_rt_hdr *ipw_rt; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7617 | |
| 7618 | short len = le16_to_cpu(pkt->u.frame.length); |
| 7619 | |
| 7620 | /* We received data from the HW, so stop the watchdog */ |
| 7621 | priv->net_dev->trans_start = jiffies; |
| 7622 | |
| 7623 | /* We only process data packets if the |
| 7624 | * interface is open */ |
| 7625 | if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) > |
| 7626 | skb_tailroom(rxb->skb))) { |
| 7627 | priv->ieee->stats.rx_errors++; |
| 7628 | priv->wstats.discard.misc++; |
| 7629 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 7630 | return; |
| 7631 | } else if (unlikely(!netif_running(priv->net_dev))) { |
| 7632 | priv->ieee->stats.rx_dropped++; |
| 7633 | priv->wstats.discard.misc++; |
| 7634 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 7635 | return; |
| 7636 | } |
| 7637 | |
| 7638 | /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use |
| 7639 | * that now */ |
| 7640 | if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) { |
| 7641 | /* FIXME: Should alloc bigger skb instead */ |
| 7642 | priv->ieee->stats.rx_dropped++; |
| 7643 | priv->wstats.discard.misc++; |
| 7644 | IPW_DEBUG_DROP("Dropping too large packet in monitor\n"); |
| 7645 | return; |
| 7646 | } |
| 7647 | |
| 7648 | /* copy the frame itself */ |
| 7649 | memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr), |
| 7650 | rxb->skb->data + IPW_RX_FRAME_SIZE, len); |
| 7651 | |
| 7652 | /* Zero the radiotap static buffer ... We only need to zero the bytes NOT |
| 7653 | * part of our real header, saves a little time. |
| 7654 | * |
| 7655 | * No longer necessary since we fill in all our data. Purge before merging |
| 7656 | * patch officially. |
| 7657 | * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0, |
| 7658 | * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr)); |
| 7659 | */ |
| 7660 | |
| 7661 | ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data; |
| 7662 | |
| 7663 | ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 7664 | ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ |
| 7665 | ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */ |
| 7666 | |
| 7667 | /* Big bitfield of all the fields we provide in radiotap */ |
| 7668 | ipw_rt->rt_hdr.it_present = |
| 7669 | ((1 << IEEE80211_RADIOTAP_FLAGS) | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7670 | (1 << IEEE80211_RADIOTAP_TSFT) | |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7671 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 7672 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 7673 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7674 | (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7675 | (1 << IEEE80211_RADIOTAP_ANTENNA)); |
| 7676 | |
| 7677 | /* Zero the flags, we'll add to them as we go */ |
| 7678 | ipw_rt->rt_flags = 0; |
| 7679 | |
| 7680 | /* Convert signal to DBM */ |
| 7681 | ipw_rt->rt_dbmsignal = antsignal; |
| 7682 | |
| 7683 | /* Convert the channel data and set the flags */ |
| 7684 | ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel)); |
| 7685 | if (received_channel > 14) { /* 802.11a */ |
| 7686 | ipw_rt->rt_chbitmask = |
| 7687 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); |
| 7688 | } else if (antennaAndPhy & 32) { /* 802.11b */ |
| 7689 | ipw_rt->rt_chbitmask = |
| 7690 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); |
| 7691 | } else { /* 802.11g */ |
| 7692 | ipw_rt->rt_chbitmask = |
| 7693 | (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ); |
| 7694 | } |
| 7695 | |
| 7696 | /* set the rate in multiples of 500k/s */ |
| 7697 | switch (pktrate) { |
| 7698 | case IPW_TX_RATE_1MB: |
| 7699 | ipw_rt->rt_rate = 2; |
| 7700 | break; |
| 7701 | case IPW_TX_RATE_2MB: |
| 7702 | ipw_rt->rt_rate = 4; |
| 7703 | break; |
| 7704 | case IPW_TX_RATE_5MB: |
| 7705 | ipw_rt->rt_rate = 10; |
| 7706 | break; |
| 7707 | case IPW_TX_RATE_6MB: |
| 7708 | ipw_rt->rt_rate = 12; |
| 7709 | break; |
| 7710 | case IPW_TX_RATE_9MB: |
| 7711 | ipw_rt->rt_rate = 18; |
| 7712 | break; |
| 7713 | case IPW_TX_RATE_11MB: |
| 7714 | ipw_rt->rt_rate = 22; |
| 7715 | break; |
| 7716 | case IPW_TX_RATE_12MB: |
| 7717 | ipw_rt->rt_rate = 24; |
| 7718 | break; |
| 7719 | case IPW_TX_RATE_18MB: |
| 7720 | ipw_rt->rt_rate = 36; |
| 7721 | break; |
| 7722 | case IPW_TX_RATE_24MB: |
| 7723 | ipw_rt->rt_rate = 48; |
| 7724 | break; |
| 7725 | case IPW_TX_RATE_36MB: |
| 7726 | ipw_rt->rt_rate = 72; |
| 7727 | break; |
| 7728 | case IPW_TX_RATE_48MB: |
| 7729 | ipw_rt->rt_rate = 96; |
| 7730 | break; |
| 7731 | case IPW_TX_RATE_54MB: |
| 7732 | ipw_rt->rt_rate = 108; |
| 7733 | break; |
| 7734 | default: |
| 7735 | ipw_rt->rt_rate = 0; |
| 7736 | break; |
| 7737 | } |
| 7738 | |
| 7739 | /* antenna number */ |
| 7740 | ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */ |
| 7741 | |
| 7742 | /* set the preamble flag if we have it */ |
| 7743 | if ((antennaAndPhy & 64)) |
| 7744 | ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; |
| 7745 | |
| 7746 | /* Set the size of the skb to the size of the frame */ |
| 7747 | skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7748 | |
| 7749 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); |
| 7750 | |
| 7751 | if (!ieee80211_rx(priv->ieee, rxb->skb, stats)) |
| 7752 | priv->ieee->stats.rx_errors++; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7753 | else { /* ieee80211_rx succeeded, so it now owns the SKB */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7754 | rxb->skb = NULL; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7755 | /* no LED during capture */ |
| 7756 | } |
| 7757 | } |
| 7758 | #endif |
| 7759 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7760 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 7761 | #define ieee80211_is_probe_response(fc) \ |
| 7762 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \ |
| 7763 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP ) |
| 7764 | |
| 7765 | #define ieee80211_is_management(fc) \ |
| 7766 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) |
| 7767 | |
| 7768 | #define ieee80211_is_control(fc) \ |
| 7769 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) |
| 7770 | |
| 7771 | #define ieee80211_is_data(fc) \ |
| 7772 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) |
| 7773 | |
| 7774 | #define ieee80211_is_assoc_request(fc) \ |
| 7775 | ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ) |
| 7776 | |
| 7777 | #define ieee80211_is_reassoc_request(fc) \ |
| 7778 | ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ) |
| 7779 | |
| 7780 | static void ipw_handle_promiscuous_rx(struct ipw_priv *priv, |
| 7781 | struct ipw_rx_mem_buffer *rxb, |
| 7782 | struct ieee80211_rx_stats *stats) |
| 7783 | { |
| 7784 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7785 | struct ipw_rx_frame *frame = &pkt->u.frame; |
| 7786 | struct ipw_rt_hdr *ipw_rt; |
| 7787 | |
| 7788 | /* First cache any information we need before we overwrite |
| 7789 | * the information provided in the skb from the hardware */ |
| 7790 | struct ieee80211_hdr *hdr; |
| 7791 | u16 channel = frame->received_channel; |
| 7792 | u8 phy_flags = frame->antennaAndPhy; |
| 7793 | s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM; |
| 7794 | s8 noise = frame->noise; |
| 7795 | u8 rate = frame->rate; |
| 7796 | short len = le16_to_cpu(pkt->u.frame.length); |
| 7797 | u64 tsf = 0; |
| 7798 | struct sk_buff *skb; |
| 7799 | int hdr_only = 0; |
| 7800 | u16 filter = priv->prom_priv->filter; |
| 7801 | |
| 7802 | /* If the filter is set to not include Rx frames then return */ |
| 7803 | if (filter & IPW_PROM_NO_RX) |
| 7804 | return; |
| 7805 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7806 | /* We received data from the HW, so stop the watchdog */ |
| 7807 | priv->prom_net_dev->trans_start = jiffies; |
| 7808 | |
| 7809 | if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) { |
| 7810 | priv->prom_priv->ieee->stats.rx_errors++; |
| 7811 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 7812 | return; |
| 7813 | } |
| 7814 | |
| 7815 | /* We only process data packets if the interface is open */ |
| 7816 | if (unlikely(!netif_running(priv->prom_net_dev))) { |
| 7817 | priv->prom_priv->ieee->stats.rx_dropped++; |
| 7818 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 7819 | return; |
| 7820 | } |
| 7821 | |
| 7822 | /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use |
| 7823 | * that now */ |
| 7824 | if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) { |
| 7825 | /* FIXME: Should alloc bigger skb instead */ |
| 7826 | priv->prom_priv->ieee->stats.rx_dropped++; |
| 7827 | IPW_DEBUG_DROP("Dropping too large packet in monitor\n"); |
| 7828 | return; |
| 7829 | } |
| 7830 | |
| 7831 | hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE; |
| 7832 | if (ieee80211_is_management(hdr->frame_ctl)) { |
| 7833 | if (filter & IPW_PROM_NO_MGMT) |
| 7834 | return; |
| 7835 | if (filter & IPW_PROM_MGMT_HEADER_ONLY) |
| 7836 | hdr_only = 1; |
| 7837 | } else if (ieee80211_is_control(hdr->frame_ctl)) { |
| 7838 | if (filter & IPW_PROM_NO_CTL) |
| 7839 | return; |
| 7840 | if (filter & IPW_PROM_CTL_HEADER_ONLY) |
| 7841 | hdr_only = 1; |
| 7842 | } else if (ieee80211_is_data(hdr->frame_ctl)) { |
| 7843 | if (filter & IPW_PROM_NO_DATA) |
| 7844 | return; |
| 7845 | if (filter & IPW_PROM_DATA_HEADER_ONLY) |
| 7846 | hdr_only = 1; |
| 7847 | } |
| 7848 | |
| 7849 | /* Copy the SKB since this is for the promiscuous side */ |
| 7850 | skb = skb_copy(rxb->skb, GFP_ATOMIC); |
| 7851 | if (skb == NULL) { |
| 7852 | IPW_ERROR("skb_clone failed for promiscuous copy.\n"); |
| 7853 | return; |
| 7854 | } |
| 7855 | |
| 7856 | /* copy the frame data to write after where the radiotap header goes */ |
| 7857 | ipw_rt = (void *)skb->data; |
| 7858 | |
| 7859 | if (hdr_only) |
| 7860 | len = ieee80211_get_hdrlen(hdr->frame_ctl); |
| 7861 | |
| 7862 | memcpy(ipw_rt->payload, hdr, len); |
| 7863 | |
| 7864 | /* Zero the radiotap static buffer ... We only need to zero the bytes |
| 7865 | * NOT part of our real header, saves a little time. |
| 7866 | * |
| 7867 | * No longer necessary since we fill in all our data. Purge before |
| 7868 | * merging patch officially. |
| 7869 | * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0, |
| 7870 | * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr)); |
| 7871 | */ |
| 7872 | |
| 7873 | ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 7874 | ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ |
| 7875 | ipw_rt->rt_hdr.it_len = sizeof(*ipw_rt); /* total header+data */ |
| 7876 | |
| 7877 | /* Set the size of the skb to the size of the frame */ |
| 7878 | skb_put(skb, ipw_rt->rt_hdr.it_len + len); |
| 7879 | |
| 7880 | /* Big bitfield of all the fields we provide in radiotap */ |
| 7881 | ipw_rt->rt_hdr.it_present = |
| 7882 | ((1 << IEEE80211_RADIOTAP_FLAGS) | |
| 7883 | (1 << IEEE80211_RADIOTAP_TSFT) | |
| 7884 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 7885 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 7886 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | |
| 7887 | (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | |
| 7888 | (1 << IEEE80211_RADIOTAP_ANTENNA)); |
| 7889 | |
| 7890 | /* Zero the flags, we'll add to them as we go */ |
| 7891 | ipw_rt->rt_flags = 0; |
| 7892 | |
| 7893 | ipw_rt->rt_tsf = tsf; |
| 7894 | |
| 7895 | /* Convert to DBM */ |
| 7896 | ipw_rt->rt_dbmsignal = signal; |
| 7897 | ipw_rt->rt_dbmnoise = noise; |
| 7898 | |
| 7899 | /* Convert the channel data and set the flags */ |
| 7900 | ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel)); |
| 7901 | if (channel > 14) { /* 802.11a */ |
| 7902 | ipw_rt->rt_chbitmask = |
| 7903 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); |
| 7904 | } else if (phy_flags & (1 << 5)) { /* 802.11b */ |
| 7905 | ipw_rt->rt_chbitmask = |
| 7906 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); |
| 7907 | } else { /* 802.11g */ |
| 7908 | ipw_rt->rt_chbitmask = |
| 7909 | (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ); |
| 7910 | } |
| 7911 | |
| 7912 | /* set the rate in multiples of 500k/s */ |
| 7913 | switch (rate) { |
| 7914 | case IPW_TX_RATE_1MB: |
| 7915 | ipw_rt->rt_rate = 2; |
| 7916 | break; |
| 7917 | case IPW_TX_RATE_2MB: |
| 7918 | ipw_rt->rt_rate = 4; |
| 7919 | break; |
| 7920 | case IPW_TX_RATE_5MB: |
| 7921 | ipw_rt->rt_rate = 10; |
| 7922 | break; |
| 7923 | case IPW_TX_RATE_6MB: |
| 7924 | ipw_rt->rt_rate = 12; |
| 7925 | break; |
| 7926 | case IPW_TX_RATE_9MB: |
| 7927 | ipw_rt->rt_rate = 18; |
| 7928 | break; |
| 7929 | case IPW_TX_RATE_11MB: |
| 7930 | ipw_rt->rt_rate = 22; |
| 7931 | break; |
| 7932 | case IPW_TX_RATE_12MB: |
| 7933 | ipw_rt->rt_rate = 24; |
| 7934 | break; |
| 7935 | case IPW_TX_RATE_18MB: |
| 7936 | ipw_rt->rt_rate = 36; |
| 7937 | break; |
| 7938 | case IPW_TX_RATE_24MB: |
| 7939 | ipw_rt->rt_rate = 48; |
| 7940 | break; |
| 7941 | case IPW_TX_RATE_36MB: |
| 7942 | ipw_rt->rt_rate = 72; |
| 7943 | break; |
| 7944 | case IPW_TX_RATE_48MB: |
| 7945 | ipw_rt->rt_rate = 96; |
| 7946 | break; |
| 7947 | case IPW_TX_RATE_54MB: |
| 7948 | ipw_rt->rt_rate = 108; |
| 7949 | break; |
| 7950 | default: |
| 7951 | ipw_rt->rt_rate = 0; |
| 7952 | break; |
| 7953 | } |
| 7954 | |
| 7955 | /* antenna number */ |
| 7956 | ipw_rt->rt_antenna = (phy_flags & 3); |
| 7957 | |
| 7958 | /* set the preamble flag if we have it */ |
| 7959 | if (phy_flags & (1 << 6)) |
| 7960 | ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; |
| 7961 | |
| 7962 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len); |
| 7963 | |
| 7964 | if (!ieee80211_rx(priv->prom_priv->ieee, skb, stats)) { |
| 7965 | priv->prom_priv->ieee->stats.rx_errors++; |
| 7966 | dev_kfree_skb_any(skb); |
| 7967 | } |
| 7968 | } |
| 7969 | #endif |
| 7970 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 7971 | static int is_network_packet(struct ipw_priv *priv, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7972 | struct ieee80211_hdr_4addr *header) |
| 7973 | { |
| 7974 | /* Filter incoming packets to determine if they are targetted toward |
| 7975 | * this network, discarding packets coming from ourselves */ |
| 7976 | switch (priv->ieee->iw_mode) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7977 | case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7978 | /* packets from our adapter are dropped (echo) */ |
| 7979 | if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN)) |
| 7980 | return 0; |
| 7981 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 7982 | /* {broad,multi}cast packets to our BSSID go through */ |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 7983 | if (is_multicast_ether_addr(header->addr1)) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7984 | return !memcmp(header->addr3, priv->bssid, ETH_ALEN); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7985 | |
| 7986 | /* packets to our adapter go through */ |
| 7987 | return !memcmp(header->addr1, priv->net_dev->dev_addr, |
| 7988 | ETH_ALEN); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7989 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 7990 | case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7991 | /* packets from our adapter are dropped (echo) */ |
| 7992 | if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN)) |
| 7993 | return 0; |
| 7994 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 7995 | /* {broad,multi}cast packets to our BSS go through */ |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 7996 | if (is_multicast_ether_addr(header->addr1)) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7997 | return !memcmp(header->addr2, priv->bssid, ETH_ALEN); |
| 7998 | |
| 7999 | /* packets to our adapter go through */ |
| 8000 | return !memcmp(header->addr1, priv->net_dev->dev_addr, |
| 8001 | ETH_ALEN); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8002 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8003 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8004 | return 1; |
| 8005 | } |
| 8006 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8007 | #define IPW_PACKET_RETRY_TIME HZ |
| 8008 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 8009 | static int is_duplicate_packet(struct ipw_priv *priv, |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8010 | struct ieee80211_hdr_4addr *header) |
| 8011 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8012 | u16 sc = le16_to_cpu(header->seq_ctl); |
| 8013 | u16 seq = WLAN_GET_SEQ_SEQ(sc); |
| 8014 | u16 frag = WLAN_GET_SEQ_FRAG(sc); |
| 8015 | u16 *last_seq, *last_frag; |
| 8016 | unsigned long *last_time; |
| 8017 | |
| 8018 | switch (priv->ieee->iw_mode) { |
| 8019 | case IW_MODE_ADHOC: |
| 8020 | { |
| 8021 | struct list_head *p; |
| 8022 | struct ipw_ibss_seq *entry = NULL; |
| 8023 | u8 *mac = header->addr2; |
| 8024 | int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE; |
| 8025 | |
| 8026 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
| 8027 | entry = |
| 8028 | list_entry(p, struct ipw_ibss_seq, list); |
| 8029 | if (!memcmp(entry->mac, mac, ETH_ALEN)) |
| 8030 | break; |
| 8031 | } |
| 8032 | if (p == &priv->ibss_mac_hash[index]) { |
| 8033 | entry = kmalloc(sizeof(*entry), GFP_ATOMIC); |
| 8034 | if (!entry) { |
| 8035 | IPW_ERROR |
| 8036 | ("Cannot malloc new mac entry\n"); |
| 8037 | return 0; |
| 8038 | } |
| 8039 | memcpy(entry->mac, mac, ETH_ALEN); |
| 8040 | entry->seq_num = seq; |
| 8041 | entry->frag_num = frag; |
| 8042 | entry->packet_time = jiffies; |
| 8043 | list_add(&entry->list, |
| 8044 | &priv->ibss_mac_hash[index]); |
| 8045 | return 0; |
| 8046 | } |
| 8047 | last_seq = &entry->seq_num; |
| 8048 | last_frag = &entry->frag_num; |
| 8049 | last_time = &entry->packet_time; |
| 8050 | break; |
| 8051 | } |
| 8052 | case IW_MODE_INFRA: |
| 8053 | last_seq = &priv->last_seq_num; |
| 8054 | last_frag = &priv->last_frag_num; |
| 8055 | last_time = &priv->last_packet_time; |
| 8056 | break; |
| 8057 | default: |
| 8058 | return 0; |
| 8059 | } |
| 8060 | if ((*last_seq == seq) && |
| 8061 | time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) { |
| 8062 | if (*last_frag == frag) |
| 8063 | goto drop; |
| 8064 | if (*last_frag + 1 != frag) |
| 8065 | /* out-of-order fragment */ |
| 8066 | goto drop; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8067 | } else |
| 8068 | *last_seq = seq; |
| 8069 | |
Zhu Yi | f57ce7c | 2005-07-13 12:22:15 -0500 | [diff] [blame] | 8070 | *last_frag = frag; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8071 | *last_time = jiffies; |
| 8072 | return 0; |
| 8073 | |
| 8074 | drop: |
Zhu Yi | 87b016c | 2005-08-05 17:17:35 +0800 | [diff] [blame] | 8075 | /* Comment this line now since we observed the card receives |
| 8076 | * duplicate packets but the FCTL_RETRY bit is not set in the |
| 8077 | * IBSS mode with fragmentation enabled. |
| 8078 | BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8079 | return 1; |
| 8080 | } |
| 8081 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8082 | static void ipw_handle_mgmt_packet(struct ipw_priv *priv, |
| 8083 | struct ipw_rx_mem_buffer *rxb, |
| 8084 | struct ieee80211_rx_stats *stats) |
| 8085 | { |
| 8086 | struct sk_buff *skb = rxb->skb; |
| 8087 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data; |
| 8088 | struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *) |
| 8089 | (skb->data + IPW_RX_FRAME_SIZE); |
| 8090 | |
| 8091 | ieee80211_rx_mgt(priv->ieee, header, stats); |
| 8092 | |
| 8093 | if (priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 8094 | ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == |
| 8095 | IEEE80211_STYPE_PROBE_RESP) || |
| 8096 | (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == |
| 8097 | IEEE80211_STYPE_BEACON))) { |
| 8098 | if (!memcmp(header->addr3, priv->bssid, ETH_ALEN)) |
| 8099 | ipw_add_station(priv, header->addr2); |
| 8100 | } |
| 8101 | |
| 8102 | if (priv->config & CFG_NET_STATS) { |
| 8103 | IPW_DEBUG_HC("sending stat packet\n"); |
| 8104 | |
| 8105 | /* Set the size of the skb to the size of the full |
| 8106 | * ipw header and 802.11 frame */ |
| 8107 | skb_put(skb, le16_to_cpu(pkt->u.frame.length) + |
| 8108 | IPW_RX_FRAME_SIZE); |
| 8109 | |
| 8110 | /* Advance past the ipw packet header to the 802.11 frame */ |
| 8111 | skb_pull(skb, IPW_RX_FRAME_SIZE); |
| 8112 | |
| 8113 | /* Push the ieee80211_rx_stats before the 802.11 frame */ |
| 8114 | memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats)); |
| 8115 | |
| 8116 | skb->dev = priv->ieee->dev; |
| 8117 | |
| 8118 | /* Point raw at the ieee80211_stats */ |
| 8119 | skb->mac.raw = skb->data; |
| 8120 | |
| 8121 | skb->pkt_type = PACKET_OTHERHOST; |
| 8122 | skb->protocol = __constant_htons(ETH_P_80211_STATS); |
| 8123 | memset(skb->cb, 0, sizeof(rxb->skb->cb)); |
| 8124 | netif_rx(skb); |
| 8125 | rxb->skb = NULL; |
| 8126 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8127 | } |
| 8128 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8129 | /* |
| 8130 | * Main entry function for recieving a packet with 80211 headers. This |
| 8131 | * should be called when ever the FW has notified us that there is a new |
| 8132 | * skb in the recieve queue. |
| 8133 | */ |
| 8134 | static void ipw_rx(struct ipw_priv *priv) |
| 8135 | { |
| 8136 | struct ipw_rx_mem_buffer *rxb; |
| 8137 | struct ipw_rx_packet *pkt; |
James Ketrenos | 0dacca1 | 2005-09-21 12:23:41 -0500 | [diff] [blame] | 8138 | struct ieee80211_hdr_4addr *header; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8139 | u32 r, w, i; |
| 8140 | u8 network_packet; |
| 8141 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8142 | r = ipw_read32(priv, IPW_RX_READ_INDEX); |
| 8143 | w = ipw_read32(priv, IPW_RX_WRITE_INDEX); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8144 | i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE; |
| 8145 | |
| 8146 | while (i != r) { |
| 8147 | rxb = priv->rxq->queue[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8148 | if (unlikely(rxb == NULL)) { |
| 8149 | printk(KERN_CRIT "Queue not allocated!\n"); |
| 8150 | break; |
| 8151 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8152 | priv->rxq->queue[i] = NULL; |
| 8153 | |
| 8154 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8155 | IPW_RX_BUF_SIZE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8156 | PCI_DMA_FROMDEVICE); |
| 8157 | |
| 8158 | pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 8159 | IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n", |
| 8160 | pkt->header.message_type, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8161 | pkt->header.rx_seq_num, pkt->header.control_bits); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8162 | |
| 8163 | switch (pkt->header.message_type) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8164 | case RX_FRAME_TYPE: /* 802.11 frame */ { |
| 8165 | struct ieee80211_rx_stats stats = { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8166 | .rssi = |
| 8167 | le16_to_cpu(pkt->u.frame.rssi_dbm) - |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8168 | IPW_RSSI_TO_DBM, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8169 | .signal = |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 8170 | le16_to_cpu(pkt->u.frame.rssi_dbm) - |
| 8171 | IPW_RSSI_TO_DBM + 0x100, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8172 | .noise = |
| 8173 | le16_to_cpu(pkt->u.frame.noise), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8174 | .rate = pkt->u.frame.rate, |
| 8175 | .mac_time = jiffies, |
| 8176 | .received_channel = |
| 8177 | pkt->u.frame.received_channel, |
| 8178 | .freq = |
| 8179 | (pkt->u.frame. |
| 8180 | control & (1 << 0)) ? |
| 8181 | IEEE80211_24GHZ_BAND : |
| 8182 | IEEE80211_52GHZ_BAND, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8183 | .len = le16_to_cpu(pkt->u.frame.length), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8184 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8185 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8186 | if (stats.rssi != 0) |
| 8187 | stats.mask |= IEEE80211_STATMASK_RSSI; |
| 8188 | if (stats.signal != 0) |
| 8189 | stats.mask |= IEEE80211_STATMASK_SIGNAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8190 | if (stats.noise != 0) |
| 8191 | stats.mask |= IEEE80211_STATMASK_NOISE; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8192 | if (stats.rate != 0) |
| 8193 | stats.mask |= IEEE80211_STATMASK_RATE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8194 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8195 | priv->rx_packets++; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8196 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8197 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 8198 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) |
| 8199 | ipw_handle_promiscuous_rx(priv, rxb, &stats); |
| 8200 | #endif |
| 8201 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8202 | #ifdef CONFIG_IPW2200_MONITOR |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8203 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 8204 | #ifdef CONFIG_IPW2200_RADIOTAP |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8205 | |
| 8206 | ipw_handle_data_packet_monitor(priv, |
| 8207 | rxb, |
| 8208 | &stats); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8209 | #else |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8210 | ipw_handle_data_packet(priv, rxb, |
| 8211 | &stats); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8212 | #endif |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8213 | break; |
| 8214 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8215 | #endif |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8216 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8217 | header = |
James Ketrenos | 0dacca1 | 2005-09-21 12:23:41 -0500 | [diff] [blame] | 8218 | (struct ieee80211_hdr_4addr *)(rxb->skb-> |
| 8219 | data + |
| 8220 | IPW_RX_FRAME_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8221 | /* TODO: Check Ad-Hoc dest/source and make sure |
| 8222 | * that we are actually parsing these packets |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8223 | * correctly -- we should probably use the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8224 | * frame control of the packet and disregard |
| 8225 | * the current iw_mode */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8226 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8227 | network_packet = |
| 8228 | is_network_packet(priv, header); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8229 | if (network_packet && priv->assoc_network) { |
| 8230 | priv->assoc_network->stats.rssi = |
| 8231 | stats.rssi; |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 8232 | priv->exp_avg_rssi = |
| 8233 | exponential_average(priv->exp_avg_rssi, |
| 8234 | stats.rssi, DEPTH_RSSI); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8235 | } |
| 8236 | |
| 8237 | IPW_DEBUG_RX("Frame: len=%u\n", |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8238 | le16_to_cpu(pkt->u.frame.length)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8239 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8240 | if (le16_to_cpu(pkt->u.frame.length) < |
Zhu Yi | 9d0be03 | 2006-02-15 06:18:19 +0800 | [diff] [blame] | 8241 | ieee80211_get_hdrlen(le16_to_cpu( |
| 8242 | header->frame_ctl))) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8243 | IPW_DEBUG_DROP |
| 8244 | ("Received packet is too small. " |
| 8245 | "Dropping.\n"); |
| 8246 | priv->ieee->stats.rx_errors++; |
| 8247 | priv->wstats.discard.misc++; |
| 8248 | break; |
| 8249 | } |
| 8250 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8251 | switch (WLAN_FC_GET_TYPE |
| 8252 | (le16_to_cpu(header->frame_ctl))) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8253 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8254 | case IEEE80211_FTYPE_MGMT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8255 | ipw_handle_mgmt_packet(priv, rxb, |
| 8256 | &stats); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8257 | break; |
| 8258 | |
| 8259 | case IEEE80211_FTYPE_CTL: |
| 8260 | break; |
| 8261 | |
| 8262 | case IEEE80211_FTYPE_DATA: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8263 | if (unlikely(!network_packet || |
| 8264 | is_duplicate_packet(priv, |
| 8265 | header))) |
| 8266 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8267 | IPW_DEBUG_DROP("Dropping: " |
| 8268 | MAC_FMT ", " |
| 8269 | MAC_FMT ", " |
| 8270 | MAC_FMT "\n", |
| 8271 | MAC_ARG(header-> |
| 8272 | addr1), |
| 8273 | MAC_ARG(header-> |
| 8274 | addr2), |
| 8275 | MAC_ARG(header-> |
| 8276 | addr3)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8277 | break; |
| 8278 | } |
| 8279 | |
| 8280 | ipw_handle_data_packet(priv, rxb, |
| 8281 | &stats); |
| 8282 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8283 | break; |
| 8284 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8285 | break; |
| 8286 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8287 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8288 | case RX_HOST_NOTIFICATION_TYPE:{ |
| 8289 | IPW_DEBUG_RX |
| 8290 | ("Notification: subtype=%02X flags=%02X size=%d\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8291 | pkt->u.notification.subtype, |
| 8292 | pkt->u.notification.flags, |
| 8293 | pkt->u.notification.size); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8294 | ipw_rx_notification(priv, &pkt->u.notification); |
| 8295 | break; |
| 8296 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8297 | |
| 8298 | default: |
| 8299 | IPW_DEBUG_RX("Bad Rx packet of type %d\n", |
| 8300 | pkt->header.message_type); |
| 8301 | break; |
| 8302 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8303 | |
| 8304 | /* For now we just don't re-use anything. We can tweak this |
| 8305 | * later to try and re-use notification packets and SKBs that |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8306 | * fail to Rx correctly */ |
| 8307 | if (rxb->skb != NULL) { |
| 8308 | dev_kfree_skb_any(rxb->skb); |
| 8309 | rxb->skb = NULL; |
| 8310 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8311 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8312 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8313 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8314 | list_add_tail(&rxb->list, &priv->rxq->rx_used); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8315 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8316 | i = (i + 1) % RX_QUEUE_SIZE; |
| 8317 | } |
| 8318 | |
| 8319 | /* Backtrack one entry */ |
| 8320 | priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1; |
| 8321 | |
| 8322 | ipw_rx_queue_restock(priv); |
| 8323 | } |
| 8324 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8325 | #define DEFAULT_RTS_THRESHOLD 2304U |
| 8326 | #define MIN_RTS_THRESHOLD 1U |
| 8327 | #define MAX_RTS_THRESHOLD 2304U |
| 8328 | #define DEFAULT_BEACON_INTERVAL 100U |
| 8329 | #define DEFAULT_SHORT_RETRY_LIMIT 7U |
| 8330 | #define DEFAULT_LONG_RETRY_LIMIT 4U |
| 8331 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 8332 | /** |
| 8333 | * ipw_sw_reset |
| 8334 | * @option: options to control different reset behaviour |
| 8335 | * 0 = reset everything except the 'disable' module_param |
| 8336 | * 1 = reset everything and print out driver info (for probe only) |
| 8337 | * 2 = reset everything |
| 8338 | */ |
| 8339 | static int ipw_sw_reset(struct ipw_priv *priv, int option) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8340 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8341 | int band, modulation; |
| 8342 | int old_mode = priv->ieee->iw_mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8343 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8344 | /* Initialize module parameter values here */ |
| 8345 | priv->config = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8346 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8347 | /* We default to disabling the LED code as right now it causes |
| 8348 | * too many systems to lock up... */ |
| 8349 | if (!led) |
| 8350 | priv->config |= CFG_NO_LED; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8351 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8352 | if (associate) |
| 8353 | priv->config |= CFG_ASSOCIATE; |
| 8354 | else |
| 8355 | IPW_DEBUG_INFO("Auto associate disabled.\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8356 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8357 | if (auto_create) |
| 8358 | priv->config |= CFG_ADHOC_CREATE; |
| 8359 | else |
| 8360 | IPW_DEBUG_INFO("Auto adhoc creation disabled.\n"); |
| 8361 | |
Zhu Yi | 17ed081 | 2006-01-24 16:36:31 +0800 | [diff] [blame] | 8362 | priv->config &= ~CFG_STATIC_ESSID; |
| 8363 | priv->essid_len = 0; |
| 8364 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 8365 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 8366 | if (disable && option) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8367 | priv->status |= STATUS_RF_KILL_SW; |
| 8368 | IPW_DEBUG_INFO("Radio disabled.\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8369 | } |
| 8370 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8371 | if (channel != 0) { |
| 8372 | priv->config |= CFG_STATIC_CHANNEL; |
| 8373 | priv->channel = channel; |
| 8374 | IPW_DEBUG_INFO("Bind to static channel %d\n", channel); |
| 8375 | /* TODO: Validate that provided channel is in range */ |
| 8376 | } |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 8377 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8378 | ipw_qos_init(priv, qos_enable, qos_burst_enable, |
| 8379 | burst_duration_CCK, burst_duration_OFDM); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 8380 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8381 | |
| 8382 | switch (mode) { |
| 8383 | case 1: |
| 8384 | priv->ieee->iw_mode = IW_MODE_ADHOC; |
| 8385 | priv->net_dev->type = ARPHRD_ETHER; |
| 8386 | |
| 8387 | break; |
| 8388 | #ifdef CONFIG_IPW2200_MONITOR |
| 8389 | case 2: |
| 8390 | priv->ieee->iw_mode = IW_MODE_MONITOR; |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 8391 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8392 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 8393 | #else |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8394 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8395 | #endif |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8396 | break; |
| 8397 | #endif |
| 8398 | default: |
| 8399 | case 0: |
| 8400 | priv->net_dev->type = ARPHRD_ETHER; |
| 8401 | priv->ieee->iw_mode = IW_MODE_INFRA; |
| 8402 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8403 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8404 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8405 | if (hwcrypto) { |
| 8406 | priv->ieee->host_encrypt = 0; |
| 8407 | priv->ieee->host_encrypt_msdu = 0; |
| 8408 | priv->ieee->host_decrypt = 0; |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 8409 | priv->ieee->host_mc_decrypt = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8410 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8411 | IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8412 | |
Zhu Yi | e402c93 | 2005-08-05 17:20:40 +0800 | [diff] [blame] | 8413 | /* IPW2200/2915 is abled to do hardware fragmentation. */ |
| 8414 | priv->ieee->host_open_frag = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8415 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8416 | if ((priv->pci_dev->device == 0x4223) || |
| 8417 | (priv->pci_dev->device == 0x4224)) { |
Zhu Yi | e8c69e2 | 2006-02-17 08:25:12 +0800 | [diff] [blame] | 8418 | if (option == 1) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8419 | printk(KERN_INFO DRV_NAME |
| 8420 | ": Detected Intel PRO/Wireless 2915ABG Network " |
| 8421 | "Connection\n"); |
| 8422 | priv->ieee->abg_true = 1; |
| 8423 | band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND; |
| 8424 | modulation = IEEE80211_OFDM_MODULATION | |
| 8425 | IEEE80211_CCK_MODULATION; |
| 8426 | priv->adapter = IPW_2915ABG; |
| 8427 | priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8428 | } else { |
Zhu Yi | e8c69e2 | 2006-02-17 08:25:12 +0800 | [diff] [blame] | 8429 | if (option == 1) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8430 | printk(KERN_INFO DRV_NAME |
| 8431 | ": Detected Intel PRO/Wireless 2200BG Network " |
| 8432 | "Connection\n"); |
| 8433 | |
| 8434 | priv->ieee->abg_true = 0; |
| 8435 | band = IEEE80211_24GHZ_BAND; |
| 8436 | modulation = IEEE80211_OFDM_MODULATION | |
| 8437 | IEEE80211_CCK_MODULATION; |
| 8438 | priv->adapter = IPW_2200BG; |
| 8439 | priv->ieee->mode = IEEE_G | IEEE_B; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8440 | } |
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 | priv->ieee->freq_band = band; |
| 8443 | priv->ieee->modulation = modulation; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8444 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8445 | priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8446 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8447 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; |
| 8448 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8449 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8450 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
| 8451 | priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT; |
| 8452 | priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8453 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8454 | /* If power management is turned on, default to AC mode */ |
| 8455 | priv->power_mode = IPW_POWER_AC; |
| 8456 | priv->tx_power = IPW_TX_POWER_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8457 | |
Zhu Yi | 0ece35b | 2005-08-05 17:26:51 +0800 | [diff] [blame] | 8458 | return old_mode == priv->ieee->iw_mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8459 | } |
| 8460 | |
| 8461 | /* |
| 8462 | * This file defines the Wireless Extension handlers. It does not |
| 8463 | * define any methods of hardware manipulation and relies on the |
| 8464 | * functions defined in ipw_main to provide the HW interaction. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8465 | * |
| 8466 | * The exception to this is the use of the ipw_get_ordinal() |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8467 | * function used to poll the hardware vs. making unecessary calls. |
| 8468 | * |
| 8469 | */ |
| 8470 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8471 | static int ipw_wx_get_name(struct net_device *dev, |
| 8472 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8473 | union iwreq_data *wrqu, char *extra) |
| 8474 | { |
| 8475 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8476 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8477 | if (priv->status & STATUS_RF_KILL_MASK) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8478 | strcpy(wrqu->name, "radio off"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8479 | else if (!(priv->status & STATUS_ASSOCIATED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8480 | strcpy(wrqu->name, "unassociated"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8481 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8482 | snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c", |
| 8483 | ipw_modes[priv->assoc_request.ieee_mode]); |
| 8484 | IPW_DEBUG_WX("Name: %s\n", wrqu->name); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8485 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8486 | return 0; |
| 8487 | } |
| 8488 | |
| 8489 | static int ipw_set_channel(struct ipw_priv *priv, u8 channel) |
| 8490 | { |
| 8491 | if (channel == 0) { |
| 8492 | IPW_DEBUG_INFO("Setting channel to ANY (0)\n"); |
| 8493 | priv->config &= ~CFG_STATIC_CHANNEL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8494 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 8495 | "parameters.\n"); |
| 8496 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8497 | return 0; |
| 8498 | } |
| 8499 | |
| 8500 | priv->config |= CFG_STATIC_CHANNEL; |
| 8501 | |
| 8502 | if (priv->channel == channel) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8503 | IPW_DEBUG_INFO("Request to set channel to current value (%d)\n", |
| 8504 | channel); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8505 | return 0; |
| 8506 | } |
| 8507 | |
| 8508 | IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel); |
| 8509 | priv->channel = channel; |
| 8510 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8511 | #ifdef CONFIG_IPW2200_MONITOR |
| 8512 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8513 | int i; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8514 | if (priv->status & STATUS_SCANNING) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8515 | IPW_DEBUG_SCAN("Scan abort triggered due to " |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8516 | "channel change.\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8517 | ipw_abort_scan(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8518 | } |
| 8519 | |
| 8520 | for (i = 1000; i && (priv->status & STATUS_SCANNING); i--) |
| 8521 | udelay(10); |
| 8522 | |
| 8523 | if (priv->status & STATUS_SCANNING) |
| 8524 | IPW_DEBUG_SCAN("Still scanning...\n"); |
| 8525 | else |
| 8526 | IPW_DEBUG_SCAN("Took %dms to abort current scan\n", |
| 8527 | 1000 - i); |
| 8528 | |
| 8529 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8530 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8531 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 8532 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8533 | /* Network configuration changed -- force [re]association */ |
| 8534 | IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n"); |
| 8535 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8536 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8537 | |
| 8538 | return 0; |
| 8539 | } |
| 8540 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8541 | static int ipw_wx_set_freq(struct net_device *dev, |
| 8542 | struct iw_request_info *info, |
| 8543 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8544 | { |
| 8545 | struct ipw_priv *priv = ieee80211_priv(dev); |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 8546 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8547 | struct iw_freq *fwrq = &wrqu->freq; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8548 | int ret = 0, i; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8549 | u8 channel, flags; |
| 8550 | int band; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8551 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8552 | if (fwrq->m == 0) { |
| 8553 | IPW_DEBUG_WX("SET Freq/Channel -> any\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8554 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8555 | ret = ipw_set_channel(priv, 0); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8556 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8557 | return ret; |
| 8558 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8559 | /* if setting by freq convert to channel */ |
| 8560 | if (fwrq->e == 1) { |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 8561 | channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8562 | if (channel == 0) |
| 8563 | return -EINVAL; |
| 8564 | } else |
| 8565 | channel = fwrq->m; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8566 | |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 8567 | if (!(band = ieee80211_is_valid_channel(priv->ieee, channel))) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8568 | return -EINVAL; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8569 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8570 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 8571 | i = ieee80211_channel_to_index(priv->ieee, channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8572 | if (i == -1) |
| 8573 | return -EINVAL; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8574 | |
| 8575 | flags = (band == IEEE80211_24GHZ_BAND) ? |
| 8576 | geo->bg[i].flags : geo->a[i].flags; |
| 8577 | if (flags & IEEE80211_CH_PASSIVE_ONLY) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8578 | IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n"); |
| 8579 | return -EINVAL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8580 | } |
| 8581 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8582 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8583 | IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8584 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8585 | ret = ipw_set_channel(priv, channel); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8586 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8587 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8588 | } |
| 8589 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8590 | static int ipw_wx_get_freq(struct net_device *dev, |
| 8591 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8592 | union iwreq_data *wrqu, char *extra) |
| 8593 | { |
| 8594 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8595 | |
| 8596 | wrqu->freq.e = 0; |
| 8597 | |
| 8598 | /* If we are associated, trying to associate, or have a statically |
| 8599 | * configured CHANNEL then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8600 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8601 | if (priv->config & CFG_STATIC_CHANNEL || |
| 8602 | priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) |
| 8603 | wrqu->freq.m = priv->channel; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8604 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8605 | wrqu->freq.m = 0; |
| 8606 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8607 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8608 | IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel); |
| 8609 | return 0; |
| 8610 | } |
| 8611 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8612 | static int ipw_wx_set_mode(struct net_device *dev, |
| 8613 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8614 | union iwreq_data *wrqu, char *extra) |
| 8615 | { |
| 8616 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8617 | int err = 0; |
| 8618 | |
| 8619 | IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode); |
| 8620 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8621 | switch (wrqu->mode) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8622 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8623 | case IW_MODE_MONITOR: |
| 8624 | #endif |
| 8625 | case IW_MODE_ADHOC: |
| 8626 | case IW_MODE_INFRA: |
| 8627 | break; |
| 8628 | case IW_MODE_AUTO: |
| 8629 | wrqu->mode = IW_MODE_INFRA; |
| 8630 | break; |
| 8631 | default: |
| 8632 | return -EINVAL; |
| 8633 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8634 | if (wrqu->mode == priv->ieee->iw_mode) |
| 8635 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8636 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8637 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8638 | |
| 8639 | ipw_sw_reset(priv, 0); |
| 8640 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8641 | #ifdef CONFIG_IPW2200_MONITOR |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8642 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8643 | priv->net_dev->type = ARPHRD_ETHER; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8644 | |
| 8645 | if (wrqu->mode == IW_MODE_MONITOR) |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 8646 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8647 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 8648 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8649 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8650 | #endif |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8651 | #endif /* CONFIG_IPW2200_MONITOR */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8652 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8653 | /* Free the existing firmware and reset the fw_loaded |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8654 | * flag so ipw_load() will bring in the new firmawre */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8655 | free_firmware(); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8656 | |
| 8657 | priv->ieee->iw_mode = wrqu->mode; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8658 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8659 | queue_work(priv->workqueue, &priv->adapter_restart); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8660 | mutex_unlock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8661 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8662 | } |
| 8663 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8664 | static int ipw_wx_get_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8665 | struct iw_request_info *info, |
| 8666 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8667 | { |
| 8668 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8669 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8670 | wrqu->mode = priv->ieee->iw_mode; |
| 8671 | IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8672 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8673 | return 0; |
| 8674 | } |
| 8675 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8676 | /* Values are in microsecond */ |
| 8677 | static const s32 timeout_duration[] = { |
| 8678 | 350000, |
| 8679 | 250000, |
| 8680 | 75000, |
| 8681 | 37000, |
| 8682 | 25000, |
| 8683 | }; |
| 8684 | |
| 8685 | static const s32 period_duration[] = { |
| 8686 | 400000, |
| 8687 | 700000, |
| 8688 | 1000000, |
| 8689 | 1000000, |
| 8690 | 1000000 |
| 8691 | }; |
| 8692 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8693 | static int ipw_wx_get_range(struct net_device *dev, |
| 8694 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8695 | union iwreq_data *wrqu, char *extra) |
| 8696 | { |
| 8697 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8698 | struct iw_range *range = (struct iw_range *)extra; |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 8699 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8700 | int i = 0, j; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8701 | |
| 8702 | wrqu->data.length = sizeof(*range); |
| 8703 | memset(range, 0, sizeof(*range)); |
| 8704 | |
| 8705 | /* 54Mbs == ~27 Mb/s real (802.11g) */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8706 | range->throughput = 27 * 1000 * 1000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8707 | |
| 8708 | range->max_qual.qual = 100; |
| 8709 | /* TODO: Find real max RSSI and stick here */ |
| 8710 | range->max_qual.level = 0; |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 8711 | range->max_qual.noise = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8712 | range->max_qual.updated = 7; /* Updated all three */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8713 | |
| 8714 | range->avg_qual.qual = 70; |
| 8715 | /* TODO: Find real 'good' to 'bad' threshol value for RSSI */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8716 | range->avg_qual.level = 0; /* FIXME to real average level */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8717 | range->avg_qual.noise = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8718 | range->avg_qual.updated = 7; /* Updated all three */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8719 | mutex_lock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8720 | range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8721 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8722 | for (i = 0; i < range->num_bitrates; i++) |
| 8723 | range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) * |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8724 | 500000; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8725 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8726 | range->max_rts = DEFAULT_RTS_THRESHOLD; |
| 8727 | range->min_frag = MIN_FRAG_THRESHOLD; |
| 8728 | range->max_frag = MAX_FRAG_THRESHOLD; |
| 8729 | |
| 8730 | range->encoding_size[0] = 5; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8731 | range->encoding_size[1] = 13; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8732 | range->num_encoding_sizes = 2; |
| 8733 | range->max_encoding_tokens = WEP_KEYS; |
| 8734 | |
| 8735 | /* Set the Wireless Extension versions */ |
| 8736 | range->we_version_compiled = WIRELESS_EXT; |
Dan Williams | f1b5086 | 2006-01-30 13:58:56 -0500 | [diff] [blame] | 8737 | range->we_version_source = 18; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8738 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8739 | i = 0; |
| 8740 | if (priv->ieee->mode & (IEEE_B | IEEE_G)) { |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8741 | for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) { |
| 8742 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
| 8743 | (geo->bg[j].flags & IEEE80211_CH_PASSIVE_ONLY)) |
| 8744 | continue; |
| 8745 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8746 | range->freq[i].i = geo->bg[j].channel; |
| 8747 | range->freq[i].m = geo->bg[j].freq * 100000; |
| 8748 | range->freq[i].e = 1; |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8749 | i++; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8750 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8751 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8752 | |
| 8753 | if (priv->ieee->mode & IEEE_A) { |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8754 | for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) { |
| 8755 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
| 8756 | (geo->a[j].flags & IEEE80211_CH_PASSIVE_ONLY)) |
| 8757 | continue; |
| 8758 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8759 | range->freq[i].i = geo->a[j].channel; |
| 8760 | range->freq[i].m = geo->a[j].freq * 100000; |
| 8761 | range->freq[i].e = 1; |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8762 | i++; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8763 | } |
| 8764 | } |
| 8765 | |
| 8766 | range->num_channels = i; |
| 8767 | range->num_frequency = i; |
| 8768 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8769 | mutex_unlock(&priv->mutex); |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 8770 | |
| 8771 | /* Event capability (kernel + driver) */ |
| 8772 | range->event_capa[0] = (IW_EVENT_CAPA_K_0 | |
| 8773 | IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) | |
Zhu Yi | 07f02e4 | 2006-04-13 17:19:25 +0800 | [diff] [blame] | 8774 | IW_EVENT_CAPA_MASK(SIOCGIWAP) | |
| 8775 | IW_EVENT_CAPA_MASK(SIOCGIWSCAN)); |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 8776 | range->event_capa[1] = IW_EVENT_CAPA_K_1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8777 | |
Dan Williams | f1b5086 | 2006-01-30 13:58:56 -0500 | [diff] [blame] | 8778 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | |
| 8779 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; |
| 8780 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8781 | IPW_DEBUG_WX("GET Range\n"); |
| 8782 | return 0; |
| 8783 | } |
| 8784 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8785 | static int ipw_wx_set_wap(struct net_device *dev, |
| 8786 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8787 | union iwreq_data *wrqu, char *extra) |
| 8788 | { |
| 8789 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8790 | |
| 8791 | static const unsigned char any[] = { |
| 8792 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff |
| 8793 | }; |
| 8794 | static const unsigned char off[] = { |
| 8795 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 8796 | }; |
| 8797 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8798 | if (wrqu->ap_addr.sa_family != ARPHRD_ETHER) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8799 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8800 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8801 | if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) || |
| 8802 | !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) { |
| 8803 | /* we disable mandatory BSSID association */ |
| 8804 | IPW_DEBUG_WX("Setting AP BSSID to ANY\n"); |
| 8805 | priv->config &= ~CFG_STATIC_BSSID; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8806 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 8807 | "parameters.\n"); |
| 8808 | ipw_associate(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8809 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8810 | return 0; |
| 8811 | } |
| 8812 | |
| 8813 | priv->config |= CFG_STATIC_BSSID; |
| 8814 | if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) { |
| 8815 | IPW_DEBUG_WX("BSSID set to current BSSID.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8816 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8817 | return 0; |
| 8818 | } |
| 8819 | |
| 8820 | IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n", |
| 8821 | MAC_ARG(wrqu->ap_addr.sa_data)); |
| 8822 | |
| 8823 | memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN); |
| 8824 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8825 | /* Network configuration changed -- force [re]association */ |
| 8826 | IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n"); |
| 8827 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8828 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8829 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8830 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8831 | return 0; |
| 8832 | } |
| 8833 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8834 | static int ipw_wx_get_wap(struct net_device *dev, |
| 8835 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8836 | union iwreq_data *wrqu, char *extra) |
| 8837 | { |
| 8838 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8839 | /* If we are associated, trying to associate, or have a statically |
| 8840 | * configured BSSID then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8841 | mutex_lock(&priv->mutex); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8842 | if (priv->config & CFG_STATIC_BSSID || |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8843 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
| 8844 | wrqu->ap_addr.sa_family = ARPHRD_ETHER; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8845 | memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8846 | } else |
| 8847 | memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN); |
| 8848 | |
| 8849 | IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n", |
| 8850 | MAC_ARG(wrqu->ap_addr.sa_data)); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8851 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8852 | return 0; |
| 8853 | } |
| 8854 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8855 | static int ipw_wx_set_essid(struct net_device *dev, |
| 8856 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8857 | union iwreq_data *wrqu, char *extra) |
| 8858 | { |
| 8859 | struct ipw_priv *priv = ieee80211_priv(dev); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8860 | char *essid = ""; /* ANY */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8861 | int length = 0; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8862 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8863 | if (wrqu->essid.flags && wrqu->essid.length) { |
| 8864 | length = wrqu->essid.length - 1; |
| 8865 | essid = extra; |
| 8866 | } |
| 8867 | if (length == 0) { |
| 8868 | IPW_DEBUG_WX("Setting ESSID to ANY\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8869 | if ((priv->config & CFG_STATIC_ESSID) && |
| 8870 | !(priv->status & (STATUS_ASSOCIATED | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8871 | STATUS_ASSOCIATING))) { |
| 8872 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 8873 | "parameters.\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8874 | priv->config &= ~CFG_STATIC_ESSID; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8875 | ipw_associate(priv); |
| 8876 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8877 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8878 | return 0; |
| 8879 | } |
| 8880 | |
| 8881 | length = min(length, IW_ESSID_MAX_SIZE); |
| 8882 | |
| 8883 | priv->config |= CFG_STATIC_ESSID; |
| 8884 | |
| 8885 | if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) { |
| 8886 | IPW_DEBUG_WX("ESSID set to current ESSID.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8887 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8888 | return 0; |
| 8889 | } |
| 8890 | |
| 8891 | IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length), |
| 8892 | length); |
| 8893 | |
| 8894 | priv->essid_len = length; |
| 8895 | memcpy(priv->essid, essid, priv->essid_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8896 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8897 | /* Network configuration changed -- force [re]association */ |
| 8898 | IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n"); |
| 8899 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8900 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8901 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8902 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8903 | return 0; |
| 8904 | } |
| 8905 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8906 | static int ipw_wx_get_essid(struct net_device *dev, |
| 8907 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8908 | union iwreq_data *wrqu, char *extra) |
| 8909 | { |
| 8910 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8911 | |
| 8912 | /* If we are associated, trying to associate, or have a statically |
| 8913 | * configured ESSID then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8914 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8915 | if (priv->config & CFG_STATIC_ESSID || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8916 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
| 8917 | IPW_DEBUG_WX("Getting essid: '%s'\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8918 | escape_essid(priv->essid, priv->essid_len)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8919 | memcpy(extra, priv->essid, priv->essid_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8920 | wrqu->essid.length = priv->essid_len; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8921 | wrqu->essid.flags = 1; /* active */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8922 | } else { |
| 8923 | IPW_DEBUG_WX("Getting essid: ANY\n"); |
| 8924 | wrqu->essid.length = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8925 | wrqu->essid.flags = 0; /* active */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8926 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8927 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8928 | return 0; |
| 8929 | } |
| 8930 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8931 | static int ipw_wx_set_nick(struct net_device *dev, |
| 8932 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8933 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8934 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8935 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8936 | |
| 8937 | IPW_DEBUG_WX("Setting nick to '%s'\n", extra); |
| 8938 | if (wrqu->data.length > IW_ESSID_MAX_SIZE) |
| 8939 | return -E2BIG; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8940 | mutex_lock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8941 | wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8942 | memset(priv->nick, 0, sizeof(priv->nick)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8943 | memcpy(priv->nick, extra, wrqu->data.length); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8944 | IPW_DEBUG_TRACE("<<\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8945 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8946 | return 0; |
| 8947 | |
| 8948 | } |
| 8949 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8950 | static int ipw_wx_get_nick(struct net_device *dev, |
| 8951 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8952 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8953 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8954 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8955 | IPW_DEBUG_WX("Getting nick\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8956 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8957 | wrqu->data.length = strlen(priv->nick) + 1; |
| 8958 | memcpy(extra, priv->nick, wrqu->data.length); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8959 | wrqu->data.flags = 1; /* active */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8960 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8961 | return 0; |
| 8962 | } |
| 8963 | |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame] | 8964 | static int ipw_wx_set_sens(struct net_device *dev, |
| 8965 | struct iw_request_info *info, |
| 8966 | union iwreq_data *wrqu, char *extra) |
| 8967 | { |
| 8968 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8969 | int err = 0; |
| 8970 | |
| 8971 | IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value); |
| 8972 | IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value); |
| 8973 | mutex_lock(&priv->mutex); |
| 8974 | |
| 8975 | if (wrqu->sens.fixed == 0) |
| 8976 | { |
| 8977 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; |
| 8978 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; |
| 8979 | goto out; |
| 8980 | } |
| 8981 | if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) || |
| 8982 | (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) { |
| 8983 | err = -EINVAL; |
| 8984 | goto out; |
| 8985 | } |
| 8986 | |
| 8987 | priv->roaming_threshold = wrqu->sens.value; |
| 8988 | priv->disassociate_threshold = 3*wrqu->sens.value; |
| 8989 | out: |
| 8990 | mutex_unlock(&priv->mutex); |
| 8991 | return err; |
| 8992 | } |
| 8993 | |
| 8994 | static int ipw_wx_get_sens(struct net_device *dev, |
| 8995 | struct iw_request_info *info, |
| 8996 | union iwreq_data *wrqu, char *extra) |
| 8997 | { |
| 8998 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8999 | mutex_lock(&priv->mutex); |
| 9000 | wrqu->sens.fixed = 1; |
| 9001 | wrqu->sens.value = priv->roaming_threshold; |
| 9002 | mutex_unlock(&priv->mutex); |
| 9003 | |
| 9004 | IPW_DEBUG_WX("GET roaming threshold -> %s %d \n", |
| 9005 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); |
| 9006 | |
| 9007 | return 0; |
| 9008 | } |
| 9009 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9010 | static int ipw_wx_set_rate(struct net_device *dev, |
| 9011 | struct iw_request_info *info, |
| 9012 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9013 | { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9014 | /* TODO: We should use semaphores or locks for access to priv */ |
| 9015 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9016 | u32 target_rate = wrqu->bitrate.value; |
| 9017 | u32 fixed, mask; |
| 9018 | |
| 9019 | /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */ |
| 9020 | /* value = X, fixed = 1 means only rate X */ |
| 9021 | /* value = X, fixed = 0 means all rates lower equal X */ |
| 9022 | |
| 9023 | if (target_rate == -1) { |
| 9024 | fixed = 0; |
| 9025 | mask = IEEE80211_DEFAULT_RATES_MASK; |
| 9026 | /* Now we should reassociate */ |
| 9027 | goto apply; |
| 9028 | } |
| 9029 | |
| 9030 | mask = 0; |
| 9031 | fixed = wrqu->bitrate.fixed; |
| 9032 | |
| 9033 | if (target_rate == 1000000 || !fixed) |
| 9034 | mask |= IEEE80211_CCK_RATE_1MB_MASK; |
| 9035 | if (target_rate == 1000000) |
| 9036 | goto apply; |
| 9037 | |
| 9038 | if (target_rate == 2000000 || !fixed) |
| 9039 | mask |= IEEE80211_CCK_RATE_2MB_MASK; |
| 9040 | if (target_rate == 2000000) |
| 9041 | goto apply; |
| 9042 | |
| 9043 | if (target_rate == 5500000 || !fixed) |
| 9044 | mask |= IEEE80211_CCK_RATE_5MB_MASK; |
| 9045 | if (target_rate == 5500000) |
| 9046 | goto apply; |
| 9047 | |
| 9048 | if (target_rate == 6000000 || !fixed) |
| 9049 | mask |= IEEE80211_OFDM_RATE_6MB_MASK; |
| 9050 | if (target_rate == 6000000) |
| 9051 | goto apply; |
| 9052 | |
| 9053 | if (target_rate == 9000000 || !fixed) |
| 9054 | mask |= IEEE80211_OFDM_RATE_9MB_MASK; |
| 9055 | if (target_rate == 9000000) |
| 9056 | goto apply; |
| 9057 | |
| 9058 | if (target_rate == 11000000 || !fixed) |
| 9059 | mask |= IEEE80211_CCK_RATE_11MB_MASK; |
| 9060 | if (target_rate == 11000000) |
| 9061 | goto apply; |
| 9062 | |
| 9063 | if (target_rate == 12000000 || !fixed) |
| 9064 | mask |= IEEE80211_OFDM_RATE_12MB_MASK; |
| 9065 | if (target_rate == 12000000) |
| 9066 | goto apply; |
| 9067 | |
| 9068 | if (target_rate == 18000000 || !fixed) |
| 9069 | mask |= IEEE80211_OFDM_RATE_18MB_MASK; |
| 9070 | if (target_rate == 18000000) |
| 9071 | goto apply; |
| 9072 | |
| 9073 | if (target_rate == 24000000 || !fixed) |
| 9074 | mask |= IEEE80211_OFDM_RATE_24MB_MASK; |
| 9075 | if (target_rate == 24000000) |
| 9076 | goto apply; |
| 9077 | |
| 9078 | if (target_rate == 36000000 || !fixed) |
| 9079 | mask |= IEEE80211_OFDM_RATE_36MB_MASK; |
| 9080 | if (target_rate == 36000000) |
| 9081 | goto apply; |
| 9082 | |
| 9083 | if (target_rate == 48000000 || !fixed) |
| 9084 | mask |= IEEE80211_OFDM_RATE_48MB_MASK; |
| 9085 | if (target_rate == 48000000) |
| 9086 | goto apply; |
| 9087 | |
| 9088 | if (target_rate == 54000000 || !fixed) |
| 9089 | mask |= IEEE80211_OFDM_RATE_54MB_MASK; |
| 9090 | if (target_rate == 54000000) |
| 9091 | goto apply; |
| 9092 | |
| 9093 | IPW_DEBUG_WX("invalid rate specified, returning error\n"); |
| 9094 | return -EINVAL; |
| 9095 | |
| 9096 | apply: |
| 9097 | IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n", |
| 9098 | mask, fixed ? "fixed" : "sub-rates"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9099 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9100 | if (mask == IEEE80211_DEFAULT_RATES_MASK) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9101 | priv->config &= ~CFG_FIXED_RATE; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9102 | ipw_set_fixed_rate(priv, priv->ieee->mode); |
| 9103 | } else |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9104 | priv->config |= CFG_FIXED_RATE; |
| 9105 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9106 | if (priv->rates_mask == mask) { |
| 9107 | IPW_DEBUG_WX("Mask set to current mask.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9108 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9109 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9110 | } |
| 9111 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9112 | priv->rates_mask = mask; |
| 9113 | |
| 9114 | /* Network configuration changed -- force [re]association */ |
| 9115 | IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n"); |
| 9116 | if (!ipw_disassociate(priv)) |
| 9117 | ipw_associate(priv); |
| 9118 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9119 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9120 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9121 | } |
| 9122 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9123 | static int ipw_wx_get_rate(struct net_device *dev, |
| 9124 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9125 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9126 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9127 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9128 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9129 | wrqu->bitrate.value = priv->last_rate; |
Zhu Yi | 455936c | 2006-04-13 17:20:05 +0800 | [diff] [blame] | 9130 | wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9131 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9132 | IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value); |
| 9133 | return 0; |
| 9134 | } |
| 9135 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9136 | static int ipw_wx_set_rts(struct net_device *dev, |
| 9137 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9138 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9139 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9140 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9141 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9142 | if (wrqu->rts.disabled) |
| 9143 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
| 9144 | else { |
| 9145 | if (wrqu->rts.value < MIN_RTS_THRESHOLD || |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9146 | wrqu->rts.value > MAX_RTS_THRESHOLD) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9147 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9148 | return -EINVAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9149 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9150 | priv->rts_threshold = wrqu->rts.value; |
| 9151 | } |
| 9152 | |
| 9153 | ipw_send_rts_threshold(priv, priv->rts_threshold); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9154 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9155 | IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold); |
| 9156 | return 0; |
| 9157 | } |
| 9158 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9159 | static int ipw_wx_get_rts(struct net_device *dev, |
| 9160 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9161 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9162 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9163 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9164 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9165 | wrqu->rts.value = priv->rts_threshold; |
| 9166 | wrqu->rts.fixed = 0; /* no auto select */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9167 | wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9168 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9169 | IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value); |
| 9170 | return 0; |
| 9171 | } |
| 9172 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9173 | static int ipw_wx_set_txpow(struct net_device *dev, |
| 9174 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9175 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9176 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9177 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9178 | int err = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9179 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9180 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9181 | if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9182 | err = -EINPROGRESS; |
| 9183 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9184 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9185 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9186 | if (!wrqu->power.fixed) |
| 9187 | wrqu->power.value = IPW_TX_POWER_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9188 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9189 | if (wrqu->power.flags != IW_TXPOW_DBM) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9190 | err = -EINVAL; |
| 9191 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9192 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9193 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9194 | if ((wrqu->power.value > IPW_TX_POWER_MAX) || |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9195 | (wrqu->power.value < IPW_TX_POWER_MIN)) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9196 | err = -EINVAL; |
| 9197 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9198 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9199 | |
| 9200 | priv->tx_power = wrqu->power.value; |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9201 | err = ipw_set_tx_power(priv); |
| 9202 | out: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9203 | mutex_unlock(&priv->mutex); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9204 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9205 | } |
| 9206 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9207 | static int ipw_wx_get_txpow(struct net_device *dev, |
| 9208 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9209 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9210 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9211 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9212 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9213 | wrqu->power.value = priv->tx_power; |
| 9214 | wrqu->power.fixed = 1; |
| 9215 | wrqu->power.flags = IW_TXPOW_DBM; |
| 9216 | wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9217 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9218 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9219 | IPW_DEBUG_WX("GET TX Power -> %s %d \n", |
Zhu Yi | 22501c8 | 2005-08-11 10:49:17 +0800 | [diff] [blame] | 9220 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9221 | |
| 9222 | return 0; |
| 9223 | } |
| 9224 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9225 | static int ipw_wx_set_frag(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9226 | struct iw_request_info *info, |
| 9227 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9228 | { |
| 9229 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9230 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9231 | if (wrqu->frag.disabled) |
| 9232 | priv->ieee->fts = DEFAULT_FTS; |
| 9233 | else { |
| 9234 | if (wrqu->frag.value < MIN_FRAG_THRESHOLD || |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9235 | wrqu->frag.value > MAX_FRAG_THRESHOLD) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9236 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9237 | return -EINVAL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9238 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9239 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9240 | priv->ieee->fts = wrqu->frag.value & ~0x1; |
| 9241 | } |
| 9242 | |
| 9243 | ipw_send_frag_threshold(priv, wrqu->frag.value); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9244 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9245 | IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value); |
| 9246 | return 0; |
| 9247 | } |
| 9248 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9249 | static int ipw_wx_get_frag(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9250 | struct iw_request_info *info, |
| 9251 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9252 | { |
| 9253 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9254 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9255 | wrqu->frag.value = priv->ieee->fts; |
| 9256 | wrqu->frag.fixed = 0; /* no auto select */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9257 | wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9258 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9259 | IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value); |
| 9260 | |
| 9261 | return 0; |
| 9262 | } |
| 9263 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9264 | static int ipw_wx_set_retry(struct net_device *dev, |
| 9265 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9266 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9267 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9268 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9269 | |
| 9270 | if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled) |
| 9271 | return -EINVAL; |
| 9272 | |
| 9273 | if (!(wrqu->retry.flags & IW_RETRY_LIMIT)) |
| 9274 | return 0; |
| 9275 | |
| 9276 | if (wrqu->retry.value < 0 || wrqu->retry.value > 255) |
| 9277 | return -EINVAL; |
| 9278 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9279 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9280 | if (wrqu->retry.flags & IW_RETRY_MIN) |
| 9281 | priv->short_retry_limit = (u8) wrqu->retry.value; |
| 9282 | else if (wrqu->retry.flags & IW_RETRY_MAX) |
| 9283 | priv->long_retry_limit = (u8) wrqu->retry.value; |
| 9284 | else { |
| 9285 | priv->short_retry_limit = (u8) wrqu->retry.value; |
| 9286 | priv->long_retry_limit = (u8) wrqu->retry.value; |
| 9287 | } |
| 9288 | |
| 9289 | ipw_send_retry_limit(priv, priv->short_retry_limit, |
| 9290 | priv->long_retry_limit); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9291 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9292 | IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n", |
| 9293 | priv->short_retry_limit, priv->long_retry_limit); |
| 9294 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9295 | } |
| 9296 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9297 | static int ipw_wx_get_retry(struct net_device *dev, |
| 9298 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9299 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9300 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9301 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9302 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9303 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9304 | wrqu->retry.disabled = 0; |
| 9305 | |
| 9306 | if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9307 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9308 | return -EINVAL; |
| 9309 | } |
| 9310 | |
| 9311 | if (wrqu->retry.flags & IW_RETRY_MAX) { |
| 9312 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX; |
| 9313 | wrqu->retry.value = priv->long_retry_limit; |
| 9314 | } else if (wrqu->retry.flags & IW_RETRY_MIN) { |
| 9315 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN; |
| 9316 | wrqu->retry.value = priv->short_retry_limit; |
| 9317 | } else { |
| 9318 | wrqu->retry.flags = IW_RETRY_LIMIT; |
| 9319 | wrqu->retry.value = priv->short_retry_limit; |
| 9320 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9321 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9322 | |
| 9323 | IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value); |
| 9324 | |
| 9325 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9326 | } |
| 9327 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9328 | static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid, |
| 9329 | int essid_len) |
| 9330 | { |
| 9331 | struct ipw_scan_request_ext scan; |
| 9332 | int err = 0, scan_type; |
| 9333 | |
Pekka Enberg | efb3442 | 2005-11-16 21:55:05 +0200 | [diff] [blame] | 9334 | if (!(priv->status & STATUS_INIT) || |
| 9335 | (priv->status & STATUS_EXIT_PENDING)) |
| 9336 | return 0; |
| 9337 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9338 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9339 | |
| 9340 | if (priv->status & STATUS_RF_KILL_MASK) { |
| 9341 | IPW_DEBUG_HC("Aborting scan due to RF kill activation\n"); |
| 9342 | priv->status |= STATUS_SCAN_PENDING; |
| 9343 | goto done; |
| 9344 | } |
| 9345 | |
| 9346 | IPW_DEBUG_HC("starting request direct scan!\n"); |
| 9347 | |
| 9348 | if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) { |
Olaf Kirch | d834a41 | 2006-01-09 17:00:37 +0100 | [diff] [blame] | 9349 | /* We should not sleep here; otherwise we will block most |
| 9350 | * of the system (for instance, we hold rtnl_lock when we |
| 9351 | * get here). |
| 9352 | */ |
| 9353 | err = -EAGAIN; |
| 9354 | goto done; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9355 | } |
| 9356 | memset(&scan, 0, sizeof(scan)); |
| 9357 | |
| 9358 | if (priv->config & CFG_SPEED_SCAN) |
| 9359 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
| 9360 | cpu_to_le16(30); |
| 9361 | else |
| 9362 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
| 9363 | cpu_to_le16(20); |
| 9364 | |
| 9365 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = |
| 9366 | cpu_to_le16(20); |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 9367 | 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] | 9368 | scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20); |
| 9369 | |
| 9370 | scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee)); |
| 9371 | |
| 9372 | err = ipw_send_ssid(priv, essid, essid_len); |
| 9373 | if (err) { |
| 9374 | IPW_DEBUG_HC("Attempt to send SSID command failed\n"); |
| 9375 | goto done; |
| 9376 | } |
| 9377 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; |
| 9378 | |
| 9379 | ipw_add_scan_channels(priv, &scan, scan_type); |
| 9380 | |
| 9381 | err = ipw_send_scan_request_ext(priv, &scan); |
| 9382 | if (err) { |
| 9383 | IPW_DEBUG_HC("Sending scan command failed: %08X\n", err); |
| 9384 | goto done; |
| 9385 | } |
| 9386 | |
| 9387 | priv->status |= STATUS_SCANNING; |
| 9388 | |
| 9389 | done: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9390 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9391 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9392 | } |
| 9393 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9394 | static int ipw_wx_set_scan(struct net_device *dev, |
| 9395 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9396 | union iwreq_data *wrqu, char *extra) |
| 9397 | { |
| 9398 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9399 | struct iw_scan_req *req = NULL; |
| 9400 | if (wrqu->data.length |
| 9401 | && wrqu->data.length == sizeof(struct iw_scan_req)) { |
| 9402 | req = (struct iw_scan_req *)extra; |
| 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 | } |
| 9408 | } |
James Ketrenos | 8935f39 | 2005-10-05 15:59:08 -0500 | [diff] [blame] | 9409 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9410 | IPW_DEBUG_WX("Start scan\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9411 | |
| 9412 | queue_work(priv->workqueue, &priv->request_scan); |
| 9413 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9414 | return 0; |
| 9415 | } |
| 9416 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9417 | static int ipw_wx_get_scan(struct net_device *dev, |
| 9418 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9419 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9420 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9421 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9422 | return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra); |
| 9423 | } |
| 9424 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9425 | static int ipw_wx_set_encode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9426 | struct iw_request_info *info, |
| 9427 | union iwreq_data *wrqu, char *key) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9428 | { |
| 9429 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9430 | int ret; |
Hong Liu | caeff81 | 2005-08-05 17:25:50 +0800 | [diff] [blame] | 9431 | u32 cap = priv->capability; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9432 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9433 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9434 | ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9435 | |
Hong Liu | caeff81 | 2005-08-05 17:25:50 +0800 | [diff] [blame] | 9436 | /* In IBSS mode, we need to notify the firmware to update |
| 9437 | * the beacon info after we changed the capability. */ |
| 9438 | if (cap != priv->capability && |
| 9439 | priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 9440 | priv->status & STATUS_ASSOCIATED) |
| 9441 | ipw_disassociate(priv); |
| 9442 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9443 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9444 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9445 | } |
| 9446 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9447 | static int ipw_wx_get_encode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9448 | struct iw_request_info *info, |
| 9449 | union iwreq_data *wrqu, char *key) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9450 | { |
| 9451 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9452 | return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key); |
| 9453 | } |
| 9454 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9455 | static int ipw_wx_set_power(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9456 | struct iw_request_info *info, |
| 9457 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9458 | { |
| 9459 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9460 | int err; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9461 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9462 | if (wrqu->power.disabled) { |
| 9463 | priv->power_mode = IPW_POWER_LEVEL(priv->power_mode); |
| 9464 | err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM); |
| 9465 | if (err) { |
| 9466 | IPW_DEBUG_WX("failed setting power mode.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9467 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9468 | return err; |
| 9469 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9470 | IPW_DEBUG_WX("SET Power Management Mode -> off\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9471 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9472 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9473 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9474 | |
| 9475 | switch (wrqu->power.flags & IW_POWER_MODE) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9476 | case IW_POWER_ON: /* If not specified */ |
| 9477 | case IW_POWER_MODE: /* If set all mask */ |
| 9478 | case IW_POWER_ALL_R: /* If explicitely state all */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9479 | break; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9480 | default: /* Otherwise we don't support it */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9481 | IPW_DEBUG_WX("SET PM Mode: %X not supported.\n", |
| 9482 | wrqu->power.flags); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9483 | mutex_unlock(&priv->mutex); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9484 | return -EOPNOTSUPP; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9485 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9486 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9487 | /* If the user hasn't specified a power management mode yet, default |
| 9488 | * to BATTERY */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9489 | if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9490 | priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9491 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9492 | priv->power_mode = IPW_POWER_ENABLED | priv->power_mode; |
| 9493 | err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode)); |
| 9494 | if (err) { |
| 9495 | IPW_DEBUG_WX("failed setting power mode.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9496 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9497 | return err; |
| 9498 | } |
| 9499 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9500 | 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] | 9501 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9502 | return 0; |
| 9503 | } |
| 9504 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9505 | static int ipw_wx_get_power(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9506 | struct iw_request_info *info, |
| 9507 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9508 | { |
| 9509 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9510 | mutex_lock(&priv->mutex); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9511 | if (!(priv->power_mode & IPW_POWER_ENABLED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9512 | wrqu->power.disabled = 1; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9513 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9514 | wrqu->power.disabled = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9515 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9516 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9517 | IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9518 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9519 | return 0; |
| 9520 | } |
| 9521 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9522 | static int ipw_wx_set_powermode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9523 | struct iw_request_info *info, |
| 9524 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9525 | { |
| 9526 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9527 | int mode = *(int *)extra; |
| 9528 | int err; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9529 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9530 | if ((mode < 1) || (mode > IPW_POWER_LIMIT)) { |
| 9531 | mode = IPW_POWER_AC; |
| 9532 | priv->power_mode = mode; |
| 9533 | } else { |
| 9534 | priv->power_mode = IPW_POWER_ENABLED | mode; |
| 9535 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9536 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9537 | if (priv->power_mode != mode) { |
| 9538 | err = ipw_send_power_mode(priv, mode); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9539 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9540 | if (err) { |
| 9541 | IPW_DEBUG_WX("failed setting power mode.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9542 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9543 | return err; |
| 9544 | } |
| 9545 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9546 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9547 | return 0; |
| 9548 | } |
| 9549 | |
| 9550 | #define MAX_WX_STRING 80 |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9551 | static int ipw_wx_get_powermode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9552 | struct iw_request_info *info, |
| 9553 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9554 | { |
| 9555 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9556 | int level = IPW_POWER_LEVEL(priv->power_mode); |
| 9557 | char *p = extra; |
| 9558 | |
| 9559 | p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level); |
| 9560 | |
| 9561 | switch (level) { |
| 9562 | case IPW_POWER_AC: |
| 9563 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)"); |
| 9564 | break; |
| 9565 | case IPW_POWER_BATTERY: |
| 9566 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)"); |
| 9567 | break; |
| 9568 | default: |
| 9569 | p += snprintf(p, MAX_WX_STRING - (p - extra), |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9570 | "(Timeout %dms, Period %dms)", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9571 | timeout_duration[level - 1] / 1000, |
| 9572 | period_duration[level - 1] / 1000); |
| 9573 | } |
| 9574 | |
| 9575 | if (!(priv->power_mode & IPW_POWER_ENABLED)) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9576 | p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9577 | |
| 9578 | wrqu->data.length = p - extra + 1; |
| 9579 | |
| 9580 | return 0; |
| 9581 | } |
| 9582 | |
| 9583 | static int ipw_wx_set_wireless_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9584 | struct iw_request_info *info, |
| 9585 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9586 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9587 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9588 | int mode = *(int *)extra; |
| 9589 | u8 band = 0, modulation = 0; |
| 9590 | |
| 9591 | if (mode == 0 || mode & ~IEEE_MODE_MASK) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9592 | IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9593 | return -EINVAL; |
| 9594 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9595 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9596 | if (priv->adapter == IPW_2915ABG) { |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9597 | priv->ieee->abg_true = 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9598 | if (mode & IEEE_A) { |
| 9599 | band |= IEEE80211_52GHZ_BAND; |
| 9600 | modulation |= IEEE80211_OFDM_MODULATION; |
| 9601 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9602 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9603 | } else { |
| 9604 | if (mode & IEEE_A) { |
| 9605 | IPW_WARNING("Attempt to set 2200BG into " |
| 9606 | "802.11a mode\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9607 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9608 | return -EINVAL; |
| 9609 | } |
| 9610 | |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9611 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9612 | } |
| 9613 | |
| 9614 | if (mode & IEEE_B) { |
| 9615 | band |= IEEE80211_24GHZ_BAND; |
| 9616 | modulation |= IEEE80211_CCK_MODULATION; |
| 9617 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9618 | priv->ieee->abg_true = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9619 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9620 | if (mode & IEEE_G) { |
| 9621 | band |= IEEE80211_24GHZ_BAND; |
| 9622 | modulation |= IEEE80211_OFDM_MODULATION; |
| 9623 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9624 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9625 | |
| 9626 | priv->ieee->mode = mode; |
| 9627 | priv->ieee->freq_band = band; |
| 9628 | priv->ieee->modulation = modulation; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9629 | init_supported_rates(priv, &priv->rates); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9630 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9631 | /* Network configuration changed -- force [re]association */ |
| 9632 | IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n"); |
| 9633 | if (!ipw_disassociate(priv)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9634 | ipw_send_supported_rates(priv, &priv->rates); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9635 | ipw_associate(priv); |
| 9636 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9637 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9638 | /* Update the band LEDs */ |
| 9639 | ipw_led_band_on(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9640 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9641 | IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9642 | mode & IEEE_A ? 'a' : '.', |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9643 | mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.'); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9644 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9645 | return 0; |
| 9646 | } |
| 9647 | |
| 9648 | static int ipw_wx_get_wireless_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9649 | struct iw_request_info *info, |
| 9650 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9651 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9652 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9653 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9654 | switch (priv->ieee->mode) { |
| 9655 | case IEEE_A: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9656 | strncpy(extra, "802.11a (1)", MAX_WX_STRING); |
| 9657 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9658 | case IEEE_B: |
| 9659 | strncpy(extra, "802.11b (2)", MAX_WX_STRING); |
| 9660 | break; |
| 9661 | case IEEE_A | IEEE_B: |
| 9662 | strncpy(extra, "802.11ab (3)", MAX_WX_STRING); |
| 9663 | break; |
| 9664 | case IEEE_G: |
| 9665 | strncpy(extra, "802.11g (4)", MAX_WX_STRING); |
| 9666 | break; |
| 9667 | case IEEE_A | IEEE_G: |
| 9668 | strncpy(extra, "802.11ag (5)", MAX_WX_STRING); |
| 9669 | break; |
| 9670 | case IEEE_B | IEEE_G: |
| 9671 | strncpy(extra, "802.11bg (6)", MAX_WX_STRING); |
| 9672 | break; |
| 9673 | case IEEE_A | IEEE_B | IEEE_G: |
| 9674 | strncpy(extra, "802.11abg (7)", MAX_WX_STRING); |
| 9675 | break; |
| 9676 | default: |
| 9677 | strncpy(extra, "unknown", MAX_WX_STRING); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9678 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9679 | } |
| 9680 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9681 | IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra); |
| 9682 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9683 | wrqu->data.length = strlen(extra) + 1; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9684 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9685 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9686 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9687 | } |
| 9688 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9689 | static int ipw_wx_set_preamble(struct net_device *dev, |
| 9690 | struct iw_request_info *info, |
| 9691 | union iwreq_data *wrqu, char *extra) |
| 9692 | { |
| 9693 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9694 | int mode = *(int *)extra; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9695 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9696 | /* Switching from SHORT -> LONG requires a disassociation */ |
| 9697 | if (mode == 1) { |
| 9698 | if (!(priv->config & CFG_PREAMBLE_LONG)) { |
| 9699 | priv->config |= CFG_PREAMBLE_LONG; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9700 | |
| 9701 | /* Network configuration changed -- force [re]association */ |
| 9702 | IPW_DEBUG_ASSOC |
| 9703 | ("[re]association triggered due to preamble change.\n"); |
| 9704 | if (!ipw_disassociate(priv)) |
| 9705 | ipw_associate(priv); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9706 | } |
| 9707 | goto done; |
| 9708 | } |
| 9709 | |
| 9710 | if (mode == 0) { |
| 9711 | priv->config &= ~CFG_PREAMBLE_LONG; |
| 9712 | goto done; |
| 9713 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9714 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9715 | return -EINVAL; |
| 9716 | |
| 9717 | done: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9718 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9719 | return 0; |
| 9720 | } |
| 9721 | |
| 9722 | static int ipw_wx_get_preamble(struct net_device *dev, |
| 9723 | struct iw_request_info *info, |
| 9724 | union iwreq_data *wrqu, char *extra) |
| 9725 | { |
| 9726 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9727 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9728 | if (priv->config & CFG_PREAMBLE_LONG) |
| 9729 | snprintf(wrqu->name, IFNAMSIZ, "long (1)"); |
| 9730 | else |
| 9731 | snprintf(wrqu->name, IFNAMSIZ, "auto (0)"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9732 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9733 | return 0; |
| 9734 | } |
| 9735 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9736 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9737 | static int ipw_wx_set_monitor(struct net_device *dev, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9738 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9739 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9740 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9741 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9742 | int *parms = (int *)extra; |
| 9743 | int enable = (parms[0] > 0); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9744 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9745 | IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9746 | if (enable) { |
| 9747 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 9748 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 9749 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 9750 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9751 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 9752 | #endif |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9753 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9754 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9755 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9756 | ipw_set_channel(priv, parms[1]); |
| 9757 | } else { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9758 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9759 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9760 | return 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9761 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9762 | priv->net_dev->type = ARPHRD_ETHER; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9763 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9764 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9765 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9766 | return 0; |
| 9767 | } |
| 9768 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9769 | #endif // CONFIG_IPW2200_MONITOR |
| 9770 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9771 | static int ipw_wx_reset(struct net_device *dev, |
| 9772 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9773 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9774 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9775 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9776 | IPW_DEBUG_WX("RESET\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9777 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9778 | return 0; |
| 9779 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9780 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9781 | static int ipw_wx_sw_reset(struct net_device *dev, |
| 9782 | struct iw_request_info *info, |
| 9783 | union iwreq_data *wrqu, char *extra) |
| 9784 | { |
| 9785 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9786 | union iwreq_data wrqu_sec = { |
| 9787 | .encoding = { |
| 9788 | .flags = IW_ENCODE_DISABLED, |
| 9789 | }, |
| 9790 | }; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9791 | int ret; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9792 | |
| 9793 | IPW_DEBUG_WX("SW_RESET\n"); |
| 9794 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9795 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9796 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 9797 | ret = ipw_sw_reset(priv, 2); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9798 | if (!ret) { |
| 9799 | free_firmware(); |
| 9800 | ipw_adapter_restart(priv); |
| 9801 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9802 | |
| 9803 | /* The SW reset bit might have been toggled on by the 'disable' |
| 9804 | * module parameter, so take appropriate action */ |
| 9805 | ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW); |
| 9806 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9807 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9808 | ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9809 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9810 | |
| 9811 | if (!(priv->status & STATUS_RF_KILL_MASK)) { |
| 9812 | /* Configuration likely changed -- force [re]association */ |
| 9813 | IPW_DEBUG_ASSOC("[re]association triggered due to sw " |
| 9814 | "reset.\n"); |
| 9815 | if (!ipw_disassociate(priv)) |
| 9816 | ipw_associate(priv); |
| 9817 | } |
| 9818 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9819 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9820 | |
| 9821 | return 0; |
| 9822 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9823 | |
| 9824 | /* Rebase the WE IOCTLs to zero for the handler array */ |
| 9825 | #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT] |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9826 | static iw_handler ipw_wx_handlers[] = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9827 | IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name, |
| 9828 | IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq, |
| 9829 | IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq, |
| 9830 | IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode, |
| 9831 | IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode, |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame] | 9832 | IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens, |
| 9833 | IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9834 | IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range, |
| 9835 | IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap, |
| 9836 | IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap, |
| 9837 | IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan, |
| 9838 | IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan, |
| 9839 | IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid, |
| 9840 | IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid, |
| 9841 | IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick, |
| 9842 | IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick, |
| 9843 | IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate, |
| 9844 | IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate, |
| 9845 | IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts, |
| 9846 | IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts, |
| 9847 | IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag, |
| 9848 | IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag, |
| 9849 | IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow, |
| 9850 | IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow, |
| 9851 | IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry, |
| 9852 | IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry, |
| 9853 | IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode, |
| 9854 | IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode, |
| 9855 | IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power, |
| 9856 | IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9857 | IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy, |
| 9858 | IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy, |
| 9859 | IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy, |
| 9860 | IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy, |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9861 | IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie, |
| 9862 | IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie, |
| 9863 | IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme, |
| 9864 | IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth, |
| 9865 | IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth, |
| 9866 | IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext, |
| 9867 | IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9868 | }; |
| 9869 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9870 | enum { |
| 9871 | IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV, |
| 9872 | IPW_PRIV_GET_POWER, |
| 9873 | IPW_PRIV_SET_MODE, |
| 9874 | IPW_PRIV_GET_MODE, |
| 9875 | IPW_PRIV_SET_PREAMBLE, |
| 9876 | IPW_PRIV_GET_PREAMBLE, |
| 9877 | IPW_PRIV_RESET, |
| 9878 | IPW_PRIV_SW_RESET, |
| 9879 | #ifdef CONFIG_IPW2200_MONITOR |
| 9880 | IPW_PRIV_SET_MONITOR, |
| 9881 | #endif |
| 9882 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9883 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9884 | static struct iw_priv_args ipw_priv_args[] = { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9885 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9886 | .cmd = IPW_PRIV_SET_POWER, |
| 9887 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 9888 | .name = "set_power"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9889 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9890 | .cmd = IPW_PRIV_GET_POWER, |
| 9891 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, |
| 9892 | .name = "get_power"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9893 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9894 | .cmd = IPW_PRIV_SET_MODE, |
| 9895 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 9896 | .name = "set_mode"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9897 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9898 | .cmd = IPW_PRIV_GET_MODE, |
| 9899 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, |
| 9900 | .name = "get_mode"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9901 | { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9902 | .cmd = IPW_PRIV_SET_PREAMBLE, |
| 9903 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 9904 | .name = "set_preamble"}, |
| 9905 | { |
| 9906 | .cmd = IPW_PRIV_GET_PREAMBLE, |
| 9907 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, |
| 9908 | .name = "get_preamble"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9909 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9910 | IPW_PRIV_RESET, |
| 9911 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"}, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9912 | { |
| 9913 | IPW_PRIV_SW_RESET, |
| 9914 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"}, |
| 9915 | #ifdef CONFIG_IPW2200_MONITOR |
| 9916 | { |
| 9917 | IPW_PRIV_SET_MONITOR, |
| 9918 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"}, |
| 9919 | #endif /* CONFIG_IPW2200_MONITOR */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9920 | }; |
| 9921 | |
| 9922 | static iw_handler ipw_priv_handler[] = { |
| 9923 | ipw_wx_set_powermode, |
| 9924 | ipw_wx_get_powermode, |
| 9925 | ipw_wx_set_wireless_mode, |
| 9926 | ipw_wx_get_wireless_mode, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9927 | ipw_wx_set_preamble, |
| 9928 | ipw_wx_get_preamble, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9929 | ipw_wx_reset, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9930 | ipw_wx_sw_reset, |
| 9931 | #ifdef CONFIG_IPW2200_MONITOR |
| 9932 | ipw_wx_set_monitor, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9933 | #endif |
| 9934 | }; |
| 9935 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9936 | static struct iw_handler_def ipw_wx_handler_def = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9937 | .standard = ipw_wx_handlers, |
| 9938 | .num_standard = ARRAY_SIZE(ipw_wx_handlers), |
| 9939 | .num_private = ARRAY_SIZE(ipw_priv_handler), |
| 9940 | .num_private_args = ARRAY_SIZE(ipw_priv_args), |
| 9941 | .private = ipw_priv_handler, |
| 9942 | .private_args = ipw_priv_args, |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 9943 | .get_wireless_stats = ipw_get_wireless_stats, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9944 | }; |
| 9945 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9946 | /* |
| 9947 | * Get wireless statistics. |
| 9948 | * Called by /proc/net/wireless |
| 9949 | * Also called by SIOCGIWSTATS |
| 9950 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9951 | static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9952 | { |
| 9953 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9954 | struct iw_statistics *wstats; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9955 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9956 | wstats = &priv->wstats; |
| 9957 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9958 | /* if hw is disabled, then ipw_get_ordinal() can't be called. |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9959 | * netdev->get_wireless_stats seems to be called before fw is |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9960 | * initialized. STATUS_ASSOCIATED will only be set if the hw is up |
| 9961 | * and associated; if not associcated, the values are all meaningless |
| 9962 | * anyway, so set them all to NULL and INVALID */ |
| 9963 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 9964 | wstats->miss.beacon = 0; |
| 9965 | wstats->discard.retries = 0; |
| 9966 | wstats->qual.qual = 0; |
| 9967 | wstats->qual.level = 0; |
| 9968 | wstats->qual.noise = 0; |
| 9969 | wstats->qual.updated = 7; |
| 9970 | wstats->qual.updated |= IW_QUAL_NOISE_INVALID | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9971 | IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9972 | return wstats; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9973 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9974 | |
| 9975 | wstats->qual.qual = priv->quality; |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 9976 | wstats->qual.level = priv->exp_avg_rssi; |
| 9977 | wstats->qual.noise = priv->exp_avg_noise; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9978 | wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 9979 | IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9980 | |
| 9981 | wstats->miss.beacon = average_value(&priv->average_missed_beacons); |
| 9982 | wstats->discard.retries = priv->last_tx_failures; |
| 9983 | wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9984 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9985 | /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len)) |
| 9986 | goto fail_get_ordinal; |
| 9987 | wstats->discard.retries += tx_retry; */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9988 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9989 | return wstats; |
| 9990 | } |
| 9991 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9992 | /* net device stuff */ |
| 9993 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 9994 | static void init_sys_config(struct ipw_sys_config *sys_config) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9995 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9996 | memset(sys_config, 0, sizeof(struct ipw_sys_config)); |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 9997 | sys_config->bt_coexistence = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9998 | sys_config->answer_broadcast_ssid_probe = 0; |
| 9999 | sys_config->accept_all_data_frames = 0; |
| 10000 | sys_config->accept_non_directed_frames = 1; |
| 10001 | sys_config->exclude_unicast_unencrypted = 0; |
| 10002 | sys_config->disable_unicast_decryption = 1; |
| 10003 | sys_config->exclude_multicast_unencrypted = 0; |
| 10004 | sys_config->disable_multicast_decryption = 1; |
Zhu Yi | d2b83e1 | 2006-04-13 17:19:36 +0800 | [diff] [blame] | 10005 | if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B) |
| 10006 | antenna = CFG_SYS_ANTENNA_BOTH; |
| 10007 | sys_config->antenna_diversity = antenna; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10008 | 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] | 10009 | sys_config->dot11g_auto_detection = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10010 | sys_config->enable_cts_to_self = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10011 | sys_config->bt_coexist_collision_thr = 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10012 | 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] | 10013 | sys_config->silence_threshold = 0x1e; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10014 | } |
| 10015 | |
| 10016 | static int ipw_net_open(struct net_device *dev) |
| 10017 | { |
| 10018 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 10019 | IPW_DEBUG_INFO("dev->open\n"); |
| 10020 | /* we should be verifying the device is ready to be opened */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10021 | mutex_lock(&priv->mutex); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10022 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
| 10023 | (priv->status & STATUS_ASSOCIATED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10024 | netif_start_queue(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10025 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10026 | return 0; |
| 10027 | } |
| 10028 | |
| 10029 | static int ipw_net_stop(struct net_device *dev) |
| 10030 | { |
| 10031 | IPW_DEBUG_INFO("dev->close\n"); |
| 10032 | netif_stop_queue(dev); |
| 10033 | return 0; |
| 10034 | } |
| 10035 | |
| 10036 | /* |
| 10037 | todo: |
| 10038 | |
| 10039 | modify to send one tfd per fragment instead of using chunking. otherwise |
| 10040 | we need to heavily modify the ieee80211_skb_to_txb. |
| 10041 | */ |
| 10042 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 10043 | 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] | 10044 | int pri) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10045 | { |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 10046 | struct ieee80211_hdr_3addrqos *hdr = (struct ieee80211_hdr_3addrqos *) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10047 | txb->fragments[0]->data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10048 | int i = 0; |
| 10049 | struct tfd_frame *tfd; |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10050 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10051 | int tx_id = ipw_get_tx_queue_number(priv, pri); |
| 10052 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; |
| 10053 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10054 | struct clx2_tx_queue *txq = &priv->txq[0]; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10055 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10056 | struct clx2_queue *q = &txq->q; |
| 10057 | u8 id, hdr_len, unicast; |
| 10058 | u16 remaining_bytes; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10059 | int fc; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10060 | |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 10061 | hdr_len = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10062 | switch (priv->ieee->iw_mode) { |
| 10063 | case IW_MODE_ADHOC: |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 10064 | unicast = !is_multicast_ether_addr(hdr->addr1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10065 | id = ipw_find_station(priv, hdr->addr1); |
| 10066 | if (id == IPW_INVALID_STATION) { |
| 10067 | id = ipw_add_station(priv, hdr->addr1); |
| 10068 | if (id == IPW_INVALID_STATION) { |
| 10069 | IPW_WARNING("Attempt to send data to " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10070 | "invalid cell: " MAC_FMT "\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10071 | MAC_ARG(hdr->addr1)); |
| 10072 | goto drop; |
| 10073 | } |
| 10074 | } |
| 10075 | break; |
| 10076 | |
| 10077 | case IW_MODE_INFRA: |
| 10078 | default: |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 10079 | unicast = !is_multicast_ether_addr(hdr->addr3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10080 | id = 0; |
| 10081 | break; |
| 10082 | } |
| 10083 | |
| 10084 | tfd = &txq->bd[q->first_empty]; |
| 10085 | txq->txb[q->first_empty] = txb; |
| 10086 | memset(tfd, 0, sizeof(*tfd)); |
| 10087 | tfd->u.data.station_number = id; |
| 10088 | |
| 10089 | tfd->control_flags.message_type = TX_FRAME_TYPE; |
| 10090 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; |
| 10091 | |
| 10092 | tfd->u.data.cmd_id = DINO_CMD_TX; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10093 | tfd->u.data.len = cpu_to_le16(txb->payload_size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10094 | remaining_bytes = txb->payload_size; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10095 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10096 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10097 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10098 | else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10099 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10100 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10101 | if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE) |
| 10102 | tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10103 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10104 | fc = le16_to_cpu(hdr->frame_ctl); |
| 10105 | hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10106 | |
| 10107 | memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len); |
| 10108 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10109 | if (likely(unicast)) |
| 10110 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; |
| 10111 | |
| 10112 | if (txb->encrypted && !priv->ieee->host_encrypt) { |
| 10113 | switch (priv->ieee->sec.level) { |
| 10114 | case SEC_LEVEL_3: |
| 10115 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
| 10116 | IEEE80211_FCTL_PROTECTED; |
| 10117 | /* XXX: ACK flag must be set for CCMP even if it |
| 10118 | * is a multicast/broadcast packet, because CCMP |
| 10119 | * group communication encrypted by GTK is |
| 10120 | * actually done by the AP. */ |
| 10121 | if (!unicast) |
| 10122 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; |
| 10123 | |
| 10124 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; |
| 10125 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM; |
| 10126 | tfd->u.data.key_index = 0; |
| 10127 | tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE; |
| 10128 | break; |
| 10129 | case SEC_LEVEL_2: |
| 10130 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
| 10131 | IEEE80211_FCTL_PROTECTED; |
| 10132 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; |
| 10133 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP; |
| 10134 | tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE; |
| 10135 | break; |
| 10136 | case SEC_LEVEL_1: |
| 10137 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
| 10138 | IEEE80211_FCTL_PROTECTED; |
| 10139 | tfd->u.data.key_index = priv->ieee->tx_keyidx; |
| 10140 | if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <= |
| 10141 | 40) |
| 10142 | tfd->u.data.key_index |= DCT_WEP_KEY_64Bit; |
| 10143 | else |
| 10144 | tfd->u.data.key_index |= DCT_WEP_KEY_128Bit; |
| 10145 | break; |
| 10146 | case SEC_LEVEL_0: |
| 10147 | break; |
| 10148 | default: |
| 10149 | printk(KERN_ERR "Unknow security level %d\n", |
| 10150 | priv->ieee->sec.level); |
| 10151 | break; |
| 10152 | } |
| 10153 | } else |
| 10154 | /* No hardware encryption */ |
| 10155 | tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP; |
| 10156 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10157 | #ifdef CONFIG_IPW2200_QOS |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 10158 | if (fc & IEEE80211_STYPE_QOS_DATA) |
| 10159 | ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data)); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10160 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10161 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10162 | /* payload */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10163 | tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2), |
| 10164 | txb->nr_frags)); |
| 10165 | IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n", |
| 10166 | txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks)); |
| 10167 | for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) { |
| 10168 | IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n", |
| 10169 | i, le32_to_cpu(tfd->u.data.num_chunks), |
| 10170 | txb->fragments[i]->len - hdr_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10171 | 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] | 10172 | i, tfd->u.data.num_chunks, |
| 10173 | txb->fragments[i]->len - hdr_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10174 | printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10175 | txb->fragments[i]->len - hdr_len); |
| 10176 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10177 | tfd->u.data.chunk_ptr[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10178 | cpu_to_le32(pci_map_single |
| 10179 | (priv->pci_dev, |
| 10180 | txb->fragments[i]->data + hdr_len, |
| 10181 | txb->fragments[i]->len - hdr_len, |
| 10182 | PCI_DMA_TODEVICE)); |
| 10183 | tfd->u.data.chunk_len[i] = |
| 10184 | cpu_to_le16(txb->fragments[i]->len - hdr_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10185 | } |
| 10186 | |
| 10187 | if (i != txb->nr_frags) { |
| 10188 | struct sk_buff *skb; |
| 10189 | u16 remaining_bytes = 0; |
| 10190 | int j; |
| 10191 | |
| 10192 | for (j = i; j < txb->nr_frags; j++) |
| 10193 | remaining_bytes += txb->fragments[j]->len - hdr_len; |
| 10194 | |
| 10195 | printk(KERN_INFO "Trying to reallocate for %d bytes\n", |
| 10196 | remaining_bytes); |
| 10197 | skb = alloc_skb(remaining_bytes, GFP_ATOMIC); |
| 10198 | if (skb != NULL) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10199 | tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10200 | for (j = i; j < txb->nr_frags; j++) { |
| 10201 | int size = txb->fragments[j]->len - hdr_len; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10202 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10203 | printk(KERN_INFO "Adding frag %d %d...\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10204 | j, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10205 | memcpy(skb_put(skb, size), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10206 | txb->fragments[j]->data + hdr_len, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10207 | } |
| 10208 | dev_kfree_skb_any(txb->fragments[i]); |
| 10209 | txb->fragments[i] = skb; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10210 | tfd->u.data.chunk_ptr[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10211 | cpu_to_le32(pci_map_single |
| 10212 | (priv->pci_dev, skb->data, |
| 10213 | tfd->u.data.chunk_len[i], |
| 10214 | PCI_DMA_TODEVICE)); |
| 10215 | |
| 10216 | tfd->u.data.num_chunks = |
| 10217 | cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) + |
| 10218 | 1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10219 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10220 | } |
| 10221 | |
| 10222 | /* kick DMA */ |
| 10223 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); |
| 10224 | ipw_write32(priv, q->reg_w, q->first_empty); |
| 10225 | |
James Ketrenos | f697014 | 2006-02-14 09:10:51 +0800 | [diff] [blame] | 10226 | if (ipw_queue_space(q) < q->high_mark) |
| 10227 | netif_stop_queue(priv->net_dev); |
| 10228 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10229 | return NETDEV_TX_OK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10230 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10231 | drop: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10232 | IPW_DEBUG_DROP("Silently dropping Tx packet.\n"); |
| 10233 | ieee80211_txb_free(txb); |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10234 | return NETDEV_TX_OK; |
| 10235 | } |
| 10236 | |
| 10237 | static int ipw_net_is_queue_full(struct net_device *dev, int pri) |
| 10238 | { |
| 10239 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10240 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10241 | int tx_id = ipw_get_tx_queue_number(priv, pri); |
| 10242 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; |
| 10243 | #else |
| 10244 | struct clx2_tx_queue *txq = &priv->txq[0]; |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10245 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10246 | |
| 10247 | if (ipw_queue_space(&txq->q) < txq->q.high_mark) |
| 10248 | return 1; |
| 10249 | |
| 10250 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10251 | } |
| 10252 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10253 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 10254 | static void ipw_handle_promiscuous_tx(struct ipw_priv *priv, |
| 10255 | struct ieee80211_txb *txb) |
| 10256 | { |
| 10257 | struct ieee80211_rx_stats dummystats; |
| 10258 | struct ieee80211_hdr *hdr; |
| 10259 | u8 n; |
| 10260 | u16 filter = priv->prom_priv->filter; |
| 10261 | int hdr_only = 0; |
| 10262 | |
| 10263 | if (filter & IPW_PROM_NO_TX) |
| 10264 | return; |
| 10265 | |
| 10266 | memset(&dummystats, 0, sizeof(dummystats)); |
| 10267 | |
| 10268 | /* Filtering of fragment chains is done agains the first fragment */ |
| 10269 | hdr = (void *)txb->fragments[0]->data; |
| 10270 | if (ieee80211_is_management(hdr->frame_ctl)) { |
| 10271 | if (filter & IPW_PROM_NO_MGMT) |
| 10272 | return; |
| 10273 | if (filter & IPW_PROM_MGMT_HEADER_ONLY) |
| 10274 | hdr_only = 1; |
| 10275 | } else if (ieee80211_is_control(hdr->frame_ctl)) { |
| 10276 | if (filter & IPW_PROM_NO_CTL) |
| 10277 | return; |
| 10278 | if (filter & IPW_PROM_CTL_HEADER_ONLY) |
| 10279 | hdr_only = 1; |
| 10280 | } else if (ieee80211_is_data(hdr->frame_ctl)) { |
| 10281 | if (filter & IPW_PROM_NO_DATA) |
| 10282 | return; |
| 10283 | if (filter & IPW_PROM_DATA_HEADER_ONLY) |
| 10284 | hdr_only = 1; |
| 10285 | } |
| 10286 | |
| 10287 | for(n=0; n<txb->nr_frags; ++n) { |
| 10288 | struct sk_buff *src = txb->fragments[n]; |
| 10289 | struct sk_buff *dst; |
| 10290 | struct ieee80211_radiotap_header *rt_hdr; |
| 10291 | int len; |
| 10292 | |
| 10293 | if (hdr_only) { |
| 10294 | hdr = (void *)src->data; |
| 10295 | len = ieee80211_get_hdrlen(hdr->frame_ctl); |
| 10296 | } else |
| 10297 | len = src->len; |
| 10298 | |
| 10299 | dst = alloc_skb( |
| 10300 | len + IEEE80211_RADIOTAP_HDRLEN, GFP_ATOMIC); |
| 10301 | if (!dst) continue; |
| 10302 | |
| 10303 | rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr)); |
| 10304 | |
| 10305 | rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION; |
| 10306 | rt_hdr->it_pad = 0; |
| 10307 | rt_hdr->it_present = 0; /* after all, it's just an idea */ |
| 10308 | rt_hdr->it_present |= (1 << IEEE80211_RADIOTAP_CHANNEL); |
| 10309 | |
| 10310 | *(u16*)skb_put(dst, sizeof(u16)) = cpu_to_le16( |
| 10311 | ieee80211chan2mhz(priv->channel)); |
| 10312 | if (priv->channel > 14) /* 802.11a */ |
| 10313 | *(u16*)skb_put(dst, sizeof(u16)) = |
| 10314 | cpu_to_le16(IEEE80211_CHAN_OFDM | |
| 10315 | IEEE80211_CHAN_5GHZ); |
| 10316 | else if (priv->ieee->mode == IEEE_B) /* 802.11b */ |
| 10317 | *(u16*)skb_put(dst, sizeof(u16)) = |
| 10318 | cpu_to_le16(IEEE80211_CHAN_CCK | |
| 10319 | IEEE80211_CHAN_2GHZ); |
| 10320 | else /* 802.11g */ |
| 10321 | *(u16*)skb_put(dst, sizeof(u16)) = |
| 10322 | cpu_to_le16(IEEE80211_CHAN_OFDM | |
| 10323 | IEEE80211_CHAN_2GHZ); |
| 10324 | |
| 10325 | rt_hdr->it_len = dst->len; |
| 10326 | |
| 10327 | memcpy(skb_put(dst, len), src->data, len); |
| 10328 | |
| 10329 | if (!ieee80211_rx(priv->prom_priv->ieee, dst, &dummystats)) |
| 10330 | dev_kfree_skb_any(dst); |
| 10331 | } |
| 10332 | } |
| 10333 | #endif |
| 10334 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10335 | static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb, |
James Ketrenos | c8d42d1 | 2005-09-21 12:23:43 -0500 | [diff] [blame] | 10336 | struct net_device *dev, int pri) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10337 | { |
| 10338 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 10339 | unsigned long flags; |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10340 | int ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10341 | |
| 10342 | IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10343 | spin_lock_irqsave(&priv->lock, flags); |
| 10344 | |
| 10345 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 10346 | IPW_DEBUG_INFO("Tx attempt while not associated.\n"); |
| 10347 | priv->ieee->stats.tx_carrier_errors++; |
| 10348 | netif_stop_queue(dev); |
| 10349 | goto fail_unlock; |
| 10350 | } |
| 10351 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10352 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 10353 | if (rtap_iface && netif_running(priv->prom_net_dev)) |
| 10354 | ipw_handle_promiscuous_tx(priv, txb); |
| 10355 | #endif |
| 10356 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10357 | ret = ipw_tx_skb(priv, txb, pri); |
| 10358 | if (ret == NETDEV_TX_OK) |
| 10359 | __ipw_led_activity_on(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10360 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10361 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10362 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10363 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10364 | fail_unlock: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10365 | spin_unlock_irqrestore(&priv->lock, flags); |
| 10366 | return 1; |
| 10367 | } |
| 10368 | |
| 10369 | static struct net_device_stats *ipw_net_get_stats(struct net_device *dev) |
| 10370 | { |
| 10371 | struct ipw_priv *priv = ieee80211_priv(dev); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10372 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10373 | priv->ieee->stats.tx_packets = priv->tx_packets; |
| 10374 | priv->ieee->stats.rx_packets = priv->rx_packets; |
| 10375 | return &priv->ieee->stats; |
| 10376 | } |
| 10377 | |
| 10378 | static void ipw_net_set_multicast_list(struct net_device *dev) |
| 10379 | { |
| 10380 | |
| 10381 | } |
| 10382 | |
| 10383 | static int ipw_net_set_mac_address(struct net_device *dev, void *p) |
| 10384 | { |
| 10385 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 10386 | struct sockaddr *addr = p; |
| 10387 | if (!is_valid_ether_addr(addr->sa_data)) |
| 10388 | return -EADDRNOTAVAIL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10389 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10390 | priv->config |= CFG_CUSTOM_MAC; |
| 10391 | memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN); |
| 10392 | printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n", |
| 10393 | priv->net_dev->name, MAC_ARG(priv->mac_addr)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10394 | queue_work(priv->workqueue, &priv->adapter_restart); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10395 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10396 | return 0; |
| 10397 | } |
| 10398 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10399 | static void ipw_ethtool_get_drvinfo(struct net_device *dev, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10400 | struct ethtool_drvinfo *info) |
| 10401 | { |
| 10402 | struct ipw_priv *p = ieee80211_priv(dev); |
| 10403 | char vers[64]; |
| 10404 | char date[32]; |
| 10405 | u32 len; |
| 10406 | |
| 10407 | strcpy(info->driver, DRV_NAME); |
| 10408 | strcpy(info->version, DRV_VERSION); |
| 10409 | |
| 10410 | len = sizeof(vers); |
| 10411 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len); |
| 10412 | len = sizeof(date); |
| 10413 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len); |
| 10414 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10415 | snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10416 | vers, date); |
| 10417 | strcpy(info->bus_info, pci_name(p->pci_dev)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10418 | info->eedump_len = IPW_EEPROM_IMAGE_SIZE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10419 | } |
| 10420 | |
| 10421 | static u32 ipw_ethtool_get_link(struct net_device *dev) |
| 10422 | { |
| 10423 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 10424 | return (priv->status & STATUS_ASSOCIATED) != 0; |
| 10425 | } |
| 10426 | |
| 10427 | static int ipw_ethtool_get_eeprom_len(struct net_device *dev) |
| 10428 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10429 | return IPW_EEPROM_IMAGE_SIZE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10430 | } |
| 10431 | |
| 10432 | static int ipw_ethtool_get_eeprom(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10433 | struct ethtool_eeprom *eeprom, u8 * bytes) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10434 | { |
| 10435 | struct ipw_priv *p = ieee80211_priv(dev); |
| 10436 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10437 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10438 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10439 | mutex_lock(&p->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10440 | memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10441 | mutex_unlock(&p->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10442 | return 0; |
| 10443 | } |
| 10444 | |
| 10445 | static int ipw_ethtool_set_eeprom(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10446 | struct ethtool_eeprom *eeprom, u8 * bytes) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10447 | { |
| 10448 | struct ipw_priv *p = ieee80211_priv(dev); |
| 10449 | int i; |
| 10450 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10451 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10452 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10453 | mutex_lock(&p->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10454 | memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len); |
Adrian Bunk | 71e585f | 2006-03-11 04:42:58 +0100 | [diff] [blame] | 10455 | for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) |
| 10456 | ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10457 | mutex_unlock(&p->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10458 | return 0; |
| 10459 | } |
| 10460 | |
| 10461 | static struct ethtool_ops ipw_ethtool_ops = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10462 | .get_link = ipw_ethtool_get_link, |
| 10463 | .get_drvinfo = ipw_ethtool_get_drvinfo, |
| 10464 | .get_eeprom_len = ipw_ethtool_get_eeprom_len, |
| 10465 | .get_eeprom = ipw_ethtool_get_eeprom, |
| 10466 | .set_eeprom = ipw_ethtool_set_eeprom, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10467 | }; |
| 10468 | |
| 10469 | static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs) |
| 10470 | { |
| 10471 | struct ipw_priv *priv = data; |
| 10472 | u32 inta, inta_mask; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10473 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10474 | if (!priv) |
| 10475 | return IRQ_NONE; |
| 10476 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 10477 | spin_lock(&priv->irq_lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10478 | |
| 10479 | if (!(priv->status & STATUS_INT_ENABLED)) { |
| 10480 | /* Shared IRQ */ |
| 10481 | goto none; |
| 10482 | } |
| 10483 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10484 | inta = ipw_read32(priv, IPW_INTA_RW); |
| 10485 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10486 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10487 | if (inta == 0xFFFFFFFF) { |
| 10488 | /* Hardware disappeared */ |
| 10489 | IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n"); |
| 10490 | goto none; |
| 10491 | } |
| 10492 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10493 | if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10494 | /* Shared interrupt */ |
| 10495 | goto none; |
| 10496 | } |
| 10497 | |
| 10498 | /* tell the device to stop sending interrupts */ |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 10499 | __ipw_disable_interrupts(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10500 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10501 | /* ack current interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10502 | inta &= (IPW_INTA_MASK_ALL & inta_mask); |
| 10503 | ipw_write32(priv, IPW_INTA_RW, inta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10504 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10505 | /* Cache INTA value for our tasklet */ |
| 10506 | priv->isr_inta = inta; |
| 10507 | |
| 10508 | tasklet_schedule(&priv->irq_tasklet); |
| 10509 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 10510 | spin_unlock(&priv->irq_lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10511 | |
| 10512 | return IRQ_HANDLED; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10513 | none: |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 10514 | spin_unlock(&priv->irq_lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10515 | return IRQ_NONE; |
| 10516 | } |
| 10517 | |
| 10518 | static void ipw_rf_kill(void *adapter) |
| 10519 | { |
| 10520 | struct ipw_priv *priv = adapter; |
| 10521 | unsigned long flags; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10522 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10523 | spin_lock_irqsave(&priv->lock, flags); |
| 10524 | |
| 10525 | if (rf_kill_active(priv)) { |
| 10526 | IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n"); |
| 10527 | if (priv->workqueue) |
| 10528 | queue_delayed_work(priv->workqueue, |
| 10529 | &priv->rf_kill, 2 * HZ); |
| 10530 | goto exit_unlock; |
| 10531 | } |
| 10532 | |
| 10533 | /* RF Kill is now disabled, so bring the device back up */ |
| 10534 | |
| 10535 | if (!(priv->status & STATUS_RF_KILL_MASK)) { |
| 10536 | IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting " |
| 10537 | "device\n"); |
| 10538 | |
| 10539 | /* we can not do an adapter restart while inside an irq lock */ |
| 10540 | queue_work(priv->workqueue, &priv->adapter_restart); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10541 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10542 | IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still " |
| 10543 | "enabled\n"); |
| 10544 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10545 | exit_unlock: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10546 | spin_unlock_irqrestore(&priv->lock, flags); |
| 10547 | } |
| 10548 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10549 | static void ipw_bg_rf_kill(void *data) |
| 10550 | { |
| 10551 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10552 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10553 | ipw_rf_kill(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10554 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10555 | } |
| 10556 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 10557 | static void ipw_link_up(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10558 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10559 | priv->last_seq_num = -1; |
| 10560 | priv->last_frag_num = -1; |
| 10561 | priv->last_packet_time = 0; |
| 10562 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10563 | netif_carrier_on(priv->net_dev); |
| 10564 | if (netif_queue_stopped(priv->net_dev)) { |
| 10565 | IPW_DEBUG_NOTIF("waking queue\n"); |
| 10566 | netif_wake_queue(priv->net_dev); |
| 10567 | } else { |
| 10568 | IPW_DEBUG_NOTIF("starting queue\n"); |
| 10569 | netif_start_queue(priv->net_dev); |
| 10570 | } |
| 10571 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10572 | cancel_delayed_work(&priv->request_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10573 | ipw_reset_stats(priv); |
| 10574 | /* Ensure the rate is updated immediately */ |
| 10575 | priv->last_rate = ipw_get_current_rate(priv); |
| 10576 | ipw_gather_stats(priv); |
| 10577 | ipw_led_link_up(priv); |
| 10578 | notify_wx_assoc_event(priv); |
| 10579 | |
| 10580 | if (priv->config & CFG_BACKGROUND_SCAN) |
| 10581 | queue_delayed_work(priv->workqueue, &priv->request_scan, HZ); |
| 10582 | } |
| 10583 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10584 | static void ipw_bg_link_up(void *data) |
| 10585 | { |
| 10586 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10587 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10588 | ipw_link_up(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10589 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10590 | } |
| 10591 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 10592 | static void ipw_link_down(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10593 | { |
| 10594 | ipw_led_link_down(priv); |
| 10595 | netif_carrier_off(priv->net_dev); |
| 10596 | netif_stop_queue(priv->net_dev); |
| 10597 | notify_wx_assoc_event(priv); |
| 10598 | |
| 10599 | /* Cancel any queued work ... */ |
| 10600 | cancel_delayed_work(&priv->request_scan); |
| 10601 | cancel_delayed_work(&priv->adhoc_check); |
| 10602 | cancel_delayed_work(&priv->gather_stats); |
| 10603 | |
| 10604 | ipw_reset_stats(priv); |
| 10605 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10606 | if (!(priv->status & STATUS_EXIT_PENDING)) { |
| 10607 | /* Queue up another scan... */ |
| 10608 | queue_work(priv->workqueue, &priv->request_scan); |
| 10609 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10610 | } |
| 10611 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10612 | static void ipw_bg_link_down(void *data) |
| 10613 | { |
| 10614 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10615 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10616 | ipw_link_down(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10617 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10618 | } |
| 10619 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10620 | static int ipw_setup_deferred_work(struct ipw_priv *priv) |
| 10621 | { |
| 10622 | int ret = 0; |
| 10623 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10624 | priv->workqueue = create_workqueue(DRV_NAME); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10625 | init_waitqueue_head(&priv->wait_command_queue); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10626 | init_waitqueue_head(&priv->wait_state); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10627 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10628 | INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv); |
| 10629 | INIT_WORK(&priv->associate, ipw_bg_associate, priv); |
| 10630 | INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv); |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 10631 | INIT_WORK(&priv->system_config, ipw_system_config, priv); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10632 | INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv); |
| 10633 | INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv); |
| 10634 | INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv); |
| 10635 | INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv); |
| 10636 | INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10637 | INIT_WORK(&priv->request_scan, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10638 | (void (*)(void *))ipw_request_scan, priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10639 | INIT_WORK(&priv->gather_stats, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10640 | (void (*)(void *))ipw_bg_gather_stats, priv); |
| 10641 | INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv); |
| 10642 | INIT_WORK(&priv->roam, ipw_bg_roam, priv); |
| 10643 | INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv); |
| 10644 | INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv); |
| 10645 | INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv); |
| 10646 | 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] | 10647 | priv); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10648 | 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] | 10649 | priv); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10650 | INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off, |
| 10651 | priv); |
| 10652 | INIT_WORK(&priv->merge_networks, |
| 10653 | (void (*)(void *))ipw_merge_adhoc_network, priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10654 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10655 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10656 | INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate, |
| 10657 | priv); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10658 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10659 | |
| 10660 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
| 10661 | ipw_irq_tasklet, (unsigned long)priv); |
| 10662 | |
| 10663 | return ret; |
| 10664 | } |
| 10665 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10666 | static void shim__set_security(struct net_device *dev, |
| 10667 | struct ieee80211_security *sec) |
| 10668 | { |
| 10669 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 10670 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10671 | for (i = 0; i < 4; i++) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10672 | if (sec->flags & (1 << i)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10673 | priv->ieee->sec.encode_alg[i] = sec->encode_alg[i]; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10674 | priv->ieee->sec.key_sizes[i] = sec->key_sizes[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10675 | if (sec->key_sizes[i] == 0) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10676 | priv->ieee->sec.flags &= ~(1 << i); |
| 10677 | else { |
| 10678 | memcpy(priv->ieee->sec.keys[i], sec->keys[i], |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10679 | sec->key_sizes[i]); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10680 | priv->ieee->sec.flags |= (1 << i); |
| 10681 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10682 | priv->status |= STATUS_SECURITY_UPDATED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10683 | } else if (sec->level != SEC_LEVEL_1) |
| 10684 | priv->ieee->sec.flags &= ~(1 << i); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10685 | } |
| 10686 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10687 | if (sec->flags & SEC_ACTIVE_KEY) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10688 | if (sec->active_key <= 3) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10689 | priv->ieee->sec.active_key = sec->active_key; |
| 10690 | priv->ieee->sec.flags |= SEC_ACTIVE_KEY; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10691 | } else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10692 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10693 | priv->status |= STATUS_SECURITY_UPDATED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10694 | } else |
| 10695 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10696 | |
| 10697 | if ((sec->flags & SEC_AUTH_MODE) && |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10698 | (priv->ieee->sec.auth_mode != sec->auth_mode)) { |
| 10699 | priv->ieee->sec.auth_mode = sec->auth_mode; |
| 10700 | priv->ieee->sec.flags |= SEC_AUTH_MODE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10701 | if (sec->auth_mode == WLAN_AUTH_SHARED_KEY) |
| 10702 | priv->capability |= CAP_SHARED_KEY; |
| 10703 | else |
| 10704 | priv->capability &= ~CAP_SHARED_KEY; |
| 10705 | priv->status |= STATUS_SECURITY_UPDATED; |
| 10706 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10707 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10708 | if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) { |
| 10709 | priv->ieee->sec.flags |= SEC_ENABLED; |
| 10710 | priv->ieee->sec.enabled = sec->enabled; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10711 | priv->status |= STATUS_SECURITY_UPDATED; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10712 | if (sec->enabled) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10713 | priv->capability |= CAP_PRIVACY_ON; |
| 10714 | else |
| 10715 | priv->capability &= ~CAP_PRIVACY_ON; |
| 10716 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10717 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10718 | if (sec->flags & SEC_ENCRYPT) |
| 10719 | priv->ieee->sec.encrypt = sec->encrypt; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10720 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10721 | if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) { |
| 10722 | priv->ieee->sec.level = sec->level; |
| 10723 | priv->ieee->sec.flags |= SEC_LEVEL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10724 | priv->status |= STATUS_SECURITY_UPDATED; |
| 10725 | } |
| 10726 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 10727 | if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT)) |
| 10728 | ipw_set_hwcrypto_keys(priv); |
| 10729 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10730 | /* To match current functionality of ipw2100 (which works well w/ |
| 10731 | * various supplicants, we don't force a disassociate if the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10732 | * privacy capability changes ... */ |
| 10733 | #if 0 |
| 10734 | if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) && |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10735 | (((priv->assoc_request.capability & |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10736 | WLAN_CAPABILITY_PRIVACY) && !sec->enabled) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10737 | (!(priv->assoc_request.capability & |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10738 | WLAN_CAPABILITY_PRIVACY) && sec->enabled))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10739 | IPW_DEBUG_ASSOC("Disassociating due to capability " |
| 10740 | "change.\n"); |
| 10741 | ipw_disassociate(priv); |
| 10742 | } |
| 10743 | #endif |
| 10744 | } |
| 10745 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10746 | static int init_supported_rates(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10747 | struct ipw_supported_rates *rates) |
| 10748 | { |
| 10749 | /* TODO: Mask out rates based on priv->rates_mask */ |
| 10750 | |
| 10751 | memset(rates, 0, sizeof(*rates)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10752 | /* configure supported rates */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10753 | switch (priv->ieee->freq_band) { |
| 10754 | case IEEE80211_52GHZ_BAND: |
| 10755 | rates->ieee_mode = IPW_A_MODE; |
| 10756 | rates->purpose = IPW_RATE_CAPABILITIES; |
| 10757 | ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION, |
| 10758 | IEEE80211_OFDM_DEFAULT_RATES_MASK); |
| 10759 | break; |
| 10760 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10761 | default: /* Mixed or 2.4Ghz */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10762 | rates->ieee_mode = IPW_G_MODE; |
| 10763 | rates->purpose = IPW_RATE_CAPABILITIES; |
| 10764 | ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION, |
| 10765 | IEEE80211_CCK_DEFAULT_RATES_MASK); |
| 10766 | if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) { |
| 10767 | ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION, |
| 10768 | IEEE80211_OFDM_DEFAULT_RATES_MASK); |
| 10769 | } |
| 10770 | break; |
| 10771 | } |
| 10772 | |
| 10773 | return 0; |
| 10774 | } |
| 10775 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10776 | static int ipw_config(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10777 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10778 | /* This is only called from ipw_up, which resets/reloads the firmware |
| 10779 | so, we don't need to first disable the card before we configure |
| 10780 | it */ |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 10781 | if (ipw_set_tx_power(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10782 | goto error; |
| 10783 | |
| 10784 | /* initialize adapter address */ |
| 10785 | if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr)) |
| 10786 | goto error; |
| 10787 | |
| 10788 | /* set basic system config settings */ |
| 10789 | init_sys_config(&priv->sys_config); |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10790 | |
| 10791 | /* Support Bluetooth if we have BT h/w on board, and user wants to. |
| 10792 | * Does not support BT priority yet (don't abort or defer our Tx) */ |
| 10793 | if (bt_coexist) { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10794 | unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY]; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10795 | |
| 10796 | if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG) |
| 10797 | priv->sys_config.bt_coexistence |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10798 | |= CFG_BT_COEXISTENCE_SIGNAL_CHNL; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10799 | if (bt_caps & EEPROM_SKU_CAP_BT_OOB) |
| 10800 | priv->sys_config.bt_coexistence |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10801 | |= CFG_BT_COEXISTENCE_OOB; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10802 | } |
| 10803 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10804 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 10805 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) { |
| 10806 | priv->sys_config.accept_all_data_frames = 1; |
| 10807 | priv->sys_config.accept_non_directed_frames = 1; |
| 10808 | priv->sys_config.accept_all_mgmt_bcpr = 1; |
| 10809 | priv->sys_config.accept_all_mgmt_frames = 1; |
| 10810 | } |
| 10811 | #endif |
| 10812 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10813 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 10814 | priv->sys_config.answer_broadcast_ssid_probe = 1; |
| 10815 | else |
| 10816 | priv->sys_config.answer_broadcast_ssid_probe = 0; |
| 10817 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10818 | if (ipw_send_system_config(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10819 | goto error; |
| 10820 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10821 | init_supported_rates(priv, &priv->rates); |
| 10822 | if (ipw_send_supported_rates(priv, &priv->rates)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10823 | goto error; |
| 10824 | |
| 10825 | /* Set request-to-send threshold */ |
| 10826 | if (priv->rts_threshold) { |
| 10827 | if (ipw_send_rts_threshold(priv, priv->rts_threshold)) |
| 10828 | goto error; |
| 10829 | } |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10830 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10831 | IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n"); |
| 10832 | ipw_qos_activate(priv, NULL); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10833 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10834 | |
| 10835 | if (ipw_set_random_seed(priv)) |
| 10836 | goto error; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10837 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10838 | /* final state transition to the RUN state */ |
| 10839 | if (ipw_send_host_complete(priv)) |
| 10840 | goto error; |
| 10841 | |
James Ketrenos | e666619 | 2005-08-12 09:17:04 -0500 | [diff] [blame] | 10842 | priv->status |= STATUS_INIT; |
| 10843 | |
| 10844 | ipw_led_init(priv); |
| 10845 | ipw_led_radio_on(priv); |
| 10846 | priv->notif_missed_beacons = 0; |
| 10847 | |
| 10848 | /* Set hardware WEP key if it is configured. */ |
| 10849 | if ((priv->capability & CAP_PRIVACY_ON) && |
| 10850 | (priv->ieee->sec.level == SEC_LEVEL_1) && |
| 10851 | !(priv->ieee->host_encrypt || priv->ieee->host_decrypt)) |
| 10852 | ipw_set_hwcrypto_keys(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10853 | |
| 10854 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10855 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10856 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10857 | return -EIO; |
| 10858 | } |
| 10859 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10860 | /* |
| 10861 | * NOTE: |
| 10862 | * |
| 10863 | * These tables have been tested in conjunction with the |
| 10864 | * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters. |
| 10865 | * |
| 10866 | * Altering this values, using it on other hardware, or in geographies |
| 10867 | * not intended for resale of the above mentioned Intel adapters has |
| 10868 | * not been tested. |
| 10869 | * |
Henrik Brix Andersen | 48a8477 | 2006-02-14 09:09:52 +0800 | [diff] [blame] | 10870 | * Remember to update the table in README.ipw2200 when changing this |
| 10871 | * table. |
| 10872 | * |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10873 | */ |
| 10874 | static const struct ieee80211_geo ipw_geos[] = { |
| 10875 | { /* Restricted */ |
| 10876 | "---", |
| 10877 | .bg_channels = 11, |
| 10878 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10879 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10880 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10881 | {2457, 10}, {2462, 11}}, |
| 10882 | }, |
| 10883 | |
| 10884 | { /* Custom US/Canada */ |
| 10885 | "ZZF", |
| 10886 | .bg_channels = 11, |
| 10887 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10888 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10889 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10890 | {2457, 10}, {2462, 11}}, |
| 10891 | .a_channels = 8, |
| 10892 | .a = {{5180, 36}, |
| 10893 | {5200, 40}, |
| 10894 | {5220, 44}, |
| 10895 | {5240, 48}, |
| 10896 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10897 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10898 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10899 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10900 | }, |
| 10901 | |
| 10902 | { /* Rest of World */ |
| 10903 | "ZZD", |
| 10904 | .bg_channels = 13, |
| 10905 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10906 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10907 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10908 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 10909 | {2472, 13}}, |
| 10910 | }, |
| 10911 | |
| 10912 | { /* Custom USA & Europe & High */ |
| 10913 | "ZZA", |
| 10914 | .bg_channels = 11, |
| 10915 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10916 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10917 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10918 | {2457, 10}, {2462, 11}}, |
| 10919 | .a_channels = 13, |
| 10920 | .a = {{5180, 36}, |
| 10921 | {5200, 40}, |
| 10922 | {5220, 44}, |
| 10923 | {5240, 48}, |
| 10924 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10925 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10926 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10927 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10928 | {5745, 149}, |
| 10929 | {5765, 153}, |
| 10930 | {5785, 157}, |
| 10931 | {5805, 161}, |
| 10932 | {5825, 165}}, |
| 10933 | }, |
| 10934 | |
| 10935 | { /* Custom NA & Europe */ |
| 10936 | "ZZB", |
| 10937 | .bg_channels = 11, |
| 10938 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10939 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10940 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10941 | {2457, 10}, {2462, 11}}, |
| 10942 | .a_channels = 13, |
| 10943 | .a = {{5180, 36}, |
| 10944 | {5200, 40}, |
| 10945 | {5220, 44}, |
| 10946 | {5240, 48}, |
| 10947 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10948 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10949 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10950 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10951 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, |
| 10952 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, |
| 10953 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, |
| 10954 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, |
| 10955 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10956 | }, |
| 10957 | |
| 10958 | { /* Custom Japan */ |
| 10959 | "ZZC", |
| 10960 | .bg_channels = 11, |
| 10961 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10962 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10963 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10964 | {2457, 10}, {2462, 11}}, |
| 10965 | .a_channels = 4, |
| 10966 | .a = {{5170, 34}, {5190, 38}, |
| 10967 | {5210, 42}, {5230, 46}}, |
| 10968 | }, |
| 10969 | |
| 10970 | { /* Custom */ |
| 10971 | "ZZM", |
| 10972 | .bg_channels = 11, |
| 10973 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10974 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10975 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10976 | {2457, 10}, {2462, 11}}, |
| 10977 | }, |
| 10978 | |
| 10979 | { /* Europe */ |
| 10980 | "ZZE", |
| 10981 | .bg_channels = 13, |
| 10982 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10983 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10984 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10985 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 10986 | {2472, 13}}, |
| 10987 | .a_channels = 19, |
| 10988 | .a = {{5180, 36}, |
| 10989 | {5200, 40}, |
| 10990 | {5220, 44}, |
| 10991 | {5240, 48}, |
| 10992 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10993 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10994 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10995 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10996 | {5500, 100, IEEE80211_CH_PASSIVE_ONLY}, |
| 10997 | {5520, 104, IEEE80211_CH_PASSIVE_ONLY}, |
| 10998 | {5540, 108, IEEE80211_CH_PASSIVE_ONLY}, |
| 10999 | {5560, 112, IEEE80211_CH_PASSIVE_ONLY}, |
| 11000 | {5580, 116, IEEE80211_CH_PASSIVE_ONLY}, |
| 11001 | {5600, 120, IEEE80211_CH_PASSIVE_ONLY}, |
| 11002 | {5620, 124, IEEE80211_CH_PASSIVE_ONLY}, |
| 11003 | {5640, 128, IEEE80211_CH_PASSIVE_ONLY}, |
| 11004 | {5660, 132, IEEE80211_CH_PASSIVE_ONLY}, |
| 11005 | {5680, 136, IEEE80211_CH_PASSIVE_ONLY}, |
| 11006 | {5700, 140, IEEE80211_CH_PASSIVE_ONLY}}, |
| 11007 | }, |
| 11008 | |
| 11009 | { /* Custom Japan */ |
| 11010 | "ZZJ", |
| 11011 | .bg_channels = 14, |
| 11012 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11013 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11014 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11015 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 11016 | {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}}, |
| 11017 | .a_channels = 4, |
| 11018 | .a = {{5170, 34}, {5190, 38}, |
| 11019 | {5210, 42}, {5230, 46}}, |
| 11020 | }, |
| 11021 | |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 11022 | { /* Rest of World */ |
| 11023 | "ZZR", |
| 11024 | .bg_channels = 14, |
| 11025 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11026 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11027 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11028 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 11029 | {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY | |
| 11030 | IEEE80211_CH_PASSIVE_ONLY}}, |
| 11031 | }, |
| 11032 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11033 | { /* High Band */ |
| 11034 | "ZZH", |
| 11035 | .bg_channels = 13, |
| 11036 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11037 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11038 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11039 | {2457, 10}, {2462, 11}, |
| 11040 | {2467, 12, IEEE80211_CH_PASSIVE_ONLY}, |
| 11041 | {2472, 13, IEEE80211_CH_PASSIVE_ONLY}}, |
| 11042 | .a_channels = 4, |
| 11043 | .a = {{5745, 149}, {5765, 153}, |
| 11044 | {5785, 157}, {5805, 161}}, |
| 11045 | }, |
| 11046 | |
| 11047 | { /* Custom Europe */ |
| 11048 | "ZZG", |
| 11049 | .bg_channels = 13, |
| 11050 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11051 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11052 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11053 | {2457, 10}, {2462, 11}, |
| 11054 | {2467, 12}, {2472, 13}}, |
| 11055 | .a_channels = 4, |
| 11056 | .a = {{5180, 36}, {5200, 40}, |
| 11057 | {5220, 44}, {5240, 48}}, |
| 11058 | }, |
| 11059 | |
| 11060 | { /* Europe */ |
| 11061 | "ZZK", |
| 11062 | .bg_channels = 13, |
| 11063 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11064 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11065 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11066 | {2457, 10}, {2462, 11}, |
| 11067 | {2467, 12, IEEE80211_CH_PASSIVE_ONLY}, |
| 11068 | {2472, 13, IEEE80211_CH_PASSIVE_ONLY}}, |
| 11069 | .a_channels = 24, |
| 11070 | .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY}, |
| 11071 | {5200, 40, IEEE80211_CH_PASSIVE_ONLY}, |
| 11072 | {5220, 44, IEEE80211_CH_PASSIVE_ONLY}, |
| 11073 | {5240, 48, IEEE80211_CH_PASSIVE_ONLY}, |
| 11074 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 11075 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 11076 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 11077 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 11078 | {5500, 100, IEEE80211_CH_PASSIVE_ONLY}, |
| 11079 | {5520, 104, IEEE80211_CH_PASSIVE_ONLY}, |
| 11080 | {5540, 108, IEEE80211_CH_PASSIVE_ONLY}, |
| 11081 | {5560, 112, IEEE80211_CH_PASSIVE_ONLY}, |
| 11082 | {5580, 116, IEEE80211_CH_PASSIVE_ONLY}, |
| 11083 | {5600, 120, IEEE80211_CH_PASSIVE_ONLY}, |
| 11084 | {5620, 124, IEEE80211_CH_PASSIVE_ONLY}, |
| 11085 | {5640, 128, IEEE80211_CH_PASSIVE_ONLY}, |
| 11086 | {5660, 132, IEEE80211_CH_PASSIVE_ONLY}, |
| 11087 | {5680, 136, IEEE80211_CH_PASSIVE_ONLY}, |
| 11088 | {5700, 140, IEEE80211_CH_PASSIVE_ONLY}, |
| 11089 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, |
| 11090 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, |
| 11091 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, |
| 11092 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, |
| 11093 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, |
| 11094 | }, |
| 11095 | |
| 11096 | { /* Europe */ |
| 11097 | "ZZL", |
| 11098 | .bg_channels = 11, |
| 11099 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11100 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11101 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11102 | {2457, 10}, {2462, 11}}, |
| 11103 | .a_channels = 13, |
| 11104 | .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY}, |
| 11105 | {5200, 40, IEEE80211_CH_PASSIVE_ONLY}, |
| 11106 | {5220, 44, IEEE80211_CH_PASSIVE_ONLY}, |
| 11107 | {5240, 48, IEEE80211_CH_PASSIVE_ONLY}, |
| 11108 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 11109 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 11110 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 11111 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 11112 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, |
| 11113 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, |
| 11114 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, |
| 11115 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, |
| 11116 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, |
| 11117 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11118 | }; |
| 11119 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11120 | #define MAX_HW_RESTARTS 5 |
| 11121 | static int ipw_up(struct ipw_priv *priv) |
| 11122 | { |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11123 | int rc, i, j; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11124 | |
| 11125 | if (priv->status & STATUS_EXIT_PENDING) |
| 11126 | return -EIO; |
| 11127 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11128 | if (cmdlog && !priv->cmdlog) { |
| 11129 | priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog, |
| 11130 | GFP_KERNEL); |
| 11131 | if (priv->cmdlog == NULL) { |
| 11132 | IPW_ERROR("Error allocating %d command log entries.\n", |
| 11133 | cmdlog); |
Zhu Yi | d0b526b | 2006-04-13 17:19:50 +0800 | [diff] [blame] | 11134 | return -ENOMEM; |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11135 | } else { |
| 11136 | memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog); |
| 11137 | priv->cmdlog_len = cmdlog; |
| 11138 | } |
| 11139 | } |
| 11140 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11141 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11142 | /* Load the microcode, firmware, and eeprom. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11143 | * Also start the clocks. */ |
| 11144 | rc = ipw_load(priv); |
| 11145 | if (rc) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 11146 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11147 | return rc; |
| 11148 | } |
| 11149 | |
| 11150 | ipw_init_ordinals(priv); |
| 11151 | if (!(priv->config & CFG_CUSTOM_MAC)) |
| 11152 | eeprom_parse_mac(priv, priv->mac_addr); |
| 11153 | memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN); |
| 11154 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11155 | for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) { |
| 11156 | if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE], |
| 11157 | ipw_geos[j].name, 3)) |
| 11158 | break; |
| 11159 | } |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 11160 | if (j == ARRAY_SIZE(ipw_geos)) { |
| 11161 | IPW_WARNING("SKU [%c%c%c] not recognized.\n", |
| 11162 | priv->eeprom[EEPROM_COUNTRY_CODE + 0], |
| 11163 | priv->eeprom[EEPROM_COUNTRY_CODE + 1], |
| 11164 | priv->eeprom[EEPROM_COUNTRY_CODE + 2]); |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11165 | j = 0; |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 11166 | } |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 11167 | if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) { |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11168 | IPW_WARNING("Could not set geography."); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11169 | return 0; |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11170 | } |
| 11171 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11172 | if (priv->status & STATUS_RF_KILL_SW) { |
| 11173 | IPW_WARNING("Radio disabled by module parameter.\n"); |
| 11174 | return 0; |
| 11175 | } else if (rf_kill_active(priv)) { |
| 11176 | IPW_WARNING("Radio Frequency Kill Switch is On:\n" |
| 11177 | "Kill switch must be turned off for " |
| 11178 | "wireless networking to work.\n"); |
| 11179 | queue_delayed_work(priv->workqueue, &priv->rf_kill, |
| 11180 | 2 * HZ); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11181 | return 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11182 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11183 | |
| 11184 | rc = ipw_config(priv); |
| 11185 | if (!rc) { |
| 11186 | IPW_DEBUG_INFO("Configured device on count %i\n", i); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11187 | |
James Ketrenos | e666619 | 2005-08-12 09:17:04 -0500 | [diff] [blame] | 11188 | /* If configure to try and auto-associate, kick |
| 11189 | * off a scan. */ |
| 11190 | queue_work(priv->workqueue, &priv->request_scan); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11191 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11192 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11193 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11194 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11195 | IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11196 | IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n", |
| 11197 | i, MAX_HW_RESTARTS); |
| 11198 | |
| 11199 | /* We had an error bringing up the hardware, so take it |
| 11200 | * all the way back down so we can try again */ |
| 11201 | ipw_down(priv); |
| 11202 | } |
| 11203 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11204 | /* tried to restart and config the device for as long as our |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11205 | * patience could withstand */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11206 | IPW_ERROR("Unable to initialize device after %d attempts.\n", i); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11207 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11208 | return -EIO; |
| 11209 | } |
| 11210 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11211 | static void ipw_bg_up(void *data) |
| 11212 | { |
| 11213 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11214 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11215 | ipw_up(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11216 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11217 | } |
| 11218 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11219 | static void ipw_deinit(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11220 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11221 | int i; |
| 11222 | |
| 11223 | if (priv->status & STATUS_SCANNING) { |
| 11224 | IPW_DEBUG_INFO("Aborting scan during shutdown.\n"); |
| 11225 | ipw_abort_scan(priv); |
| 11226 | } |
| 11227 | |
| 11228 | if (priv->status & STATUS_ASSOCIATED) { |
| 11229 | IPW_DEBUG_INFO("Disassociating during shutdown.\n"); |
| 11230 | ipw_disassociate(priv); |
| 11231 | } |
| 11232 | |
| 11233 | ipw_led_shutdown(priv); |
| 11234 | |
| 11235 | /* Wait up to 1s for status to change to not scanning and not |
| 11236 | * associated (disassociation can take a while for a ful 802.11 |
| 11237 | * exchange */ |
| 11238 | for (i = 1000; i && (priv->status & |
| 11239 | (STATUS_DISASSOCIATING | |
| 11240 | STATUS_ASSOCIATED | STATUS_SCANNING)); i--) |
| 11241 | udelay(10); |
| 11242 | |
| 11243 | if (priv->status & (STATUS_DISASSOCIATING | |
| 11244 | STATUS_ASSOCIATED | STATUS_SCANNING)) |
| 11245 | IPW_DEBUG_INFO("Still associated or scanning...\n"); |
| 11246 | else |
| 11247 | IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i); |
| 11248 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11249 | /* Attempt to disable the card */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11250 | ipw_send_card_disable(priv, 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11251 | |
| 11252 | priv->status &= ~STATUS_INIT; |
| 11253 | } |
| 11254 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11255 | static void ipw_down(struct ipw_priv *priv) |
| 11256 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11257 | int exit_pending = priv->status & STATUS_EXIT_PENDING; |
| 11258 | |
| 11259 | priv->status |= STATUS_EXIT_PENDING; |
| 11260 | |
| 11261 | if (ipw_is_init(priv)) |
| 11262 | ipw_deinit(priv); |
| 11263 | |
| 11264 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 11265 | * exiting the module */ |
| 11266 | if (!exit_pending) |
| 11267 | priv->status &= ~STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11268 | |
| 11269 | /* tell the device to stop sending interrupts */ |
| 11270 | ipw_disable_interrupts(priv); |
| 11271 | |
| 11272 | /* Clear all bits but the RF Kill */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11273 | priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11274 | netif_carrier_off(priv->net_dev); |
| 11275 | netif_stop_queue(priv->net_dev); |
| 11276 | |
| 11277 | ipw_stop_nic(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11278 | |
| 11279 | ipw_led_radio_off(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11280 | } |
| 11281 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11282 | static void ipw_bg_down(void *data) |
| 11283 | { |
| 11284 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11285 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11286 | ipw_down(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11287 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11288 | } |
| 11289 | |
| 11290 | /* Called by register_netdev() */ |
| 11291 | static int ipw_net_init(struct net_device *dev) |
| 11292 | { |
| 11293 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11294 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11295 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11296 | if (ipw_up(priv)) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11297 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11298 | return -EIO; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11299 | } |
| 11300 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11301 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11302 | return 0; |
| 11303 | } |
| 11304 | |
| 11305 | /* PCI driver stuff */ |
| 11306 | static struct pci_device_id card_ids[] = { |
| 11307 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0}, |
| 11308 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0}, |
| 11309 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0}, |
| 11310 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0}, |
| 11311 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0}, |
| 11312 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0}, |
| 11313 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0}, |
| 11314 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0}, |
| 11315 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0}, |
| 11316 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0}, |
| 11317 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0}, |
| 11318 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0}, |
| 11319 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0}, |
| 11320 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0}, |
| 11321 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0}, |
| 11322 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0}, |
| 11323 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0}, |
| 11324 | {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] | 11325 | {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] | 11326 | {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] | 11327 | {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */ |
| 11328 | {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] | 11329 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11330 | /* required last entry */ |
| 11331 | {0,} |
| 11332 | }; |
| 11333 | |
| 11334 | MODULE_DEVICE_TABLE(pci, card_ids); |
| 11335 | |
| 11336 | static struct attribute *ipw_sysfs_entries[] = { |
| 11337 | &dev_attr_rf_kill.attr, |
| 11338 | &dev_attr_direct_dword.attr, |
| 11339 | &dev_attr_indirect_byte.attr, |
| 11340 | &dev_attr_indirect_dword.attr, |
| 11341 | &dev_attr_mem_gpio_reg.attr, |
| 11342 | &dev_attr_command_event_reg.attr, |
| 11343 | &dev_attr_nic_type.attr, |
| 11344 | &dev_attr_status.attr, |
| 11345 | &dev_attr_cfg.attr, |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 11346 | &dev_attr_error.attr, |
| 11347 | &dev_attr_event_log.attr, |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11348 | &dev_attr_cmd_log.attr, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11349 | &dev_attr_eeprom_delay.attr, |
| 11350 | &dev_attr_ucode_version.attr, |
| 11351 | &dev_attr_rtc.attr, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11352 | &dev_attr_scan_age.attr, |
| 11353 | &dev_attr_led.attr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11354 | &dev_attr_speed_scan.attr, |
| 11355 | &dev_attr_net_stats.attr, |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11356 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11357 | &dev_attr_rtap_iface.attr, |
| 11358 | &dev_attr_rtap_filter.attr, |
| 11359 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11360 | NULL |
| 11361 | }; |
| 11362 | |
| 11363 | static struct attribute_group ipw_attribute_group = { |
| 11364 | .name = NULL, /* put in device directory */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11365 | .attrs = ipw_sysfs_entries, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11366 | }; |
| 11367 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11368 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11369 | static int ipw_prom_open(struct net_device *dev) |
| 11370 | { |
| 11371 | struct ipw_prom_priv *prom_priv = ieee80211_priv(dev); |
| 11372 | struct ipw_priv *priv = prom_priv->priv; |
| 11373 | |
| 11374 | IPW_DEBUG_INFO("prom dev->open\n"); |
| 11375 | netif_carrier_off(dev); |
| 11376 | netif_stop_queue(dev); |
| 11377 | |
| 11378 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
| 11379 | priv->sys_config.accept_all_data_frames = 1; |
| 11380 | priv->sys_config.accept_non_directed_frames = 1; |
| 11381 | priv->sys_config.accept_all_mgmt_bcpr = 1; |
| 11382 | priv->sys_config.accept_all_mgmt_frames = 1; |
| 11383 | |
| 11384 | ipw_send_system_config(priv); |
| 11385 | } |
| 11386 | |
| 11387 | return 0; |
| 11388 | } |
| 11389 | |
| 11390 | static int ipw_prom_stop(struct net_device *dev) |
| 11391 | { |
| 11392 | struct ipw_prom_priv *prom_priv = ieee80211_priv(dev); |
| 11393 | struct ipw_priv *priv = prom_priv->priv; |
| 11394 | |
| 11395 | IPW_DEBUG_INFO("prom dev->stop\n"); |
| 11396 | |
| 11397 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
| 11398 | priv->sys_config.accept_all_data_frames = 0; |
| 11399 | priv->sys_config.accept_non_directed_frames = 0; |
| 11400 | priv->sys_config.accept_all_mgmt_bcpr = 0; |
| 11401 | priv->sys_config.accept_all_mgmt_frames = 0; |
| 11402 | |
| 11403 | ipw_send_system_config(priv); |
| 11404 | } |
| 11405 | |
| 11406 | return 0; |
| 11407 | } |
| 11408 | |
| 11409 | static int ipw_prom_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 11410 | { |
| 11411 | IPW_DEBUG_INFO("prom dev->xmit\n"); |
| 11412 | netif_stop_queue(dev); |
| 11413 | return -EOPNOTSUPP; |
| 11414 | } |
| 11415 | |
| 11416 | static struct net_device_stats *ipw_prom_get_stats(struct net_device *dev) |
| 11417 | { |
| 11418 | struct ipw_prom_priv *prom_priv = ieee80211_priv(dev); |
| 11419 | return &prom_priv->ieee->stats; |
| 11420 | } |
| 11421 | |
| 11422 | static int ipw_prom_alloc(struct ipw_priv *priv) |
| 11423 | { |
| 11424 | int rc = 0; |
| 11425 | |
| 11426 | if (priv->prom_net_dev) |
| 11427 | return -EPERM; |
| 11428 | |
| 11429 | priv->prom_net_dev = alloc_ieee80211(sizeof(struct ipw_prom_priv)); |
| 11430 | if (priv->prom_net_dev == NULL) |
| 11431 | return -ENOMEM; |
| 11432 | |
| 11433 | priv->prom_priv = ieee80211_priv(priv->prom_net_dev); |
| 11434 | priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev); |
| 11435 | priv->prom_priv->priv = priv; |
| 11436 | |
| 11437 | strcpy(priv->prom_net_dev->name, "rtap%d"); |
| 11438 | |
| 11439 | priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 11440 | priv->prom_net_dev->open = ipw_prom_open; |
| 11441 | priv->prom_net_dev->stop = ipw_prom_stop; |
| 11442 | priv->prom_net_dev->get_stats = ipw_prom_get_stats; |
| 11443 | priv->prom_net_dev->hard_start_xmit = ipw_prom_hard_start_xmit; |
| 11444 | |
| 11445 | priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR; |
| 11446 | |
| 11447 | rc = register_netdev(priv->prom_net_dev); |
| 11448 | if (rc) { |
| 11449 | free_ieee80211(priv->prom_net_dev); |
| 11450 | priv->prom_net_dev = NULL; |
| 11451 | return rc; |
| 11452 | } |
| 11453 | |
| 11454 | return 0; |
| 11455 | } |
| 11456 | |
| 11457 | static void ipw_prom_free(struct ipw_priv *priv) |
| 11458 | { |
| 11459 | if (!priv->prom_net_dev) |
| 11460 | return; |
| 11461 | |
| 11462 | unregister_netdev(priv->prom_net_dev); |
| 11463 | free_ieee80211(priv->prom_net_dev); |
| 11464 | |
| 11465 | priv->prom_net_dev = NULL; |
| 11466 | } |
| 11467 | |
| 11468 | #endif |
| 11469 | |
| 11470 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11471 | 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] | 11472 | { |
| 11473 | int err = 0; |
| 11474 | struct net_device *net_dev; |
| 11475 | void __iomem *base; |
| 11476 | u32 length, val; |
| 11477 | struct ipw_priv *priv; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11478 | int i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11479 | |
| 11480 | net_dev = alloc_ieee80211(sizeof(struct ipw_priv)); |
| 11481 | if (net_dev == NULL) { |
| 11482 | err = -ENOMEM; |
| 11483 | goto out; |
| 11484 | } |
| 11485 | |
| 11486 | priv = ieee80211_priv(net_dev); |
| 11487 | priv->ieee = netdev_priv(net_dev); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11488 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11489 | priv->net_dev = net_dev; |
| 11490 | priv->pci_dev = pdev; |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 11491 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11492 | ipw_debug_level = debug; |
| 11493 | #endif |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 11494 | spin_lock_init(&priv->irq_lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11495 | spin_lock_init(&priv->lock); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11496 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) |
| 11497 | INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11498 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11499 | mutex_init(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11500 | if (pci_enable_device(pdev)) { |
| 11501 | err = -ENODEV; |
| 11502 | goto out_free_ieee80211; |
| 11503 | } |
| 11504 | |
| 11505 | pci_set_master(pdev); |
| 11506 | |
Tobias Klauser | 0e08b44 | 2005-06-20 14:28:41 -0700 | [diff] [blame] | 11507 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11508 | if (!err) |
Tobias Klauser | 0e08b44 | 2005-06-20 14:28:41 -0700 | [diff] [blame] | 11509 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11510 | if (err) { |
| 11511 | printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n"); |
| 11512 | goto out_pci_disable_device; |
| 11513 | } |
| 11514 | |
| 11515 | pci_set_drvdata(pdev, priv); |
| 11516 | |
| 11517 | err = pci_request_regions(pdev, DRV_NAME); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11518 | if (err) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11519 | goto out_pci_disable_device; |
| 11520 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11521 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11522 | * PCI Tx retries from interfering with C3 CPU state */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11523 | pci_read_config_dword(pdev, 0x40, &val); |
| 11524 | if ((val & 0x0000ff00) != 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11525 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11526 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11527 | length = pci_resource_len(pdev, 0); |
| 11528 | priv->hw_len = length; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11529 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11530 | base = ioremap_nocache(pci_resource_start(pdev, 0), length); |
| 11531 | if (!base) { |
| 11532 | err = -ENODEV; |
| 11533 | goto out_pci_release_regions; |
| 11534 | } |
| 11535 | |
| 11536 | priv->hw_base = base; |
| 11537 | IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length); |
| 11538 | IPW_DEBUG_INFO("pci_resource_base = %p\n", base); |
| 11539 | |
| 11540 | err = ipw_setup_deferred_work(priv); |
| 11541 | if (err) { |
| 11542 | IPW_ERROR("Unable to setup deferred work\n"); |
| 11543 | goto out_iounmap; |
| 11544 | } |
| 11545 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11546 | ipw_sw_reset(priv, 1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11547 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11548 | err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11549 | if (err) { |
| 11550 | IPW_ERROR("Error allocating IRQ %d\n", pdev->irq); |
| 11551 | goto out_destroy_workqueue; |
| 11552 | } |
| 11553 | |
| 11554 | SET_MODULE_OWNER(net_dev); |
| 11555 | SET_NETDEV_DEV(net_dev, &pdev->dev); |
| 11556 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11557 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11558 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11559 | priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit; |
| 11560 | priv->ieee->set_security = shim__set_security; |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 11561 | priv->ieee->is_queue_full = ipw_net_is_queue_full; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11562 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 11563 | #ifdef CONFIG_IPW2200_QOS |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 11564 | priv->ieee->is_qos_active = ipw_is_qos_active; |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 11565 | priv->ieee->handle_probe_response = ipw_handle_beacon; |
| 11566 | priv->ieee->handle_beacon = ipw_handle_probe_response; |
| 11567 | priv->ieee->handle_assoc_response = ipw_handle_assoc_response; |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 11568 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11569 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11570 | priv->ieee->perfect_rssi = -20; |
| 11571 | priv->ieee->worst_rssi = -85; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11572 | |
| 11573 | net_dev->open = ipw_net_open; |
| 11574 | net_dev->stop = ipw_net_stop; |
| 11575 | net_dev->init = ipw_net_init; |
| 11576 | net_dev->get_stats = ipw_net_get_stats; |
| 11577 | net_dev->set_multicast_list = ipw_net_set_multicast_list; |
| 11578 | net_dev->set_mac_address = ipw_net_set_mac_address; |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 11579 | priv->wireless_data.spy_data = &priv->ieee->spy_data; |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 11580 | net_dev->wireless_data = &priv->wireless_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11581 | net_dev->wireless_handlers = &ipw_wx_handler_def; |
| 11582 | net_dev->ethtool_ops = &ipw_ethtool_ops; |
| 11583 | net_dev->irq = pdev->irq; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11584 | net_dev->base_addr = (unsigned long)priv->hw_base; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11585 | net_dev->mem_start = pci_resource_start(pdev, 0); |
| 11586 | net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1; |
| 11587 | |
| 11588 | err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group); |
| 11589 | if (err) { |
| 11590 | IPW_ERROR("failed to create sysfs device attributes\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11591 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11592 | goto out_release_irq; |
| 11593 | } |
| 11594 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11595 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11596 | err = register_netdev(net_dev); |
| 11597 | if (err) { |
| 11598 | IPW_ERROR("failed to register network device\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11599 | goto out_remove_sysfs; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11600 | } |
Henrik Brix Andersen | 48a8477 | 2006-02-14 09:09:52 +0800 | [diff] [blame] | 11601 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11602 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11603 | if (rtap_iface) { |
| 11604 | err = ipw_prom_alloc(priv); |
| 11605 | if (err) { |
| 11606 | IPW_ERROR("Failed to register promiscuous network " |
| 11607 | "device (error %d).\n", err); |
| 11608 | unregister_netdev(priv->net_dev); |
| 11609 | goto out_remove_sysfs; |
| 11610 | } |
| 11611 | } |
| 11612 | #endif |
| 11613 | |
Henrik Brix Andersen | 48a8477 | 2006-02-14 09:09:52 +0800 | [diff] [blame] | 11614 | printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg " |
| 11615 | "channels, %d 802.11a channels)\n", |
| 11616 | priv->ieee->geo.name, priv->ieee->geo.bg_channels, |
| 11617 | priv->ieee->geo.a_channels); |
| 11618 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11619 | return 0; |
| 11620 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11621 | out_remove_sysfs: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11622 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11623 | out_release_irq: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11624 | free_irq(pdev->irq, priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11625 | out_destroy_workqueue: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11626 | destroy_workqueue(priv->workqueue); |
| 11627 | priv->workqueue = NULL; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11628 | out_iounmap: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11629 | iounmap(priv->hw_base); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11630 | out_pci_release_regions: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11631 | pci_release_regions(pdev); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11632 | out_pci_disable_device: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11633 | pci_disable_device(pdev); |
| 11634 | pci_set_drvdata(pdev, NULL); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11635 | out_free_ieee80211: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11636 | free_ieee80211(priv->net_dev); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11637 | out: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11638 | return err; |
| 11639 | } |
| 11640 | |
| 11641 | static void ipw_pci_remove(struct pci_dev *pdev) |
| 11642 | { |
| 11643 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11644 | struct list_head *p, *q; |
| 11645 | int i; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11646 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11647 | if (!priv) |
| 11648 | return; |
| 11649 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11650 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11651 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11652 | priv->status |= STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11653 | ipw_down(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11654 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
| 11655 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11656 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11657 | |
| 11658 | unregister_netdev(priv->net_dev); |
| 11659 | |
| 11660 | if (priv->rxq) { |
| 11661 | ipw_rx_queue_free(priv, priv->rxq); |
| 11662 | priv->rxq = NULL; |
| 11663 | } |
| 11664 | ipw_tx_queue_free(priv); |
| 11665 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11666 | if (priv->cmdlog) { |
| 11667 | kfree(priv->cmdlog); |
| 11668 | priv->cmdlog = NULL; |
| 11669 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11670 | /* ipw_down will ensure that there is no more pending work |
| 11671 | * in the workqueue's, so we can safely remove them now. */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11672 | cancel_delayed_work(&priv->adhoc_check); |
| 11673 | cancel_delayed_work(&priv->gather_stats); |
| 11674 | cancel_delayed_work(&priv->request_scan); |
| 11675 | cancel_delayed_work(&priv->rf_kill); |
| 11676 | cancel_delayed_work(&priv->scan_check); |
| 11677 | destroy_workqueue(priv->workqueue); |
| 11678 | priv->workqueue = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11679 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11680 | /* Free MAC hash list for ADHOC */ |
| 11681 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) { |
| 11682 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11683 | list_del(p); |
Zhu Yi | 489f445 | 2006-01-24 16:37:41 +0800 | [diff] [blame] | 11684 | kfree(list_entry(p, struct ipw_ibss_seq, list)); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11685 | } |
| 11686 | } |
| 11687 | |
Jesper Juhl | 8f76078 | 2006-06-27 02:55:06 -0700 | [diff] [blame^] | 11688 | kfree(priv->error); |
| 11689 | priv->error = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11690 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11691 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11692 | ipw_prom_free(priv); |
| 11693 | #endif |
| 11694 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11695 | free_irq(pdev->irq, priv); |
| 11696 | iounmap(priv->hw_base); |
| 11697 | pci_release_regions(pdev); |
| 11698 | pci_disable_device(pdev); |
| 11699 | pci_set_drvdata(pdev, NULL); |
| 11700 | free_ieee80211(priv->net_dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11701 | free_firmware(); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11702 | } |
| 11703 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11704 | #ifdef CONFIG_PM |
Pavel Machek | 583a4e8 | 2005-09-03 15:56:58 -0700 | [diff] [blame] | 11705 | 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] | 11706 | { |
| 11707 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 11708 | struct net_device *dev = priv->net_dev; |
| 11709 | |
| 11710 | printk(KERN_INFO "%s: Going into suspend...\n", dev->name); |
| 11711 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11712 | /* Take down the device; powers it off, etc. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11713 | ipw_down(priv); |
| 11714 | |
| 11715 | /* Remove the PRESENT state of the device */ |
| 11716 | netif_device_detach(dev); |
| 11717 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11718 | pci_save_state(pdev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11719 | pci_disable_device(pdev); |
Pavel Machek | 583a4e8 | 2005-09-03 15:56:58 -0700 | [diff] [blame] | 11720 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11721 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11722 | return 0; |
| 11723 | } |
| 11724 | |
| 11725 | static int ipw_pci_resume(struct pci_dev *pdev) |
| 11726 | { |
| 11727 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 11728 | struct net_device *dev = priv->net_dev; |
| 11729 | u32 val; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11730 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11731 | printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name); |
| 11732 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 11733 | pci_set_power_state(pdev, PCI_D0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11734 | pci_enable_device(pdev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11735 | pci_restore_state(pdev); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 11736 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11737 | /* |
| 11738 | * Suspend/Resume resets the PCI configuration space, so we have to |
| 11739 | * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries |
| 11740 | * from interfering with C3 CPU state. pci_restore_state won't help |
| 11741 | * here since it only restores the first 64 bytes pci config header. |
| 11742 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11743 | pci_read_config_dword(pdev, 0x40, &val); |
| 11744 | if ((val & 0x0000ff00) != 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11745 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
| 11746 | |
| 11747 | /* Set the device back into the PRESENT state; this will also wake |
| 11748 | * the queue of needed */ |
| 11749 | netif_device_attach(dev); |
| 11750 | |
| 11751 | /* Bring the device back up */ |
| 11752 | queue_work(priv->workqueue, &priv->up); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11753 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11754 | return 0; |
| 11755 | } |
| 11756 | #endif |
| 11757 | |
| 11758 | /* driver initialization stuff */ |
| 11759 | static struct pci_driver ipw_driver = { |
| 11760 | .name = DRV_NAME, |
| 11761 | .id_table = card_ids, |
| 11762 | .probe = ipw_pci_probe, |
| 11763 | .remove = __devexit_p(ipw_pci_remove), |
| 11764 | #ifdef CONFIG_PM |
| 11765 | .suspend = ipw_pci_suspend, |
| 11766 | .resume = ipw_pci_resume, |
| 11767 | #endif |
| 11768 | }; |
| 11769 | |
| 11770 | static int __init ipw_init(void) |
| 11771 | { |
| 11772 | int ret; |
| 11773 | |
| 11774 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 11775 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
| 11776 | |
| 11777 | ret = pci_module_init(&ipw_driver); |
| 11778 | if (ret) { |
| 11779 | IPW_ERROR("Unable to initialize PCI module\n"); |
| 11780 | return ret; |
| 11781 | } |
| 11782 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11783 | ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11784 | if (ret) { |
| 11785 | IPW_ERROR("Unable to create driver sysfs file\n"); |
| 11786 | pci_unregister_driver(&ipw_driver); |
| 11787 | return ret; |
| 11788 | } |
| 11789 | |
| 11790 | return ret; |
| 11791 | } |
| 11792 | |
| 11793 | static void __exit ipw_exit(void) |
| 11794 | { |
| 11795 | driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level); |
| 11796 | pci_unregister_driver(&ipw_driver); |
| 11797 | } |
| 11798 | |
| 11799 | module_param(disable, int, 0444); |
| 11800 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
| 11801 | |
| 11802 | module_param(associate, int, 0444); |
| 11803 | MODULE_PARM_DESC(associate, "auto associate when scanning (default on)"); |
| 11804 | |
| 11805 | module_param(auto_create, int, 0444); |
| 11806 | MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)"); |
| 11807 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11808 | module_param(led, int, 0444); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11809 | 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] | 11810 | |
Zhu Yi | 3e1555b | 2006-03-06 05:48:37 +0800 | [diff] [blame] | 11811 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11812 | module_param(debug, int, 0444); |
| 11813 | MODULE_PARM_DESC(debug, "debug output mask"); |
Zhu Yi | 3e1555b | 2006-03-06 05:48:37 +0800 | [diff] [blame] | 11814 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11815 | |
| 11816 | module_param(channel, int, 0444); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11817 | MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11818 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11819 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11820 | module_param(rtap_iface, int, 0444); |
| 11821 | MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)"); |
| 11822 | #endif |
| 11823 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 11824 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11825 | module_param(qos_enable, int, 0444); |
| 11826 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11827 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11828 | module_param(qos_burst_enable, int, 0444); |
| 11829 | MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode"); |
| 11830 | |
| 11831 | module_param(qos_no_ack_mask, int, 0444); |
| 11832 | MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack"); |
| 11833 | |
| 11834 | module_param(burst_duration_CCK, int, 0444); |
| 11835 | MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value"); |
| 11836 | |
| 11837 | module_param(burst_duration_OFDM, int, 0444); |
| 11838 | MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value"); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 11839 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11840 | |
| 11841 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11842 | module_param(mode, int, 0444); |
| 11843 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)"); |
| 11844 | #else |
| 11845 | module_param(mode, int, 0444); |
| 11846 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)"); |
| 11847 | #endif |
| 11848 | |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 11849 | module_param(bt_coexist, int, 0444); |
| 11850 | MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)"); |
| 11851 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11852 | module_param(hwcrypto, int, 0444); |
Zhu Yi | bde37d0 | 2006-01-24 16:38:08 +0800 | [diff] [blame] | 11853 | MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11854 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11855 | module_param(cmdlog, int, 0444); |
| 11856 | MODULE_PARM_DESC(cmdlog, |
| 11857 | "allocate a ring buffer for logging firmware commands"); |
| 11858 | |
Zhu Yi | 4bfdb91 | 2006-01-24 16:37:16 +0800 | [diff] [blame] | 11859 | module_param(roaming, int, 0444); |
| 11860 | MODULE_PARM_DESC(roaming, "enable roaming support (default on)"); |
| 11861 | |
Zhu Yi | d2b83e1 | 2006-04-13 17:19:36 +0800 | [diff] [blame] | 11862 | module_param(antenna, int, 0444); |
| 11863 | MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)"); |
| 11864 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11865 | module_exit(ipw_exit); |
| 11866 | module_init(ipw_init); |