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: |
Reinette Chatre | c1eb2c8 | 2009-08-21 13:34:26 -0700 | [diff] [blame] | 28 | Intel Linux Wireless <ilw@linux.intel.com> |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 29 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 30 | |
| 31 | ******************************************************************************/ |
| 32 | |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 33 | #include <linux/sched.h> |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 34 | #include "ipw2200.h" |
| 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 | ee2c4ad | 2007-07-12 16:09:47 +0800 | [diff] [blame] | 73 | #define IPW2200_VERSION "1.2.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; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 86 | static int debug = 0; |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 87 | static int default_channel = 0; |
| 88 | static int network_mode = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 89 | |
| 90 | static u32 ipw_debug_level; |
Tim Gardner | 5c7f9b7 | 2008-10-14 10:38:03 -0600 | [diff] [blame] | 91 | static int associate; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 92 | static int auto_create = 1; |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 93 | static int led_support = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 94 | static int disable = 0; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 95 | static int bt_coexist = 0; |
Zhu Yi | bde37d0 | 2006-01-24 16:38:08 +0800 | [diff] [blame] | 96 | static int hwcrypto = 0; |
Zhu Yi | 4bfdb91 | 2006-01-24 16:37:16 +0800 | [diff] [blame] | 97 | static int roaming = 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 98 | static const char ipw_modes[] = { |
| 99 | 'a', 'b', 'g', '?' |
| 100 | }; |
Zhu Yi | d2b83e1 | 2006-04-13 17:19:36 +0800 | [diff] [blame] | 101 | static int antenna = CFG_SYS_ANTENNA_BOTH; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 102 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 103 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 104 | static int rtap_iface = 0; /* def: 0 -- do not create rtap interface */ |
| 105 | #endif |
| 106 | |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 107 | static struct ieee80211_rate ipw2200_rates[] = { |
| 108 | { .bitrate = 10 }, |
| 109 | { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 110 | { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 111 | { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 112 | { .bitrate = 60 }, |
| 113 | { .bitrate = 90 }, |
| 114 | { .bitrate = 120 }, |
| 115 | { .bitrate = 180 }, |
| 116 | { .bitrate = 240 }, |
| 117 | { .bitrate = 360 }, |
| 118 | { .bitrate = 480 }, |
| 119 | { .bitrate = 540 } |
| 120 | }; |
| 121 | |
| 122 | #define ipw2200_a_rates (ipw2200_rates + 4) |
| 123 | #define ipw2200_num_a_rates 8 |
| 124 | #define ipw2200_bg_rates (ipw2200_rates + 0) |
| 125 | #define ipw2200_num_bg_rates 12 |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 126 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 127 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 128 | static int qos_enable = 0; |
| 129 | static int qos_burst_enable = 0; |
| 130 | static int qos_no_ack_mask = 0; |
| 131 | static int burst_duration_CCK = 0; |
| 132 | static int burst_duration_OFDM = 0; |
| 133 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 134 | static struct libipw_qos_parameters def_qos_parameters_OFDM = { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 135 | {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM, |
| 136 | QOS_TX3_CW_MIN_OFDM}, |
| 137 | {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM, |
| 138 | QOS_TX3_CW_MAX_OFDM}, |
| 139 | {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS}, |
| 140 | {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM}, |
| 141 | {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM, |
| 142 | QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM} |
| 143 | }; |
| 144 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 145 | static struct libipw_qos_parameters def_qos_parameters_CCK = { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 146 | {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK, |
| 147 | QOS_TX3_CW_MIN_CCK}, |
| 148 | {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK, |
| 149 | QOS_TX3_CW_MAX_CCK}, |
| 150 | {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS}, |
| 151 | {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM}, |
| 152 | {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK, |
| 153 | QOS_TX3_TXOP_LIMIT_CCK} |
| 154 | }; |
| 155 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 156 | static struct libipw_qos_parameters def_parameters_OFDM = { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 157 | {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM, |
| 158 | DEF_TX3_CW_MIN_OFDM}, |
| 159 | {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM, |
| 160 | DEF_TX3_CW_MAX_OFDM}, |
| 161 | {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS}, |
| 162 | {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM}, |
| 163 | {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM, |
| 164 | DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM} |
| 165 | }; |
| 166 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 167 | static struct libipw_qos_parameters def_parameters_CCK = { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 168 | {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK, |
| 169 | DEF_TX3_CW_MIN_CCK}, |
| 170 | {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK, |
| 171 | DEF_TX3_CW_MAX_CCK}, |
| 172 | {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS}, |
| 173 | {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM}, |
| 174 | {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK, |
| 175 | DEF_TX3_TXOP_LIMIT_CCK} |
| 176 | }; |
| 177 | |
| 178 | static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 }; |
| 179 | |
| 180 | static int from_priority_to_tx_queue[] = { |
| 181 | IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1, |
| 182 | IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4 |
| 183 | }; |
| 184 | |
| 185 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv); |
| 186 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 187 | static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 188 | *qos_param); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 189 | static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 190 | *qos_param); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 191 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 192 | |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 193 | static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 194 | static void ipw_remove_current_network(struct ipw_priv *priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 195 | static void ipw_rx(struct ipw_priv *priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 196 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 197 | struct clx2_tx_queue *txq, int qindex); |
| 198 | static int ipw_queue_reset(struct ipw_priv *priv); |
| 199 | |
| 200 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, |
| 201 | int len, int sync); |
| 202 | |
| 203 | static void ipw_tx_queue_free(struct ipw_priv *); |
| 204 | |
| 205 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *); |
| 206 | static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *); |
| 207 | static void ipw_rx_queue_replenish(void *); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 208 | static int ipw_up(struct ipw_priv *); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 209 | static void ipw_bg_up(struct work_struct *work); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 210 | static void ipw_down(struct ipw_priv *); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 211 | static void ipw_bg_down(struct work_struct *work); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 212 | static int ipw_config(struct ipw_priv *); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 213 | static int init_supported_rates(struct ipw_priv *priv, |
| 214 | struct ipw_supported_rates *prates); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 215 | static void ipw_set_hwcrypto_keys(struct ipw_priv *); |
| 216 | static void ipw_send_wep_keys(struct ipw_priv *, int); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 217 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 218 | static int snprint_line(char *buf, size_t count, |
| 219 | const u8 * data, u32 len, u32 ofs) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 220 | { |
| 221 | int out, i, j, l; |
| 222 | char c; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 223 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 224 | out = snprintf(buf, count, "%08X", ofs); |
| 225 | |
| 226 | for (l = 0, i = 0; i < 2; i++) { |
| 227 | out += snprintf(buf + out, count - out, " "); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 228 | for (j = 0; j < 8 && l < len; j++, l++) |
| 229 | out += snprintf(buf + out, count - out, "%02X ", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 230 | data[(i * 8 + j)]); |
| 231 | for (; j < 8; j++) |
| 232 | out += snprintf(buf + out, count - out, " "); |
| 233 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 234 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 235 | out += snprintf(buf + out, count - out, " "); |
| 236 | for (l = 0, i = 0; i < 2; i++) { |
| 237 | out += snprintf(buf + out, count - out, " "); |
| 238 | for (j = 0; j < 8 && l < len; j++, l++) { |
| 239 | c = data[(i * 8 + j)]; |
| 240 | if (!isascii(c) || !isprint(c)) |
| 241 | c = '.'; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 242 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 243 | out += snprintf(buf + out, count - out, "%c", c); |
| 244 | } |
| 245 | |
| 246 | for (; j < 8; j++) |
| 247 | out += snprintf(buf + out, count - out, " "); |
| 248 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 249 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 250 | return out; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 251 | } |
| 252 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 253 | static void printk_buf(int level, const u8 * data, u32 len) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 254 | { |
| 255 | char line[81]; |
| 256 | u32 ofs = 0; |
| 257 | if (!(ipw_debug_level & level)) |
| 258 | return; |
| 259 | |
| 260 | while (len) { |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 261 | snprint_line(line, sizeof(line), &data[ofs], |
| 262 | min(len, 16U), ofs); |
| 263 | printk(KERN_DEBUG "%s\n", line); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 264 | ofs += 16; |
| 265 | len -= min(len, 16U); |
| 266 | } |
| 267 | } |
| 268 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 269 | static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len) |
| 270 | { |
| 271 | size_t out = size; |
| 272 | u32 ofs = 0; |
| 273 | int total = 0; |
| 274 | |
| 275 | while (size && len) { |
| 276 | out = snprint_line(output, size, &data[ofs], |
| 277 | min_t(size_t, len, 16U), ofs); |
| 278 | |
| 279 | ofs += 16; |
| 280 | output += out; |
| 281 | size -= out; |
| 282 | len -= min_t(size_t, len, 16U); |
| 283 | total += out; |
| 284 | } |
| 285 | return total; |
| 286 | } |
| 287 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 288 | /* 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] | 289 | static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg); |
| 290 | #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b) |
| 291 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 292 | /* 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] | 293 | static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg); |
| 294 | #define ipw_read_reg8(a, b) _ipw_read_reg8(a, b) |
| 295 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 296 | /* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 297 | static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value); |
| 298 | static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c) |
| 299 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 300 | IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__, |
| 301 | __LINE__, (u32) (b), (u32) (c)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 302 | _ipw_write_reg8(a, b, c); |
| 303 | } |
| 304 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 305 | /* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 306 | static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value); |
| 307 | static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c) |
| 308 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 309 | IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__, |
| 310 | __LINE__, (u32) (b), (u32) (c)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 311 | _ipw_write_reg16(a, b, c); |
| 312 | } |
| 313 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 314 | /* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 315 | static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value); |
| 316 | static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c) |
| 317 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 318 | IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__, |
| 319 | __LINE__, (u32) (b), (u32) (c)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 320 | _ipw_write_reg32(a, b, c); |
| 321 | } |
| 322 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 323 | /* 8-bit direct write (low 4K) */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 324 | static inline void _ipw_write8(struct ipw_priv *ipw, unsigned long ofs, |
| 325 | u8 val) |
| 326 | { |
| 327 | writeb(val, ipw->hw_base + ofs); |
| 328 | } |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 329 | |
| 330 | /* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */ |
Takashi Iwai | fb55d88 | 2008-07-31 19:02:06 +0200 | [diff] [blame] | 331 | #define ipw_write8(ipw, ofs, val) do { \ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 332 | IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, \ |
| 333 | __LINE__, (u32)(ofs), (u32)(val)); \ |
| 334 | _ipw_write8(ipw, ofs, val); \ |
| 335 | } while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 336 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 337 | /* 16-bit direct write (low 4K) */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 338 | static inline void _ipw_write16(struct ipw_priv *ipw, unsigned long ofs, |
| 339 | u16 val) |
| 340 | { |
| 341 | writew(val, ipw->hw_base + ofs); |
| 342 | } |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 343 | |
| 344 | /* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 345 | #define ipw_write16(ipw, ofs, val) do { \ |
| 346 | IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, \ |
| 347 | __LINE__, (u32)(ofs), (u32)(val)); \ |
| 348 | _ipw_write16(ipw, ofs, val); \ |
| 349 | } while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 350 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 351 | /* 32-bit direct write (low 4K) */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 352 | static inline void _ipw_write32(struct ipw_priv *ipw, unsigned long ofs, |
| 353 | u32 val) |
| 354 | { |
| 355 | writel(val, ipw->hw_base + ofs); |
| 356 | } |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 357 | |
| 358 | /* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 359 | #define ipw_write32(ipw, ofs, val) do { \ |
| 360 | IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, \ |
| 361 | __LINE__, (u32)(ofs), (u32)(val)); \ |
| 362 | _ipw_write32(ipw, ofs, val); \ |
| 363 | } while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 364 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 365 | /* 8-bit direct read (low 4K) */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 366 | static inline u8 _ipw_read8(struct ipw_priv *ipw, unsigned long ofs) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 367 | { |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 368 | return readb(ipw->hw_base + ofs); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 369 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 370 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 371 | /* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 372 | #define ipw_read8(ipw, ofs) ({ \ |
| 373 | IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", __FILE__, __LINE__, \ |
| 374 | (u32)(ofs)); \ |
| 375 | _ipw_read8(ipw, ofs); \ |
| 376 | }) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 377 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 378 | /* 16-bit direct read (low 4K) */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 379 | static inline u16 _ipw_read16(struct ipw_priv *ipw, unsigned long ofs) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 380 | { |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 381 | return readw(ipw->hw_base + ofs); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 382 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 383 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 384 | /* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 385 | #define ipw_read16(ipw, ofs) ({ \ |
| 386 | IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", __FILE__, __LINE__, \ |
| 387 | (u32)(ofs)); \ |
| 388 | _ipw_read16(ipw, ofs); \ |
| 389 | }) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 390 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 391 | /* 32-bit direct read (low 4K) */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 392 | static inline u32 _ipw_read32(struct ipw_priv *ipw, unsigned long ofs) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 393 | { |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 394 | return readl(ipw->hw_base + ofs); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 395 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 396 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 397 | /* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 398 | #define ipw_read32(ipw, ofs) ({ \ |
| 399 | IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", __FILE__, __LINE__, \ |
| 400 | (u32)(ofs)); \ |
| 401 | _ipw_read32(ipw, ofs); \ |
| 402 | }) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 403 | |
| 404 | static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int); |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 405 | /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 406 | #define ipw_read_indirect(a, b, c, d) ({ \ |
| 407 | IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %u bytes\n", __FILE__, \ |
| 408 | __LINE__, (u32)(b), (u32)(d)); \ |
| 409 | _ipw_read_indirect(a, b, c, d); \ |
| 410 | }) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 411 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 412 | /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 413 | static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data, |
| 414 | int num); |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 415 | #define ipw_write_indirect(a, b, c, d) do { \ |
| 416 | IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %u bytes\n", __FILE__, \ |
| 417 | __LINE__, (u32)(b), (u32)(d)); \ |
| 418 | _ipw_write_indirect(a, b, c, d); \ |
| 419 | } while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 420 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 421 | /* 32-bit indirect write (above 4K) */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 422 | 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] | 423 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 424 | 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] | 425 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg); |
| 426 | _ipw_write32(priv, IPW_INDIRECT_DATA, value); |
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 | /* 8-bit indirect write (above 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 430 | static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value) |
| 431 | { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 432 | u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 433 | u32 dif_len = reg - aligned_addr; |
| 434 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 435 | IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 436 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
| 437 | _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 438 | } |
| 439 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 440 | /* 16-bit indirect write (above 4K) */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 441 | 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] | 442 | { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 443 | u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 444 | u32 dif_len = (reg - aligned_addr) & (~0x1ul); |
| 445 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 446 | IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 447 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
| 448 | _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 449 | } |
| 450 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 451 | /* 8-bit indirect read (above 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 452 | static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg) |
| 453 | { |
| 454 | u32 word; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 455 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 456 | IPW_DEBUG_IO(" reg = 0x%8X : \n", reg); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 457 | word = _ipw_read32(priv, IPW_INDIRECT_DATA); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 458 | return (word >> ((reg & 0x3) * 8)) & 0xff; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 459 | } |
| 460 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 461 | /* 32-bit indirect read (above 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 462 | static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg) |
| 463 | { |
| 464 | u32 value; |
| 465 | |
| 466 | IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg); |
| 467 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 468 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg); |
| 469 | value = _ipw_read32(priv, IPW_INDIRECT_DATA); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 470 | IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value); |
| 471 | return value; |
| 472 | } |
| 473 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 474 | /* General purpose, no alignment requirement, iterative (multi-byte) read, */ |
| 475 | /* for area above 1st 4K of SRAM/reg space */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 476 | static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf, |
| 477 | int num) |
| 478 | { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 479 | u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 480 | u32 dif_len = addr - aligned_addr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 481 | u32 i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 482 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 483 | IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num); |
| 484 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 485 | if (num <= 0) { |
| 486 | return; |
| 487 | } |
| 488 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 489 | /* Read the first dword (or portion) byte by byte */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 490 | if (unlikely(dif_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 491 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 492 | /* Start reading at aligned_addr + dif_len */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 493 | for (i = dif_len; ((i < 4) && (num > 0)); i++, num--) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 494 | *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 495 | aligned_addr += 4; |
| 496 | } |
| 497 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 498 | /* Read all of the middle dwords as dwords, with auto-increment */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 499 | _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 500 | for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 501 | *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA); |
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 | /* Read the last dword (or portion) byte by byte */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 504 | if (unlikely(num)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 505 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 506 | for (i = 0; num > 0; i++, num--) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 507 | *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 508 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 509 | } |
| 510 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 511 | /* General purpose, no alignment requirement, iterative (multi-byte) write, */ |
| 512 | /* for area above 1st 4K of SRAM/reg space */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 513 | 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] | 514 | int num) |
| 515 | { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 516 | u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 517 | u32 dif_len = addr - aligned_addr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 518 | u32 i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 519 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 520 | 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] | 521 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 522 | if (num <= 0) { |
| 523 | return; |
| 524 | } |
| 525 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 526 | /* Write the first dword (or portion) byte by byte */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 527 | if (unlikely(dif_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 528 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 529 | /* Start writing at aligned_addr + dif_len */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 530 | for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 531 | _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 532 | aligned_addr += 4; |
| 533 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 534 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 535 | /* Write all of the middle dwords as dwords, with auto-increment */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 536 | _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 537 | for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 538 | _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 539 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 540 | /* Write the last dword (or portion) byte by byte */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 541 | if (unlikely(num)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 542 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 543 | for (i = 0; num > 0; i++, num--, buf++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 544 | _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 545 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 546 | } |
| 547 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 548 | /* General purpose, no alignment requirement, iterative (multi-byte) write, */ |
| 549 | /* for 1st 4K of SRAM/regs space */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 550 | 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] | 551 | int num) |
| 552 | { |
| 553 | memcpy_toio((priv->hw_base + addr), buf, num); |
| 554 | } |
| 555 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 556 | /* Set bit(s) in low 4K of SRAM/regs */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 557 | static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask) |
| 558 | { |
| 559 | ipw_write32(priv, reg, ipw_read32(priv, reg) | mask); |
| 560 | } |
| 561 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 562 | /* Clear bit(s) in low 4K of SRAM/regs */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 563 | static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask) |
| 564 | { |
| 565 | ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask); |
| 566 | } |
| 567 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 568 | static inline void __ipw_enable_interrupts(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 569 | { |
| 570 | if (priv->status & STATUS_INT_ENABLED) |
| 571 | return; |
| 572 | priv->status |= STATUS_INT_ENABLED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 573 | ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 574 | } |
| 575 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 576 | static inline void __ipw_disable_interrupts(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 577 | { |
| 578 | if (!(priv->status & STATUS_INT_ENABLED)) |
| 579 | return; |
| 580 | priv->status &= ~STATUS_INT_ENABLED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 581 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 582 | } |
| 583 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 584 | static inline void ipw_enable_interrupts(struct ipw_priv *priv) |
| 585 | { |
| 586 | unsigned long flags; |
| 587 | |
| 588 | spin_lock_irqsave(&priv->irq_lock, flags); |
| 589 | __ipw_enable_interrupts(priv); |
| 590 | spin_unlock_irqrestore(&priv->irq_lock, flags); |
| 591 | } |
| 592 | |
| 593 | static inline void ipw_disable_interrupts(struct ipw_priv *priv) |
| 594 | { |
| 595 | unsigned long flags; |
| 596 | |
| 597 | spin_lock_irqsave(&priv->irq_lock, flags); |
| 598 | __ipw_disable_interrupts(priv); |
| 599 | spin_unlock_irqrestore(&priv->irq_lock, flags); |
| 600 | } |
| 601 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 602 | static char *ipw_error_desc(u32 val) |
| 603 | { |
| 604 | switch (val) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 605 | case IPW_FW_ERROR_OK: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 606 | return "ERROR_OK"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 607 | case IPW_FW_ERROR_FAIL: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 608 | return "ERROR_FAIL"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 609 | case IPW_FW_ERROR_MEMORY_UNDERFLOW: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 610 | return "MEMORY_UNDERFLOW"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 611 | case IPW_FW_ERROR_MEMORY_OVERFLOW: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 612 | return "MEMORY_OVERFLOW"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 613 | case IPW_FW_ERROR_BAD_PARAM: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 614 | return "BAD_PARAM"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 615 | case IPW_FW_ERROR_BAD_CHECKSUM: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 616 | return "BAD_CHECKSUM"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 617 | case IPW_FW_ERROR_NMI_INTERRUPT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 618 | return "NMI_INTERRUPT"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 619 | case IPW_FW_ERROR_BAD_DATABASE: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 620 | return "BAD_DATABASE"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 621 | case IPW_FW_ERROR_ALLOC_FAIL: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 622 | return "ALLOC_FAIL"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 623 | case IPW_FW_ERROR_DMA_UNDERRUN: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 624 | return "DMA_UNDERRUN"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 625 | case IPW_FW_ERROR_DMA_STATUS: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 626 | return "DMA_STATUS"; |
| 627 | case IPW_FW_ERROR_DINO_ERROR: |
| 628 | return "DINO_ERROR"; |
| 629 | case IPW_FW_ERROR_EEPROM_ERROR: |
| 630 | return "EEPROM_ERROR"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 631 | case IPW_FW_ERROR_SYSASSERT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 632 | return "SYSASSERT"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 633 | case IPW_FW_ERROR_FATAL_ERROR: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 634 | return "FATAL_ERROR"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 635 | default: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 636 | return "UNKNOWN_ERROR"; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 637 | } |
| 638 | } |
| 639 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 640 | static void ipw_dump_error_log(struct ipw_priv *priv, |
| 641 | struct ipw_fw_error *error) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 642 | { |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 643 | u32 i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 644 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 645 | if (!error) { |
| 646 | IPW_ERROR("Error allocating and capturing error log. " |
| 647 | "Nothing to dump.\n"); |
| 648 | return; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 649 | } |
| 650 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 651 | IPW_ERROR("Start IPW Error Log Dump:\n"); |
| 652 | IPW_ERROR("Status: 0x%08X, Config: %08X\n", |
| 653 | error->status, error->config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 654 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 655 | for (i = 0; i < error->elem_len; i++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 656 | 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] | 657 | ipw_error_desc(error->elem[i].desc), |
| 658 | error->elem[i].time, |
| 659 | error->elem[i].blink1, |
| 660 | error->elem[i].blink2, |
| 661 | error->elem[i].link1, |
| 662 | error->elem[i].link2, error->elem[i].data); |
| 663 | for (i = 0; i < error->log_len; i++) |
| 664 | IPW_ERROR("%i\t0x%08x\t%i\n", |
| 665 | error->log[i].time, |
James Ketrenos | 286568a | 2005-08-30 10:34:25 -0500 | [diff] [blame] | 666 | error->log[i].data, error->log[i].event); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 667 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 668 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 669 | static inline int ipw_is_init(struct ipw_priv *priv) |
| 670 | { |
| 671 | return (priv->status & STATUS_INIT) ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 672 | } |
| 673 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 674 | 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] | 675 | { |
| 676 | u32 addr, field_info, field_len, field_count, total_len; |
| 677 | |
| 678 | IPW_DEBUG_ORD("ordinal = %i\n", ord); |
| 679 | |
| 680 | if (!priv || !val || !len) { |
| 681 | IPW_DEBUG_ORD("Invalid argument\n"); |
| 682 | return -EINVAL; |
| 683 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 684 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 685 | /* verify device ordinal tables have been initialized */ |
| 686 | if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) { |
| 687 | IPW_DEBUG_ORD("Access ordinals before initialization\n"); |
| 688 | return -EINVAL; |
| 689 | } |
| 690 | |
| 691 | switch (IPW_ORD_TABLE_ID_MASK & ord) { |
| 692 | case IPW_ORD_TABLE_0_MASK: |
| 693 | /* |
| 694 | * TABLE 0: Direct access to a table of 32 bit values |
| 695 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 696 | * This is a very simple table with the data directly |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 697 | * read from the table |
| 698 | */ |
| 699 | |
| 700 | /* remove the table id from the ordinal */ |
| 701 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
| 702 | |
| 703 | /* boundary check */ |
| 704 | if (ord > priv->table0_len) { |
| 705 | IPW_DEBUG_ORD("ordinal value (%i) longer then " |
| 706 | "max (%i)\n", ord, priv->table0_len); |
| 707 | return -EINVAL; |
| 708 | } |
| 709 | |
| 710 | /* verify we have enough room to store the value */ |
| 711 | if (*len < sizeof(u32)) { |
| 712 | IPW_DEBUG_ORD("ordinal buffer length too small, " |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 713 | "need %zd\n", sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 714 | return -EINVAL; |
| 715 | } |
| 716 | |
| 717 | IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 718 | ord, priv->table0_addr + (ord << 2)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 719 | |
| 720 | *len = sizeof(u32); |
| 721 | ord <<= 2; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 722 | *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 723 | break; |
| 724 | |
| 725 | case IPW_ORD_TABLE_1_MASK: |
| 726 | /* |
| 727 | * TABLE 1: Indirect access to a table of 32 bit values |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 728 | * |
| 729 | * This is a fairly large table of u32 values each |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 730 | * representing starting addr for the data (which is |
| 731 | * also a u32) |
| 732 | */ |
| 733 | |
| 734 | /* remove the table id from the ordinal */ |
| 735 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 736 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 737 | /* boundary check */ |
| 738 | if (ord > priv->table1_len) { |
| 739 | IPW_DEBUG_ORD("ordinal value too long\n"); |
| 740 | return -EINVAL; |
| 741 | } |
| 742 | |
| 743 | /* verify we have enough room to store the value */ |
| 744 | if (*len < sizeof(u32)) { |
| 745 | IPW_DEBUG_ORD("ordinal buffer length too small, " |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 746 | "need %zd\n", sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 747 | return -EINVAL; |
| 748 | } |
| 749 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 750 | *((u32 *) val) = |
| 751 | ipw_read_reg32(priv, (priv->table1_addr + (ord << 2))); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 752 | *len = sizeof(u32); |
| 753 | break; |
| 754 | |
| 755 | case IPW_ORD_TABLE_2_MASK: |
| 756 | /* |
| 757 | * TABLE 2: Indirect access to a table of variable sized values |
| 758 | * |
| 759 | * This table consist of six values, each containing |
| 760 | * - dword containing the starting offset of the data |
| 761 | * - dword containing the lengh in the first 16bits |
| 762 | * and the count in the second 16bits |
| 763 | */ |
| 764 | |
| 765 | /* remove the table id from the ordinal */ |
| 766 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
| 767 | |
| 768 | /* boundary check */ |
| 769 | if (ord > priv->table2_len) { |
| 770 | IPW_DEBUG_ORD("ordinal value too long\n"); |
| 771 | return -EINVAL; |
| 772 | } |
| 773 | |
| 774 | /* get the address of statistic */ |
| 775 | addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 776 | |
| 777 | /* get the second DW of statistics ; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 778 | * two 16-bit words - first is length, second is count */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 779 | field_info = |
| 780 | ipw_read_reg32(priv, |
| 781 | priv->table2_addr + (ord << 3) + |
| 782 | sizeof(u32)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 783 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 784 | /* get each entry length */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 785 | field_len = *((u16 *) & field_info); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 786 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 787 | /* get number of entries */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 788 | field_count = *(((u16 *) & field_info) + 1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 789 | |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame^] | 790 | /* abort if not enough memory */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 791 | total_len = field_len * field_count; |
| 792 | if (total_len > *len) { |
| 793 | *len = total_len; |
| 794 | return -EINVAL; |
| 795 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 796 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 797 | *len = total_len; |
| 798 | if (!total_len) |
| 799 | return 0; |
| 800 | |
| 801 | IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 802 | "field_info = 0x%08x\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 803 | addr, total_len, field_info); |
| 804 | ipw_read_indirect(priv, addr, val, total_len); |
| 805 | break; |
| 806 | |
| 807 | default: |
| 808 | IPW_DEBUG_ORD("Invalid ordinal!\n"); |
| 809 | return -EINVAL; |
| 810 | |
| 811 | } |
| 812 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 813 | return 0; |
| 814 | } |
| 815 | |
| 816 | static void ipw_init_ordinals(struct ipw_priv *priv) |
| 817 | { |
| 818 | priv->table0_addr = IPW_ORDINALS_TABLE_LOWER; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 819 | priv->table0_len = ipw_read32(priv, priv->table0_addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 820 | |
| 821 | IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n", |
| 822 | priv->table0_addr, priv->table0_len); |
| 823 | |
| 824 | priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1); |
| 825 | priv->table1_len = ipw_read_reg32(priv, priv->table1_addr); |
| 826 | |
| 827 | IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n", |
| 828 | priv->table1_addr, priv->table1_len); |
| 829 | |
| 830 | priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2); |
| 831 | priv->table2_len = ipw_read_reg32(priv, priv->table2_addr); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 832 | priv->table2_len &= 0x0000ffff; /* use first two bytes */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 833 | |
| 834 | IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n", |
| 835 | priv->table2_addr, priv->table2_len); |
| 836 | |
| 837 | } |
| 838 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 839 | static u32 ipw_register_toggle(u32 reg) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 840 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 841 | reg &= ~IPW_START_STANDBY; |
| 842 | if (reg & IPW_GATE_ODMA) |
| 843 | reg &= ~IPW_GATE_ODMA; |
| 844 | if (reg & IPW_GATE_IDMA) |
| 845 | reg &= ~IPW_GATE_IDMA; |
| 846 | if (reg & IPW_GATE_ADMA) |
| 847 | reg &= ~IPW_GATE_ADMA; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 848 | return reg; |
| 849 | } |
| 850 | |
| 851 | /* |
| 852 | * LED behavior: |
| 853 | * - On radio ON, turn on any LEDs that require to be on during start |
| 854 | * - On initialization, start unassociated blink |
| 855 | * - On association, disable unassociated blink |
| 856 | * - On disassociation, start unassociated blink |
| 857 | * - On radio OFF, turn off any LEDs started during radio on |
| 858 | * |
| 859 | */ |
Zhu Yi | ede6111 | 2006-01-24 16:37:10 +0800 | [diff] [blame] | 860 | #define LD_TIME_LINK_ON msecs_to_jiffies(300) |
| 861 | #define LD_TIME_LINK_OFF msecs_to_jiffies(2700) |
| 862 | #define LD_TIME_ACT_ON msecs_to_jiffies(250) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 863 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 864 | static void ipw_led_link_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 865 | { |
| 866 | unsigned long flags; |
| 867 | u32 led; |
| 868 | |
| 869 | /* If configured to not use LEDs, or nic_type is 1, |
| 870 | * then we don't toggle a LINK led */ |
| 871 | if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) |
| 872 | return; |
| 873 | |
| 874 | spin_lock_irqsave(&priv->lock, flags); |
| 875 | |
| 876 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
| 877 | !(priv->status & STATUS_LED_LINK_ON)) { |
| 878 | IPW_DEBUG_LED("Link LED On\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 879 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 880 | led |= priv->led_association_on; |
| 881 | |
| 882 | led = ipw_register_toggle(led); |
| 883 | |
| 884 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 885 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 886 | |
| 887 | priv->status |= STATUS_LED_LINK_ON; |
| 888 | |
| 889 | /* If we aren't associated, schedule turning the LED off */ |
| 890 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 891 | queue_delayed_work(priv->workqueue, |
| 892 | &priv->led_link_off, |
| 893 | LD_TIME_LINK_ON); |
| 894 | } |
| 895 | |
| 896 | spin_unlock_irqrestore(&priv->lock, flags); |
| 897 | } |
| 898 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 899 | static void ipw_bg_led_link_on(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 900 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 901 | struct ipw_priv *priv = |
| 902 | container_of(work, struct ipw_priv, led_link_on.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 903 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 904 | ipw_led_link_on(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 905 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 906 | } |
| 907 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 908 | static void ipw_led_link_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 909 | { |
| 910 | unsigned long flags; |
| 911 | u32 led; |
| 912 | |
| 913 | /* If configured not to use LEDs, or nic type is 1, |
| 914 | * then we don't goggle the LINK led. */ |
| 915 | if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) |
| 916 | return; |
| 917 | |
| 918 | spin_lock_irqsave(&priv->lock, flags); |
| 919 | |
| 920 | if (priv->status & STATUS_LED_LINK_ON) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 921 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 922 | led &= priv->led_association_off; |
| 923 | led = ipw_register_toggle(led); |
| 924 | |
| 925 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 926 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 927 | |
| 928 | IPW_DEBUG_LED("Link LED Off\n"); |
| 929 | |
| 930 | priv->status &= ~STATUS_LED_LINK_ON; |
| 931 | |
| 932 | /* If we aren't associated and the radio is on, schedule |
| 933 | * turning the LED on (blink while unassociated) */ |
| 934 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
| 935 | !(priv->status & STATUS_ASSOCIATED)) |
| 936 | queue_delayed_work(priv->workqueue, &priv->led_link_on, |
| 937 | LD_TIME_LINK_OFF); |
| 938 | |
| 939 | } |
| 940 | |
| 941 | spin_unlock_irqrestore(&priv->lock, flags); |
| 942 | } |
| 943 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 944 | static void ipw_bg_led_link_off(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 945 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 946 | struct ipw_priv *priv = |
| 947 | container_of(work, struct ipw_priv, led_link_off.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 948 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 949 | ipw_led_link_off(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 950 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 951 | } |
| 952 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 953 | static void __ipw_led_activity_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 954 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 955 | u32 led; |
| 956 | |
| 957 | if (priv->config & CFG_NO_LED) |
| 958 | return; |
| 959 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 960 | if (priv->status & STATUS_RF_KILL_MASK) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 961 | return; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 962 | |
| 963 | if (!(priv->status & STATUS_LED_ACT_ON)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 964 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 965 | led |= priv->led_activity_on; |
| 966 | |
| 967 | led = ipw_register_toggle(led); |
| 968 | |
| 969 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 970 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 971 | |
| 972 | IPW_DEBUG_LED("Activity LED On\n"); |
| 973 | |
| 974 | priv->status |= STATUS_LED_ACT_ON; |
| 975 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 976 | cancel_delayed_work(&priv->led_act_off); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 977 | queue_delayed_work(priv->workqueue, &priv->led_act_off, |
| 978 | LD_TIME_ACT_ON); |
| 979 | } else { |
| 980 | /* Reschedule LED off for full time period */ |
| 981 | cancel_delayed_work(&priv->led_act_off); |
| 982 | queue_delayed_work(priv->workqueue, &priv->led_act_off, |
| 983 | LD_TIME_ACT_ON); |
| 984 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 985 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 986 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 987 | #if 0 |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 988 | void ipw_led_activity_on(struct ipw_priv *priv) |
| 989 | { |
| 990 | unsigned long flags; |
| 991 | spin_lock_irqsave(&priv->lock, flags); |
| 992 | __ipw_led_activity_on(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 993 | spin_unlock_irqrestore(&priv->lock, flags); |
| 994 | } |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 995 | #endif /* 0 */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 996 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 997 | static void ipw_led_activity_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 998 | { |
| 999 | unsigned long flags; |
| 1000 | u32 led; |
| 1001 | |
| 1002 | if (priv->config & CFG_NO_LED) |
| 1003 | return; |
| 1004 | |
| 1005 | spin_lock_irqsave(&priv->lock, flags); |
| 1006 | |
| 1007 | if (priv->status & STATUS_LED_ACT_ON) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1008 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1009 | led &= priv->led_activity_off; |
| 1010 | |
| 1011 | led = ipw_register_toggle(led); |
| 1012 | |
| 1013 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1014 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1015 | |
| 1016 | IPW_DEBUG_LED("Activity LED Off\n"); |
| 1017 | |
| 1018 | priv->status &= ~STATUS_LED_ACT_ON; |
| 1019 | } |
| 1020 | |
| 1021 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1022 | } |
| 1023 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1024 | static void ipw_bg_led_activity_off(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 1025 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1026 | struct ipw_priv *priv = |
| 1027 | container_of(work, struct ipw_priv, led_act_off.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 1028 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1029 | ipw_led_activity_off(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 1030 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 1031 | } |
| 1032 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1033 | static void ipw_led_band_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1034 | { |
| 1035 | unsigned long flags; |
| 1036 | u32 led; |
| 1037 | |
| 1038 | /* Only nic type 1 supports mode LEDs */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 1039 | if (priv->config & CFG_NO_LED || |
| 1040 | priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1041 | return; |
| 1042 | |
| 1043 | spin_lock_irqsave(&priv->lock, flags); |
| 1044 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1045 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1046 | if (priv->assoc_network->mode == IEEE_A) { |
| 1047 | led |= priv->led_ofdm_on; |
| 1048 | led &= priv->led_association_off; |
| 1049 | IPW_DEBUG_LED("Mode LED On: 802.11a\n"); |
| 1050 | } else if (priv->assoc_network->mode == IEEE_G) { |
| 1051 | led |= priv->led_ofdm_on; |
| 1052 | led |= priv->led_association_on; |
| 1053 | IPW_DEBUG_LED("Mode LED On: 802.11g\n"); |
| 1054 | } else { |
| 1055 | led &= priv->led_ofdm_off; |
| 1056 | led |= priv->led_association_on; |
| 1057 | IPW_DEBUG_LED("Mode LED On: 802.11b\n"); |
| 1058 | } |
| 1059 | |
| 1060 | led = ipw_register_toggle(led); |
| 1061 | |
| 1062 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1063 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1064 | |
| 1065 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1066 | } |
| 1067 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1068 | static void ipw_led_band_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1069 | { |
| 1070 | unsigned long flags; |
| 1071 | u32 led; |
| 1072 | |
| 1073 | /* Only nic type 1 supports mode LEDs */ |
| 1074 | if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1) |
| 1075 | return; |
| 1076 | |
| 1077 | spin_lock_irqsave(&priv->lock, flags); |
| 1078 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1079 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1080 | led &= priv->led_ofdm_off; |
| 1081 | led &= priv->led_association_off; |
| 1082 | |
| 1083 | led = ipw_register_toggle(led); |
| 1084 | |
| 1085 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1086 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1087 | |
| 1088 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1089 | } |
| 1090 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1091 | static void ipw_led_radio_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1092 | { |
| 1093 | ipw_led_link_on(priv); |
| 1094 | } |
| 1095 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1096 | static void ipw_led_radio_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1097 | { |
| 1098 | ipw_led_activity_off(priv); |
| 1099 | ipw_led_link_off(priv); |
| 1100 | } |
| 1101 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1102 | static void ipw_led_link_up(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1103 | { |
| 1104 | /* Set the Link Led on for all nic types */ |
| 1105 | ipw_led_link_on(priv); |
| 1106 | } |
| 1107 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1108 | static void ipw_led_link_down(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1109 | { |
| 1110 | ipw_led_activity_off(priv); |
| 1111 | ipw_led_link_off(priv); |
| 1112 | |
| 1113 | if (priv->status & STATUS_RF_KILL_MASK) |
| 1114 | ipw_led_radio_off(priv); |
| 1115 | } |
| 1116 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1117 | static void ipw_led_init(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1118 | { |
| 1119 | priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE]; |
| 1120 | |
| 1121 | /* Set the default PINs for the link and activity leds */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1122 | priv->led_activity_on = IPW_ACTIVITY_LED; |
| 1123 | priv->led_activity_off = ~(IPW_ACTIVITY_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1124 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1125 | priv->led_association_on = IPW_ASSOCIATED_LED; |
| 1126 | priv->led_association_off = ~(IPW_ASSOCIATED_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1127 | |
| 1128 | /* Set the default PINs for the OFDM leds */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1129 | priv->led_ofdm_on = IPW_OFDM_LED; |
| 1130 | priv->led_ofdm_off = ~(IPW_OFDM_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1131 | |
| 1132 | switch (priv->nic_type) { |
| 1133 | case EEPROM_NIC_TYPE_1: |
| 1134 | /* In this NIC type, the LEDs are reversed.... */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1135 | priv->led_activity_on = IPW_ASSOCIATED_LED; |
| 1136 | priv->led_activity_off = ~(IPW_ASSOCIATED_LED); |
| 1137 | priv->led_association_on = IPW_ACTIVITY_LED; |
| 1138 | priv->led_association_off = ~(IPW_ACTIVITY_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1139 | |
| 1140 | if (!(priv->config & CFG_NO_LED)) |
| 1141 | ipw_led_band_on(priv); |
| 1142 | |
| 1143 | /* And we don't blink link LEDs for this nic, so |
| 1144 | * just return here */ |
| 1145 | return; |
| 1146 | |
| 1147 | case EEPROM_NIC_TYPE_3: |
| 1148 | case EEPROM_NIC_TYPE_2: |
| 1149 | case EEPROM_NIC_TYPE_4: |
| 1150 | case EEPROM_NIC_TYPE_0: |
| 1151 | break; |
| 1152 | |
| 1153 | default: |
| 1154 | IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n", |
| 1155 | priv->nic_type); |
| 1156 | priv->nic_type = EEPROM_NIC_TYPE_0; |
| 1157 | break; |
| 1158 | } |
| 1159 | |
| 1160 | if (!(priv->config & CFG_NO_LED)) { |
| 1161 | if (priv->status & STATUS_ASSOCIATED) |
| 1162 | ipw_led_link_on(priv); |
| 1163 | else |
| 1164 | ipw_led_link_off(priv); |
| 1165 | } |
| 1166 | } |
| 1167 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1168 | static void ipw_led_shutdown(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1169 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1170 | ipw_led_activity_off(priv); |
| 1171 | ipw_led_link_off(priv); |
| 1172 | ipw_led_band_off(priv); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1173 | cancel_delayed_work(&priv->led_link_on); |
| 1174 | cancel_delayed_work(&priv->led_link_off); |
| 1175 | cancel_delayed_work(&priv->led_act_off); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1176 | } |
| 1177 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1178 | /* |
| 1179 | * The following adds a new attribute to the sysfs representation |
| 1180 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/) |
| 1181 | * used for controling the debug level. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1182 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1183 | * See the level definitions in ipw for details. |
| 1184 | */ |
| 1185 | static ssize_t show_debug_level(struct device_driver *d, char *buf) |
| 1186 | { |
| 1187 | return sprintf(buf, "0x%08X\n", ipw_debug_level); |
| 1188 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1189 | |
| 1190 | static ssize_t store_debug_level(struct device_driver *d, const char *buf, |
| 1191 | size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1192 | { |
| 1193 | char *p = (char *)buf; |
| 1194 | u32 val; |
| 1195 | |
| 1196 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { |
| 1197 | p++; |
| 1198 | if (p[0] == 'x' || p[0] == 'X') |
| 1199 | p++; |
| 1200 | val = simple_strtoul(p, &p, 16); |
| 1201 | } else |
| 1202 | val = simple_strtoul(p, &p, 10); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1203 | if (p == buf) |
| 1204 | printk(KERN_INFO DRV_NAME |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1205 | ": %s is not in hex or decimal form.\n", buf); |
| 1206 | else |
| 1207 | ipw_debug_level = val; |
| 1208 | |
| 1209 | return strnlen(buf, count); |
| 1210 | } |
| 1211 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1212 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1213 | show_debug_level, store_debug_level); |
| 1214 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1215 | static inline u32 ipw_get_event_log_len(struct ipw_priv *priv) |
| 1216 | { |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 1217 | /* length = 1st dword in log */ |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1218 | return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG)); |
| 1219 | } |
| 1220 | |
| 1221 | static void ipw_capture_event_log(struct ipw_priv *priv, |
| 1222 | u32 log_len, struct ipw_event *log) |
| 1223 | { |
| 1224 | u32 base; |
| 1225 | |
| 1226 | if (log_len) { |
| 1227 | base = ipw_read32(priv, IPW_EVENT_LOG); |
| 1228 | ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32), |
| 1229 | (u8 *) log, sizeof(*log) * log_len); |
| 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv) |
| 1234 | { |
| 1235 | struct ipw_fw_error *error; |
| 1236 | u32 log_len = ipw_get_event_log_len(priv); |
| 1237 | u32 base = ipw_read32(priv, IPW_ERROR_LOG); |
| 1238 | u32 elem_len = ipw_read_reg32(priv, base); |
| 1239 | |
| 1240 | error = kmalloc(sizeof(*error) + |
| 1241 | sizeof(*error->elem) * elem_len + |
| 1242 | sizeof(*error->log) * log_len, GFP_ATOMIC); |
| 1243 | if (!error) { |
| 1244 | IPW_ERROR("Memory allocation for firmware error log " |
| 1245 | "failed.\n"); |
| 1246 | return NULL; |
| 1247 | } |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1248 | error->jiffies = jiffies; |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1249 | error->status = priv->status; |
| 1250 | error->config = priv->config; |
| 1251 | error->elem_len = elem_len; |
| 1252 | error->log_len = log_len; |
| 1253 | error->elem = (struct ipw_error_elem *)error->payload; |
Zhu Yi | 3b26b11 | 2005-11-17 13:58:30 +0800 | [diff] [blame] | 1254 | error->log = (struct ipw_event *)(error->elem + elem_len); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1255 | |
| 1256 | ipw_capture_event_log(priv, log_len, error->log); |
| 1257 | |
| 1258 | if (elem_len) |
| 1259 | ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem, |
| 1260 | sizeof(*error->elem) * elem_len); |
| 1261 | |
| 1262 | return error; |
| 1263 | } |
| 1264 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1265 | static ssize_t show_event_log(struct device *d, |
| 1266 | struct device_attribute *attr, char *buf) |
| 1267 | { |
| 1268 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1269 | u32 log_len = ipw_get_event_log_len(priv); |
Reinette Chatre | 412e9e7 | 2007-12-18 22:01:02 -0800 | [diff] [blame] | 1270 | u32 log_size; |
| 1271 | struct ipw_event *log; |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1272 | u32 len = 0, i; |
| 1273 | |
Reinette Chatre | 412e9e7 | 2007-12-18 22:01:02 -0800 | [diff] [blame] | 1274 | /* not using min() because of its strict type checking */ |
| 1275 | log_size = PAGE_SIZE / sizeof(*log) > log_len ? |
| 1276 | sizeof(*log) * log_len : PAGE_SIZE; |
| 1277 | log = kzalloc(log_size, GFP_KERNEL); |
| 1278 | if (!log) { |
| 1279 | IPW_ERROR("Unable to allocate memory for log\n"); |
| 1280 | return 0; |
| 1281 | } |
| 1282 | log_len = log_size / sizeof(*log); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1283 | ipw_capture_event_log(priv, log_len, log); |
| 1284 | |
| 1285 | len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len); |
| 1286 | for (i = 0; i < log_len; i++) |
| 1287 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1288 | "\n%08X%08X%08X", |
| 1289 | log[i].time, log[i].event, log[i].data); |
| 1290 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
Reinette Chatre | 412e9e7 | 2007-12-18 22:01:02 -0800 | [diff] [blame] | 1291 | kfree(log); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1292 | return len; |
| 1293 | } |
| 1294 | |
| 1295 | static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL); |
| 1296 | |
| 1297 | static ssize_t show_error(struct device *d, |
| 1298 | struct device_attribute *attr, char *buf) |
| 1299 | { |
| 1300 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1301 | u32 len = 0, i; |
| 1302 | if (!priv->error) |
| 1303 | return 0; |
| 1304 | len += snprintf(buf + len, PAGE_SIZE - len, |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1305 | "%08lX%08X%08X%08X", |
| 1306 | priv->error->jiffies, |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1307 | priv->error->status, |
| 1308 | priv->error->config, priv->error->elem_len); |
| 1309 | for (i = 0; i < priv->error->elem_len; i++) |
| 1310 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1311 | "\n%08X%08X%08X%08X%08X%08X%08X", |
| 1312 | priv->error->elem[i].time, |
| 1313 | priv->error->elem[i].desc, |
| 1314 | priv->error->elem[i].blink1, |
| 1315 | priv->error->elem[i].blink2, |
| 1316 | priv->error->elem[i].link1, |
| 1317 | priv->error->elem[i].link2, |
| 1318 | priv->error->elem[i].data); |
| 1319 | |
| 1320 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1321 | "\n%08X", priv->error->log_len); |
| 1322 | for (i = 0; i < priv->error->log_len; i++) |
| 1323 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1324 | "\n%08X%08X%08X", |
| 1325 | priv->error->log[i].time, |
| 1326 | priv->error->log[i].event, |
| 1327 | priv->error->log[i].data); |
| 1328 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1329 | return len; |
| 1330 | } |
| 1331 | |
| 1332 | static ssize_t clear_error(struct device *d, |
| 1333 | struct device_attribute *attr, |
| 1334 | const char *buf, size_t count) |
| 1335 | { |
| 1336 | struct ipw_priv *priv = dev_get_drvdata(d); |
Jesper Juhl | 8f76078 | 2006-06-27 02:55:06 -0700 | [diff] [blame] | 1337 | |
| 1338 | kfree(priv->error); |
| 1339 | priv->error = NULL; |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1340 | return count; |
| 1341 | } |
| 1342 | |
| 1343 | static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error); |
| 1344 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1345 | static ssize_t show_cmd_log(struct device *d, |
| 1346 | struct device_attribute *attr, char *buf) |
| 1347 | { |
| 1348 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1349 | u32 len = 0, i; |
| 1350 | if (!priv->cmdlog) |
| 1351 | return 0; |
| 1352 | for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len; |
| 1353 | (i != priv->cmdlog_pos) && (PAGE_SIZE - len); |
| 1354 | i = (i + 1) % priv->cmdlog_len) { |
| 1355 | len += |
| 1356 | snprintf(buf + len, PAGE_SIZE - len, |
| 1357 | "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies, |
| 1358 | priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd, |
| 1359 | priv->cmdlog[i].cmd.len); |
| 1360 | len += |
| 1361 | snprintk_buf(buf + len, PAGE_SIZE - len, |
| 1362 | (u8 *) priv->cmdlog[i].cmd.param, |
| 1363 | priv->cmdlog[i].cmd.len); |
| 1364 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1365 | } |
| 1366 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1367 | return len; |
| 1368 | } |
| 1369 | |
| 1370 | static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL); |
| 1371 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 1372 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 1373 | static void ipw_prom_free(struct ipw_priv *priv); |
| 1374 | static int ipw_prom_alloc(struct ipw_priv *priv); |
| 1375 | static ssize_t store_rtap_iface(struct device *d, |
| 1376 | struct device_attribute *attr, |
| 1377 | const char *buf, size_t count) |
| 1378 | { |
| 1379 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1380 | int rc = 0; |
| 1381 | |
| 1382 | if (count < 1) |
| 1383 | return -EINVAL; |
| 1384 | |
| 1385 | switch (buf[0]) { |
| 1386 | case '0': |
| 1387 | if (!rtap_iface) |
| 1388 | return count; |
| 1389 | |
| 1390 | if (netif_running(priv->prom_net_dev)) { |
| 1391 | IPW_WARNING("Interface is up. Cannot unregister.\n"); |
| 1392 | return count; |
| 1393 | } |
| 1394 | |
| 1395 | ipw_prom_free(priv); |
| 1396 | rtap_iface = 0; |
| 1397 | break; |
| 1398 | |
| 1399 | case '1': |
| 1400 | if (rtap_iface) |
| 1401 | return count; |
| 1402 | |
| 1403 | rc = ipw_prom_alloc(priv); |
| 1404 | if (!rc) |
| 1405 | rtap_iface = 1; |
| 1406 | break; |
| 1407 | |
| 1408 | default: |
| 1409 | return -EINVAL; |
| 1410 | } |
| 1411 | |
| 1412 | if (rc) { |
| 1413 | IPW_ERROR("Failed to register promiscuous network " |
| 1414 | "device (error %d).\n", rc); |
| 1415 | } |
| 1416 | |
| 1417 | return count; |
| 1418 | } |
| 1419 | |
| 1420 | static ssize_t show_rtap_iface(struct device *d, |
| 1421 | struct device_attribute *attr, |
| 1422 | char *buf) |
| 1423 | { |
| 1424 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1425 | if (rtap_iface) |
| 1426 | return sprintf(buf, "%s", priv->prom_net_dev->name); |
| 1427 | else { |
| 1428 | buf[0] = '-'; |
| 1429 | buf[1] = '1'; |
| 1430 | buf[2] = '\0'; |
| 1431 | return 3; |
| 1432 | } |
| 1433 | } |
| 1434 | |
| 1435 | static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface, |
| 1436 | store_rtap_iface); |
| 1437 | |
| 1438 | static ssize_t store_rtap_filter(struct device *d, |
| 1439 | struct device_attribute *attr, |
| 1440 | const char *buf, size_t count) |
| 1441 | { |
| 1442 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1443 | |
| 1444 | if (!priv->prom_priv) { |
| 1445 | IPW_ERROR("Attempting to set filter without " |
| 1446 | "rtap_iface enabled.\n"); |
| 1447 | return -EPERM; |
| 1448 | } |
| 1449 | |
| 1450 | priv->prom_priv->filter = simple_strtol(buf, NULL, 0); |
| 1451 | |
| 1452 | IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n", |
| 1453 | BIT_ARG16(priv->prom_priv->filter)); |
| 1454 | |
| 1455 | return count; |
| 1456 | } |
| 1457 | |
| 1458 | static ssize_t show_rtap_filter(struct device *d, |
| 1459 | struct device_attribute *attr, |
| 1460 | char *buf) |
| 1461 | { |
| 1462 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1463 | return sprintf(buf, "0x%04X", |
| 1464 | priv->prom_priv ? priv->prom_priv->filter : 0); |
| 1465 | } |
| 1466 | |
| 1467 | static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter, |
| 1468 | store_rtap_filter); |
| 1469 | #endif |
| 1470 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1471 | static ssize_t show_scan_age(struct device *d, struct device_attribute *attr, |
| 1472 | char *buf) |
| 1473 | { |
| 1474 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1475 | return sprintf(buf, "%d\n", priv->ieee->scan_age); |
| 1476 | } |
| 1477 | |
| 1478 | static ssize_t store_scan_age(struct device *d, struct device_attribute *attr, |
| 1479 | const char *buf, size_t count) |
| 1480 | { |
| 1481 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1482 | struct net_device *dev = priv->net_dev; |
| 1483 | char buffer[] = "00000000"; |
| 1484 | unsigned long len = |
| 1485 | (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1; |
| 1486 | unsigned long val; |
| 1487 | char *p = buffer; |
| 1488 | |
| 1489 | IPW_DEBUG_INFO("enter\n"); |
| 1490 | |
| 1491 | strncpy(buffer, buf, len); |
| 1492 | buffer[len] = 0; |
| 1493 | |
| 1494 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { |
| 1495 | p++; |
| 1496 | if (p[0] == 'x' || p[0] == 'X') |
| 1497 | p++; |
| 1498 | val = simple_strtoul(p, &p, 16); |
| 1499 | } else |
| 1500 | val = simple_strtoul(p, &p, 10); |
| 1501 | if (p == buffer) { |
| 1502 | IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name); |
| 1503 | } else { |
| 1504 | priv->ieee->scan_age = val; |
| 1505 | IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age); |
| 1506 | } |
| 1507 | |
| 1508 | IPW_DEBUG_INFO("exit\n"); |
| 1509 | return len; |
| 1510 | } |
| 1511 | |
| 1512 | static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age); |
| 1513 | |
| 1514 | static ssize_t show_led(struct device *d, struct device_attribute *attr, |
| 1515 | char *buf) |
| 1516 | { |
| 1517 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1518 | return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1); |
| 1519 | } |
| 1520 | |
| 1521 | static ssize_t store_led(struct device *d, struct device_attribute *attr, |
| 1522 | const char *buf, size_t count) |
| 1523 | { |
| 1524 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1525 | |
| 1526 | IPW_DEBUG_INFO("enter\n"); |
| 1527 | |
| 1528 | if (count == 0) |
| 1529 | return 0; |
| 1530 | |
| 1531 | if (*buf == 0) { |
| 1532 | IPW_DEBUG_LED("Disabling LED control.\n"); |
| 1533 | priv->config |= CFG_NO_LED; |
| 1534 | ipw_led_shutdown(priv); |
| 1535 | } else { |
| 1536 | IPW_DEBUG_LED("Enabling LED control.\n"); |
| 1537 | priv->config &= ~CFG_NO_LED; |
| 1538 | ipw_led_init(priv); |
| 1539 | } |
| 1540 | |
| 1541 | IPW_DEBUG_INFO("exit\n"); |
| 1542 | return count; |
| 1543 | } |
| 1544 | |
| 1545 | static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led); |
| 1546 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1547 | static ssize_t show_status(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1548 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1549 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1550 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1551 | return sprintf(buf, "0x%08x\n", (int)p->status); |
| 1552 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1553 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1554 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 1555 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1556 | static ssize_t show_cfg(struct device *d, struct device_attribute *attr, |
| 1557 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1558 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1559 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1560 | return sprintf(buf, "0x%08x\n", (int)p->config); |
| 1561 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1562 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1563 | static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL); |
| 1564 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1565 | static ssize_t show_nic_type(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1566 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1567 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1568 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1569 | return sprintf(buf, "TYPE: %d\n", priv->nic_type); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1570 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1571 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1572 | static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL); |
| 1573 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1574 | static ssize_t show_ucode_version(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1575 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1576 | { |
| 1577 | u32 len = sizeof(u32), tmp = 0; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1578 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1579 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1580 | if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1581 | return 0; |
| 1582 | |
| 1583 | return sprintf(buf, "0x%08x\n", tmp); |
| 1584 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1585 | |
| 1586 | 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] | 1587 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1588 | static ssize_t show_rtc(struct device *d, struct device_attribute *attr, |
| 1589 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1590 | { |
| 1591 | u32 len = sizeof(u32), tmp = 0; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1592 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1593 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1594 | if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1595 | return 0; |
| 1596 | |
| 1597 | return sprintf(buf, "0x%08x\n", tmp); |
| 1598 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1599 | |
| 1600 | static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1601 | |
| 1602 | /* |
| 1603 | * Add a device attribute to view/control the delay between eeprom |
| 1604 | * operations. |
| 1605 | */ |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1606 | static ssize_t show_eeprom_delay(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 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1609 | struct ipw_priv *p = dev_get_drvdata(d); |
| 1610 | int n = p->eeprom_delay; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1611 | return sprintf(buf, "%i\n", n); |
| 1612 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1613 | static ssize_t store_eeprom_delay(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1614 | struct device_attribute *attr, |
| 1615 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1616 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1617 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1618 | sscanf(buf, "%i", &p->eeprom_delay); |
| 1619 | return strnlen(buf, count); |
| 1620 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1621 | |
| 1622 | static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO, |
| 1623 | show_eeprom_delay, store_eeprom_delay); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1624 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1625 | static ssize_t show_command_event_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1626 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1627 | { |
| 1628 | u32 reg = 0; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1629 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1630 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1631 | reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1632 | return sprintf(buf, "0x%08x\n", reg); |
| 1633 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1634 | static ssize_t store_command_event_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1635 | struct device_attribute *attr, |
| 1636 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1637 | { |
| 1638 | u32 reg; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1639 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1640 | |
| 1641 | sscanf(buf, "%x", ®); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1642 | ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1643 | return strnlen(buf, count); |
| 1644 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1645 | |
| 1646 | static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO, |
| 1647 | show_command_event_reg, store_command_event_reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1648 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1649 | static ssize_t show_mem_gpio_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1650 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1651 | { |
| 1652 | u32 reg = 0; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1653 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1654 | |
| 1655 | reg = ipw_read_reg32(p, 0x301100); |
| 1656 | return sprintf(buf, "0x%08x\n", reg); |
| 1657 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1658 | static ssize_t store_mem_gpio_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1659 | struct device_attribute *attr, |
| 1660 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1661 | { |
| 1662 | u32 reg; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1663 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1664 | |
| 1665 | sscanf(buf, "%x", ®); |
| 1666 | ipw_write_reg32(p, 0x301100, reg); |
| 1667 | return strnlen(buf, count); |
| 1668 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1669 | |
| 1670 | static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO, |
| 1671 | show_mem_gpio_reg, store_mem_gpio_reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1672 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1673 | static ssize_t show_indirect_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1674 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1675 | { |
| 1676 | u32 reg = 0; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1677 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1678 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1679 | if (priv->status & STATUS_INDIRECT_DWORD) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1680 | reg = ipw_read_reg32(priv, priv->indirect_dword); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1681 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1682 | reg = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1683 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1684 | return sprintf(buf, "0x%08x\n", reg); |
| 1685 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1686 | static ssize_t store_indirect_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1687 | struct device_attribute *attr, |
| 1688 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1689 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1690 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1691 | |
| 1692 | sscanf(buf, "%x", &priv->indirect_dword); |
| 1693 | priv->status |= STATUS_INDIRECT_DWORD; |
| 1694 | return strnlen(buf, count); |
| 1695 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1696 | |
| 1697 | static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO, |
| 1698 | show_indirect_dword, store_indirect_dword); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1699 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1700 | static ssize_t show_indirect_byte(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1701 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1702 | { |
| 1703 | u8 reg = 0; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1704 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1705 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1706 | if (priv->status & STATUS_INDIRECT_BYTE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1707 | reg = ipw_read_reg8(priv, priv->indirect_byte); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1708 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1709 | reg = 0; |
| 1710 | |
| 1711 | return sprintf(buf, "0x%02x\n", reg); |
| 1712 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1713 | static ssize_t store_indirect_byte(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1714 | struct device_attribute *attr, |
| 1715 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1716 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1717 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1718 | |
| 1719 | sscanf(buf, "%x", &priv->indirect_byte); |
| 1720 | priv->status |= STATUS_INDIRECT_BYTE; |
| 1721 | return strnlen(buf, count); |
| 1722 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1723 | |
| 1724 | static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1725 | show_indirect_byte, store_indirect_byte); |
| 1726 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1727 | static ssize_t show_direct_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1728 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1729 | { |
| 1730 | u32 reg = 0; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1731 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1732 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1733 | if (priv->status & STATUS_DIRECT_DWORD) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1734 | reg = ipw_read32(priv, priv->direct_dword); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1735 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1736 | reg = 0; |
| 1737 | |
| 1738 | return sprintf(buf, "0x%08x\n", reg); |
| 1739 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1740 | static ssize_t store_direct_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1741 | struct device_attribute *attr, |
| 1742 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1743 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1744 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1745 | |
| 1746 | sscanf(buf, "%x", &priv->direct_dword); |
| 1747 | priv->status |= STATUS_DIRECT_DWORD; |
| 1748 | return strnlen(buf, count); |
| 1749 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1750 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1751 | static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO, |
| 1752 | show_direct_dword, store_direct_dword); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1753 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1754 | static int rf_kill_active(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1755 | { |
| 1756 | if (0 == (ipw_read32(priv, 0x30) & 0x10000)) |
| 1757 | priv->status |= STATUS_RF_KILL_HW; |
| 1758 | else |
| 1759 | priv->status &= ~STATUS_RF_KILL_HW; |
| 1760 | |
| 1761 | return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0; |
| 1762 | } |
| 1763 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1764 | 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] | 1765 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1766 | { |
| 1767 | /* 0 - RF kill not enabled |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1768 | 1 - SW based RF kill active (sysfs) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1769 | 2 - HW based RF kill active |
| 1770 | 3 - Both HW and SW baed RF kill active */ |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1771 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1772 | int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1773 | (rf_kill_active(priv) ? 0x2 : 0x0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1774 | return sprintf(buf, "%i\n", val); |
| 1775 | } |
| 1776 | |
| 1777 | static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio) |
| 1778 | { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1779 | if ((disable_radio ? 1 : 0) == |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 1780 | ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0)) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1781 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1782 | |
| 1783 | IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n", |
| 1784 | disable_radio ? "OFF" : "ON"); |
| 1785 | |
| 1786 | if (disable_radio) { |
| 1787 | priv->status |= STATUS_RF_KILL_SW; |
| 1788 | |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 1789 | if (priv->workqueue) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1790 | cancel_delayed_work(&priv->request_scan); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 1791 | cancel_delayed_work(&priv->request_direct_scan); |
| 1792 | cancel_delayed_work(&priv->request_passive_scan); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 1793 | cancel_delayed_work(&priv->scan_event); |
| 1794 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1795 | queue_work(priv->workqueue, &priv->down); |
| 1796 | } else { |
| 1797 | priv->status &= ~STATUS_RF_KILL_SW; |
| 1798 | if (rf_kill_active(priv)) { |
| 1799 | IPW_DEBUG_RF_KILL("Can not turn radio back on - " |
| 1800 | "disabled by HW switch\n"); |
| 1801 | /* Make sure the RF_KILL check timer is running */ |
| 1802 | cancel_delayed_work(&priv->rf_kill); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1803 | queue_delayed_work(priv->workqueue, &priv->rf_kill, |
Anton Blanchard | be84e3d | 2007-10-15 00:38:01 -0500 | [diff] [blame] | 1804 | round_jiffies_relative(2 * HZ)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1805 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1806 | queue_work(priv->workqueue, &priv->up); |
| 1807 | } |
| 1808 | |
| 1809 | return 1; |
| 1810 | } |
| 1811 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1812 | static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr, |
| 1813 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1814 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1815 | struct ipw_priv *priv = dev_get_drvdata(d); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1816 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1817 | ipw_radio_kill_sw(priv, buf[0] == '1'); |
| 1818 | |
| 1819 | return count; |
| 1820 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1821 | |
| 1822 | 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] | 1823 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1824 | static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr, |
| 1825 | char *buf) |
| 1826 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1827 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1828 | int pos = 0, len = 0; |
| 1829 | if (priv->config & CFG_SPEED_SCAN) { |
| 1830 | while (priv->speed_scan[pos] != 0) |
| 1831 | len += sprintf(&buf[len], "%d ", |
| 1832 | priv->speed_scan[pos++]); |
| 1833 | return len + sprintf(&buf[len], "\n"); |
| 1834 | } |
| 1835 | |
| 1836 | return sprintf(buf, "0\n"); |
| 1837 | } |
| 1838 | |
| 1839 | static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr, |
| 1840 | const char *buf, size_t count) |
| 1841 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1842 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1843 | int channel, pos = 0; |
| 1844 | const char *p = buf; |
| 1845 | |
| 1846 | /* list of space separated channels to scan, optionally ending with 0 */ |
| 1847 | while ((channel = simple_strtol(p, NULL, 0))) { |
| 1848 | if (pos == MAX_SPEED_SCAN - 1) { |
| 1849 | priv->speed_scan[pos] = 0; |
| 1850 | break; |
| 1851 | } |
| 1852 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1853 | if (libipw_is_valid_channel(priv->ieee, channel)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1854 | priv->speed_scan[pos++] = channel; |
| 1855 | else |
| 1856 | IPW_WARNING("Skipping invalid channel request: %d\n", |
| 1857 | channel); |
| 1858 | p = strchr(p, ' '); |
| 1859 | if (!p) |
| 1860 | break; |
| 1861 | while (*p == ' ' || *p == '\t') |
| 1862 | p++; |
| 1863 | } |
| 1864 | |
| 1865 | if (pos == 0) |
| 1866 | priv->config &= ~CFG_SPEED_SCAN; |
| 1867 | else { |
| 1868 | priv->speed_scan_pos = 0; |
| 1869 | priv->config |= CFG_SPEED_SCAN; |
| 1870 | } |
| 1871 | |
| 1872 | return count; |
| 1873 | } |
| 1874 | |
| 1875 | static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan, |
| 1876 | store_speed_scan); |
| 1877 | |
| 1878 | static ssize_t show_net_stats(struct device *d, struct device_attribute *attr, |
| 1879 | char *buf) |
| 1880 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1881 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1882 | return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0'); |
| 1883 | } |
| 1884 | |
| 1885 | static ssize_t store_net_stats(struct device *d, struct device_attribute *attr, |
| 1886 | const char *buf, size_t count) |
| 1887 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1888 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1889 | if (buf[0] == '1') |
| 1890 | priv->config |= CFG_NET_STATS; |
| 1891 | else |
| 1892 | priv->config &= ~CFG_NET_STATS; |
| 1893 | |
| 1894 | return count; |
| 1895 | } |
| 1896 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1897 | static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO, |
| 1898 | show_net_stats, store_net_stats); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1899 | |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1900 | static ssize_t show_channels(struct device *d, |
| 1901 | struct device_attribute *attr, |
| 1902 | char *buf) |
| 1903 | { |
| 1904 | struct ipw_priv *priv = dev_get_drvdata(d); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1905 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1906 | int len = 0, i; |
| 1907 | |
| 1908 | len = sprintf(&buf[len], |
| 1909 | "Displaying %d channels in 2.4Ghz band " |
| 1910 | "(802.11bg):\n", geo->bg_channels); |
| 1911 | |
| 1912 | for (i = 0; i < geo->bg_channels; i++) { |
| 1913 | len += sprintf(&buf[len], "%d: BSS%s%s, %s, Band %s.\n", |
| 1914 | geo->bg[i].channel, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1915 | geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT ? |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1916 | " (radar spectrum)" : "", |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1917 | ((geo->bg[i].flags & LIBIPW_CH_NO_IBSS) || |
| 1918 | (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)) |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1919 | ? "" : ", IBSS", |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1920 | geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY ? |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1921 | "passive only" : "active/passive", |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1922 | geo->bg[i].flags & LIBIPW_CH_B_ONLY ? |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1923 | "B" : "B/G"); |
| 1924 | } |
| 1925 | |
| 1926 | len += sprintf(&buf[len], |
| 1927 | "Displaying %d channels in 5.2Ghz band " |
| 1928 | "(802.11a):\n", geo->a_channels); |
| 1929 | for (i = 0; i < geo->a_channels; i++) { |
| 1930 | len += sprintf(&buf[len], "%d: BSS%s%s, %s.\n", |
| 1931 | geo->a[i].channel, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1932 | geo->a[i].flags & LIBIPW_CH_RADAR_DETECT ? |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1933 | " (radar spectrum)" : "", |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1934 | ((geo->a[i].flags & LIBIPW_CH_NO_IBSS) || |
| 1935 | (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT)) |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1936 | ? "" : ", IBSS", |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1937 | geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY ? |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1938 | "passive only" : "active/passive"); |
| 1939 | } |
| 1940 | |
| 1941 | return len; |
| 1942 | } |
| 1943 | |
| 1944 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 1945 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 1946 | static void notify_wx_assoc_event(struct ipw_priv *priv) |
| 1947 | { |
| 1948 | union iwreq_data wrqu; |
| 1949 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 1950 | if (priv->status & STATUS_ASSOCIATED) |
| 1951 | memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN); |
| 1952 | else |
| 1953 | memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); |
| 1954 | wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL); |
| 1955 | } |
| 1956 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1957 | static void ipw_irq_tasklet(struct ipw_priv *priv) |
| 1958 | { |
| 1959 | u32 inta, inta_mask, handled = 0; |
| 1960 | unsigned long flags; |
| 1961 | int rc = 0; |
| 1962 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 1963 | spin_lock_irqsave(&priv->irq_lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1964 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1965 | inta = ipw_read32(priv, IPW_INTA_RW); |
| 1966 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); |
| 1967 | inta &= (IPW_INTA_MASK_ALL & inta_mask); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1968 | |
| 1969 | /* Add any cached INTA values that need to be handled */ |
| 1970 | inta |= priv->isr_inta; |
| 1971 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 1972 | spin_unlock_irqrestore(&priv->irq_lock, flags); |
| 1973 | |
| 1974 | spin_lock_irqsave(&priv->lock, flags); |
| 1975 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1976 | /* handle all the justifications for the interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1977 | if (inta & IPW_INTA_BIT_RX_TRANSFER) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1978 | ipw_rx(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1979 | handled |= IPW_INTA_BIT_RX_TRANSFER; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1980 | } |
| 1981 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1982 | if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1983 | IPW_DEBUG_HC("Command completed.\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1984 | rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1985 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 1986 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1987 | handled |= IPW_INTA_BIT_TX_CMD_QUEUE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1988 | } |
| 1989 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1990 | if (inta & IPW_INTA_BIT_TX_QUEUE_1) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1991 | IPW_DEBUG_TX("TX_QUEUE_1\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1992 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1993 | handled |= IPW_INTA_BIT_TX_QUEUE_1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1994 | } |
| 1995 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1996 | if (inta & IPW_INTA_BIT_TX_QUEUE_2) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1997 | IPW_DEBUG_TX("TX_QUEUE_2\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1998 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1999 | handled |= IPW_INTA_BIT_TX_QUEUE_2; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2000 | } |
| 2001 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2002 | if (inta & IPW_INTA_BIT_TX_QUEUE_3) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2003 | IPW_DEBUG_TX("TX_QUEUE_3\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2004 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2005 | handled |= IPW_INTA_BIT_TX_QUEUE_3; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2006 | } |
| 2007 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2008 | if (inta & IPW_INTA_BIT_TX_QUEUE_4) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2009 | IPW_DEBUG_TX("TX_QUEUE_4\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2010 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2011 | handled |= IPW_INTA_BIT_TX_QUEUE_4; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2012 | } |
| 2013 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2014 | if (inta & IPW_INTA_BIT_STATUS_CHANGE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2015 | IPW_WARNING("STATUS_CHANGE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2016 | handled |= IPW_INTA_BIT_STATUS_CHANGE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2017 | } |
| 2018 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2019 | if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2020 | IPW_WARNING("TX_PERIOD_EXPIRED\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2021 | handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2022 | } |
| 2023 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2024 | if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2025 | IPW_WARNING("HOST_CMD_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2026 | handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2027 | } |
| 2028 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2029 | if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2030 | IPW_WARNING("FW_INITIALIZATION_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2031 | handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2032 | } |
| 2033 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2034 | if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2035 | IPW_WARNING("PHY_OFF_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2036 | handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2037 | } |
| 2038 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2039 | if (inta & IPW_INTA_BIT_RF_KILL_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2040 | IPW_DEBUG_RF_KILL("RF_KILL_DONE\n"); |
| 2041 | priv->status |= STATUS_RF_KILL_HW; |
| 2042 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 2043 | priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2044 | cancel_delayed_work(&priv->request_scan); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 2045 | cancel_delayed_work(&priv->request_direct_scan); |
| 2046 | cancel_delayed_work(&priv->request_passive_scan); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 2047 | cancel_delayed_work(&priv->scan_event); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2048 | schedule_work(&priv->link_down); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2049 | queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2050 | handled |= IPW_INTA_BIT_RF_KILL_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2051 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2052 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2053 | if (inta & IPW_INTA_BIT_FATAL_ERROR) { |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 2054 | IPW_WARNING("Firmware error detected. Restarting.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2055 | if (priv->error) { |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 2056 | IPW_DEBUG_FW("Sysfs 'error' log already exists.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2057 | if (ipw_debug_level & IPW_DL_FW_ERRORS) { |
| 2058 | struct ipw_fw_error *error = |
| 2059 | ipw_alloc_error_log(priv); |
| 2060 | ipw_dump_error_log(priv, error); |
Jesper Juhl | 8f76078 | 2006-06-27 02:55:06 -0700 | [diff] [blame] | 2061 | kfree(error); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2062 | } |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2063 | } else { |
| 2064 | priv->error = ipw_alloc_error_log(priv); |
| 2065 | if (priv->error) |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 2066 | IPW_DEBUG_FW("Sysfs 'error' log captured.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2067 | else |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 2068 | IPW_DEBUG_FW("Error allocating sysfs 'error' " |
| 2069 | "log.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2070 | if (ipw_debug_level & IPW_DL_FW_ERRORS) |
| 2071 | ipw_dump_error_log(priv, priv->error); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2072 | } |
| 2073 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2074 | /* XXX: If hardware encryption is for WPA/WPA2, |
| 2075 | * we have to notify the supplicant. */ |
| 2076 | if (priv->ieee->sec.encrypt) { |
| 2077 | priv->status &= ~STATUS_ASSOCIATED; |
| 2078 | notify_wx_assoc_event(priv); |
| 2079 | } |
| 2080 | |
| 2081 | /* Keep the restart process from trying to send host |
| 2082 | * commands by clearing the INIT status bit */ |
| 2083 | priv->status &= ~STATUS_INIT; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2084 | |
| 2085 | /* Cancel currently queued command. */ |
| 2086 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 2087 | wake_up_interruptible(&priv->wait_command_queue); |
| 2088 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2089 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2090 | handled |= IPW_INTA_BIT_FATAL_ERROR; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2091 | } |
| 2092 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2093 | if (inta & IPW_INTA_BIT_PARITY_ERROR) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2094 | IPW_ERROR("Parity error\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2095 | handled |= IPW_INTA_BIT_PARITY_ERROR; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2096 | } |
| 2097 | |
| 2098 | if (handled != inta) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2099 | IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2100 | } |
| 2101 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 2102 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2103 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2104 | /* enable all interrupts */ |
| 2105 | ipw_enable_interrupts(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2106 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2107 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2108 | #define IPW_CMD(x) case IPW_CMD_ ## x : return #x |
| 2109 | static char *get_cmd_string(u8 cmd) |
| 2110 | { |
| 2111 | switch (cmd) { |
| 2112 | IPW_CMD(HOST_COMPLETE); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2113 | IPW_CMD(POWER_DOWN); |
| 2114 | IPW_CMD(SYSTEM_CONFIG); |
| 2115 | IPW_CMD(MULTICAST_ADDRESS); |
| 2116 | IPW_CMD(SSID); |
| 2117 | IPW_CMD(ADAPTER_ADDRESS); |
| 2118 | IPW_CMD(PORT_TYPE); |
| 2119 | IPW_CMD(RTS_THRESHOLD); |
| 2120 | IPW_CMD(FRAG_THRESHOLD); |
| 2121 | IPW_CMD(POWER_MODE); |
| 2122 | IPW_CMD(WEP_KEY); |
| 2123 | IPW_CMD(TGI_TX_KEY); |
| 2124 | IPW_CMD(SCAN_REQUEST); |
| 2125 | IPW_CMD(SCAN_REQUEST_EXT); |
| 2126 | IPW_CMD(ASSOCIATE); |
| 2127 | IPW_CMD(SUPPORTED_RATES); |
| 2128 | IPW_CMD(SCAN_ABORT); |
| 2129 | IPW_CMD(TX_FLUSH); |
| 2130 | IPW_CMD(QOS_PARAMETERS); |
| 2131 | IPW_CMD(DINO_CONFIG); |
| 2132 | IPW_CMD(RSN_CAPABILITIES); |
| 2133 | IPW_CMD(RX_KEY); |
| 2134 | IPW_CMD(CARD_DISABLE); |
| 2135 | IPW_CMD(SEED_NUMBER); |
| 2136 | IPW_CMD(TX_POWER); |
| 2137 | IPW_CMD(COUNTRY_INFO); |
| 2138 | IPW_CMD(AIRONET_INFO); |
| 2139 | IPW_CMD(AP_TX_POWER); |
| 2140 | IPW_CMD(CCKM_INFO); |
| 2141 | IPW_CMD(CCX_VER_INFO); |
| 2142 | IPW_CMD(SET_CALIBRATION); |
| 2143 | IPW_CMD(SENSITIVITY_CALIB); |
| 2144 | IPW_CMD(RETRY_LIMIT); |
| 2145 | IPW_CMD(IPW_PRE_POWER_DOWN); |
| 2146 | IPW_CMD(VAP_BEACON_TEMPLATE); |
| 2147 | IPW_CMD(VAP_DTIM_PERIOD); |
| 2148 | IPW_CMD(EXT_SUPPORTED_RATES); |
| 2149 | IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT); |
| 2150 | IPW_CMD(VAP_QUIET_INTERVALS); |
| 2151 | IPW_CMD(VAP_CHANNEL_SWITCH); |
| 2152 | IPW_CMD(VAP_MANDATORY_CHANNELS); |
| 2153 | IPW_CMD(VAP_CELL_PWR_LIMIT); |
| 2154 | IPW_CMD(VAP_CF_PARAM_SET); |
| 2155 | IPW_CMD(VAP_SET_BEACONING_STATE); |
| 2156 | IPW_CMD(MEASUREMENT); |
| 2157 | IPW_CMD(POWER_CAPABILITY); |
| 2158 | IPW_CMD(SUPPORTED_CHANNELS); |
| 2159 | IPW_CMD(TPC_REPORT); |
| 2160 | IPW_CMD(WME_INFO); |
| 2161 | IPW_CMD(PRODUCTION_COMMAND); |
| 2162 | default: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2163 | return "UNKNOWN"; |
| 2164 | } |
| 2165 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2166 | |
| 2167 | #define HOST_COMPLETE_TIMEOUT HZ |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2168 | |
| 2169 | 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] | 2170 | { |
| 2171 | int rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2172 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2173 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2174 | spin_lock_irqsave(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2175 | if (priv->status & STATUS_HCMD_ACTIVE) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2176 | IPW_ERROR("Failed to send %s: Already sending a command.\n", |
| 2177 | get_cmd_string(cmd->cmd)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2178 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2179 | return -EAGAIN; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2180 | } |
| 2181 | |
| 2182 | priv->status |= STATUS_HCMD_ACTIVE; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2183 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2184 | if (priv->cmdlog) { |
| 2185 | priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies; |
| 2186 | priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd; |
| 2187 | priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len; |
| 2188 | memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param, |
| 2189 | cmd->len); |
| 2190 | priv->cmdlog[priv->cmdlog_pos].retcode = -1; |
| 2191 | } |
| 2192 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2193 | IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n", |
| 2194 | get_cmd_string(cmd->cmd), cmd->cmd, cmd->len, |
| 2195 | priv->status); |
Zhu Yi | f516dbc | 2006-01-24 16:36:44 +0800 | [diff] [blame] | 2196 | |
| 2197 | #ifndef DEBUG_CMD_WEP_KEY |
| 2198 | if (cmd->cmd == IPW_CMD_WEP_KEY) |
| 2199 | IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n"); |
| 2200 | else |
| 2201 | #endif |
| 2202 | printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len); |
| 2203 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2204 | 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] | 2205 | if (rc) { |
| 2206 | priv->status &= ~STATUS_HCMD_ACTIVE; |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2207 | IPW_ERROR("Failed to send %s: Reason %d\n", |
| 2208 | get_cmd_string(cmd->cmd), rc); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2209 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2210 | goto exit; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2211 | } |
| 2212 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2213 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2214 | rc = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 2215 | !(priv-> |
| 2216 | status & STATUS_HCMD_ACTIVE), |
| 2217 | HOST_COMPLETE_TIMEOUT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2218 | if (rc == 0) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2219 | spin_lock_irqsave(&priv->lock, flags); |
| 2220 | if (priv->status & STATUS_HCMD_ACTIVE) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2221 | IPW_ERROR("Failed to send %s: Command timed out.\n", |
| 2222 | get_cmd_string(cmd->cmd)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2223 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 2224 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2225 | rc = -EIO; |
| 2226 | goto exit; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2227 | } |
| 2228 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 2229 | } else |
| 2230 | rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2231 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2232 | if (priv->status & STATUS_RF_KILL_HW) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2233 | IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n", |
| 2234 | get_cmd_string(cmd->cmd)); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2235 | rc = -EIO; |
| 2236 | goto exit; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2237 | } |
| 2238 | |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2239 | exit: |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2240 | if (priv->cmdlog) { |
| 2241 | priv->cmdlog[priv->cmdlog_pos++].retcode = rc; |
| 2242 | priv->cmdlog_pos %= priv->cmdlog_len; |
| 2243 | } |
| 2244 | return rc; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2245 | } |
| 2246 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2247 | static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2248 | { |
| 2249 | struct host_cmd cmd = { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2250 | .cmd = command, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2251 | }; |
| 2252 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2253 | return __ipw_send_cmd(priv, &cmd); |
| 2254 | } |
| 2255 | |
| 2256 | static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len, |
| 2257 | void *data) |
| 2258 | { |
| 2259 | struct host_cmd cmd = { |
| 2260 | .cmd = command, |
| 2261 | .len = len, |
| 2262 | .param = data, |
| 2263 | }; |
| 2264 | |
| 2265 | return __ipw_send_cmd(priv, &cmd); |
| 2266 | } |
| 2267 | |
| 2268 | static int ipw_send_host_complete(struct ipw_priv *priv) |
| 2269 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2270 | if (!priv) { |
| 2271 | IPW_ERROR("Invalid args\n"); |
| 2272 | return -1; |
| 2273 | } |
| 2274 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2275 | return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2276 | } |
| 2277 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 2278 | static int ipw_send_system_config(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2279 | { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 2280 | return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG, |
| 2281 | sizeof(priv->sys_config), |
| 2282 | &priv->sys_config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2283 | } |
| 2284 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2285 | 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] | 2286 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2287 | if (!priv || !ssid) { |
| 2288 | IPW_ERROR("Invalid args\n"); |
| 2289 | return -1; |
| 2290 | } |
| 2291 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2292 | 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] | 2293 | ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2294 | } |
| 2295 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2296 | static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2297 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2298 | if (!priv || !mac) { |
| 2299 | IPW_ERROR("Invalid args\n"); |
| 2300 | return -1; |
| 2301 | } |
| 2302 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 2303 | IPW_DEBUG_INFO("%s: Setting MAC to %pM\n", |
| 2304 | priv->net_dev->name, mac); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2305 | |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2306 | 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] | 2307 | } |
| 2308 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2309 | /* |
| 2310 | * NOTE: This must be executed from our workqueue as it results in udelay |
| 2311 | * being called which may corrupt the keyboard if executed on default |
| 2312 | * workqueue |
| 2313 | */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2314 | static void ipw_adapter_restart(void *adapter) |
| 2315 | { |
| 2316 | struct ipw_priv *priv = adapter; |
| 2317 | |
| 2318 | if (priv->status & STATUS_RF_KILL_MASK) |
| 2319 | return; |
| 2320 | |
| 2321 | ipw_down(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2322 | |
| 2323 | if (priv->assoc_network && |
| 2324 | (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS)) |
| 2325 | ipw_remove_current_network(priv); |
| 2326 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2327 | if (ipw_up(priv)) { |
| 2328 | IPW_ERROR("Failed to up device\n"); |
| 2329 | return; |
| 2330 | } |
| 2331 | } |
| 2332 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2333 | static void ipw_bg_adapter_restart(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2334 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2335 | struct ipw_priv *priv = |
| 2336 | container_of(work, struct ipw_priv, adapter_restart); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2337 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2338 | ipw_adapter_restart(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2339 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2340 | } |
| 2341 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2342 | #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ) |
| 2343 | |
| 2344 | static void ipw_scan_check(void *data) |
| 2345 | { |
| 2346 | struct ipw_priv *priv = data; |
| 2347 | if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) { |
| 2348 | IPW_DEBUG_SCAN("Scan completion watchdog resetting " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2349 | "adapter after (%dms).\n", |
| 2350 | jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2351 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2352 | } |
| 2353 | } |
| 2354 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2355 | static void ipw_bg_scan_check(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2356 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2357 | struct ipw_priv *priv = |
| 2358 | container_of(work, struct ipw_priv, scan_check.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2359 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2360 | ipw_scan_check(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2361 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2362 | } |
| 2363 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2364 | static int ipw_send_scan_request_ext(struct ipw_priv *priv, |
| 2365 | struct ipw_scan_request_ext *request) |
| 2366 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2367 | return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2368 | sizeof(*request), request); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2369 | } |
| 2370 | |
| 2371 | static int ipw_send_scan_abort(struct ipw_priv *priv) |
| 2372 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2373 | if (!priv) { |
| 2374 | IPW_ERROR("Invalid args\n"); |
| 2375 | return -1; |
| 2376 | } |
| 2377 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2378 | return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2379 | } |
| 2380 | |
| 2381 | static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens) |
| 2382 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2383 | struct ipw_sensitivity_calib calib = { |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 2384 | .beacon_rssi_raw = cpu_to_le16(sens), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2385 | }; |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2386 | |
| 2387 | return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2388 | &calib); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2389 | } |
| 2390 | |
| 2391 | static int ipw_send_associate(struct ipw_priv *priv, |
| 2392 | struct ipw_associate *associate) |
| 2393 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2394 | if (!priv || !associate) { |
| 2395 | IPW_ERROR("Invalid args\n"); |
| 2396 | return -1; |
| 2397 | } |
| 2398 | |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 2399 | return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(*associate), |
| 2400 | associate); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2401 | } |
| 2402 | |
| 2403 | static int ipw_send_supported_rates(struct ipw_priv *priv, |
| 2404 | struct ipw_supported_rates *rates) |
| 2405 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2406 | if (!priv || !rates) { |
| 2407 | IPW_ERROR("Invalid args\n"); |
| 2408 | return -1; |
| 2409 | } |
| 2410 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2411 | return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2412 | rates); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2413 | } |
| 2414 | |
| 2415 | static int ipw_set_random_seed(struct ipw_priv *priv) |
| 2416 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2417 | u32 val; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2418 | |
| 2419 | if (!priv) { |
| 2420 | IPW_ERROR("Invalid args\n"); |
| 2421 | return -1; |
| 2422 | } |
| 2423 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2424 | get_random_bytes(&val, sizeof(val)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2425 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2426 | 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] | 2427 | } |
| 2428 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2429 | static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off) |
| 2430 | { |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2431 | __le32 v = cpu_to_le32(phy_off); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2432 | if (!priv) { |
| 2433 | IPW_ERROR("Invalid args\n"); |
| 2434 | return -1; |
| 2435 | } |
| 2436 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2437 | return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(v), &v); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2438 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2439 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2440 | 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] | 2441 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2442 | if (!priv || !power) { |
| 2443 | IPW_ERROR("Invalid args\n"); |
| 2444 | return -1; |
| 2445 | } |
| 2446 | |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2447 | 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] | 2448 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2449 | |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 2450 | static int ipw_set_tx_power(struct ipw_priv *priv) |
| 2451 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 2452 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 2453 | struct ipw_tx_power tx_power; |
| 2454 | s8 max_power; |
| 2455 | int i; |
| 2456 | |
| 2457 | memset(&tx_power, 0, sizeof(tx_power)); |
| 2458 | |
| 2459 | /* configure device for 'G' band */ |
| 2460 | tx_power.ieee_mode = IPW_G_MODE; |
| 2461 | tx_power.num_channels = geo->bg_channels; |
| 2462 | for (i = 0; i < geo->bg_channels; i++) { |
| 2463 | max_power = geo->bg[i].max_power; |
| 2464 | tx_power.channels_tx_power[i].channel_number = |
| 2465 | geo->bg[i].channel; |
| 2466 | tx_power.channels_tx_power[i].tx_power = max_power ? |
| 2467 | min(max_power, priv->tx_power) : priv->tx_power; |
| 2468 | } |
| 2469 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2470 | return -EIO; |
| 2471 | |
| 2472 | /* configure device to also handle 'B' band */ |
| 2473 | tx_power.ieee_mode = IPW_B_MODE; |
| 2474 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2475 | return -EIO; |
| 2476 | |
| 2477 | /* configure device to also handle 'A' band */ |
| 2478 | if (priv->ieee->abg_true) { |
| 2479 | tx_power.ieee_mode = IPW_A_MODE; |
| 2480 | tx_power.num_channels = geo->a_channels; |
| 2481 | for (i = 0; i < tx_power.num_channels; i++) { |
| 2482 | max_power = geo->a[i].max_power; |
| 2483 | tx_power.channels_tx_power[i].channel_number = |
| 2484 | geo->a[i].channel; |
| 2485 | tx_power.channels_tx_power[i].tx_power = max_power ? |
| 2486 | min(max_power, priv->tx_power) : priv->tx_power; |
| 2487 | } |
| 2488 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2489 | return -EIO; |
| 2490 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2491 | return 0; |
| 2492 | } |
| 2493 | |
| 2494 | static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts) |
| 2495 | { |
| 2496 | struct ipw_rts_threshold rts_threshold = { |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 2497 | .rts_threshold = cpu_to_le16(rts), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2498 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2499 | |
| 2500 | if (!priv) { |
| 2501 | IPW_ERROR("Invalid args\n"); |
| 2502 | return -1; |
| 2503 | } |
| 2504 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2505 | return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD, |
| 2506 | sizeof(rts_threshold), &rts_threshold); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2507 | } |
| 2508 | |
| 2509 | static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag) |
| 2510 | { |
| 2511 | struct ipw_frag_threshold frag_threshold = { |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 2512 | .frag_threshold = cpu_to_le16(frag), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2513 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2514 | |
| 2515 | if (!priv) { |
| 2516 | IPW_ERROR("Invalid args\n"); |
| 2517 | return -1; |
| 2518 | } |
| 2519 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2520 | return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD, |
| 2521 | sizeof(frag_threshold), &frag_threshold); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2522 | } |
| 2523 | |
| 2524 | static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode) |
| 2525 | { |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2526 | __le32 param; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2527 | |
| 2528 | if (!priv) { |
| 2529 | IPW_ERROR("Invalid args\n"); |
| 2530 | return -1; |
| 2531 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2532 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2533 | /* If on battery, set to 3, if AC set to CAM, else user |
| 2534 | * level */ |
| 2535 | switch (mode) { |
| 2536 | case IPW_POWER_BATTERY: |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2537 | param = cpu_to_le32(IPW_POWER_INDEX_3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2538 | break; |
| 2539 | case IPW_POWER_AC: |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2540 | param = cpu_to_le32(IPW_POWER_MODE_CAM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2541 | break; |
| 2542 | default: |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2543 | param = cpu_to_le32(mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2544 | break; |
| 2545 | } |
| 2546 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2547 | return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2548 | ¶m); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2549 | } |
| 2550 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2551 | static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit) |
| 2552 | { |
| 2553 | struct ipw_retry_limit retry_limit = { |
| 2554 | .short_retry_limit = slimit, |
| 2555 | .long_retry_limit = llimit |
| 2556 | }; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2557 | |
| 2558 | if (!priv) { |
| 2559 | IPW_ERROR("Invalid args\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2560 | return -1; |
| 2561 | } |
| 2562 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2563 | 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] | 2564 | &retry_limit); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2565 | } |
| 2566 | |
| 2567 | /* |
| 2568 | * The IPW device contains a Microwire compatible EEPROM that stores |
| 2569 | * various data like the MAC address. Usually the firmware has exclusive |
| 2570 | * access to the eeprom, but during device initialization (before the |
| 2571 | * device driver has sent the HostComplete command to the firmware) the |
| 2572 | * device driver has read access to the EEPROM by way of indirect addressing |
| 2573 | * through a couple of memory mapped registers. |
| 2574 | * |
| 2575 | * The following is a simplified implementation for pulling data out of the |
| 2576 | * the eeprom, along with some helper functions to find information in |
| 2577 | * the per device private data's copy of the eeprom. |
| 2578 | * |
| 2579 | * NOTE: To better understand how these functions work (i.e what is a chip |
| 2580 | * select and why do have to keep driving the eeprom clock?), read |
| 2581 | * just about any data sheet for a Microwire compatible EEPROM. |
| 2582 | */ |
| 2583 | |
| 2584 | /* write a 32 bit value into the indirect accessor register */ |
| 2585 | static inline void eeprom_write_reg(struct ipw_priv *p, u32 data) |
| 2586 | { |
| 2587 | ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2588 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2589 | /* the eeprom requires some time to complete the operation */ |
| 2590 | udelay(p->eeprom_delay); |
| 2591 | |
| 2592 | return; |
| 2593 | } |
| 2594 | |
| 2595 | /* perform a chip select operation */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2596 | static void eeprom_cs(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2597 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2598 | eeprom_write_reg(priv, 0); |
| 2599 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2600 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); |
| 2601 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2602 | } |
| 2603 | |
| 2604 | /* perform a chip select operation */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2605 | static void eeprom_disable_cs(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2606 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2607 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2608 | eeprom_write_reg(priv, 0); |
| 2609 | eeprom_write_reg(priv, EEPROM_BIT_SK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2610 | } |
| 2611 | |
| 2612 | /* push a single bit down to the eeprom */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2613 | static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2614 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2615 | int d = (bit ? EEPROM_BIT_DI : 0); |
| 2616 | eeprom_write_reg(p, EEPROM_BIT_CS | d); |
| 2617 | eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2618 | } |
| 2619 | |
| 2620 | /* push an opcode followed by an address down to the eeprom */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2621 | static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2622 | { |
| 2623 | int i; |
| 2624 | |
| 2625 | eeprom_cs(priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2626 | eeprom_write_bit(priv, 1); |
| 2627 | eeprom_write_bit(priv, op & 2); |
| 2628 | eeprom_write_bit(priv, op & 1); |
| 2629 | for (i = 7; i >= 0; i--) { |
| 2630 | eeprom_write_bit(priv, addr & (1 << i)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2631 | } |
| 2632 | } |
| 2633 | |
| 2634 | /* pull 16 bits off the eeprom, one bit at a time */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2635 | static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2636 | { |
| 2637 | int i; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2638 | u16 r = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2639 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2640 | /* Send READ Opcode */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2641 | eeprom_op(priv, EEPROM_CMD_READ, addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2642 | |
| 2643 | /* Send dummy bit */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2644 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2645 | |
| 2646 | /* Read the byte off the eeprom one bit at a time */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2647 | for (i = 0; i < 16; i++) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2648 | u32 data = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2649 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); |
| 2650 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2651 | data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS); |
| 2652 | r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2653 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2654 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2655 | /* Send another dummy bit */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2656 | eeprom_write_reg(priv, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2657 | eeprom_disable_cs(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2658 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2659 | return r; |
| 2660 | } |
| 2661 | |
| 2662 | /* helper function for pulling the mac address out of the private */ |
| 2663 | /* data's copy of the eeprom data */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2664 | static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2665 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2666 | memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2667 | } |
| 2668 | |
| 2669 | /* |
| 2670 | * Either the device driver (i.e. the host) or the firmware can |
| 2671 | * load eeprom data into the designated region in SRAM. If neither |
| 2672 | * happens then the FW will shutdown with a fatal error. |
| 2673 | * |
| 2674 | * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE |
| 2675 | * bit needs region of shared SRAM needs to be non-zero. |
| 2676 | */ |
| 2677 | static void ipw_eeprom_init_sram(struct ipw_priv *priv) |
| 2678 | { |
| 2679 | int i; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2680 | __le16 *eeprom = (__le16 *) priv->eeprom; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2681 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2682 | IPW_DEBUG_TRACE(">>\n"); |
| 2683 | |
| 2684 | /* read entire contents of eeprom into private buffer */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2685 | for (i = 0; i < 128; i++) |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2686 | eeprom[i] = cpu_to_le16(eeprom_read_u16(priv, (u8) i)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2687 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2688 | /* |
| 2689 | If the data looks correct, then copy it to our private |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2690 | copy. Otherwise let the firmware know to perform the operation |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2691 | on its own. |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2692 | */ |
Alexey Dobriyan | 386093e | 2006-02-01 03:04:57 -0800 | [diff] [blame] | 2693 | if (priv->eeprom[EEPROM_VERSION] != 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2694 | IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n"); |
| 2695 | |
| 2696 | /* write the eeprom data to sram */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2697 | for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2698 | ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2699 | |
| 2700 | /* Do not load eeprom data on fatal error or suspend */ |
| 2701 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); |
| 2702 | } else { |
| 2703 | IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n"); |
| 2704 | |
| 2705 | /* Load eeprom data on fatal error or suspend */ |
| 2706 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1); |
| 2707 | } |
| 2708 | |
| 2709 | IPW_DEBUG_TRACE("<<\n"); |
| 2710 | } |
| 2711 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2712 | 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] | 2713 | { |
| 2714 | count >>= 2; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2715 | if (!count) |
| 2716 | return; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2717 | _ipw_write32(priv, IPW_AUTOINC_ADDR, start); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2718 | while (count--) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2719 | _ipw_write32(priv, IPW_AUTOINC_DATA, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2720 | } |
| 2721 | |
| 2722 | static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv) |
| 2723 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2724 | ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2725 | CB_NUMBER_OF_ELEMENTS_SMALL * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2726 | sizeof(struct command_block)); |
| 2727 | } |
| 2728 | |
| 2729 | static int ipw_fw_dma_enable(struct ipw_priv *priv) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2730 | { /* start dma engine but no transfers yet */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2731 | |
| 2732 | IPW_DEBUG_FW(">> : \n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2733 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2734 | /* Start the dma */ |
| 2735 | ipw_fw_dma_reset_command_blocks(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2736 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2737 | /* Write CB base address */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2738 | 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] | 2739 | |
| 2740 | IPW_DEBUG_FW("<< : \n"); |
| 2741 | return 0; |
| 2742 | } |
| 2743 | |
| 2744 | static void ipw_fw_dma_abort(struct ipw_priv *priv) |
| 2745 | { |
| 2746 | u32 control = 0; |
| 2747 | |
| 2748 | IPW_DEBUG_FW(">> :\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2749 | |
Pavel Machek | 67fd6b4 | 2006-07-11 15:34:05 +0200 | [diff] [blame] | 2750 | /* set the Stop and Abort bit */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2751 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2752 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2753 | priv->sram_desc.last_cb_index = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2754 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2755 | IPW_DEBUG_FW("<< \n"); |
| 2756 | } |
| 2757 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2758 | static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index, |
| 2759 | struct command_block *cb) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2760 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2761 | u32 address = |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2762 | IPW_SHARED_SRAM_DMA_CONTROL + |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2763 | (sizeof(struct command_block) * index); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2764 | IPW_DEBUG_FW(">> :\n"); |
| 2765 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2766 | ipw_write_indirect(priv, address, (u8 *) cb, |
| 2767 | (int)sizeof(struct command_block)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2768 | |
| 2769 | IPW_DEBUG_FW("<< :\n"); |
| 2770 | return 0; |
| 2771 | |
| 2772 | } |
| 2773 | |
| 2774 | static int ipw_fw_dma_kick(struct ipw_priv *priv) |
| 2775 | { |
| 2776 | u32 control = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2777 | u32 index = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2778 | |
| 2779 | IPW_DEBUG_FW(">> :\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2780 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2781 | for (index = 0; index < priv->sram_desc.last_cb_index; index++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2782 | ipw_fw_dma_write_command_block(priv, index, |
| 2783 | &priv->sram_desc.cb_list[index]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2784 | |
| 2785 | /* Enable the DMA in the CSR register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2786 | ipw_clear_bit(priv, IPW_RESET_REG, |
| 2787 | IPW_RESET_REG_MASTER_DISABLED | |
| 2788 | IPW_RESET_REG_STOP_MASTER); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2789 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2790 | /* Set the Start bit. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2791 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2792 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2793 | |
| 2794 | IPW_DEBUG_FW("<< :\n"); |
| 2795 | return 0; |
| 2796 | } |
| 2797 | |
| 2798 | static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv) |
| 2799 | { |
| 2800 | u32 address; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2801 | u32 register_value = 0; |
| 2802 | u32 cb_fields_address = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2803 | |
| 2804 | IPW_DEBUG_FW(">> :\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2805 | address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2806 | IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2807 | |
| 2808 | /* Read the DMA Controlor register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2809 | register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL); |
| 2810 | 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] | 2811 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2812 | /* Print the CB values */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2813 | cb_fields_address = address; |
| 2814 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2815 | 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] | 2816 | |
| 2817 | cb_fields_address += sizeof(u32); |
| 2818 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2819 | 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] | 2820 | |
| 2821 | cb_fields_address += sizeof(u32); |
| 2822 | register_value = ipw_read_reg32(priv, cb_fields_address); |
| 2823 | IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n", |
| 2824 | register_value); |
| 2825 | |
| 2826 | cb_fields_address += sizeof(u32); |
| 2827 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2828 | 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] | 2829 | |
| 2830 | IPW_DEBUG_FW(">> :\n"); |
| 2831 | } |
| 2832 | |
| 2833 | static int ipw_fw_dma_command_block_index(struct ipw_priv *priv) |
| 2834 | { |
| 2835 | u32 current_cb_address = 0; |
| 2836 | u32 current_cb_index = 0; |
| 2837 | |
| 2838 | IPW_DEBUG_FW("<< :\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2839 | current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2840 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2841 | current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2842 | sizeof(struct command_block); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2843 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2844 | 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] | 2845 | current_cb_index, current_cb_address); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2846 | |
| 2847 | IPW_DEBUG_FW(">> :\n"); |
| 2848 | return current_cb_index; |
| 2849 | |
| 2850 | } |
| 2851 | |
| 2852 | static int ipw_fw_dma_add_command_block(struct ipw_priv *priv, |
| 2853 | u32 src_address, |
| 2854 | u32 dest_address, |
| 2855 | u32 length, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2856 | int interrupt_enabled, int is_last) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2857 | { |
| 2858 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2859 | 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] | 2860 | CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG | |
| 2861 | CB_DEST_SIZE_LONG; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2862 | struct command_block *cb; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2863 | u32 last_cb_element = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2864 | |
| 2865 | IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n", |
| 2866 | src_address, dest_address, length); |
| 2867 | |
| 2868 | if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL) |
| 2869 | return -1; |
| 2870 | |
| 2871 | last_cb_element = priv->sram_desc.last_cb_index; |
| 2872 | cb = &priv->sram_desc.cb_list[last_cb_element]; |
| 2873 | priv->sram_desc.last_cb_index++; |
| 2874 | |
| 2875 | /* Calculate the new CB control word */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2876 | if (interrupt_enabled) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2877 | control |= CB_INT_ENABLED; |
| 2878 | |
| 2879 | if (is_last) |
| 2880 | control |= CB_LAST_VALID; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2881 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2882 | control |= length; |
| 2883 | |
| 2884 | /* Calculate the CB Element's checksum value */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2885 | cb->status = control ^ src_address ^ dest_address; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2886 | |
| 2887 | /* Copy the Source and Destination addresses */ |
| 2888 | cb->dest_addr = dest_address; |
| 2889 | cb->source_addr = src_address; |
| 2890 | |
| 2891 | /* Copy the Control Word last */ |
| 2892 | cb->control = control; |
| 2893 | |
| 2894 | return 0; |
| 2895 | } |
| 2896 | |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 2897 | static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, dma_addr_t *src_address, |
| 2898 | int nr, u32 dest_address, u32 len) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2899 | { |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 2900 | int ret, i; |
| 2901 | u32 size; |
| 2902 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2903 | IPW_DEBUG_FW(">> \n"); |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 2904 | IPW_DEBUG_FW_INFO("nr=%d dest_address=0x%x len=0x%x\n", |
| 2905 | nr, dest_address, len); |
| 2906 | |
| 2907 | for (i = 0; i < nr; i++) { |
| 2908 | size = min_t(u32, len - i * CB_MAX_LENGTH, CB_MAX_LENGTH); |
| 2909 | ret = ipw_fw_dma_add_command_block(priv, src_address[i], |
| 2910 | dest_address + |
| 2911 | i * CB_MAX_LENGTH, size, |
| 2912 | 0, 0); |
| 2913 | if (ret) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2914 | IPW_DEBUG_FW_INFO(": Failed\n"); |
| 2915 | return -1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2916 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2917 | IPW_DEBUG_FW_INFO(": Added new cb\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2918 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2919 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2920 | IPW_DEBUG_FW("<< \n"); |
| 2921 | return 0; |
| 2922 | } |
| 2923 | |
| 2924 | static int ipw_fw_dma_wait(struct ipw_priv *priv) |
| 2925 | { |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2926 | u32 current_index = 0, previous_index; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2927 | u32 watchdog = 0; |
| 2928 | |
| 2929 | IPW_DEBUG_FW(">> : \n"); |
| 2930 | |
| 2931 | current_index = ipw_fw_dma_command_block_index(priv); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2932 | IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2933 | (int)priv->sram_desc.last_cb_index); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2934 | |
| 2935 | while (current_index < priv->sram_desc.last_cb_index) { |
| 2936 | udelay(50); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2937 | previous_index = current_index; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2938 | current_index = ipw_fw_dma_command_block_index(priv); |
| 2939 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2940 | if (previous_index < current_index) { |
| 2941 | watchdog = 0; |
| 2942 | continue; |
| 2943 | } |
| 2944 | if (++watchdog > 400) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2945 | IPW_DEBUG_FW_INFO("Timeout\n"); |
| 2946 | ipw_fw_dma_dump_command_block(priv); |
| 2947 | ipw_fw_dma_abort(priv); |
| 2948 | return -1; |
| 2949 | } |
| 2950 | } |
| 2951 | |
| 2952 | ipw_fw_dma_abort(priv); |
| 2953 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2954 | /*Disable the DMA in the CSR register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2955 | ipw_set_bit(priv, IPW_RESET_REG, |
| 2956 | IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2957 | |
| 2958 | IPW_DEBUG_FW("<< dmaWaitSync \n"); |
| 2959 | return 0; |
| 2960 | } |
| 2961 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2962 | static void ipw_remove_current_network(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2963 | { |
| 2964 | struct list_head *element, *safe; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 2965 | struct libipw_network *network = NULL; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2966 | unsigned long flags; |
| 2967 | |
| 2968 | spin_lock_irqsave(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2969 | list_for_each_safe(element, safe, &priv->ieee->network_list) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 2970 | network = list_entry(element, struct libipw_network, list); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2971 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
| 2972 | list_del(element); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2973 | list_add_tail(&network->list, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2974 | &priv->ieee->network_free_list); |
| 2975 | } |
| 2976 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2977 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2978 | } |
| 2979 | |
| 2980 | /** |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2981 | * Check that card is still alive. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2982 | * Reads debug register from domain0. |
| 2983 | * If card is present, pre-defined value should |
| 2984 | * be found there. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2985 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2986 | * @param priv |
| 2987 | * @return 1 if card is present, 0 otherwise |
| 2988 | */ |
| 2989 | static inline int ipw_alive(struct ipw_priv *priv) |
| 2990 | { |
| 2991 | return ipw_read32(priv, 0x90) == 0xd55555d5; |
| 2992 | } |
| 2993 | |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2994 | /* timeout in msec, attempted in 10-msec quanta */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2995 | 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] | 2996 | int timeout) |
| 2997 | { |
| 2998 | int i = 0; |
| 2999 | |
| 3000 | do { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3001 | if ((ipw_read32(priv, addr) & mask) == mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3002 | return i; |
| 3003 | mdelay(10); |
| 3004 | i += 10; |
| 3005 | } while (i < timeout); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3006 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3007 | return -ETIME; |
| 3008 | } |
| 3009 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3010 | /* These functions load the firmware and micro code for the operation of |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3011 | * the ipw hardware. It assumes the buffer has all the bits for the |
| 3012 | * image and the caller is handling the memory allocation and clean up. |
| 3013 | */ |
| 3014 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3015 | static int ipw_stop_master(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3016 | { |
| 3017 | int rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3018 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3019 | IPW_DEBUG_TRACE(">> \n"); |
| 3020 | /* stop master. typical delay - 0 */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3021 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3022 | |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3023 | /* timeout is in msec, polled in 10-msec quanta */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3024 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
| 3025 | IPW_RESET_REG_MASTER_DISABLED, 100); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3026 | if (rc < 0) { |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3027 | IPW_ERROR("wait for stop master failed after 100ms\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3028 | return -1; |
| 3029 | } |
| 3030 | |
| 3031 | IPW_DEBUG_INFO("stop master %dms\n", rc); |
| 3032 | |
| 3033 | return rc; |
| 3034 | } |
| 3035 | |
| 3036 | static void ipw_arc_release(struct ipw_priv *priv) |
| 3037 | { |
| 3038 | IPW_DEBUG_TRACE(">> \n"); |
| 3039 | mdelay(5); |
| 3040 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3041 | ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3042 | |
| 3043 | /* no one knows timing, for safety add some delay */ |
| 3044 | mdelay(5); |
| 3045 | } |
| 3046 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3047 | struct fw_chunk { |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3048 | __le32 address; |
| 3049 | __le32 length; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3050 | }; |
| 3051 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3052 | 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] | 3053 | { |
| 3054 | int rc = 0, i, addr; |
| 3055 | u8 cr = 0; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3056 | __le16 *image; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3057 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3058 | image = (__le16 *) data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3059 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3060 | IPW_DEBUG_TRACE(">> \n"); |
| 3061 | |
| 3062 | rc = ipw_stop_master(priv); |
| 3063 | |
| 3064 | if (rc < 0) |
| 3065 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3066 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3067 | for (addr = IPW_SHARED_LOWER_BOUND; |
| 3068 | addr < IPW_REGISTER_DOMAIN1_END; addr += 4) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3069 | ipw_write32(priv, addr, 0); |
| 3070 | } |
| 3071 | |
| 3072 | /* no ucode (yet) */ |
| 3073 | memset(&priv->dino_alive, 0, sizeof(priv->dino_alive)); |
| 3074 | /* destroy DMA queues */ |
| 3075 | /* reset sequence */ |
| 3076 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3077 | 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] | 3078 | ipw_arc_release(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3079 | 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] | 3080 | mdelay(1); |
| 3081 | |
| 3082 | /* reset PHY */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3083 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3084 | mdelay(1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3085 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3086 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3087 | mdelay(1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3088 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3089 | /* enable ucode store */ |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 3090 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0); |
| 3091 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3092 | mdelay(1); |
| 3093 | |
| 3094 | /* write ucode */ |
| 3095 | /** |
| 3096 | * @bug |
| 3097 | * Do NOT set indirect address register once and then |
| 3098 | * store data to indirect data register in the loop. |
| 3099 | * It seems very reasonable, but in this case DINO do not |
| 3100 | * accept ucode. It is essential to set address each time. |
| 3101 | */ |
| 3102 | /* load new ipw uCode */ |
| 3103 | for (i = 0; i < len / 2; i++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3104 | ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE, |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3105 | le16_to_cpu(image[i])); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3106 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3107 | /* enable DINO */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3108 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
| 3109 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3110 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3111 | /* this is where the igx / win driver deveates from the VAP driver. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3112 | |
| 3113 | /* wait for alive response */ |
| 3114 | for (i = 0; i < 100; i++) { |
| 3115 | /* poll for incoming data */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3116 | cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3117 | if (cr & DINO_RXFIFO_DATA) |
| 3118 | break; |
| 3119 | mdelay(1); |
| 3120 | } |
| 3121 | |
| 3122 | if (cr & DINO_RXFIFO_DATA) { |
| 3123 | /* alive_command_responce size is NOT multiple of 4 */ |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3124 | __le32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4]; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3125 | |
| 3126 | for (i = 0; i < ARRAY_SIZE(response_buffer); i++) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3127 | response_buffer[i] = |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3128 | cpu_to_le32(ipw_read_reg32(priv, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3129 | IPW_BASEBAND_RX_FIFO_READ)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3130 | memcpy(&priv->dino_alive, response_buffer, |
| 3131 | sizeof(priv->dino_alive)); |
| 3132 | if (priv->dino_alive.alive_command == 1 |
| 3133 | && priv->dino_alive.ucode_valid == 1) { |
| 3134 | rc = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3135 | IPW_DEBUG_INFO |
| 3136 | ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) " |
| 3137 | "of %02d/%02d/%02d %02d:%02d\n", |
| 3138 | priv->dino_alive.software_revision, |
| 3139 | priv->dino_alive.software_revision, |
| 3140 | priv->dino_alive.device_identifier, |
| 3141 | priv->dino_alive.device_identifier, |
| 3142 | priv->dino_alive.time_stamp[0], |
| 3143 | priv->dino_alive.time_stamp[1], |
| 3144 | priv->dino_alive.time_stamp[2], |
| 3145 | priv->dino_alive.time_stamp[3], |
| 3146 | priv->dino_alive.time_stamp[4]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3147 | } else { |
| 3148 | IPW_DEBUG_INFO("Microcode is not alive\n"); |
| 3149 | rc = -EINVAL; |
| 3150 | } |
| 3151 | } else { |
| 3152 | IPW_DEBUG_INFO("No alive response from DINO\n"); |
| 3153 | rc = -ETIME; |
| 3154 | } |
| 3155 | |
| 3156 | /* disable DINO, otherwise for some reason |
| 3157 | firmware have problem getting alive resp. */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3158 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3159 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3160 | return rc; |
| 3161 | } |
| 3162 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3163 | 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] | 3164 | { |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3165 | int ret = -1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3166 | int offset = 0; |
| 3167 | struct fw_chunk *chunk; |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3168 | int total_nr = 0; |
| 3169 | int i; |
| 3170 | struct pci_pool *pool; |
| 3171 | u32 *virts[CB_NUMBER_OF_ELEMENTS_SMALL]; |
| 3172 | dma_addr_t phys[CB_NUMBER_OF_ELEMENTS_SMALL]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3173 | |
| 3174 | IPW_DEBUG_TRACE("<< : \n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3175 | |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3176 | pool = pci_pool_create("ipw2200", priv->pci_dev, CB_MAX_LENGTH, 0, 0); |
| 3177 | if (!pool) { |
| 3178 | IPW_ERROR("pci_pool_create failed\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3179 | return -ENOMEM; |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3180 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3181 | |
| 3182 | /* Start the Dma */ |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3183 | ret = ipw_fw_dma_enable(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3184 | |
Alexander Beregalov | 0ee904c | 2009-04-11 14:50:23 +0000 | [diff] [blame] | 3185 | /* the DMA is already ready this would be a bug. */ |
| 3186 | BUG_ON(priv->sram_desc.last_cb_index > 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3187 | |
| 3188 | do { |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3189 | u32 chunk_len; |
| 3190 | u8 *start; |
| 3191 | int size; |
| 3192 | int nr = 0; |
| 3193 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3194 | chunk = (struct fw_chunk *)(data + offset); |
| 3195 | offset += sizeof(struct fw_chunk); |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3196 | chunk_len = le32_to_cpu(chunk->length); |
| 3197 | start = data + offset; |
| 3198 | |
| 3199 | nr = (chunk_len + CB_MAX_LENGTH - 1) / CB_MAX_LENGTH; |
| 3200 | for (i = 0; i < nr; i++) { |
| 3201 | virts[total_nr] = pci_pool_alloc(pool, GFP_KERNEL, |
| 3202 | &phys[total_nr]); |
| 3203 | if (!virts[total_nr]) { |
| 3204 | ret = -ENOMEM; |
| 3205 | goto out; |
| 3206 | } |
| 3207 | size = min_t(u32, chunk_len - i * CB_MAX_LENGTH, |
| 3208 | CB_MAX_LENGTH); |
| 3209 | memcpy(virts[total_nr], start, size); |
| 3210 | start += size; |
| 3211 | total_nr++; |
| 3212 | /* We don't support fw chunk larger than 64*8K */ |
| 3213 | BUG_ON(total_nr > CB_NUMBER_OF_ELEMENTS_SMALL); |
| 3214 | } |
| 3215 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3216 | /* build DMA packet and queue up for sending */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3217 | /* dma to chunk->address, the chunk->length bytes from data + |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3218 | * offeset*/ |
| 3219 | /* Dma loading */ |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3220 | ret = ipw_fw_dma_add_buffer(priv, &phys[total_nr - nr], |
| 3221 | nr, le32_to_cpu(chunk->address), |
| 3222 | chunk_len); |
| 3223 | if (ret) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3224 | IPW_DEBUG_INFO("dmaAddBuffer Failed\n"); |
| 3225 | goto out; |
| 3226 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3227 | |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3228 | offset += chunk_len; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3229 | } while (offset < len); |
| 3230 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3231 | /* Run the DMA and wait for the answer */ |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3232 | ret = ipw_fw_dma_kick(priv); |
| 3233 | if (ret) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3234 | IPW_ERROR("dmaKick Failed\n"); |
| 3235 | goto out; |
| 3236 | } |
| 3237 | |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3238 | ret = ipw_fw_dma_wait(priv); |
| 3239 | if (ret) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3240 | IPW_ERROR("dmaWaitSync Failed\n"); |
| 3241 | goto out; |
| 3242 | } |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3243 | out: |
| 3244 | for (i = 0; i < total_nr; i++) |
| 3245 | pci_pool_free(pool, virts[i], phys[i]); |
| 3246 | |
| 3247 | pci_pool_destroy(pool); |
| 3248 | |
| 3249 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3250 | } |
| 3251 | |
| 3252 | /* stop nic */ |
| 3253 | static int ipw_stop_nic(struct ipw_priv *priv) |
| 3254 | { |
| 3255 | int rc = 0; |
| 3256 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3257 | /* stop */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3258 | ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3259 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3260 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
| 3261 | IPW_RESET_REG_MASTER_DISABLED, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3262 | if (rc < 0) { |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3263 | IPW_ERROR("wait for reg master disabled failed after 500ms\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3264 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3265 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3266 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3267 | ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3268 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3269 | return rc; |
| 3270 | } |
| 3271 | |
| 3272 | static void ipw_start_nic(struct ipw_priv *priv) |
| 3273 | { |
| 3274 | IPW_DEBUG_TRACE(">>\n"); |
| 3275 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3276 | /* prvHwStartNic release ARC */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3277 | ipw_clear_bit(priv, IPW_RESET_REG, |
| 3278 | IPW_RESET_REG_MASTER_DISABLED | |
| 3279 | IPW_RESET_REG_STOP_MASTER | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3280 | CBD_RESET_REG_PRINCETON_RESET); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3281 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3282 | /* enable power management */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3283 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, |
| 3284 | IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3285 | |
| 3286 | IPW_DEBUG_TRACE("<<\n"); |
| 3287 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3288 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3289 | static int ipw_init_nic(struct ipw_priv *priv) |
| 3290 | { |
| 3291 | int rc; |
| 3292 | |
| 3293 | IPW_DEBUG_TRACE(">>\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3294 | /* reset */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3295 | /*prvHwInitNic */ |
| 3296 | /* set "initialization complete" bit to move adapter to D0 state */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3297 | 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] | 3298 | |
| 3299 | /* low-level PLL activation */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3300 | ipw_write32(priv, IPW_READ_INT_REGISTER, |
| 3301 | IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3302 | |
| 3303 | /* wait for clock stabilization */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3304 | rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW, |
| 3305 | IPW_GP_CNTRL_BIT_CLOCK_READY, 250); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3306 | if (rc < 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3307 | IPW_DEBUG_INFO("FAILED wait for clock stablization\n"); |
| 3308 | |
| 3309 | /* assert SW reset */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3310 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3311 | |
| 3312 | udelay(10); |
| 3313 | |
| 3314 | /* set "initialization complete" bit to move adapter to D0 state */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3315 | 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] | 3316 | |
| 3317 | IPW_DEBUG_TRACE(">>\n"); |
| 3318 | return 0; |
| 3319 | } |
| 3320 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3321 | /* Call this function from process context, it will sleep in request_firmware. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3322 | * Probe is an ok place to call this from. |
| 3323 | */ |
| 3324 | static int ipw_reset_nic(struct ipw_priv *priv) |
| 3325 | { |
| 3326 | int rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3327 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3328 | |
| 3329 | IPW_DEBUG_TRACE(">>\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3330 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3331 | rc = ipw_init_nic(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3332 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3333 | spin_lock_irqsave(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3334 | /* Clear the 'host command active' bit... */ |
| 3335 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 3336 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3337 | priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); |
| 3338 | wake_up_interruptible(&priv->wait_state); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3339 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3340 | |
| 3341 | IPW_DEBUG_TRACE("<<\n"); |
| 3342 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3343 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3344 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3345 | |
| 3346 | struct ipw_fw { |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3347 | __le32 ver; |
| 3348 | __le32 boot_size; |
| 3349 | __le32 ucode_size; |
| 3350 | __le32 fw_size; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3351 | u8 data[0]; |
| 3352 | }; |
| 3353 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3354 | static int ipw_get_fw(struct ipw_priv *priv, |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3355 | const struct firmware **raw, const char *name) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3356 | { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3357 | struct ipw_fw *fw; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3358 | int rc; |
| 3359 | |
| 3360 | /* ask firmware_class module to get the boot firmware off disk */ |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3361 | rc = request_firmware(raw, name, &priv->pci_dev->dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3362 | if (rc < 0) { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3363 | IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3364 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3365 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3366 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3367 | if ((*raw)->size < sizeof(*fw)) { |
| 3368 | IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3369 | return -EINVAL; |
| 3370 | } |
| 3371 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3372 | fw = (void *)(*raw)->data; |
| 3373 | |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3374 | if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) + |
| 3375 | le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3376 | IPW_ERROR("%s is too small or corrupt (%zd)\n", |
| 3377 | name, (*raw)->size); |
| 3378 | return -EINVAL; |
| 3379 | } |
| 3380 | |
| 3381 | 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] | 3382 | name, |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3383 | le32_to_cpu(fw->ver) >> 16, |
| 3384 | le32_to_cpu(fw->ver) & 0xff, |
| 3385 | (*raw)->size - sizeof(*fw)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3386 | return 0; |
| 3387 | } |
| 3388 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3389 | #define IPW_RX_BUF_SIZE (3000) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3390 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3391 | static void ipw_rx_queue_reset(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3392 | struct ipw_rx_queue *rxq) |
| 3393 | { |
| 3394 | unsigned long flags; |
| 3395 | int i; |
| 3396 | |
| 3397 | spin_lock_irqsave(&rxq->lock, flags); |
| 3398 | |
| 3399 | INIT_LIST_HEAD(&rxq->rx_free); |
| 3400 | INIT_LIST_HEAD(&rxq->rx_used); |
| 3401 | |
| 3402 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 3403 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { |
| 3404 | /* In the reset function, these buffers may have been allocated |
| 3405 | * to an SKB, so we need to unmap and free potential storage */ |
| 3406 | if (rxq->pool[i].skb != NULL) { |
| 3407 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3408 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3409 | dev_kfree_skb(rxq->pool[i].skb); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3410 | rxq->pool[i].skb = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3411 | } |
| 3412 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 3413 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3414 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3415 | /* Set us so that we have processed and used all buffers, but have |
| 3416 | * not restocked the Rx queue with fresh buffers */ |
| 3417 | rxq->read = rxq->write = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3418 | rxq->free_count = 0; |
| 3419 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3420 | } |
| 3421 | |
| 3422 | #ifdef CONFIG_PM |
| 3423 | static int fw_loaded = 0; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3424 | static const struct firmware *raw = NULL; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3425 | |
| 3426 | static void free_firmware(void) |
| 3427 | { |
| 3428 | if (fw_loaded) { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3429 | release_firmware(raw); |
| 3430 | raw = NULL; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3431 | fw_loaded = 0; |
| 3432 | } |
| 3433 | } |
| 3434 | #else |
| 3435 | #define free_firmware() do {} while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3436 | #endif |
| 3437 | |
| 3438 | static int ipw_load(struct ipw_priv *priv) |
| 3439 | { |
| 3440 | #ifndef CONFIG_PM |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3441 | const struct firmware *raw = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3442 | #endif |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3443 | struct ipw_fw *fw; |
| 3444 | u8 *boot_img, *ucode_img, *fw_img; |
| 3445 | u8 *name = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3446 | int rc = 0, retries = 3; |
| 3447 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3448 | switch (priv->ieee->iw_mode) { |
| 3449 | case IW_MODE_ADHOC: |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3450 | name = "ipw2200-ibss.fw"; |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3451 | break; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3452 | #ifdef CONFIG_IPW2200_MONITOR |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3453 | case IW_MODE_MONITOR: |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3454 | name = "ipw2200-sniffer.fw"; |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3455 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3456 | #endif |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3457 | case IW_MODE_INFRA: |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3458 | name = "ipw2200-bss.fw"; |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3459 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3460 | } |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3461 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3462 | if (!name) { |
| 3463 | rc = -EINVAL; |
| 3464 | goto error; |
| 3465 | } |
| 3466 | |
| 3467 | #ifdef CONFIG_PM |
| 3468 | if (!fw_loaded) { |
| 3469 | #endif |
| 3470 | rc = ipw_get_fw(priv, &raw, name); |
| 3471 | if (rc < 0) |
| 3472 | goto error; |
| 3473 | #ifdef CONFIG_PM |
| 3474 | } |
| 3475 | #endif |
| 3476 | |
| 3477 | fw = (void *)raw->data; |
| 3478 | boot_img = &fw->data[0]; |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3479 | ucode_img = &fw->data[le32_to_cpu(fw->boot_size)]; |
| 3480 | fw_img = &fw->data[le32_to_cpu(fw->boot_size) + |
| 3481 | le32_to_cpu(fw->ucode_size)]; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3482 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3483 | if (rc < 0) |
| 3484 | goto error; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3485 | |
| 3486 | if (!priv->rxq) |
| 3487 | priv->rxq = ipw_rx_queue_alloc(priv); |
| 3488 | else |
| 3489 | ipw_rx_queue_reset(priv, priv->rxq); |
| 3490 | if (!priv->rxq) { |
| 3491 | IPW_ERROR("Unable to initialize Rx queue\n"); |
| 3492 | goto error; |
| 3493 | } |
| 3494 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3495 | retry: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3496 | /* Ensure interrupts are disabled */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3497 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3498 | priv->status &= ~STATUS_INT_ENABLED; |
| 3499 | |
| 3500 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3501 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3502 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3503 | ipw_stop_nic(priv); |
| 3504 | |
| 3505 | rc = ipw_reset_nic(priv); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3506 | if (rc < 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3507 | IPW_ERROR("Unable to reset NIC\n"); |
| 3508 | goto error; |
| 3509 | } |
| 3510 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3511 | ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND, |
| 3512 | IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3513 | |
| 3514 | /* DMA the initial boot firmware into the device */ |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3515 | 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] | 3516 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3517 | IPW_ERROR("Unable to load boot firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3518 | goto error; |
| 3519 | } |
| 3520 | |
| 3521 | /* kick start the device */ |
| 3522 | ipw_start_nic(priv); |
| 3523 | |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3524 | /* wait for the device to finish its initial startup sequence */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3525 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
| 3526 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3527 | if (rc < 0) { |
| 3528 | IPW_ERROR("device failed to boot initial fw image\n"); |
| 3529 | goto error; |
| 3530 | } |
| 3531 | IPW_DEBUG_INFO("initial device response after %dms\n", rc); |
| 3532 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3533 | /* ack fw init done interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3534 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3535 | |
| 3536 | /* DMA the ucode into the device */ |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3537 | 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] | 3538 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3539 | IPW_ERROR("Unable to load ucode: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3540 | goto error; |
| 3541 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3542 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3543 | /* stop nic */ |
| 3544 | ipw_stop_nic(priv); |
| 3545 | |
| 3546 | /* DMA bss firmware into the device */ |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3547 | 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] | 3548 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3549 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3550 | goto error; |
| 3551 | } |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3552 | #ifdef CONFIG_PM |
| 3553 | fw_loaded = 1; |
| 3554 | #endif |
| 3555 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3556 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); |
| 3557 | |
| 3558 | rc = ipw_queue_reset(priv); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3559 | if (rc < 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3560 | IPW_ERROR("Unable to initialize queues\n"); |
| 3561 | goto error; |
| 3562 | } |
| 3563 | |
| 3564 | /* Ensure interrupts are disabled */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3565 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3566 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3567 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3568 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3569 | /* kick start the device */ |
| 3570 | ipw_start_nic(priv); |
| 3571 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3572 | if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3573 | if (retries > 0) { |
| 3574 | IPW_WARNING("Parity error. Retrying init.\n"); |
| 3575 | retries--; |
| 3576 | goto retry; |
| 3577 | } |
| 3578 | |
| 3579 | IPW_ERROR("TODO: Handle parity error -- schedule restart?\n"); |
| 3580 | rc = -EIO; |
| 3581 | goto error; |
| 3582 | } |
| 3583 | |
| 3584 | /* wait for the device */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3585 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
| 3586 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3587 | if (rc < 0) { |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3588 | IPW_ERROR("device failed to start within 500ms\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3589 | goto error; |
| 3590 | } |
| 3591 | IPW_DEBUG_INFO("device response after %dms\n", rc); |
| 3592 | |
| 3593 | /* ack fw init done interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3594 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3595 | |
| 3596 | /* read eeprom data and initialize the eeprom region of sram */ |
| 3597 | priv->eeprom_delay = 1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3598 | ipw_eeprom_init_sram(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3599 | |
| 3600 | /* enable interrupts */ |
| 3601 | ipw_enable_interrupts(priv); |
| 3602 | |
| 3603 | /* Ensure our queue has valid packets */ |
| 3604 | ipw_rx_queue_replenish(priv); |
| 3605 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3606 | ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3607 | |
| 3608 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3609 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3610 | |
| 3611 | #ifndef CONFIG_PM |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3612 | release_firmware(raw); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3613 | #endif |
| 3614 | return 0; |
| 3615 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3616 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3617 | if (priv->rxq) { |
| 3618 | ipw_rx_queue_free(priv, priv->rxq); |
| 3619 | priv->rxq = NULL; |
| 3620 | } |
| 3621 | ipw_tx_queue_free(priv); |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3622 | if (raw) |
| 3623 | release_firmware(raw); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3624 | #ifdef CONFIG_PM |
| 3625 | fw_loaded = 0; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3626 | raw = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3627 | #endif |
| 3628 | |
| 3629 | return rc; |
| 3630 | } |
| 3631 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3632 | /** |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3633 | * DMA services |
| 3634 | * |
| 3635 | * Theory of operation |
| 3636 | * |
| 3637 | * A queue is a circular buffers with 'Read' and 'Write' pointers. |
| 3638 | * 2 empty entries always kept in the buffer to protect from overflow. |
| 3639 | * |
| 3640 | * 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] | 3641 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 3642 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3643 | * Tx queue resumed. |
| 3644 | * |
| 3645 | * The IPW operates with six queues, one receive queue in the device's |
| 3646 | * sram, one transmit queue for sending commands to the device firmware, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3647 | * and four transmit queues for data. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3648 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3649 | * The four transmit queues allow for performing quality of service (qos) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3650 | * transmissions as per the 802.11 protocol. Currently Linux does not |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3651 | * provide a mechanism to the user for utilizing prioritized queues, so |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3652 | * we only utilize the first data transmit queue (queue1). |
| 3653 | */ |
| 3654 | |
| 3655 | /** |
| 3656 | * Driver allocates buffers of this size for Rx |
| 3657 | */ |
| 3658 | |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 3659 | /** |
| 3660 | * ipw_rx_queue_space - Return number of free slots available in queue. |
| 3661 | */ |
| 3662 | static int ipw_rx_queue_space(const struct ipw_rx_queue *q) |
| 3663 | { |
| 3664 | int s = q->read - q->write; |
| 3665 | if (s <= 0) |
| 3666 | s += RX_QUEUE_SIZE; |
| 3667 | /* keep some buffer to not confuse full and empty queue */ |
| 3668 | s -= 2; |
| 3669 | if (s < 0) |
| 3670 | s = 0; |
| 3671 | return s; |
| 3672 | } |
| 3673 | |
| 3674 | static inline int ipw_tx_queue_space(const struct clx2_queue *q) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3675 | { |
| 3676 | int s = q->last_used - q->first_empty; |
| 3677 | if (s <= 0) |
| 3678 | s += q->n_bd; |
| 3679 | s -= 2; /* keep some reserve to not confuse empty and full situations */ |
| 3680 | if (s < 0) |
| 3681 | s = 0; |
| 3682 | return s; |
| 3683 | } |
| 3684 | |
| 3685 | static inline int ipw_queue_inc_wrap(int index, int n_bd) |
| 3686 | { |
| 3687 | return (++index == n_bd) ? 0 : index; |
| 3688 | } |
| 3689 | |
| 3690 | /** |
| 3691 | * Initialize common DMA queue structure |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3692 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3693 | * @param q queue to init |
| 3694 | * @param count Number of BD's to allocate. Should be power of 2 |
| 3695 | * @param read_register Address for 'read' register |
| 3696 | * (not offset within BAR, full address) |
| 3697 | * @param write_register Address for 'write' register |
| 3698 | * (not offset within BAR, full address) |
| 3699 | * @param base_register Address for 'base' register |
| 3700 | * (not offset within BAR, full address) |
| 3701 | * @param size Address for 'size' register |
| 3702 | * (not offset within BAR, full address) |
| 3703 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3704 | 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] | 3705 | int count, u32 read, u32 write, u32 base, u32 size) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3706 | { |
| 3707 | q->n_bd = count; |
| 3708 | |
| 3709 | q->low_mark = q->n_bd / 4; |
| 3710 | if (q->low_mark < 4) |
| 3711 | q->low_mark = 4; |
| 3712 | |
| 3713 | q->high_mark = q->n_bd / 8; |
| 3714 | if (q->high_mark < 2) |
| 3715 | q->high_mark = 2; |
| 3716 | |
| 3717 | q->first_empty = q->last_used = 0; |
| 3718 | q->reg_r = read; |
| 3719 | q->reg_w = write; |
| 3720 | |
| 3721 | ipw_write32(priv, base, q->dma_addr); |
| 3722 | ipw_write32(priv, size, count); |
| 3723 | ipw_write32(priv, read, 0); |
| 3724 | ipw_write32(priv, write, 0); |
| 3725 | |
| 3726 | _ipw_read32(priv, 0x90); |
| 3727 | } |
| 3728 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3729 | static int ipw_queue_tx_init(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3730 | struct clx2_tx_queue *q, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3731 | int count, u32 read, u32 write, u32 base, u32 size) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3732 | { |
| 3733 | struct pci_dev *dev = priv->pci_dev; |
| 3734 | |
| 3735 | q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL); |
| 3736 | if (!q->txb) { |
| 3737 | IPW_ERROR("vmalloc for auxilary BD structures failed\n"); |
| 3738 | return -ENOMEM; |
| 3739 | } |
| 3740 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3741 | q->bd = |
| 3742 | 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] | 3743 | if (!q->bd) { |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 3744 | IPW_ERROR("pci_alloc_consistent(%zd) failed\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3745 | sizeof(q->bd[0]) * count); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3746 | kfree(q->txb); |
| 3747 | q->txb = NULL; |
| 3748 | return -ENOMEM; |
| 3749 | } |
| 3750 | |
| 3751 | ipw_queue_init(priv, &q->q, count, read, write, base, size); |
| 3752 | return 0; |
| 3753 | } |
| 3754 | |
| 3755 | /** |
| 3756 | * Free one TFD, those at index [txq->q.last_used]. |
| 3757 | * Do NOT advance any indexes |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3758 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3759 | * @param dev |
| 3760 | * @param txq |
| 3761 | */ |
| 3762 | static void ipw_queue_tx_free_tfd(struct ipw_priv *priv, |
| 3763 | struct clx2_tx_queue *txq) |
| 3764 | { |
| 3765 | struct tfd_frame *bd = &txq->bd[txq->q.last_used]; |
| 3766 | struct pci_dev *dev = priv->pci_dev; |
| 3767 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3768 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3769 | /* classify bd */ |
| 3770 | if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE) |
| 3771 | /* nothing to cleanup after for host commands */ |
| 3772 | return; |
| 3773 | |
| 3774 | /* sanity check */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3775 | if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) { |
| 3776 | IPW_ERROR("Too many chunks: %i\n", |
| 3777 | le32_to_cpu(bd->u.data.num_chunks)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3778 | /** @todo issue fatal error, it is quite serious situation */ |
| 3779 | return; |
| 3780 | } |
| 3781 | |
| 3782 | /* unmap chunks if any */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3783 | for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) { |
| 3784 | pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]), |
| 3785 | le16_to_cpu(bd->u.data.chunk_len[i]), |
| 3786 | PCI_DMA_TODEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3787 | if (txq->txb[txq->q.last_used]) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 3788 | libipw_txb_free(txq->txb[txq->q.last_used]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3789 | txq->txb[txq->q.last_used] = NULL; |
| 3790 | } |
| 3791 | } |
| 3792 | } |
| 3793 | |
| 3794 | /** |
| 3795 | * Deallocate DMA queue. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3796 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3797 | * Empty queue by removing and destroying all BD's. |
| 3798 | * Free all buffers. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3799 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3800 | * @param dev |
| 3801 | * @param q |
| 3802 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3803 | 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] | 3804 | { |
| 3805 | struct clx2_queue *q = &txq->q; |
| 3806 | struct pci_dev *dev = priv->pci_dev; |
| 3807 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3808 | if (q->n_bd == 0) |
| 3809 | return; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3810 | |
| 3811 | /* first, empty all BD's */ |
| 3812 | for (; q->first_empty != q->last_used; |
| 3813 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { |
| 3814 | ipw_queue_tx_free_tfd(priv, txq); |
| 3815 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3816 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3817 | /* free buffers belonging to queue itself */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3818 | 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] | 3819 | q->dma_addr); |
| 3820 | kfree(txq->txb); |
| 3821 | |
| 3822 | /* 0 fill whole structure */ |
| 3823 | memset(txq, 0, sizeof(*txq)); |
| 3824 | } |
| 3825 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3826 | /** |
| 3827 | * Destroy all DMA queues and structures |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3828 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3829 | * @param priv |
| 3830 | */ |
| 3831 | static void ipw_tx_queue_free(struct ipw_priv *priv) |
| 3832 | { |
| 3833 | /* Tx CMD queue */ |
| 3834 | ipw_queue_tx_free(priv, &priv->txq_cmd); |
| 3835 | |
| 3836 | /* Tx queues */ |
| 3837 | ipw_queue_tx_free(priv, &priv->txq[0]); |
| 3838 | ipw_queue_tx_free(priv, &priv->txq[1]); |
| 3839 | ipw_queue_tx_free(priv, &priv->txq[2]); |
| 3840 | ipw_queue_tx_free(priv, &priv->txq[3]); |
| 3841 | } |
| 3842 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3843 | static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3844 | { |
| 3845 | /* First 3 bytes are manufacturer */ |
| 3846 | bssid[0] = priv->mac_addr[0]; |
| 3847 | bssid[1] = priv->mac_addr[1]; |
| 3848 | bssid[2] = priv->mac_addr[2]; |
| 3849 | |
| 3850 | /* Last bytes are random */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3851 | get_random_bytes(&bssid[3], ETH_ALEN - 3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3852 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3853 | bssid[0] &= 0xfe; /* clear multicast bit */ |
| 3854 | bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3855 | } |
| 3856 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3857 | static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3858 | { |
| 3859 | struct ipw_station_entry entry; |
| 3860 | int i; |
| 3861 | |
| 3862 | for (i = 0; i < priv->num_stations; i++) { |
| 3863 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) { |
| 3864 | /* Another node is active in network */ |
| 3865 | priv->missed_adhoc_beacons = 0; |
| 3866 | if (!(priv->config & CFG_STATIC_CHANNEL)) |
| 3867 | /* when other nodes drop out, we drop out */ |
| 3868 | priv->config &= ~CFG_ADHOC_PERSIST; |
| 3869 | |
| 3870 | return i; |
| 3871 | } |
| 3872 | } |
| 3873 | |
| 3874 | if (i == MAX_STATIONS) |
| 3875 | return IPW_INVALID_STATION; |
| 3876 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 3877 | IPW_DEBUG_SCAN("Adding AdHoc station: %pM\n", bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3878 | |
| 3879 | entry.reserved = 0; |
| 3880 | entry.support_mode = 0; |
| 3881 | memcpy(entry.mac_addr, bssid, ETH_ALEN); |
| 3882 | memcpy(priv->stations[i], bssid, ETH_ALEN); |
| 3883 | ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3884 | &entry, sizeof(entry)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3885 | priv->num_stations++; |
| 3886 | |
| 3887 | return i; |
| 3888 | } |
| 3889 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3890 | static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3891 | { |
| 3892 | int i; |
| 3893 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3894 | for (i = 0; i < priv->num_stations; i++) |
| 3895 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3896 | return i; |
| 3897 | |
| 3898 | return IPW_INVALID_STATION; |
| 3899 | } |
| 3900 | |
| 3901 | static void ipw_send_disassociate(struct ipw_priv *priv, int quiet) |
| 3902 | { |
| 3903 | int err; |
| 3904 | |
Hong Liu | 7b99659 | 2005-08-25 17:36:13 +0800 | [diff] [blame] | 3905 | if (priv->status & STATUS_ASSOCIATING) { |
| 3906 | IPW_DEBUG_ASSOC("Disassociating while associating.\n"); |
| 3907 | queue_work(priv->workqueue, &priv->disassociate); |
| 3908 | return; |
| 3909 | } |
| 3910 | |
| 3911 | if (!(priv->status & STATUS_ASSOCIATED)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3912 | IPW_DEBUG_ASSOC("Disassociating while not associated.\n"); |
| 3913 | return; |
| 3914 | } |
| 3915 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 3916 | IPW_DEBUG_ASSOC("Disassocation attempt from %pM " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3917 | "on channel %d.\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 3918 | priv->assoc_request.bssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3919 | priv->assoc_request.channel); |
| 3920 | |
| 3921 | priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED); |
| 3922 | priv->status |= STATUS_DISASSOCIATING; |
| 3923 | |
| 3924 | if (quiet) |
| 3925 | priv->assoc_request.assoc_type = HC_DISASSOC_QUIET; |
| 3926 | else |
| 3927 | priv->assoc_request.assoc_type = HC_DISASSOCIATE; |
Hong Liu | e632472 | 2005-09-14 21:04:15 -0500 | [diff] [blame] | 3928 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3929 | err = ipw_send_associate(priv, &priv->assoc_request); |
| 3930 | if (err) { |
| 3931 | IPW_DEBUG_HC("Attempt to send [dis]associate command " |
| 3932 | "failed.\n"); |
| 3933 | return; |
| 3934 | } |
| 3935 | |
| 3936 | } |
| 3937 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3938 | static int ipw_disassociate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3939 | { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3940 | struct ipw_priv *priv = data; |
| 3941 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) |
| 3942 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3943 | ipw_send_disassociate(data, 0); |
Zhu Yi | b8ddafd | 2008-11-27 13:42:20 +0800 | [diff] [blame] | 3944 | netif_carrier_off(priv->net_dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3945 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3946 | } |
| 3947 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3948 | static void ipw_bg_disassociate(struct work_struct *work) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3949 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3950 | struct ipw_priv *priv = |
| 3951 | container_of(work, struct ipw_priv, disassociate); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 3952 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3953 | ipw_disassociate(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 3954 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3955 | } |
| 3956 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3957 | static void ipw_system_config(struct work_struct *work) |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 3958 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3959 | struct ipw_priv *priv = |
| 3960 | container_of(work, struct ipw_priv, system_config); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 3961 | |
| 3962 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 3963 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) { |
| 3964 | priv->sys_config.accept_all_data_frames = 1; |
| 3965 | priv->sys_config.accept_non_directed_frames = 1; |
| 3966 | priv->sys_config.accept_all_mgmt_bcpr = 1; |
| 3967 | priv->sys_config.accept_all_mgmt_frames = 1; |
| 3968 | } |
| 3969 | #endif |
| 3970 | |
| 3971 | ipw_send_system_config(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3972 | } |
| 3973 | |
| 3974 | struct ipw_status_code { |
| 3975 | u16 status; |
| 3976 | const char *reason; |
| 3977 | }; |
| 3978 | |
| 3979 | static const struct ipw_status_code ipw_status_codes[] = { |
| 3980 | {0x00, "Successful"}, |
| 3981 | {0x01, "Unspecified failure"}, |
| 3982 | {0x0A, "Cannot support all requested capabilities in the " |
| 3983 | "Capability information field"}, |
| 3984 | {0x0B, "Reassociation denied due to inability to confirm that " |
| 3985 | "association exists"}, |
| 3986 | {0x0C, "Association denied due to reason outside the scope of this " |
| 3987 | "standard"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3988 | {0x0D, |
| 3989 | "Responding station does not support the specified authentication " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3990 | "algorithm"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3991 | {0x0E, |
| 3992 | "Received an Authentication frame with authentication sequence " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3993 | "transaction sequence number out of expected sequence"}, |
| 3994 | {0x0F, "Authentication rejected because of challenge failure"}, |
| 3995 | {0x10, "Authentication rejected due to timeout waiting for next " |
| 3996 | "frame in sequence"}, |
| 3997 | {0x11, "Association denied because AP is unable to handle additional " |
| 3998 | "associated stations"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3999 | {0x12, |
| 4000 | "Association denied due to requesting station not supporting all " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4001 | "of the datarates in the BSSBasicServiceSet Parameter"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4002 | {0x13, |
| 4003 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4004 | "short preamble operation"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4005 | {0x14, |
| 4006 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4007 | "PBCC encoding"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4008 | {0x15, |
| 4009 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4010 | "channel agility"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4011 | {0x19, |
| 4012 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4013 | "short slot operation"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4014 | {0x1A, |
| 4015 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4016 | "DSSS-OFDM operation"}, |
| 4017 | {0x28, "Invalid Information Element"}, |
| 4018 | {0x29, "Group Cipher is not valid"}, |
| 4019 | {0x2A, "Pairwise Cipher is not valid"}, |
| 4020 | {0x2B, "AKMP is not valid"}, |
| 4021 | {0x2C, "Unsupported RSN IE version"}, |
| 4022 | {0x2D, "Invalid RSN IE Capabilities"}, |
| 4023 | {0x2E, "Cipher suite is rejected per security policy"}, |
| 4024 | }; |
| 4025 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4026 | static const char *ipw_get_status_code(u16 status) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4027 | { |
| 4028 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4029 | for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4030 | if (ipw_status_codes[i].status == (status & 0xff)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4031 | return ipw_status_codes[i].reason; |
| 4032 | return "Unknown status value."; |
| 4033 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4034 | |
| 4035 | static void inline average_init(struct average *avg) |
| 4036 | { |
| 4037 | memset(avg, 0, sizeof(*avg)); |
| 4038 | } |
| 4039 | |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 4040 | #define DEPTH_RSSI 8 |
| 4041 | #define DEPTH_NOISE 16 |
| 4042 | static s16 exponential_average(s16 prev_avg, s16 val, u8 depth) |
| 4043 | { |
| 4044 | return ((depth-1)*prev_avg + val)/depth; |
| 4045 | } |
| 4046 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4047 | static void average_add(struct average *avg, s16 val) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4048 | { |
| 4049 | avg->sum -= avg->entries[avg->pos]; |
| 4050 | avg->sum += val; |
| 4051 | avg->entries[avg->pos++] = val; |
| 4052 | if (unlikely(avg->pos == AVG_ENTRIES)) { |
| 4053 | avg->init = 1; |
| 4054 | avg->pos = 0; |
| 4055 | } |
| 4056 | } |
| 4057 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4058 | static s16 average_value(struct average *avg) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4059 | { |
| 4060 | if (!unlikely(avg->init)) { |
| 4061 | if (avg->pos) |
| 4062 | return avg->sum / avg->pos; |
| 4063 | return 0; |
| 4064 | } |
| 4065 | |
| 4066 | return avg->sum / AVG_ENTRIES; |
| 4067 | } |
| 4068 | |
| 4069 | static void ipw_reset_stats(struct ipw_priv *priv) |
| 4070 | { |
| 4071 | u32 len = sizeof(u32); |
| 4072 | |
| 4073 | priv->quality = 0; |
| 4074 | |
| 4075 | average_init(&priv->average_missed_beacons); |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 4076 | priv->exp_avg_rssi = -60; |
| 4077 | priv->exp_avg_noise = -85 + 0x100; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4078 | |
| 4079 | priv->last_rate = 0; |
| 4080 | priv->last_missed_beacons = 0; |
| 4081 | priv->last_rx_packets = 0; |
| 4082 | priv->last_tx_packets = 0; |
| 4083 | priv->last_tx_failures = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4084 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4085 | /* Firmware managed, reset only when NIC is restarted, so we have to |
| 4086 | * normalize on the current value */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4087 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4088 | &priv->last_rx_err, &len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4089 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4090 | &priv->last_tx_failures, &len); |
| 4091 | |
| 4092 | /* Driver managed, reset with each association */ |
| 4093 | priv->missed_adhoc_beacons = 0; |
| 4094 | priv->missed_beacons = 0; |
| 4095 | priv->tx_packets = 0; |
| 4096 | priv->rx_packets = 0; |
| 4097 | |
| 4098 | } |
| 4099 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4100 | static u32 ipw_get_max_rate(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4101 | { |
| 4102 | u32 i = 0x80000000; |
| 4103 | u32 mask = priv->rates_mask; |
| 4104 | /* If currently associated in B mode, restrict the maximum |
| 4105 | * rate match to B rates */ |
| 4106 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4107 | mask &= LIBIPW_CCK_RATES_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4108 | |
| 4109 | /* TODO: Verify that the rate is supported by the current rates |
| 4110 | * list. */ |
| 4111 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4112 | while (i && !(mask & i)) |
| 4113 | i >>= 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4114 | switch (i) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4115 | case LIBIPW_CCK_RATE_1MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4116 | return 1000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4117 | case LIBIPW_CCK_RATE_2MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4118 | return 2000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4119 | case LIBIPW_CCK_RATE_5MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4120 | return 5500000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4121 | case LIBIPW_OFDM_RATE_6MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4122 | return 6000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4123 | case LIBIPW_OFDM_RATE_9MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4124 | return 9000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4125 | case LIBIPW_CCK_RATE_11MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4126 | return 11000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4127 | case LIBIPW_OFDM_RATE_12MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4128 | return 12000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4129 | case LIBIPW_OFDM_RATE_18MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4130 | return 18000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4131 | case LIBIPW_OFDM_RATE_24MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4132 | return 24000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4133 | case LIBIPW_OFDM_RATE_36MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4134 | return 36000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4135 | case LIBIPW_OFDM_RATE_48MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4136 | return 48000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4137 | case LIBIPW_OFDM_RATE_54MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4138 | return 54000000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4139 | } |
| 4140 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4141 | if (priv->ieee->mode == IEEE_B) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4142 | return 11000000; |
| 4143 | else |
| 4144 | return 54000000; |
| 4145 | } |
| 4146 | |
| 4147 | static u32 ipw_get_current_rate(struct ipw_priv *priv) |
| 4148 | { |
| 4149 | u32 rate, len = sizeof(rate); |
| 4150 | int err; |
| 4151 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4152 | if (!(priv->status & STATUS_ASSOCIATED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4153 | return 0; |
| 4154 | |
| 4155 | if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4156 | err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4157 | &len); |
| 4158 | if (err) { |
| 4159 | IPW_DEBUG_INFO("failed querying ordinals.\n"); |
| 4160 | return 0; |
| 4161 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4162 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4163 | return ipw_get_max_rate(priv); |
| 4164 | |
| 4165 | switch (rate) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4166 | case IPW_TX_RATE_1MB: |
| 4167 | return 1000000; |
| 4168 | case IPW_TX_RATE_2MB: |
| 4169 | return 2000000; |
| 4170 | case IPW_TX_RATE_5MB: |
| 4171 | return 5500000; |
| 4172 | case IPW_TX_RATE_6MB: |
| 4173 | return 6000000; |
| 4174 | case IPW_TX_RATE_9MB: |
| 4175 | return 9000000; |
| 4176 | case IPW_TX_RATE_11MB: |
| 4177 | return 11000000; |
| 4178 | case IPW_TX_RATE_12MB: |
| 4179 | return 12000000; |
| 4180 | case IPW_TX_RATE_18MB: |
| 4181 | return 18000000; |
| 4182 | case IPW_TX_RATE_24MB: |
| 4183 | return 24000000; |
| 4184 | case IPW_TX_RATE_36MB: |
| 4185 | return 36000000; |
| 4186 | case IPW_TX_RATE_48MB: |
| 4187 | return 48000000; |
| 4188 | case IPW_TX_RATE_54MB: |
| 4189 | return 54000000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4190 | } |
| 4191 | |
| 4192 | return 0; |
| 4193 | } |
| 4194 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4195 | #define IPW_STATS_INTERVAL (2 * HZ) |
| 4196 | static void ipw_gather_stats(struct ipw_priv *priv) |
| 4197 | { |
| 4198 | u32 rx_err, rx_err_delta, rx_packets_delta; |
| 4199 | u32 tx_failures, tx_failures_delta, tx_packets_delta; |
| 4200 | u32 missed_beacons_percent, missed_beacons_delta; |
| 4201 | u32 quality = 0; |
| 4202 | u32 len = sizeof(u32); |
| 4203 | s16 rssi; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4204 | u32 beacon_quality, signal_quality, tx_quality, rx_quality, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4205 | rate_quality; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4206 | u32 max_rate; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4207 | |
| 4208 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 4209 | priv->quality = 0; |
| 4210 | return; |
| 4211 | } |
| 4212 | |
| 4213 | /* Update the statistics */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4214 | ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4215 | &priv->missed_beacons, &len); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4216 | missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4217 | priv->last_missed_beacons = priv->missed_beacons; |
| 4218 | if (priv->assoc_request.beacon_interval) { |
| 4219 | missed_beacons_percent = missed_beacons_delta * |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 4220 | (HZ * le16_to_cpu(priv->assoc_request.beacon_interval)) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4221 | (IPW_STATS_INTERVAL * 10); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4222 | } else { |
| 4223 | missed_beacons_percent = 0; |
| 4224 | } |
| 4225 | average_add(&priv->average_missed_beacons, missed_beacons_percent); |
| 4226 | |
| 4227 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len); |
| 4228 | rx_err_delta = rx_err - priv->last_rx_err; |
| 4229 | priv->last_rx_err = rx_err; |
| 4230 | |
| 4231 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len); |
| 4232 | tx_failures_delta = tx_failures - priv->last_tx_failures; |
| 4233 | priv->last_tx_failures = tx_failures; |
| 4234 | |
| 4235 | rx_packets_delta = priv->rx_packets - priv->last_rx_packets; |
| 4236 | priv->last_rx_packets = priv->rx_packets; |
| 4237 | |
| 4238 | tx_packets_delta = priv->tx_packets - priv->last_tx_packets; |
| 4239 | priv->last_tx_packets = priv->tx_packets; |
| 4240 | |
| 4241 | /* Calculate quality based on the following: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4242 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4243 | * Missed beacon: 100% = 0, 0% = 70% missed |
| 4244 | * Rate: 60% = 1Mbs, 100% = Max |
| 4245 | * Rx and Tx errors represent a straight % of total Rx/Tx |
| 4246 | * RSSI: 100% = > -50, 0% = < -80 |
| 4247 | * Rx errors: 100% = 0, 0% = 50% missed |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4248 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4249 | * The lowest computed quality is used. |
| 4250 | * |
| 4251 | */ |
| 4252 | #define BEACON_THRESHOLD 5 |
| 4253 | beacon_quality = 100 - missed_beacons_percent; |
| 4254 | if (beacon_quality < BEACON_THRESHOLD) |
| 4255 | beacon_quality = 0; |
| 4256 | else |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4257 | beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4258 | (100 - BEACON_THRESHOLD); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4259 | IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4260 | beacon_quality, missed_beacons_percent); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4261 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4262 | priv->last_rate = ipw_get_current_rate(priv); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4263 | max_rate = ipw_get_max_rate(priv); |
| 4264 | rate_quality = priv->last_rate * 40 / max_rate + 60; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4265 | IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n", |
| 4266 | rate_quality, priv->last_rate / 1000000); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4267 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4268 | if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4269 | rx_quality = 100 - (rx_err_delta * 100) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4270 | (rx_packets_delta + rx_err_delta); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4271 | else |
| 4272 | rx_quality = 100; |
| 4273 | IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n", |
| 4274 | rx_quality, rx_err_delta, rx_packets_delta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4275 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4276 | if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4277 | tx_quality = 100 - (tx_failures_delta * 100) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4278 | (tx_packets_delta + tx_failures_delta); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4279 | else |
| 4280 | tx_quality = 100; |
| 4281 | IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n", |
| 4282 | tx_quality, tx_failures_delta, tx_packets_delta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4283 | |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 4284 | rssi = priv->exp_avg_rssi; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4285 | signal_quality = |
| 4286 | (100 * |
| 4287 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * |
| 4288 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) - |
| 4289 | (priv->ieee->perfect_rssi - rssi) * |
| 4290 | (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) + |
| 4291 | 62 * (priv->ieee->perfect_rssi - rssi))) / |
| 4292 | ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * |
| 4293 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi)); |
| 4294 | if (signal_quality > 100) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4295 | signal_quality = 100; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4296 | else if (signal_quality < 1) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4297 | signal_quality = 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4298 | |
Zhu Yi | 61fb9ed | 2006-04-13 17:19:55 +0800 | [diff] [blame] | 4299 | IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4300 | signal_quality, rssi); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4301 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 4302 | quality = min(rx_quality, signal_quality); |
| 4303 | quality = min(tx_quality, quality); |
| 4304 | quality = min(rate_quality, quality); |
| 4305 | quality = min(beacon_quality, quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4306 | if (quality == beacon_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4307 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n", |
| 4308 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4309 | if (quality == rate_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4310 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n", |
| 4311 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4312 | if (quality == tx_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4313 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n", |
| 4314 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4315 | if (quality == rx_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4316 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n", |
| 4317 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4318 | if (quality == signal_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4319 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n", |
| 4320 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4321 | |
| 4322 | priv->quality = quality; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4323 | |
| 4324 | queue_delayed_work(priv->workqueue, &priv->gather_stats, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4325 | IPW_STATS_INTERVAL); |
| 4326 | } |
| 4327 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4328 | static void ipw_bg_gather_stats(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4329 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4330 | struct ipw_priv *priv = |
| 4331 | container_of(work, struct ipw_priv, gather_stats.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 4332 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4333 | ipw_gather_stats(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 4334 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4335 | } |
| 4336 | |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4337 | /* Missed beacon behavior: |
| 4338 | * 1st missed -> roaming_threshold, just wait, don't do any scan/roam. |
| 4339 | * roaming_threshold -> disassociate_threshold, scan and roam for better signal. |
| 4340 | * Above disassociate threshold, give up and stop scanning. |
| 4341 | * Roaming is disabled if disassociate_threshold <= roaming_threshold */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4342 | static void ipw_handle_missed_beacon(struct ipw_priv *priv, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4343 | int missed_count) |
| 4344 | { |
| 4345 | priv->notif_missed_beacons = missed_count; |
| 4346 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4347 | if (missed_count > priv->disassociate_threshold && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4348 | priv->status & STATUS_ASSOCIATED) { |
| 4349 | /* If associated and we've hit the missed |
| 4350 | * beacon threshold, disassociate, turn |
| 4351 | * off roaming, and abort any active scans */ |
| 4352 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4353 | IPW_DL_STATE | IPW_DL_ASSOC, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4354 | "Missed beacon: %d - disassociate\n", missed_count); |
| 4355 | priv->status &= ~STATUS_ROAMING; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4356 | if (priv->status & STATUS_SCANNING) { |
| 4357 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
| 4358 | IPW_DL_STATE, |
| 4359 | "Aborting scan with missed beacon.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4360 | queue_work(priv->workqueue, &priv->abort_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4361 | } |
| 4362 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4363 | queue_work(priv->workqueue, &priv->disassociate); |
| 4364 | return; |
| 4365 | } |
| 4366 | |
| 4367 | if (priv->status & STATUS_ROAMING) { |
| 4368 | /* If we are currently roaming, then just |
| 4369 | * print a debug statement... */ |
| 4370 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4371 | "Missed beacon: %d - roam in progress\n", |
| 4372 | missed_count); |
| 4373 | return; |
| 4374 | } |
| 4375 | |
Zhu Yi | 4bfdb91 | 2006-01-24 16:37:16 +0800 | [diff] [blame] | 4376 | if (roaming && |
| 4377 | (missed_count > priv->roaming_threshold && |
| 4378 | missed_count <= priv->disassociate_threshold)) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4379 | /* If we are not already roaming, set the ROAM |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4380 | * bit in the status and kick off a scan. |
| 4381 | * This can happen several times before we reach |
| 4382 | * disassociate_threshold. */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4383 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4384 | "Missed beacon: %d - initiate " |
| 4385 | "roaming\n", missed_count); |
| 4386 | if (!(priv->status & STATUS_ROAMING)) { |
| 4387 | priv->status |= STATUS_ROAMING; |
| 4388 | if (!(priv->status & STATUS_SCANNING)) |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4389 | queue_delayed_work(priv->workqueue, |
| 4390 | &priv->request_scan, 0); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4391 | } |
| 4392 | return; |
| 4393 | } |
| 4394 | |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 4395 | if (priv->status & STATUS_SCANNING && |
| 4396 | missed_count > IPW_MB_SCAN_CANCEL_THRESHOLD) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4397 | /* Stop scan to keep fw from getting |
| 4398 | * stuck (only if we aren't roaming -- |
| 4399 | * otherwise we'll never scan more than 2 or 3 |
| 4400 | * channels..) */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4401 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE, |
| 4402 | "Aborting scan with missed beacon.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4403 | queue_work(priv->workqueue, &priv->abort_scan); |
| 4404 | } |
| 4405 | |
| 4406 | IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4407 | } |
| 4408 | |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 4409 | static void ipw_scan_event(struct work_struct *work) |
| 4410 | { |
| 4411 | union iwreq_data wrqu; |
| 4412 | |
| 4413 | struct ipw_priv *priv = |
| 4414 | container_of(work, struct ipw_priv, scan_event.work); |
| 4415 | |
| 4416 | wrqu.data.length = 0; |
| 4417 | wrqu.data.flags = 0; |
| 4418 | wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL); |
| 4419 | } |
| 4420 | |
| 4421 | static void handle_scan_event(struct ipw_priv *priv) |
| 4422 | { |
| 4423 | /* Only userspace-requested scan completion events go out immediately */ |
| 4424 | if (!priv->user_requested_scan) { |
| 4425 | if (!delayed_work_pending(&priv->scan_event)) |
| 4426 | queue_delayed_work(priv->workqueue, &priv->scan_event, |
Anton Blanchard | be84e3d | 2007-10-15 00:38:01 -0500 | [diff] [blame] | 4427 | round_jiffies_relative(msecs_to_jiffies(4000))); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 4428 | } else { |
| 4429 | union iwreq_data wrqu; |
| 4430 | |
| 4431 | priv->user_requested_scan = 0; |
| 4432 | cancel_delayed_work(&priv->scan_event); |
| 4433 | |
| 4434 | wrqu.data.length = 0; |
| 4435 | wrqu.data.flags = 0; |
| 4436 | wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL); |
| 4437 | } |
| 4438 | } |
| 4439 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4440 | /** |
| 4441 | * Handle host notification packet. |
| 4442 | * Called from interrupt routine |
| 4443 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4444 | static void ipw_rx_notification(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4445 | struct ipw_rx_notification *notif) |
| 4446 | { |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4447 | DECLARE_SSID_BUF(ssid); |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4448 | u16 size = le16_to_cpu(notif->size); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4449 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4450 | IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, size); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4451 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4452 | switch (notif->subtype) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4453 | case HOST_NOTIFICATION_STATUS_ASSOCIATED:{ |
| 4454 | struct notif_association *assoc = ¬if->u.assoc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4455 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4456 | switch (assoc->state) { |
| 4457 | case CMAS_ASSOCIATED:{ |
| 4458 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4459 | IPW_DL_ASSOC, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4460 | "associated: '%s' %pM \n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4461 | print_ssid(ssid, priv->essid, |
| 4462 | priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4463 | priv->bssid); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4464 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4465 | switch (priv->ieee->iw_mode) { |
| 4466 | case IW_MODE_INFRA: |
| 4467 | memcpy(priv->ieee->bssid, |
| 4468 | priv->bssid, ETH_ALEN); |
| 4469 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4470 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4471 | case IW_MODE_ADHOC: |
| 4472 | memcpy(priv->ieee->bssid, |
| 4473 | priv->bssid, ETH_ALEN); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4474 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4475 | /* clear out the station table */ |
| 4476 | priv->num_stations = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4477 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4478 | IPW_DEBUG_ASSOC |
| 4479 | ("queueing adhoc check\n"); |
| 4480 | queue_delayed_work(priv-> |
| 4481 | workqueue, |
| 4482 | &priv-> |
| 4483 | adhoc_check, |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 4484 | le16_to_cpu(priv-> |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4485 | assoc_request. |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 4486 | beacon_interval)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4487 | break; |
| 4488 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4489 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4490 | priv->status &= ~STATUS_ASSOCIATING; |
| 4491 | priv->status |= STATUS_ASSOCIATED; |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 4492 | queue_work(priv->workqueue, |
| 4493 | &priv->system_config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4494 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 4495 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4496 | #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \ |
John W. Linville | 7211801 | 2008-09-30 21:43:03 -0400 | [diff] [blame] | 4497 | le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_control)) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4498 | if ((priv->status & STATUS_AUTH) && |
| 4499 | (IPW_GET_PACKET_STYPE(¬if->u.raw) |
| 4500 | == IEEE80211_STYPE_ASSOC_RESP)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4501 | if ((sizeof |
| 4502 | (struct |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4503 | libipw_assoc_response) |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4504 | <= size) |
| 4505 | && (size <= 2314)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4506 | struct |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4507 | libipw_rx_stats |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4508 | stats = { |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4509 | .len = size - 1, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4510 | }; |
| 4511 | |
| 4512 | IPW_DEBUG_QOS |
| 4513 | ("QoS Associate " |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4514 | "size %d\n", size); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4515 | libipw_rx_mgt(priv-> |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4516 | ieee, |
| 4517 | (struct |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4518 | libipw_hdr_4addr |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4519 | *) |
| 4520 | ¬if->u.raw, &stats); |
| 4521 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4522 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4523 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4524 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4525 | schedule_work(&priv->link_up); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4526 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4527 | break; |
| 4528 | } |
| 4529 | |
| 4530 | case CMAS_AUTHENTICATED:{ |
| 4531 | if (priv-> |
| 4532 | status & (STATUS_ASSOCIATED | |
| 4533 | STATUS_AUTH)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4534 | struct notif_authenticate *auth |
| 4535 | = ¬if->u.auth; |
| 4536 | IPW_DEBUG(IPW_DL_NOTIF | |
| 4537 | IPW_DL_STATE | |
| 4538 | IPW_DL_ASSOC, |
| 4539 | "deauthenticated: '%s' " |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4540 | "%pM" |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4541 | ": (0x%04X) - %s \n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4542 | print_ssid(ssid, |
| 4543 | priv-> |
| 4544 | essid, |
| 4545 | priv-> |
| 4546 | essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4547 | priv->bssid, |
Al Viro | 83f7d57 | 2008-03-16 22:26:44 +0000 | [diff] [blame] | 4548 | le16_to_cpu(auth->status), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4549 | ipw_get_status_code |
Al Viro | 83f7d57 | 2008-03-16 22:26:44 +0000 | [diff] [blame] | 4550 | (le16_to_cpu |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4551 | (auth->status))); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4552 | |
| 4553 | priv->status &= |
| 4554 | ~(STATUS_ASSOCIATING | |
| 4555 | STATUS_AUTH | |
| 4556 | STATUS_ASSOCIATED); |
| 4557 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4558 | schedule_work(&priv->link_down); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4559 | break; |
| 4560 | } |
| 4561 | |
| 4562 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4563 | IPW_DL_ASSOC, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4564 | "authenticated: '%s' %pM\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4565 | print_ssid(ssid, priv->essid, |
| 4566 | priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4567 | priv->bssid); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4568 | break; |
| 4569 | } |
| 4570 | |
| 4571 | case CMAS_INIT:{ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4572 | if (priv->status & STATUS_AUTH) { |
| 4573 | struct |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4574 | libipw_assoc_response |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4575 | *resp; |
| 4576 | resp = |
| 4577 | (struct |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4578 | libipw_assoc_response |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4579 | *)¬if->u.raw; |
| 4580 | IPW_DEBUG(IPW_DL_NOTIF | |
| 4581 | IPW_DL_STATE | |
| 4582 | IPW_DL_ASSOC, |
| 4583 | "association failed (0x%04X): %s\n", |
Al Viro | 83f7d57 | 2008-03-16 22:26:44 +0000 | [diff] [blame] | 4584 | le16_to_cpu(resp->status), |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4585 | ipw_get_status_code |
Al Viro | 83f7d57 | 2008-03-16 22:26:44 +0000 | [diff] [blame] | 4586 | (le16_to_cpu |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4587 | (resp->status))); |
| 4588 | } |
| 4589 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4590 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4591 | IPW_DL_ASSOC, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4592 | "disassociated: '%s' %pM \n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4593 | print_ssid(ssid, priv->essid, |
| 4594 | priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4595 | priv->bssid); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4596 | |
| 4597 | priv->status &= |
| 4598 | ~(STATUS_DISASSOCIATING | |
| 4599 | STATUS_ASSOCIATING | |
| 4600 | STATUS_ASSOCIATED | STATUS_AUTH); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4601 | if (priv->assoc_network |
| 4602 | && (priv->assoc_network-> |
| 4603 | capability & |
| 4604 | WLAN_CAPABILITY_IBSS)) |
| 4605 | ipw_remove_current_network |
| 4606 | (priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4607 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4608 | schedule_work(&priv->link_down); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4609 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4610 | break; |
| 4611 | } |
| 4612 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4613 | case CMAS_RX_ASSOC_RESP: |
| 4614 | break; |
| 4615 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4616 | default: |
| 4617 | IPW_ERROR("assoc: unknown (%d)\n", |
| 4618 | assoc->state); |
| 4619 | break; |
| 4620 | } |
| 4621 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4622 | break; |
| 4623 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4624 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4625 | case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{ |
| 4626 | struct notif_authenticate *auth = ¬if->u.auth; |
| 4627 | switch (auth->state) { |
| 4628 | case CMAS_AUTHENTICATED: |
| 4629 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4630 | "authenticated: '%s' %pM \n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4631 | print_ssid(ssid, priv->essid, |
| 4632 | priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4633 | priv->bssid); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4634 | priv->status |= STATUS_AUTH; |
| 4635 | break; |
| 4636 | |
| 4637 | case CMAS_INIT: |
| 4638 | if (priv->status & STATUS_AUTH) { |
| 4639 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4640 | IPW_DL_ASSOC, |
| 4641 | "authentication failed (0x%04X): %s\n", |
Al Viro | 83f7d57 | 2008-03-16 22:26:44 +0000 | [diff] [blame] | 4642 | le16_to_cpu(auth->status), |
| 4643 | ipw_get_status_code(le16_to_cpu |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4644 | (auth-> |
| 4645 | status))); |
| 4646 | } |
| 4647 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4648 | IPW_DL_ASSOC, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4649 | "deauthenticated: '%s' %pM\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4650 | print_ssid(ssid, priv->essid, |
| 4651 | priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4652 | priv->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4653 | |
| 4654 | priv->status &= ~(STATUS_ASSOCIATING | |
| 4655 | STATUS_AUTH | |
| 4656 | STATUS_ASSOCIATED); |
| 4657 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4658 | schedule_work(&priv->link_down); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4659 | break; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4660 | |
| 4661 | case CMAS_TX_AUTH_SEQ_1: |
| 4662 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4663 | IPW_DL_ASSOC, "AUTH_SEQ_1\n"); |
| 4664 | break; |
| 4665 | case CMAS_RX_AUTH_SEQ_2: |
| 4666 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4667 | IPW_DL_ASSOC, "AUTH_SEQ_2\n"); |
| 4668 | break; |
| 4669 | case CMAS_AUTH_SEQ_1_PASS: |
| 4670 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4671 | IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n"); |
| 4672 | break; |
| 4673 | case CMAS_AUTH_SEQ_1_FAIL: |
| 4674 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4675 | IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n"); |
| 4676 | break; |
| 4677 | case CMAS_TX_AUTH_SEQ_3: |
| 4678 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4679 | IPW_DL_ASSOC, "AUTH_SEQ_3\n"); |
| 4680 | break; |
| 4681 | case CMAS_RX_AUTH_SEQ_4: |
| 4682 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4683 | IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n"); |
| 4684 | break; |
| 4685 | case CMAS_AUTH_SEQ_2_PASS: |
| 4686 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4687 | IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n"); |
| 4688 | break; |
| 4689 | case CMAS_AUTH_SEQ_2_FAIL: |
| 4690 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4691 | IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n"); |
| 4692 | break; |
| 4693 | case CMAS_TX_ASSOC: |
| 4694 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4695 | IPW_DL_ASSOC, "TX_ASSOC\n"); |
| 4696 | break; |
| 4697 | case CMAS_RX_ASSOC_RESP: |
| 4698 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4699 | IPW_DL_ASSOC, "RX_ASSOC_RESP\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4700 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4701 | break; |
| 4702 | case CMAS_ASSOCIATED: |
| 4703 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4704 | IPW_DL_ASSOC, "ASSOCIATED\n"); |
| 4705 | break; |
| 4706 | default: |
| 4707 | IPW_DEBUG_NOTIF("auth: failure - %d\n", |
| 4708 | auth->state); |
| 4709 | break; |
| 4710 | } |
| 4711 | break; |
| 4712 | } |
| 4713 | |
| 4714 | case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{ |
| 4715 | struct notif_channel_result *x = |
| 4716 | ¬if->u.channel_result; |
| 4717 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4718 | if (size == sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4719 | IPW_DEBUG_SCAN("Scan result for channel %d\n", |
| 4720 | x->channel_num); |
| 4721 | } else { |
| 4722 | IPW_DEBUG_SCAN("Scan result of wrong size %d " |
| 4723 | "(should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4724 | size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4725 | } |
| 4726 | break; |
| 4727 | } |
| 4728 | |
| 4729 | case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{ |
| 4730 | struct notif_scan_complete *x = ¬if->u.scan_complete; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4731 | if (size == sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4732 | IPW_DEBUG_SCAN |
| 4733 | ("Scan completed: type %d, %d channels, " |
| 4734 | "%d status\n", x->scan_type, |
| 4735 | x->num_channels, x->status); |
| 4736 | } else { |
| 4737 | IPW_ERROR("Scan completed of wrong size %d " |
| 4738 | "(should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4739 | size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4740 | } |
| 4741 | |
| 4742 | priv->status &= |
| 4743 | ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); |
| 4744 | |
James Ketrenos | a0e04ab | 2005-08-25 00:49:43 -0500 | [diff] [blame] | 4745 | wake_up_interruptible(&priv->wait_state); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4746 | cancel_delayed_work(&priv->scan_check); |
| 4747 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4748 | if (priv->status & STATUS_EXIT_PENDING) |
| 4749 | break; |
| 4750 | |
| 4751 | priv->ieee->scans++; |
| 4752 | |
| 4753 | #ifdef CONFIG_IPW2200_MONITOR |
| 4754 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4755 | priv->status |= STATUS_SCAN_FORCED; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4756 | queue_delayed_work(priv->workqueue, |
| 4757 | &priv->request_scan, 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4758 | break; |
| 4759 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4760 | priv->status &= ~STATUS_SCAN_FORCED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4761 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 4762 | |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 4763 | /* Do queued direct scans first */ |
| 4764 | if (priv->status & STATUS_DIRECT_SCAN_PENDING) { |
| 4765 | queue_delayed_work(priv->workqueue, |
| 4766 | &priv->request_direct_scan, 0); |
| 4767 | } |
| 4768 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4769 | if (!(priv->status & (STATUS_ASSOCIATED | |
| 4770 | STATUS_ASSOCIATING | |
| 4771 | STATUS_ROAMING | |
| 4772 | STATUS_DISASSOCIATING))) |
| 4773 | queue_work(priv->workqueue, &priv->associate); |
| 4774 | else if (priv->status & STATUS_ROAMING) { |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4775 | if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) |
| 4776 | /* If a scan completed and we are in roam mode, then |
| 4777 | * the scan that completed was the one requested as a |
| 4778 | * result of entering roam... so, schedule the |
| 4779 | * roam work */ |
| 4780 | queue_work(priv->workqueue, |
| 4781 | &priv->roam); |
| 4782 | else |
| 4783 | /* Don't schedule if we aborted the scan */ |
| 4784 | priv->status &= ~STATUS_ROAMING; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4785 | } else if (priv->status & STATUS_SCAN_PENDING) |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4786 | queue_delayed_work(priv->workqueue, |
| 4787 | &priv->request_scan, 0); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4788 | else if (priv->config & CFG_BACKGROUND_SCAN |
| 4789 | && priv->status & STATUS_ASSOCIATED) |
| 4790 | queue_delayed_work(priv->workqueue, |
Stephen Hemminger | 1c9d5e4 | 2007-06-22 21:34:06 -0700 | [diff] [blame] | 4791 | &priv->request_scan, |
Anton Blanchard | be84e3d | 2007-10-15 00:38:01 -0500 | [diff] [blame] | 4792 | round_jiffies_relative(HZ)); |
Zhu Yi | 07f02e4 | 2006-04-13 17:19:25 +0800 | [diff] [blame] | 4793 | |
| 4794 | /* Send an empty event to user space. |
| 4795 | * We don't send the received data on the event because |
| 4796 | * it would require us to do complex transcoding, and |
| 4797 | * we want to minimise the work done in the irq handler |
| 4798 | * Use a request to extract the data. |
| 4799 | * Also, we generate this even for any scan, regardless |
| 4800 | * on how the scan was initiated. User space can just |
| 4801 | * sync on periodic scan to get fresh data... |
| 4802 | * Jean II */ |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 4803 | if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) |
| 4804 | handle_scan_event(priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4805 | break; |
| 4806 | } |
| 4807 | |
| 4808 | case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{ |
| 4809 | struct notif_frag_length *x = ¬if->u.frag_len; |
| 4810 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4811 | if (size == sizeof(*x)) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4812 | IPW_ERROR("Frag length: %d\n", |
| 4813 | le16_to_cpu(x->frag_length)); |
| 4814 | else |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4815 | IPW_ERROR("Frag length of wrong size %d " |
| 4816 | "(should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4817 | size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4818 | break; |
| 4819 | } |
| 4820 | |
| 4821 | case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{ |
| 4822 | struct notif_link_deterioration *x = |
| 4823 | ¬if->u.link_deterioration; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4824 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4825 | if (size == sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4826 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
Cahill, Ben M | 1297715 | 2006-03-08 02:58:02 +0800 | [diff] [blame] | 4827 | "link deterioration: type %d, cnt %d\n", |
| 4828 | x->silence_notification_type, |
| 4829 | x->silence_count); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4830 | memcpy(&priv->last_link_deterioration, x, |
| 4831 | sizeof(*x)); |
| 4832 | } else { |
| 4833 | IPW_ERROR("Link Deterioration of wrong size %d " |
| 4834 | "(should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4835 | size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4836 | } |
| 4837 | break; |
| 4838 | } |
| 4839 | |
| 4840 | case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{ |
| 4841 | IPW_ERROR("Dino config\n"); |
| 4842 | if (priv->hcmd |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4843 | && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4844 | IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4845 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4846 | break; |
| 4847 | } |
| 4848 | |
| 4849 | case HOST_NOTIFICATION_STATUS_BEACON_STATE:{ |
| 4850 | struct notif_beacon_state *x = ¬if->u.beacon_state; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4851 | if (size != sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4852 | IPW_ERROR |
| 4853 | ("Beacon state of wrong size %d (should " |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4854 | "be %zd)\n", size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4855 | break; |
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 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4858 | if (le32_to_cpu(x->state) == |
| 4859 | HOST_NOTIFICATION_STATUS_BEACON_MISSING) |
| 4860 | ipw_handle_missed_beacon(priv, |
| 4861 | le32_to_cpu(x-> |
| 4862 | number)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4863 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4864 | break; |
| 4865 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4866 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4867 | case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{ |
| 4868 | struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4869 | if (size == sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4870 | IPW_ERROR("TGi Tx Key: state 0x%02x sec type " |
| 4871 | "0x%02x station %d\n", |
| 4872 | x->key_state, x->security_type, |
| 4873 | x->station_index); |
| 4874 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4875 | } |
| 4876 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4877 | IPW_ERROR |
| 4878 | ("TGi Tx Key of wrong size %d (should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4879 | size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4880 | break; |
| 4881 | } |
| 4882 | |
| 4883 | case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{ |
| 4884 | struct notif_calibration *x = ¬if->u.calibration; |
| 4885 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4886 | if (size == sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4887 | memcpy(&priv->calib, x, sizeof(*x)); |
| 4888 | IPW_DEBUG_INFO("TODO: Calibration\n"); |
| 4889 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4890 | } |
| 4891 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4892 | IPW_ERROR |
| 4893 | ("Calibration of wrong size %d (should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4894 | size, sizeof(*x)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4895 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4896 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4897 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4898 | case HOST_NOTIFICATION_NOISE_STATS:{ |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4899 | if (size == sizeof(u32)) { |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 4900 | priv->exp_avg_noise = |
| 4901 | exponential_average(priv->exp_avg_noise, |
| 4902 | (u8) (le32_to_cpu(notif->u.noise.value) & 0xff), |
| 4903 | DEPTH_NOISE); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4904 | break; |
| 4905 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4906 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4907 | IPW_ERROR |
| 4908 | ("Noise stat is wrong size %d (should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4909 | size, sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4910 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4911 | } |
| 4912 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4913 | default: |
Zhu Yi | 1dd31b6 | 2006-02-20 18:28:09 -0800 | [diff] [blame] | 4914 | IPW_DEBUG_NOTIF("Unknown notification: " |
| 4915 | "subtype=%d,flags=0x%2x,size=%d\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4916 | notif->subtype, notif->flags, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4917 | } |
| 4918 | } |
| 4919 | |
| 4920 | /** |
| 4921 | * Destroys all DMA structures and initialise them again |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4922 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4923 | * @param priv |
| 4924 | * @return error code |
| 4925 | */ |
| 4926 | static int ipw_queue_reset(struct ipw_priv *priv) |
| 4927 | { |
| 4928 | int rc = 0; |
| 4929 | /** @todo customize queue sizes */ |
| 4930 | int nTx = 64, nTxCmd = 8; |
| 4931 | ipw_tx_queue_free(priv); |
| 4932 | /* Tx CMD queue */ |
| 4933 | rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4934 | IPW_TX_CMD_QUEUE_READ_INDEX, |
| 4935 | IPW_TX_CMD_QUEUE_WRITE_INDEX, |
| 4936 | IPW_TX_CMD_QUEUE_BD_BASE, |
| 4937 | IPW_TX_CMD_QUEUE_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4938 | if (rc) { |
| 4939 | IPW_ERROR("Tx Cmd queue init failed\n"); |
| 4940 | goto error; |
| 4941 | } |
| 4942 | /* Tx queue(s) */ |
| 4943 | rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4944 | IPW_TX_QUEUE_0_READ_INDEX, |
| 4945 | IPW_TX_QUEUE_0_WRITE_INDEX, |
| 4946 | IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4947 | if (rc) { |
| 4948 | IPW_ERROR("Tx 0 queue init failed\n"); |
| 4949 | goto error; |
| 4950 | } |
| 4951 | rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4952 | IPW_TX_QUEUE_1_READ_INDEX, |
| 4953 | IPW_TX_QUEUE_1_WRITE_INDEX, |
| 4954 | IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4955 | if (rc) { |
| 4956 | IPW_ERROR("Tx 1 queue init failed\n"); |
| 4957 | goto error; |
| 4958 | } |
| 4959 | rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4960 | IPW_TX_QUEUE_2_READ_INDEX, |
| 4961 | IPW_TX_QUEUE_2_WRITE_INDEX, |
| 4962 | IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4963 | if (rc) { |
| 4964 | IPW_ERROR("Tx 2 queue init failed\n"); |
| 4965 | goto error; |
| 4966 | } |
| 4967 | rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4968 | IPW_TX_QUEUE_3_READ_INDEX, |
| 4969 | IPW_TX_QUEUE_3_WRITE_INDEX, |
| 4970 | IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4971 | if (rc) { |
| 4972 | IPW_ERROR("Tx 3 queue init failed\n"); |
| 4973 | goto error; |
| 4974 | } |
| 4975 | /* statistics */ |
| 4976 | priv->rx_bufs_min = 0; |
| 4977 | priv->rx_pend_max = 0; |
| 4978 | return rc; |
| 4979 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4980 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4981 | ipw_tx_queue_free(priv); |
| 4982 | return rc; |
| 4983 | } |
| 4984 | |
| 4985 | /** |
| 4986 | * Reclaim Tx queue entries no more used by NIC. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4987 | * |
Stefano Brivio | 8ff9d21 | 2008-01-12 23:12:26 +0100 | [diff] [blame] | 4988 | * When FW advances 'R' index, all entries between old and |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4989 | * new 'R' index need to be reclaimed. As result, some free space |
| 4990 | * forms. If there is enough free space (> low mark), wake Tx queue. |
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 | * @note Need to protect against garbage in 'R' index |
| 4993 | * @param priv |
| 4994 | * @param txq |
| 4995 | * @param qindex |
| 4996 | * @return Number of used entries remains in the queue |
| 4997 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4998 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4999 | struct clx2_tx_queue *txq, int qindex) |
| 5000 | { |
| 5001 | u32 hw_tail; |
| 5002 | int used; |
| 5003 | struct clx2_queue *q = &txq->q; |
| 5004 | |
| 5005 | hw_tail = ipw_read32(priv, q->reg_r); |
| 5006 | if (hw_tail >= q->n_bd) { |
| 5007 | IPW_ERROR |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5008 | ("Read index for DMA queue (%d) is out of range [0-%d)\n", |
| 5009 | hw_tail, q->n_bd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5010 | goto done; |
| 5011 | } |
| 5012 | for (; q->last_used != hw_tail; |
| 5013 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { |
| 5014 | ipw_queue_tx_free_tfd(priv, txq); |
| 5015 | priv->tx_packets++; |
| 5016 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5017 | done: |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 5018 | if ((ipw_tx_queue_space(q) > q->low_mark) && |
David S. Miller | 521c4d9 | 2008-07-22 18:32:47 -0700 | [diff] [blame] | 5019 | (qindex >= 0)) |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 5020 | netif_wake_queue(priv->net_dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5021 | used = q->first_empty - q->last_used; |
| 5022 | if (used < 0) |
| 5023 | used += q->n_bd; |
| 5024 | |
| 5025 | return used; |
| 5026 | } |
| 5027 | |
| 5028 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, |
| 5029 | int len, int sync) |
| 5030 | { |
| 5031 | struct clx2_tx_queue *txq = &priv->txq_cmd; |
| 5032 | struct clx2_queue *q = &txq->q; |
| 5033 | struct tfd_frame *tfd; |
| 5034 | |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 5035 | if (ipw_tx_queue_space(q) < (sync ? 1 : 2)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5036 | IPW_ERROR("No space for Tx\n"); |
| 5037 | return -EBUSY; |
| 5038 | } |
| 5039 | |
| 5040 | tfd = &txq->bd[q->first_empty]; |
| 5041 | txq->txb[q->first_empty] = NULL; |
| 5042 | |
| 5043 | memset(tfd, 0, sizeof(*tfd)); |
| 5044 | tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE; |
| 5045 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; |
| 5046 | priv->hcmd_seq++; |
| 5047 | tfd->u.cmd.index = hcmd; |
| 5048 | tfd->u.cmd.length = len; |
| 5049 | memcpy(tfd->u.cmd.payload, buf, len); |
| 5050 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); |
| 5051 | ipw_write32(priv, q->reg_w, q->first_empty); |
| 5052 | _ipw_read32(priv, 0x90); |
| 5053 | |
| 5054 | return 0; |
| 5055 | } |
| 5056 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5057 | /* |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5058 | * Rx theory of operation |
| 5059 | * |
| 5060 | * The host allocates 32 DMA target addresses and passes the host address |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5061 | * 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] | 5062 | * 0 to 31 |
| 5063 | * |
| 5064 | * Rx Queue Indexes |
| 5065 | * The host/firmware share two index registers for managing the Rx buffers. |
| 5066 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5067 | * The READ index maps to the first position that the firmware may be writing |
| 5068 | * to -- the driver can read up to (but not including) this position and get |
| 5069 | * good data. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5070 | * The READ index is managed by the firmware once the card is enabled. |
| 5071 | * |
| 5072 | * The WRITE index maps to the last position the driver has read from -- the |
| 5073 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 5074 | * |
| 5075 | * 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] | 5076 | * WRITE = READ. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5077 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5078 | * 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] | 5079 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 5080 | * |
| 5081 | * When the firmware places a packet in a buffer it will advance the READ index |
| 5082 | * and fire the RX interrupt. The driver can then query the READ index and |
| 5083 | * process as many packets as possible, moving the WRITE index forward as it |
| 5084 | * resets the Rx queue buffers with new memory. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5085 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5086 | * The management in the driver is as follows: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5087 | * + 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] | 5088 | * 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] | 5089 | * to replensish the ipw->rxq->rx_free. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5090 | * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the |
| 5091 | * ipw->rxq is replenished and the READ INDEX is updated (updating the |
| 5092 | * 'processed' and 'read' driver indexes as well) |
| 5093 | * + A received packet is processed and handed to the kernel network stack, |
| 5094 | * detached from the ipw->rxq. The driver 'processed' index is updated. |
| 5095 | * + 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] | 5096 | * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ |
| 5097 | * 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] | 5098 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 5099 | * |
| 5100 | * |
| 5101 | * Driver sequence: |
| 5102 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5103 | * ipw_rx_queue_alloc() Allocates rx_free |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5104 | * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls |
| 5105 | * ipw_rx_queue_restock |
| 5106 | * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx |
| 5107 | * queue, updates firmware pointers, and updates |
| 5108 | * the WRITE index. If insufficient rx_free buffers |
| 5109 | * are available, schedules ipw_rx_queue_replenish |
| 5110 | * |
| 5111 | * -- enable interrupts -- |
| 5112 | * 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] | 5113 | * READ INDEX, detaching the SKB from the pool. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5114 | * Moves the packet buffer from queue to rx_used. |
| 5115 | * Calls ipw_rx_queue_restock to refill any empty |
| 5116 | * slots. |
| 5117 | * ... |
| 5118 | * |
| 5119 | */ |
| 5120 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5121 | /* |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5122 | * If there are slots in the RX queue that need to be restocked, |
| 5123 | * and we have free pre-allocated buffers, fill the ranks as much |
| 5124 | * as we can pulling from rx_free. |
| 5125 | * |
| 5126 | * This moves the 'write' index forward to catch up with 'processed', and |
| 5127 | * also updates the memory address in the firmware to reference the new |
| 5128 | * target buffer. |
| 5129 | */ |
| 5130 | static void ipw_rx_queue_restock(struct ipw_priv *priv) |
| 5131 | { |
| 5132 | struct ipw_rx_queue *rxq = priv->rxq; |
| 5133 | struct list_head *element; |
| 5134 | struct ipw_rx_mem_buffer *rxb; |
| 5135 | unsigned long flags; |
| 5136 | int write; |
| 5137 | |
| 5138 | spin_lock_irqsave(&rxq->lock, flags); |
| 5139 | write = rxq->write; |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 5140 | while ((ipw_rx_queue_space(rxq) > 0) && (rxq->free_count)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5141 | element = rxq->rx_free.next; |
| 5142 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); |
| 5143 | list_del(element); |
| 5144 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5145 | ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5146 | rxb->dma_addr); |
| 5147 | rxq->queue[rxq->write] = rxb; |
| 5148 | rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE; |
| 5149 | rxq->free_count--; |
| 5150 | } |
| 5151 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 5152 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5153 | /* If the pre-allocated buffer pool is dropping low, schedule to |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5154 | * refill it */ |
| 5155 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 5156 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 5157 | |
| 5158 | /* 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] | 5159 | if (write != rxq->write) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5160 | ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5161 | } |
| 5162 | |
| 5163 | /* |
| 5164 | * 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] | 5165 | * Also restock the Rx queue via ipw_rx_queue_restock. |
| 5166 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5167 | * This is called as a scheduled work item (except for during intialization) |
| 5168 | */ |
| 5169 | static void ipw_rx_queue_replenish(void *data) |
| 5170 | { |
| 5171 | struct ipw_priv *priv = data; |
| 5172 | struct ipw_rx_queue *rxq = priv->rxq; |
| 5173 | struct list_head *element; |
| 5174 | struct ipw_rx_mem_buffer *rxb; |
| 5175 | unsigned long flags; |
| 5176 | |
| 5177 | spin_lock_irqsave(&rxq->lock, flags); |
| 5178 | while (!list_empty(&rxq->rx_used)) { |
| 5179 | element = rxq->rx_used.next; |
| 5180 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5181 | rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5182 | if (!rxb->skb) { |
| 5183 | printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n", |
| 5184 | priv->net_dev->name); |
| 5185 | /* We don't reschedule replenish work here -- we will |
| 5186 | * call the restock method and if it still needs |
| 5187 | * more buffers it will schedule replenish */ |
| 5188 | break; |
| 5189 | } |
| 5190 | list_del(element); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5191 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5192 | rxb->dma_addr = |
| 5193 | pci_map_single(priv->pci_dev, rxb->skb->data, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5194 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5195 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5196 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 5197 | rxq->free_count++; |
| 5198 | } |
| 5199 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 5200 | |
| 5201 | ipw_rx_queue_restock(priv); |
| 5202 | } |
| 5203 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5204 | static void ipw_bg_rx_queue_replenish(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5205 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5206 | struct ipw_priv *priv = |
| 5207 | container_of(work, struct ipw_priv, rx_replenish); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5208 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5209 | ipw_rx_queue_replenish(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5210 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5211 | } |
| 5212 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5213 | /* 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] | 5214 | * 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] | 5215 | * 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] | 5216 | * non NULL it is unmapped and freed |
| 5217 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5218 | 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] | 5219 | { |
| 5220 | int i; |
| 5221 | |
| 5222 | if (!rxq) |
| 5223 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5224 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5225 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
| 5226 | if (rxq->pool[i].skb != NULL) { |
| 5227 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5228 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5229 | dev_kfree_skb(rxq->pool[i].skb); |
| 5230 | } |
| 5231 | } |
| 5232 | |
| 5233 | kfree(rxq); |
| 5234 | } |
| 5235 | |
| 5236 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv) |
| 5237 | { |
| 5238 | struct ipw_rx_queue *rxq; |
| 5239 | int i; |
| 5240 | |
Takis | c75f474 | 2005-12-01 01:41:45 -0800 | [diff] [blame] | 5241 | rxq = kzalloc(sizeof(*rxq), GFP_KERNEL); |
Panagiotis Issaris | ad18b0e | 2005-09-05 04:14:10 +0200 | [diff] [blame] | 5242 | if (unlikely(!rxq)) { |
| 5243 | IPW_ERROR("memory allocation failed\n"); |
| 5244 | return NULL; |
| 5245 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5246 | spin_lock_init(&rxq->lock); |
| 5247 | INIT_LIST_HEAD(&rxq->rx_free); |
| 5248 | INIT_LIST_HEAD(&rxq->rx_used); |
| 5249 | |
| 5250 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5251 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5252 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 5253 | |
| 5254 | /* Set us so that we have processed and used all buffers, but have |
| 5255 | * not restocked the Rx queue with fresh buffers */ |
| 5256 | rxq->read = rxq->write = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5257 | rxq->free_count = 0; |
| 5258 | |
| 5259 | return rxq; |
| 5260 | } |
| 5261 | |
| 5262 | static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate) |
| 5263 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5264 | rate &= ~LIBIPW_BASIC_RATE_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5265 | if (ieee_mode == IEEE_A) { |
| 5266 | switch (rate) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5267 | case LIBIPW_OFDM_RATE_6MB: |
| 5268 | return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5269 | 1 : 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5270 | case LIBIPW_OFDM_RATE_9MB: |
| 5271 | return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5272 | 1 : 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5273 | case LIBIPW_OFDM_RATE_12MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5274 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5275 | rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0; |
| 5276 | case LIBIPW_OFDM_RATE_18MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5277 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5278 | rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0; |
| 5279 | case LIBIPW_OFDM_RATE_24MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5280 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5281 | rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0; |
| 5282 | case LIBIPW_OFDM_RATE_36MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5283 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5284 | rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0; |
| 5285 | case LIBIPW_OFDM_RATE_48MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5286 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5287 | rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0; |
| 5288 | case LIBIPW_OFDM_RATE_54MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5289 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5290 | rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5291 | default: |
| 5292 | return 0; |
| 5293 | } |
| 5294 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5295 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5296 | /* B and G mixed */ |
| 5297 | switch (rate) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5298 | case LIBIPW_CCK_RATE_1MB: |
| 5299 | return priv->rates_mask & LIBIPW_CCK_RATE_1MB_MASK ? 1 : 0; |
| 5300 | case LIBIPW_CCK_RATE_2MB: |
| 5301 | return priv->rates_mask & LIBIPW_CCK_RATE_2MB_MASK ? 1 : 0; |
| 5302 | case LIBIPW_CCK_RATE_5MB: |
| 5303 | return priv->rates_mask & LIBIPW_CCK_RATE_5MB_MASK ? 1 : 0; |
| 5304 | case LIBIPW_CCK_RATE_11MB: |
| 5305 | return priv->rates_mask & LIBIPW_CCK_RATE_11MB_MASK ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5306 | } |
| 5307 | |
| 5308 | /* If we are limited to B modulations, bail at this point */ |
| 5309 | if (ieee_mode == IEEE_B) |
| 5310 | return 0; |
| 5311 | |
| 5312 | /* G */ |
| 5313 | switch (rate) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5314 | case LIBIPW_OFDM_RATE_6MB: |
| 5315 | return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? 1 : 0; |
| 5316 | case LIBIPW_OFDM_RATE_9MB: |
| 5317 | return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? 1 : 0; |
| 5318 | case LIBIPW_OFDM_RATE_12MB: |
| 5319 | return priv->rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0; |
| 5320 | case LIBIPW_OFDM_RATE_18MB: |
| 5321 | return priv->rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0; |
| 5322 | case LIBIPW_OFDM_RATE_24MB: |
| 5323 | return priv->rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0; |
| 5324 | case LIBIPW_OFDM_RATE_36MB: |
| 5325 | return priv->rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0; |
| 5326 | case LIBIPW_OFDM_RATE_48MB: |
| 5327 | return priv->rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0; |
| 5328 | case LIBIPW_OFDM_RATE_54MB: |
| 5329 | return priv->rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5330 | } |
| 5331 | |
| 5332 | return 0; |
| 5333 | } |
| 5334 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5335 | static int ipw_compatible_rates(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5336 | const struct libipw_network *network, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5337 | struct ipw_supported_rates *rates) |
| 5338 | { |
| 5339 | int num_rates, i; |
| 5340 | |
| 5341 | memset(rates, 0, sizeof(*rates)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5342 | num_rates = min(network->rates_len, (u8) IPW_MAX_RATES); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5343 | rates->num_rates = 0; |
| 5344 | for (i = 0; i < num_rates; i++) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5345 | if (!ipw_is_rate_in_mask(priv, network->mode, |
| 5346 | network->rates[i])) { |
| 5347 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5348 | if (network->rates[i] & LIBIPW_BASIC_RATE_MASK) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5349 | IPW_DEBUG_SCAN("Adding masked mandatory " |
| 5350 | "rate %02X\n", |
| 5351 | network->rates[i]); |
| 5352 | rates->supported_rates[rates->num_rates++] = |
| 5353 | network->rates[i]; |
| 5354 | continue; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5355 | } |
| 5356 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5357 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
| 5358 | network->rates[i], priv->rates_mask); |
| 5359 | continue; |
| 5360 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5361 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5362 | rates->supported_rates[rates->num_rates++] = network->rates[i]; |
| 5363 | } |
| 5364 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5365 | num_rates = min(network->rates_ex_len, |
| 5366 | (u8) (IPW_MAX_RATES - num_rates)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5367 | for (i = 0; i < num_rates; i++) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5368 | if (!ipw_is_rate_in_mask(priv, network->mode, |
| 5369 | network->rates_ex[i])) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5370 | if (network->rates_ex[i] & LIBIPW_BASIC_RATE_MASK) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5371 | IPW_DEBUG_SCAN("Adding masked mandatory " |
| 5372 | "rate %02X\n", |
| 5373 | network->rates_ex[i]); |
| 5374 | rates->supported_rates[rates->num_rates++] = |
| 5375 | network->rates[i]; |
| 5376 | continue; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5377 | } |
| 5378 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5379 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
| 5380 | network->rates_ex[i], priv->rates_mask); |
| 5381 | continue; |
| 5382 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5383 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5384 | rates->supported_rates[rates->num_rates++] = |
| 5385 | network->rates_ex[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5386 | } |
| 5387 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5388 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5389 | } |
| 5390 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 5391 | static void ipw_copy_rates(struct ipw_supported_rates *dest, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5392 | const struct ipw_supported_rates *src) |
| 5393 | { |
| 5394 | u8 i; |
| 5395 | for (i = 0; i < src->num_rates; i++) |
| 5396 | dest->supported_rates[i] = src->supported_rates[i]; |
| 5397 | dest->num_rates = src->num_rates; |
| 5398 | } |
| 5399 | |
| 5400 | /* TODO: Look at sniffed packets in the air to determine if the basic rate |
| 5401 | * mask should ever be used -- right now all callers to add the scan rates are |
| 5402 | * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */ |
| 5403 | static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5404 | u8 modulation, u32 rate_mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5405 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5406 | u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ? |
| 5407 | LIBIPW_BASIC_RATE_MASK : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5408 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5409 | if (rate_mask & LIBIPW_CCK_RATE_1MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5410 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5411 | LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_1MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5412 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5413 | if (rate_mask & LIBIPW_CCK_RATE_2MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5414 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5415 | LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_2MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5416 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5417 | if (rate_mask & LIBIPW_CCK_RATE_5MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5418 | rates->supported_rates[rates->num_rates++] = basic_mask | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5419 | LIBIPW_CCK_RATE_5MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5420 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5421 | if (rate_mask & LIBIPW_CCK_RATE_11MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5422 | rates->supported_rates[rates->num_rates++] = basic_mask | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5423 | LIBIPW_CCK_RATE_11MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5424 | } |
| 5425 | |
| 5426 | static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5427 | u8 modulation, u32 rate_mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5428 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5429 | u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ? |
| 5430 | LIBIPW_BASIC_RATE_MASK : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5431 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5432 | if (rate_mask & LIBIPW_OFDM_RATE_6MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5433 | rates->supported_rates[rates->num_rates++] = basic_mask | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5434 | LIBIPW_OFDM_RATE_6MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5435 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5436 | if (rate_mask & LIBIPW_OFDM_RATE_9MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5437 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5438 | LIBIPW_OFDM_RATE_9MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5439 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5440 | if (rate_mask & LIBIPW_OFDM_RATE_12MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5441 | rates->supported_rates[rates->num_rates++] = basic_mask | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5442 | LIBIPW_OFDM_RATE_12MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5443 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5444 | if (rate_mask & LIBIPW_OFDM_RATE_18MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5445 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5446 | LIBIPW_OFDM_RATE_18MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5447 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5448 | if (rate_mask & LIBIPW_OFDM_RATE_24MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5449 | rates->supported_rates[rates->num_rates++] = basic_mask | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5450 | LIBIPW_OFDM_RATE_24MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5451 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5452 | if (rate_mask & LIBIPW_OFDM_RATE_36MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5453 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5454 | LIBIPW_OFDM_RATE_36MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5455 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5456 | if (rate_mask & LIBIPW_OFDM_RATE_48MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5457 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5458 | LIBIPW_OFDM_RATE_48MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5459 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5460 | if (rate_mask & LIBIPW_OFDM_RATE_54MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5461 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5462 | LIBIPW_OFDM_RATE_54MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5463 | } |
| 5464 | |
| 5465 | struct ipw_network_match { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5466 | struct libipw_network *network; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5467 | struct ipw_supported_rates rates; |
| 5468 | }; |
| 5469 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5470 | static int ipw_find_adhoc_network(struct ipw_priv *priv, |
| 5471 | struct ipw_network_match *match, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5472 | struct libipw_network *network, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5473 | int roaming) |
| 5474 | { |
| 5475 | struct ipw_supported_rates rates; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5476 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5477 | |
| 5478 | /* Verify that this network's capability is compatible with the |
| 5479 | * current mode (AdHoc or Infrastructure) */ |
| 5480 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 5481 | !(network->capability & WLAN_CAPABILITY_IBSS))) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5482 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded due to " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5483 | "capability mismatch.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5484 | print_ssid(ssid, network->ssid, |
| 5485 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5486 | network->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5487 | return 0; |
| 5488 | } |
| 5489 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5490 | if (unlikely(roaming)) { |
| 5491 | /* If we are roaming, then ensure check if this is a valid |
| 5492 | * network to try and roam to */ |
| 5493 | if ((network->ssid_len != match->network->ssid_len) || |
| 5494 | memcmp(network->ssid, match->network->ssid, |
| 5495 | network->ssid_len)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5496 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5497 | "because of non-network ESSID.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5498 | print_ssid(ssid, network->ssid, |
| 5499 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5500 | network->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5501 | return 0; |
| 5502 | } |
| 5503 | } else { |
| 5504 | /* If an ESSID has been configured then compare the broadcast |
| 5505 | * ESSID to ours */ |
| 5506 | if ((priv->config & CFG_STATIC_ESSID) && |
| 5507 | ((network->ssid_len != priv->essid_len) || |
| 5508 | memcmp(network->ssid, priv->essid, |
| 5509 | min(network->ssid_len, priv->essid_len)))) { |
| 5510 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5511 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5512 | strncpy(escaped, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5513 | print_ssid(ssid, network->ssid, |
| 5514 | network->ssid_len), |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5515 | sizeof(escaped)); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5516 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5517 | "because of ESSID mismatch: '%s'.\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5518 | escaped, network->bssid, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5519 | print_ssid(ssid, priv->essid, |
| 5520 | priv->essid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5521 | return 0; |
| 5522 | } |
| 5523 | } |
| 5524 | |
| 5525 | /* If the old network rate is better than this one, don't bother |
| 5526 | * testing everything else. */ |
| 5527 | |
| 5528 | if (network->time_stamp[0] < match->network->time_stamp[0]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5529 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
| 5530 | "current network.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5531 | print_ssid(ssid, match->network->ssid, |
| 5532 | match->network->ssid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5533 | return 0; |
| 5534 | } else if (network->time_stamp[1] < match->network->time_stamp[1]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5535 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
| 5536 | "current network.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5537 | print_ssid(ssid, match->network->ssid, |
| 5538 | match->network->ssid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5539 | return 0; |
| 5540 | } |
| 5541 | |
| 5542 | /* Now go through and see if the requested network is valid... */ |
| 5543 | if (priv->ieee->scan_age != 0 && |
| 5544 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5545 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5546 | "because of age: %ums.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5547 | print_ssid(ssid, network->ssid, |
| 5548 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5549 | network->bssid, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5550 | jiffies_to_msecs(jiffies - |
| 5551 | network->last_scanned)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5552 | return 0; |
| 5553 | } |
| 5554 | |
| 5555 | if ((priv->config & CFG_STATIC_CHANNEL) && |
| 5556 | (network->channel != priv->channel)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5557 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5558 | "because of channel mismatch: %d != %d.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5559 | print_ssid(ssid, network->ssid, |
| 5560 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5561 | network->bssid, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5562 | network->channel, priv->channel); |
| 5563 | return 0; |
| 5564 | } |
| 5565 | |
| 5566 | /* Verify privacy compatability */ |
| 5567 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
| 5568 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5569 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5570 | "because of privacy mismatch: %s != %s.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5571 | print_ssid(ssid, network->ssid, |
| 5572 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5573 | network->bssid, |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5574 | priv-> |
| 5575 | capability & CAP_PRIVACY_ON ? "on" : "off", |
| 5576 | network-> |
| 5577 | capability & WLAN_CAPABILITY_PRIVACY ? "on" : |
| 5578 | "off"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5579 | return 0; |
| 5580 | } |
| 5581 | |
| 5582 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5583 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
| 5584 | "because of the same BSSID match: %pM" |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5585 | ".\n", print_ssid(ssid, network->ssid, |
| 5586 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5587 | network->bssid, |
| 5588 | priv->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5589 | return 0; |
| 5590 | } |
| 5591 | |
| 5592 | /* Filter out any incompatible freq / mode combinations */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5593 | if (!libipw_is_valid_mode(priv->ieee, network->mode)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5594 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5595 | "because of invalid frequency/mode " |
| 5596 | "combination.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5597 | print_ssid(ssid, network->ssid, |
| 5598 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5599 | network->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5600 | return 0; |
| 5601 | } |
| 5602 | |
| 5603 | /* Ensure that the rates supported by the driver are compatible with |
| 5604 | * this AP, including verification of basic rates (mandatory) */ |
| 5605 | if (!ipw_compatible_rates(priv, network, &rates)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5606 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5607 | "because configured rate mask excludes " |
| 5608 | "AP mandatory rate.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5609 | print_ssid(ssid, network->ssid, |
| 5610 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5611 | network->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5612 | return 0; |
| 5613 | } |
| 5614 | |
| 5615 | if (rates.num_rates == 0) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5616 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5617 | "because of no compatible rates.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5618 | print_ssid(ssid, network->ssid, |
| 5619 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5620 | network->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5621 | return 0; |
| 5622 | } |
| 5623 | |
| 5624 | /* TODO: Perform any further minimal comparititive tests. We do not |
| 5625 | * want to put too much policy logic here; intelligent scan selection |
| 5626 | * should occur within a generic IEEE 802.11 user space tool. */ |
| 5627 | |
| 5628 | /* Set up 'new' AP to this network */ |
| 5629 | ipw_copy_rates(&match->rates, &rates); |
| 5630 | match->network = network; |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5631 | IPW_DEBUG_MERGE("Network '%s (%pM)' is a viable match.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5632 | print_ssid(ssid, network->ssid, network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5633 | network->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5634 | |
| 5635 | return 1; |
| 5636 | } |
| 5637 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5638 | static void ipw_merge_adhoc_network(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5639 | { |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5640 | DECLARE_SSID_BUF(ssid); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5641 | struct ipw_priv *priv = |
| 5642 | container_of(work, struct ipw_priv, merge_networks); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5643 | struct libipw_network *network = NULL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5644 | struct ipw_network_match match = { |
| 5645 | .network = priv->assoc_network |
| 5646 | }; |
| 5647 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5648 | if ((priv->status & STATUS_ASSOCIATED) && |
| 5649 | (priv->ieee->iw_mode == IW_MODE_ADHOC)) { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5650 | /* First pass through ROAM process -- look for a better |
| 5651 | * network */ |
| 5652 | unsigned long flags; |
| 5653 | |
| 5654 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 5655 | list_for_each_entry(network, &priv->ieee->network_list, list) { |
| 5656 | if (network != priv->assoc_network) |
| 5657 | ipw_find_adhoc_network(priv, &match, network, |
| 5658 | 1); |
| 5659 | } |
| 5660 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 5661 | |
| 5662 | if (match.network == priv->assoc_network) { |
| 5663 | IPW_DEBUG_MERGE("No better ADHOC in this network to " |
| 5664 | "merge to.\n"); |
| 5665 | return; |
| 5666 | } |
| 5667 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5668 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5669 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) { |
| 5670 | IPW_DEBUG_MERGE("remove network %s\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5671 | print_ssid(ssid, priv->essid, |
| 5672 | priv->essid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5673 | ipw_remove_current_network(priv); |
| 5674 | } |
| 5675 | |
| 5676 | ipw_disassociate(priv); |
| 5677 | priv->assoc_network = match.network; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5678 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5679 | return; |
| 5680 | } |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5681 | } |
| 5682 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5683 | static int ipw_best_network(struct ipw_priv *priv, |
| 5684 | struct ipw_network_match *match, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5685 | struct libipw_network *network, int roaming) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5686 | { |
| 5687 | struct ipw_supported_rates rates; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5688 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5689 | |
| 5690 | /* Verify that this network's capability is compatible with the |
| 5691 | * current mode (AdHoc or Infrastructure) */ |
| 5692 | if ((priv->ieee->iw_mode == IW_MODE_INFRA && |
Jouni Malinen | 2474385 | 2005-08-14 20:59:59 -0700 | [diff] [blame] | 5693 | !(network->capability & WLAN_CAPABILITY_ESS)) || |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5694 | (priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 5695 | !(network->capability & WLAN_CAPABILITY_IBSS))) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5696 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded due to " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5697 | "capability mismatch.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5698 | print_ssid(ssid, network->ssid, |
| 5699 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5700 | network->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5701 | return 0; |
| 5702 | } |
| 5703 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5704 | if (unlikely(roaming)) { |
| 5705 | /* If we are roaming, then ensure check if this is a valid |
| 5706 | * network to try and roam to */ |
| 5707 | if ((network->ssid_len != match->network->ssid_len) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5708 | memcmp(network->ssid, match->network->ssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5709 | network->ssid_len)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5710 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5711 | "because of non-network ESSID.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5712 | print_ssid(ssid, network->ssid, |
| 5713 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5714 | network->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5715 | return 0; |
| 5716 | } |
| 5717 | } else { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5718 | /* If an ESSID has been configured then compare the broadcast |
| 5719 | * ESSID to ours */ |
| 5720 | if ((priv->config & CFG_STATIC_ESSID) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5721 | ((network->ssid_len != priv->essid_len) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5722 | memcmp(network->ssid, priv->essid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5723 | min(network->ssid_len, priv->essid_len)))) { |
| 5724 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5725 | strncpy(escaped, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5726 | print_ssid(ssid, network->ssid, |
| 5727 | network->ssid_len), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5728 | sizeof(escaped)); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5729 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5730 | "because of ESSID mismatch: '%s'.\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5731 | escaped, network->bssid, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5732 | print_ssid(ssid, priv->essid, |
| 5733 | priv->essid_len)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5734 | return 0; |
| 5735 | } |
| 5736 | } |
| 5737 | |
| 5738 | /* If the old network rate is better than this one, don't bother |
| 5739 | * testing everything else. */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5740 | if (match->network && match->network->stats.rssi > network->stats.rssi) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5741 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5742 | strncpy(escaped, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5743 | print_ssid(ssid, network->ssid, network->ssid_len), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5744 | sizeof(escaped)); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5745 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded because " |
| 5746 | "'%s (%pM)' has a stronger signal.\n", |
| 5747 | escaped, network->bssid, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5748 | print_ssid(ssid, match->network->ssid, |
| 5749 | match->network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5750 | match->network->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5751 | return 0; |
| 5752 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5753 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5754 | /* If this network has already had an association attempt within the |
| 5755 | * last 3 seconds, do not try and associate again... */ |
| 5756 | if (network->last_associate && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5757 | time_after(network->last_associate + (HZ * 3UL), jiffies)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5758 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5759 | "because of storming (%ums since last " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5760 | "assoc attempt).\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5761 | print_ssid(ssid, network->ssid, |
| 5762 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5763 | network->bssid, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5764 | jiffies_to_msecs(jiffies - |
| 5765 | network->last_associate)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5766 | return 0; |
| 5767 | } |
| 5768 | |
| 5769 | /* Now go through and see if the requested network is valid... */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5770 | if (priv->ieee->scan_age != 0 && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5771 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5772 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5773 | "because of age: %ums.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5774 | print_ssid(ssid, network->ssid, |
| 5775 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5776 | network->bssid, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5777 | jiffies_to_msecs(jiffies - |
| 5778 | network->last_scanned)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5779 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5780 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5781 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5782 | if ((priv->config & CFG_STATIC_CHANNEL) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5783 | (network->channel != priv->channel)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5784 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5785 | "because of channel mismatch: %d != %d.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5786 | print_ssid(ssid, network->ssid, |
| 5787 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5788 | network->bssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5789 | network->channel, priv->channel); |
| 5790 | return 0; |
| 5791 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5792 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5793 | /* Verify privacy compatability */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5794 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5795 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5796 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5797 | "because of privacy mismatch: %s != %s.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5798 | print_ssid(ssid, network->ssid, |
| 5799 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5800 | network->bssid, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5801 | priv->capability & CAP_PRIVACY_ON ? "on" : |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5802 | "off", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5803 | network->capability & |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5804 | WLAN_CAPABILITY_PRIVACY ? "on" : "off"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5805 | return 0; |
| 5806 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5807 | |
| 5808 | if ((priv->config & CFG_STATIC_BSSID) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5809 | memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5810 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
| 5811 | "because of BSSID mismatch: %pM.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5812 | print_ssid(ssid, network->ssid, |
| 5813 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5814 | network->bssid, priv->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5815 | return 0; |
| 5816 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5817 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5818 | /* Filter out any incompatible freq / mode combinations */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5819 | if (!libipw_is_valid_mode(priv->ieee, network->mode)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5820 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5821 | "because of invalid frequency/mode " |
| 5822 | "combination.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5823 | print_ssid(ssid, network->ssid, |
| 5824 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5825 | network->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5826 | return 0; |
| 5827 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5828 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5829 | /* Filter out invalid channel in current GEO */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5830 | if (!libipw_is_valid_channel(priv->ieee, network->channel)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5831 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5832 | "because of invalid channel in current GEO\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5833 | print_ssid(ssid, network->ssid, |
| 5834 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5835 | network->bssid); |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5836 | return 0; |
| 5837 | } |
| 5838 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5839 | /* Ensure that the rates supported by the driver are compatible with |
| 5840 | * this AP, including verification of basic rates (mandatory) */ |
| 5841 | if (!ipw_compatible_rates(priv, network, &rates)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5842 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5843 | "because configured rate mask excludes " |
| 5844 | "AP mandatory rate.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5845 | print_ssid(ssid, network->ssid, |
| 5846 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5847 | network->bssid); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5848 | return 0; |
| 5849 | } |
| 5850 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5851 | if (rates.num_rates == 0) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5852 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5853 | "because of no compatible rates.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5854 | print_ssid(ssid, network->ssid, |
| 5855 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5856 | network->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5857 | return 0; |
| 5858 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5859 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5860 | /* TODO: Perform any further minimal comparititive tests. We do not |
| 5861 | * want to put too much policy logic here; intelligent scan selection |
| 5862 | * should occur within a generic IEEE 802.11 user space tool. */ |
| 5863 | |
| 5864 | /* Set up 'new' AP to this network */ |
| 5865 | ipw_copy_rates(&match->rates, &rates); |
| 5866 | match->network = network; |
| 5867 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5868 | IPW_DEBUG_ASSOC("Network '%s (%pM)' is a viable match.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5869 | print_ssid(ssid, network->ssid, network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5870 | network->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5871 | |
| 5872 | return 1; |
| 5873 | } |
| 5874 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5875 | static void ipw_adhoc_create(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5876 | struct libipw_network *network) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5877 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5878 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5879 | int i; |
| 5880 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5881 | /* |
| 5882 | * For the purposes of scanning, we can set our wireless mode |
| 5883 | * to trigger scans across combinations of bands, but when it |
| 5884 | * comes to creating a new ad-hoc network, we have tell the FW |
| 5885 | * exactly which band to use. |
| 5886 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5887 | * We also have the possibility of an invalid channel for the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5888 | * chossen band. Attempting to create a new ad-hoc network |
| 5889 | * with an invalid channel for wireless mode will trigger a |
| 5890 | * FW fatal error. |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5891 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5892 | */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5893 | switch (libipw_is_valid_channel(priv->ieee, priv->channel)) { |
| 5894 | case LIBIPW_52GHZ_BAND: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5895 | network->mode = IEEE_A; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5896 | i = libipw_channel_to_index(priv->ieee, priv->channel); |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 5897 | BUG_ON(i == -1); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5898 | if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5899 | IPW_WARNING("Overriding invalid channel\n"); |
| 5900 | priv->channel = geo->a[0].channel; |
| 5901 | } |
| 5902 | break; |
| 5903 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5904 | case LIBIPW_24GHZ_BAND: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5905 | if (priv->ieee->mode & IEEE_G) |
| 5906 | network->mode = IEEE_G; |
| 5907 | else |
| 5908 | network->mode = IEEE_B; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5909 | i = libipw_channel_to_index(priv->ieee, priv->channel); |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 5910 | BUG_ON(i == -1); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5911 | if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) { |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5912 | IPW_WARNING("Overriding invalid channel\n"); |
| 5913 | priv->channel = geo->bg[0].channel; |
| 5914 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5915 | break; |
| 5916 | |
| 5917 | default: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5918 | IPW_WARNING("Overriding invalid channel\n"); |
| 5919 | if (priv->ieee->mode & IEEE_A) { |
| 5920 | network->mode = IEEE_A; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5921 | priv->channel = geo->a[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5922 | } else if (priv->ieee->mode & IEEE_G) { |
| 5923 | network->mode = IEEE_G; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5924 | priv->channel = geo->bg[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5925 | } else { |
| 5926 | network->mode = IEEE_B; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5927 | priv->channel = geo->bg[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5928 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5929 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5930 | } |
| 5931 | |
| 5932 | network->channel = priv->channel; |
| 5933 | priv->config |= CFG_ADHOC_PERSIST; |
| 5934 | ipw_create_bssid(priv, network->bssid); |
| 5935 | network->ssid_len = priv->essid_len; |
| 5936 | memcpy(network->ssid, priv->essid, priv->essid_len); |
| 5937 | memset(&network->stats, 0, sizeof(network->stats)); |
| 5938 | network->capability = WLAN_CAPABILITY_IBSS; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5939 | if (!(priv->config & CFG_PREAMBLE_LONG)) |
| 5940 | network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5941 | if (priv->capability & CAP_PRIVACY_ON) |
| 5942 | network->capability |= WLAN_CAPABILITY_PRIVACY; |
| 5943 | network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5944 | memcpy(network->rates, priv->rates.supported_rates, network->rates_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5945 | network->rates_ex_len = priv->rates.num_rates - network->rates_len; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5946 | memcpy(network->rates_ex, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5947 | &priv->rates.supported_rates[network->rates_len], |
| 5948 | network->rates_ex_len); |
| 5949 | network->last_scanned = 0; |
| 5950 | network->flags = 0; |
| 5951 | network->last_associate = 0; |
| 5952 | network->time_stamp[0] = 0; |
| 5953 | network->time_stamp[1] = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5954 | network->beacon_interval = 100; /* Default */ |
| 5955 | network->listen_interval = 10; /* Default */ |
| 5956 | network->atim_window = 0; /* Default */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5957 | network->wpa_ie_len = 0; |
| 5958 | network->rsn_ie_len = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5959 | } |
| 5960 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5961 | static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index) |
| 5962 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5963 | struct ipw_tgi_tx_key key; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5964 | |
| 5965 | if (!(priv->ieee->sec.flags & (1 << index))) |
| 5966 | return; |
| 5967 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5968 | key.key_id = index; |
| 5969 | memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH); |
| 5970 | key.security_type = type; |
| 5971 | key.station_index = 0; /* always 0 for BSS */ |
| 5972 | key.flags = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5973 | /* 0 for new key; previous value of counter (after fatal error) */ |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 5974 | key.tx_counter[0] = cpu_to_le32(0); |
| 5975 | key.tx_counter[1] = cpu_to_le32(0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5976 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5977 | 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] | 5978 | } |
| 5979 | |
| 5980 | static void ipw_send_wep_keys(struct ipw_priv *priv, int type) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5981 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5982 | struct ipw_wep_key key; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5983 | int i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5984 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5985 | key.cmd_id = DINO_CMD_WEP_KEY; |
| 5986 | key.seq_num = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5987 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5988 | /* Note: AES keys cannot be set for multiple times. |
| 5989 | * Only set it at the first time. */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5990 | for (i = 0; i < 4; i++) { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5991 | key.key_index = i | type; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5992 | if (!(priv->ieee->sec.flags & (1 << i))) { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5993 | key.key_size = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5994 | continue; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5995 | } |
| 5996 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5997 | key.key_size = priv->ieee->sec.key_sizes[i]; |
| 5998 | memcpy(key.key, priv->ieee->sec.keys[i], key.key_size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5999 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6000 | ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6001 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6002 | } |
| 6003 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6004 | static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level) |
| 6005 | { |
| 6006 | if (priv->ieee->host_encrypt) |
| 6007 | return; |
| 6008 | |
| 6009 | switch (level) { |
| 6010 | case SEC_LEVEL_3: |
| 6011 | priv->sys_config.disable_unicast_decryption = 0; |
| 6012 | priv->ieee->host_decrypt = 0; |
| 6013 | break; |
| 6014 | case SEC_LEVEL_2: |
| 6015 | priv->sys_config.disable_unicast_decryption = 1; |
| 6016 | priv->ieee->host_decrypt = 1; |
| 6017 | break; |
| 6018 | case SEC_LEVEL_1: |
| 6019 | priv->sys_config.disable_unicast_decryption = 0; |
| 6020 | priv->ieee->host_decrypt = 0; |
| 6021 | break; |
| 6022 | case SEC_LEVEL_0: |
| 6023 | priv->sys_config.disable_unicast_decryption = 1; |
| 6024 | break; |
| 6025 | default: |
| 6026 | break; |
| 6027 | } |
| 6028 | } |
| 6029 | |
| 6030 | static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level) |
| 6031 | { |
| 6032 | if (priv->ieee->host_encrypt) |
| 6033 | return; |
| 6034 | |
| 6035 | switch (level) { |
| 6036 | case SEC_LEVEL_3: |
| 6037 | priv->sys_config.disable_multicast_decryption = 0; |
| 6038 | break; |
| 6039 | case SEC_LEVEL_2: |
| 6040 | priv->sys_config.disable_multicast_decryption = 1; |
| 6041 | break; |
| 6042 | case SEC_LEVEL_1: |
| 6043 | priv->sys_config.disable_multicast_decryption = 0; |
| 6044 | break; |
| 6045 | case SEC_LEVEL_0: |
| 6046 | priv->sys_config.disable_multicast_decryption = 1; |
| 6047 | break; |
| 6048 | default: |
| 6049 | break; |
| 6050 | } |
| 6051 | } |
| 6052 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6053 | static void ipw_set_hwcrypto_keys(struct ipw_priv *priv) |
| 6054 | { |
| 6055 | switch (priv->ieee->sec.level) { |
| 6056 | case SEC_LEVEL_3: |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 6057 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
| 6058 | ipw_send_tgi_tx_key(priv, |
| 6059 | DCT_FLAG_EXT_SECURITY_CCM, |
| 6060 | priv->ieee->sec.active_key); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6061 | |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 6062 | if (!priv->ieee->host_mc_decrypt) |
| 6063 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6064 | break; |
| 6065 | case SEC_LEVEL_2: |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 6066 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
| 6067 | ipw_send_tgi_tx_key(priv, |
| 6068 | DCT_FLAG_EXT_SECURITY_TKIP, |
| 6069 | priv->ieee->sec.active_key); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6070 | break; |
| 6071 | case SEC_LEVEL_1: |
| 6072 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); |
Hong Liu | 29cb843 | 2005-09-12 10:43:33 -0500 | [diff] [blame] | 6073 | ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level); |
| 6074 | ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6075 | break; |
| 6076 | case SEC_LEVEL_0: |
| 6077 | default: |
| 6078 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6079 | } |
| 6080 | } |
| 6081 | |
| 6082 | static void ipw_adhoc_check(void *data) |
| 6083 | { |
| 6084 | struct ipw_priv *priv = data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6085 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6086 | if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6087 | !(priv->config & CFG_ADHOC_PERSIST)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6088 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
| 6089 | IPW_DL_STATE | IPW_DL_ASSOC, |
| 6090 | "Missed beacon: %d - disassociate\n", |
| 6091 | priv->missed_adhoc_beacons); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6092 | ipw_remove_current_network(priv); |
| 6093 | ipw_disassociate(priv); |
| 6094 | return; |
| 6095 | } |
| 6096 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6097 | queue_delayed_work(priv->workqueue, &priv->adhoc_check, |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 6098 | le16_to_cpu(priv->assoc_request.beacon_interval)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6099 | } |
| 6100 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6101 | static void ipw_bg_adhoc_check(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6102 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6103 | struct ipw_priv *priv = |
| 6104 | container_of(work, struct ipw_priv, adhoc_check.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6105 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6106 | ipw_adhoc_check(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6107 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6108 | } |
| 6109 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6110 | static void ipw_debug_config(struct ipw_priv *priv) |
| 6111 | { |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 6112 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6113 | IPW_DEBUG_INFO("Scan completed, no valid APs matched " |
| 6114 | "[CFG 0x%08X]\n", priv->config); |
| 6115 | if (priv->config & CFG_STATIC_CHANNEL) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 6116 | IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6117 | else |
| 6118 | IPW_DEBUG_INFO("Channel unlocked.\n"); |
| 6119 | if (priv->config & CFG_STATIC_ESSID) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6120 | IPW_DEBUG_INFO("ESSID locked to '%s'\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 6121 | print_ssid(ssid, priv->essid, priv->essid_len)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6122 | else |
| 6123 | IPW_DEBUG_INFO("ESSID unlocked.\n"); |
| 6124 | if (priv->config & CFG_STATIC_BSSID) |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6125 | IPW_DEBUG_INFO("BSSID locked to %pM\n", priv->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6126 | else |
| 6127 | IPW_DEBUG_INFO("BSSID unlocked.\n"); |
| 6128 | if (priv->capability & CAP_PRIVACY_ON) |
| 6129 | IPW_DEBUG_INFO("PRIVACY on\n"); |
| 6130 | else |
| 6131 | IPW_DEBUG_INFO("PRIVACY off\n"); |
| 6132 | IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask); |
| 6133 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6134 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 6135 | static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6136 | { |
| 6137 | /* TODO: Verify that this works... */ |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6138 | struct ipw_fixed_rate fr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6139 | u32 reg; |
| 6140 | u16 mask = 0; |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6141 | u16 new_tx_rates = priv->rates_mask; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6142 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6143 | /* Identify 'current FW band' and match it with the fixed |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6144 | * Tx rates */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6145 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6146 | switch (priv->ieee->freq_band) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6147 | case LIBIPW_52GHZ_BAND: /* A only */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6148 | /* IEEE_A */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6149 | if (priv->rates_mask & ~LIBIPW_OFDM_RATES_MASK) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6150 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6151 | IPW_DEBUG_WX |
| 6152 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6153 | new_tx_rates = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6154 | break; |
| 6155 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6156 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6157 | new_tx_rates >>= LIBIPW_OFDM_SHIFT_MASK_A; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6158 | break; |
| 6159 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 6160 | default: /* 2.4Ghz or Mixed */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6161 | /* IEEE_B */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6162 | if (mode == IEEE_B) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6163 | if (new_tx_rates & ~LIBIPW_CCK_RATES_MASK) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6164 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6165 | IPW_DEBUG_WX |
| 6166 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6167 | new_tx_rates = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6168 | } |
| 6169 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6170 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6171 | |
| 6172 | /* IEEE_G */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6173 | if (new_tx_rates & ~(LIBIPW_CCK_RATES_MASK | |
| 6174 | LIBIPW_OFDM_RATES_MASK)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6175 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6176 | IPW_DEBUG_WX |
| 6177 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6178 | new_tx_rates = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6179 | break; |
| 6180 | } |
| 6181 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6182 | if (LIBIPW_OFDM_RATE_6MB_MASK & new_tx_rates) { |
| 6183 | mask |= (LIBIPW_OFDM_RATE_6MB_MASK >> 1); |
| 6184 | new_tx_rates &= ~LIBIPW_OFDM_RATE_6MB_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6185 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6186 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6187 | if (LIBIPW_OFDM_RATE_9MB_MASK & new_tx_rates) { |
| 6188 | mask |= (LIBIPW_OFDM_RATE_9MB_MASK >> 1); |
| 6189 | new_tx_rates &= ~LIBIPW_OFDM_RATE_9MB_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6190 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6191 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6192 | if (LIBIPW_OFDM_RATE_12MB_MASK & new_tx_rates) { |
| 6193 | mask |= (LIBIPW_OFDM_RATE_12MB_MASK >> 1); |
| 6194 | new_tx_rates &= ~LIBIPW_OFDM_RATE_12MB_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6195 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6196 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6197 | new_tx_rates |= mask; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6198 | break; |
| 6199 | } |
| 6200 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6201 | fr.tx_rates = cpu_to_le16(new_tx_rates); |
| 6202 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6203 | reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 6204 | ipw_write_reg32(priv, reg, *(u32 *) & fr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6205 | } |
| 6206 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6207 | static void ipw_abort_scan(struct ipw_priv *priv) |
| 6208 | { |
| 6209 | int err; |
| 6210 | |
| 6211 | if (priv->status & STATUS_SCAN_ABORTING) { |
| 6212 | IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n"); |
| 6213 | return; |
| 6214 | } |
| 6215 | priv->status |= STATUS_SCAN_ABORTING; |
| 6216 | |
| 6217 | err = ipw_send_scan_abort(priv); |
| 6218 | if (err) |
| 6219 | IPW_DEBUG_HC("Request to abort scan failed.\n"); |
| 6220 | } |
| 6221 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6222 | static void ipw_add_scan_channels(struct ipw_priv *priv, |
| 6223 | struct ipw_scan_request_ext *scan, |
| 6224 | int scan_type) |
| 6225 | { |
| 6226 | int channel_index = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6227 | const struct libipw_geo *geo; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6228 | int i; |
| 6229 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6230 | geo = libipw_get_geo(priv->ieee); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6231 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6232 | if (priv->ieee->freq_band & LIBIPW_52GHZ_BAND) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6233 | int start = channel_index; |
| 6234 | for (i = 0; i < geo->a_channels; i++) { |
| 6235 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6236 | geo->a[i].channel == priv->channel) |
| 6237 | continue; |
| 6238 | channel_index++; |
| 6239 | scan->channels_list[channel_index] = geo->a[i].channel; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6240 | ipw_set_scan_type(scan, channel_index, |
| 6241 | geo->a[i]. |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6242 | flags & LIBIPW_CH_PASSIVE_ONLY ? |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6243 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN : |
| 6244 | scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6245 | } |
| 6246 | |
| 6247 | if (start != channel_index) { |
| 6248 | scan->channels_list[start] = (u8) (IPW_A_MODE << 6) | |
| 6249 | (channel_index - start); |
| 6250 | channel_index++; |
| 6251 | } |
| 6252 | } |
| 6253 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6254 | if (priv->ieee->freq_band & LIBIPW_24GHZ_BAND) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6255 | int start = channel_index; |
| 6256 | if (priv->config & CFG_SPEED_SCAN) { |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6257 | int index; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6258 | u8 channels[LIBIPW_24GHZ_CHANNELS] = { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6259 | /* nop out the list */ |
| 6260 | [0] = 0 |
| 6261 | }; |
| 6262 | |
| 6263 | u8 channel; |
Zhu Yi | 7dd2459 | 2009-07-27 10:10:20 +0800 | [diff] [blame] | 6264 | while (channel_index < IPW_SCAN_CHANNELS - 1) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6265 | channel = |
| 6266 | priv->speed_scan[priv->speed_scan_pos]; |
| 6267 | if (channel == 0) { |
| 6268 | priv->speed_scan_pos = 0; |
| 6269 | channel = priv->speed_scan[0]; |
| 6270 | } |
| 6271 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6272 | channel == priv->channel) { |
| 6273 | priv->speed_scan_pos++; |
| 6274 | continue; |
| 6275 | } |
| 6276 | |
| 6277 | /* If this channel has already been |
| 6278 | * added in scan, break from loop |
| 6279 | * and this will be the first channel |
| 6280 | * in the next scan. |
| 6281 | */ |
| 6282 | if (channels[channel - 1] != 0) |
| 6283 | break; |
| 6284 | |
| 6285 | channels[channel - 1] = 1; |
| 6286 | priv->speed_scan_pos++; |
| 6287 | channel_index++; |
| 6288 | scan->channels_list[channel_index] = channel; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6289 | index = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6290 | libipw_channel_to_index(priv->ieee, channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6291 | ipw_set_scan_type(scan, channel_index, |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6292 | geo->bg[index]. |
| 6293 | flags & |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6294 | LIBIPW_CH_PASSIVE_ONLY ? |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6295 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN |
| 6296 | : scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6297 | } |
| 6298 | } else { |
| 6299 | for (i = 0; i < geo->bg_channels; i++) { |
| 6300 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6301 | geo->bg[i].channel == priv->channel) |
| 6302 | continue; |
| 6303 | channel_index++; |
| 6304 | scan->channels_list[channel_index] = |
| 6305 | geo->bg[i].channel; |
| 6306 | ipw_set_scan_type(scan, channel_index, |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6307 | geo->bg[i]. |
| 6308 | flags & |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6309 | LIBIPW_CH_PASSIVE_ONLY ? |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6310 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN |
| 6311 | : scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6312 | } |
| 6313 | } |
| 6314 | |
| 6315 | if (start != channel_index) { |
| 6316 | scan->channels_list[start] = (u8) (IPW_B_MODE << 6) | |
| 6317 | (channel_index - start); |
| 6318 | } |
| 6319 | } |
| 6320 | } |
| 6321 | |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 6322 | static int ipw_passive_dwell_time(struct ipw_priv *priv) |
| 6323 | { |
| 6324 | /* staying on passive channels longer than the DTIM interval during a |
| 6325 | * scan, while associated, causes the firmware to cancel the scan |
| 6326 | * without notification. Hence, don't stay on passive channels longer |
| 6327 | * than the beacon interval. |
| 6328 | */ |
| 6329 | if (priv->status & STATUS_ASSOCIATED |
| 6330 | && priv->assoc_network->beacon_interval > 10) |
| 6331 | return priv->assoc_network->beacon_interval - 10; |
| 6332 | else |
| 6333 | return 120; |
| 6334 | } |
| 6335 | |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6336 | static int ipw_request_scan_helper(struct ipw_priv *priv, int type, int direct) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6337 | { |
| 6338 | struct ipw_scan_request_ext scan; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6339 | int err = 0, scan_type; |
| 6340 | |
| 6341 | if (!(priv->status & STATUS_INIT) || |
| 6342 | (priv->status & STATUS_EXIT_PENDING)) |
| 6343 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6344 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6345 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6346 | |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6347 | if (direct && (priv->direct_scan_ssid_len == 0)) { |
| 6348 | IPW_DEBUG_HC("Direct scan requested but no SSID to scan for\n"); |
| 6349 | priv->status &= ~STATUS_DIRECT_SCAN_PENDING; |
| 6350 | goto done; |
| 6351 | } |
| 6352 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6353 | if (priv->status & STATUS_SCANNING) { |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6354 | IPW_DEBUG_HC("Concurrent scan requested. Queuing.\n"); |
| 6355 | priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING : |
| 6356 | STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6357 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6358 | } |
| 6359 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6360 | if (!(priv->status & STATUS_SCAN_FORCED) && |
| 6361 | priv->status & STATUS_SCAN_ABORTING) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6362 | IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6363 | priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING : |
| 6364 | STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6365 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6366 | } |
| 6367 | |
| 6368 | if (priv->status & STATUS_RF_KILL_MASK) { |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6369 | IPW_DEBUG_HC("Queuing scan due to RF Kill activation\n"); |
| 6370 | priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING : |
| 6371 | STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6372 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6373 | } |
| 6374 | |
| 6375 | memset(&scan, 0, sizeof(scan)); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6376 | scan.full_scan_index = cpu_to_le32(libipw_get_scans(priv->ieee)); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6377 | |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6378 | if (type == IW_SCAN_TYPE_PASSIVE) { |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 6379 | IPW_DEBUG_WX("use passive scanning\n"); |
| 6380 | scan_type = IPW_SCAN_PASSIVE_FULL_DWELL_SCAN; |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6381 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 6382 | cpu_to_le16(ipw_passive_dwell_time(priv)); |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6383 | ipw_add_scan_channels(priv, &scan, scan_type); |
| 6384 | goto send_request; |
| 6385 | } |
| 6386 | |
| 6387 | /* Use active scan by default. */ |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 6388 | if (priv->config & CFG_SPEED_SCAN) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6389 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6390 | cpu_to_le16(30); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6391 | else |
| 6392 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6393 | cpu_to_le16(20); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6394 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6395 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6396 | cpu_to_le16(20); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6397 | |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 6398 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
| 6399 | cpu_to_le16(ipw_passive_dwell_time(priv)); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6400 | scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6401 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6402 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6403 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6404 | u8 channel; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6405 | u8 band = 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6406 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6407 | switch (libipw_is_valid_channel(priv->ieee, priv->channel)) { |
| 6408 | case LIBIPW_52GHZ_BAND: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6409 | band = (u8) (IPW_A_MODE << 6) | 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6410 | channel = priv->channel; |
| 6411 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6412 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6413 | case LIBIPW_24GHZ_BAND: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6414 | band = (u8) (IPW_B_MODE << 6) | 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6415 | channel = priv->channel; |
| 6416 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6417 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6418 | default: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6419 | band = (u8) (IPW_B_MODE << 6) | 1; |
| 6420 | channel = 9; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6421 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6422 | } |
| 6423 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6424 | scan.channels_list[0] = band; |
| 6425 | scan.channels_list[1] = channel; |
| 6426 | ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6427 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6428 | /* NOTE: The card will sit on this channel for this time |
| 6429 | * period. Scan aborts are timing sensitive and frequently |
| 6430 | * result in firmware restarts. As such, it is best to |
| 6431 | * set a small dwell_time here and just keep re-issuing |
| 6432 | * scans. Otherwise fast channel hopping will not actually |
| 6433 | * hop channels. |
| 6434 | * |
| 6435 | * TODO: Move SPEED SCAN support to all modes and bands */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6436 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6437 | cpu_to_le16(2000); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6438 | } else { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6439 | #endif /* CONFIG_IPW2200_MONITOR */ |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6440 | /* Honor direct scans first, otherwise if we are roaming make |
| 6441 | * this a direct scan for the current network. Finally, |
| 6442 | * ensure that every other scan is a fast channel hop scan */ |
| 6443 | if (direct) { |
| 6444 | err = ipw_send_ssid(priv, priv->direct_scan_ssid, |
| 6445 | priv->direct_scan_ssid_len); |
| 6446 | if (err) { |
| 6447 | IPW_DEBUG_HC("Attempt to send SSID command " |
| 6448 | "failed\n"); |
| 6449 | goto done; |
| 6450 | } |
| 6451 | |
| 6452 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; |
| 6453 | } else if ((priv->status & STATUS_ROAMING) |
| 6454 | || (!(priv->status & STATUS_ASSOCIATED) |
| 6455 | && (priv->config & CFG_STATIC_ESSID) |
| 6456 | && (le32_to_cpu(scan.full_scan_index) % 2))) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6457 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
| 6458 | if (err) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6459 | IPW_DEBUG_HC("Attempt to send SSID command " |
| 6460 | "failed.\n"); |
| 6461 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6462 | } |
| 6463 | |
| 6464 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6465 | } else |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6466 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6467 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6468 | ipw_add_scan_channels(priv, &scan, scan_type); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6469 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6470 | } |
| 6471 | #endif |
| 6472 | |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6473 | send_request: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6474 | err = ipw_send_scan_request_ext(priv, &scan); |
| 6475 | if (err) { |
| 6476 | IPW_DEBUG_HC("Sending scan command failed: %08X\n", err); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6477 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6478 | } |
| 6479 | |
| 6480 | priv->status |= STATUS_SCANNING; |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6481 | if (direct) { |
| 6482 | priv->status &= ~STATUS_DIRECT_SCAN_PENDING; |
| 6483 | priv->direct_scan_ssid_len = 0; |
| 6484 | } else |
| 6485 | priv->status &= ~STATUS_SCAN_PENDING; |
| 6486 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6487 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 6488 | IPW_SCAN_CHECK_WATCHDOG); |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6489 | done: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6490 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6491 | return err; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6492 | } |
| 6493 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6494 | static void ipw_request_passive_scan(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6495 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6496 | struct ipw_priv *priv = |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6497 | container_of(work, struct ipw_priv, request_passive_scan.work); |
| 6498 | ipw_request_scan_helper(priv, IW_SCAN_TYPE_PASSIVE, 0); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6499 | } |
| 6500 | |
| 6501 | static void ipw_request_scan(struct work_struct *work) |
| 6502 | { |
| 6503 | struct ipw_priv *priv = |
| 6504 | container_of(work, struct ipw_priv, request_scan.work); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6505 | ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 0); |
| 6506 | } |
| 6507 | |
| 6508 | static void ipw_request_direct_scan(struct work_struct *work) |
| 6509 | { |
| 6510 | struct ipw_priv *priv = |
| 6511 | container_of(work, struct ipw_priv, request_direct_scan.work); |
| 6512 | ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 1); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6513 | } |
| 6514 | |
| 6515 | static void ipw_bg_abort_scan(struct work_struct *work) |
| 6516 | { |
| 6517 | struct ipw_priv *priv = |
| 6518 | container_of(work, struct ipw_priv, abort_scan); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6519 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6520 | ipw_abort_scan(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6521 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6522 | } |
| 6523 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6524 | static int ipw_wpa_enable(struct ipw_priv *priv, int value) |
| 6525 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6526 | /* This is called when wpa_supplicant loads and closes the driver |
| 6527 | * interface. */ |
Hong Liu | cdd1fa1 | 2005-08-31 18:14:27 +0800 | [diff] [blame] | 6528 | priv->ieee->wpa_enabled = value; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6529 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6530 | } |
| 6531 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6532 | static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value) |
| 6533 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6534 | struct libipw_device *ieee = priv->ieee; |
| 6535 | struct libipw_security sec = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6536 | .flags = SEC_AUTH_MODE, |
| 6537 | }; |
| 6538 | int ret = 0; |
| 6539 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6540 | if (value & IW_AUTH_ALG_SHARED_KEY) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6541 | sec.auth_mode = WLAN_AUTH_SHARED_KEY; |
| 6542 | ieee->open_wep = 0; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6543 | } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6544 | sec.auth_mode = WLAN_AUTH_OPEN; |
| 6545 | ieee->open_wep = 1; |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 6546 | } else if (value & IW_AUTH_ALG_LEAP) { |
| 6547 | sec.auth_mode = WLAN_AUTH_LEAP; |
| 6548 | ieee->open_wep = 1; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6549 | } else |
| 6550 | return -EINVAL; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6551 | |
| 6552 | if (ieee->set_security) |
| 6553 | ieee->set_security(ieee->dev, &sec); |
| 6554 | else |
| 6555 | ret = -EOPNOTSUPP; |
| 6556 | |
| 6557 | return ret; |
| 6558 | } |
| 6559 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 6560 | static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, |
| 6561 | int wpa_ie_len) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6562 | { |
| 6563 | /* make sure WPA is enabled */ |
| 6564 | ipw_wpa_enable(priv, 1); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6565 | } |
| 6566 | |
| 6567 | static int ipw_set_rsn_capa(struct ipw_priv *priv, |
| 6568 | char *capabilities, int length) |
| 6569 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6570 | IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n"); |
| 6571 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6572 | return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 6573 | capabilities); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6574 | } |
| 6575 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6576 | /* |
| 6577 | * WE-18 support |
| 6578 | */ |
| 6579 | |
| 6580 | /* SIOCSIWGENIE */ |
| 6581 | static int ipw_wx_set_genie(struct net_device *dev, |
| 6582 | struct iw_request_info *info, |
| 6583 | union iwreq_data *wrqu, char *extra) |
| 6584 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6585 | struct ipw_priv *priv = libipw_priv(dev); |
| 6586 | struct libipw_device *ieee = priv->ieee; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6587 | u8 *buf; |
| 6588 | int err = 0; |
| 6589 | |
| 6590 | if (wrqu->data.length > MAX_WPA_IE_LEN || |
| 6591 | (wrqu->data.length && extra == NULL)) |
| 6592 | return -EINVAL; |
| 6593 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6594 | if (wrqu->data.length) { |
| 6595 | buf = kmalloc(wrqu->data.length, GFP_KERNEL); |
| 6596 | if (buf == NULL) { |
| 6597 | err = -ENOMEM; |
| 6598 | goto out; |
| 6599 | } |
| 6600 | |
| 6601 | memcpy(buf, extra, wrqu->data.length); |
| 6602 | kfree(ieee->wpa_ie); |
| 6603 | ieee->wpa_ie = buf; |
| 6604 | ieee->wpa_ie_len = wrqu->data.length; |
| 6605 | } else { |
| 6606 | kfree(ieee->wpa_ie); |
| 6607 | ieee->wpa_ie = NULL; |
| 6608 | ieee->wpa_ie_len = 0; |
| 6609 | } |
| 6610 | |
| 6611 | ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len); |
| 6612 | out: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6613 | return err; |
| 6614 | } |
| 6615 | |
| 6616 | /* SIOCGIWGENIE */ |
| 6617 | static int ipw_wx_get_genie(struct net_device *dev, |
| 6618 | struct iw_request_info *info, |
| 6619 | union iwreq_data *wrqu, char *extra) |
| 6620 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6621 | struct ipw_priv *priv = libipw_priv(dev); |
| 6622 | struct libipw_device *ieee = priv->ieee; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6623 | int err = 0; |
| 6624 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6625 | if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) { |
| 6626 | wrqu->data.length = 0; |
| 6627 | goto out; |
| 6628 | } |
| 6629 | |
| 6630 | if (wrqu->data.length < ieee->wpa_ie_len) { |
| 6631 | err = -E2BIG; |
| 6632 | goto out; |
| 6633 | } |
| 6634 | |
| 6635 | wrqu->data.length = ieee->wpa_ie_len; |
| 6636 | memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len); |
| 6637 | |
| 6638 | out: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6639 | return err; |
| 6640 | } |
| 6641 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6642 | static int wext_cipher2level(int cipher) |
| 6643 | { |
| 6644 | switch (cipher) { |
| 6645 | case IW_AUTH_CIPHER_NONE: |
| 6646 | return SEC_LEVEL_0; |
| 6647 | case IW_AUTH_CIPHER_WEP40: |
| 6648 | case IW_AUTH_CIPHER_WEP104: |
| 6649 | return SEC_LEVEL_1; |
| 6650 | case IW_AUTH_CIPHER_TKIP: |
| 6651 | return SEC_LEVEL_2; |
| 6652 | case IW_AUTH_CIPHER_CCMP: |
| 6653 | return SEC_LEVEL_3; |
| 6654 | default: |
| 6655 | return -1; |
| 6656 | } |
| 6657 | } |
| 6658 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6659 | /* SIOCSIWAUTH */ |
| 6660 | static int ipw_wx_set_auth(struct net_device *dev, |
| 6661 | struct iw_request_info *info, |
| 6662 | union iwreq_data *wrqu, char *extra) |
| 6663 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6664 | struct ipw_priv *priv = libipw_priv(dev); |
| 6665 | struct libipw_device *ieee = priv->ieee; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6666 | struct iw_param *param = &wrqu->param; |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 6667 | struct lib80211_crypt_data *crypt; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6668 | unsigned long flags; |
| 6669 | int ret = 0; |
| 6670 | |
| 6671 | switch (param->flags & IW_AUTH_INDEX) { |
| 6672 | case IW_AUTH_WPA_VERSION: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6673 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6674 | case IW_AUTH_CIPHER_PAIRWISE: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6675 | ipw_set_hw_decrypt_unicast(priv, |
| 6676 | wext_cipher2level(param->value)); |
| 6677 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6678 | case IW_AUTH_CIPHER_GROUP: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6679 | ipw_set_hw_decrypt_multicast(priv, |
| 6680 | wext_cipher2level(param->value)); |
| 6681 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6682 | case IW_AUTH_KEY_MGMT: |
| 6683 | /* |
| 6684 | * ipw2200 does not use these parameters |
| 6685 | */ |
| 6686 | break; |
| 6687 | |
| 6688 | case IW_AUTH_TKIP_COUNTERMEASURES: |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 6689 | crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx]; |
James Ketrenos | 991d1cc | 2005-10-13 09:26:48 +0000 | [diff] [blame] | 6690 | if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6691 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6692 | |
| 6693 | flags = crypt->ops->get_flags(crypt->priv); |
| 6694 | |
| 6695 | if (param->value) |
| 6696 | flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; |
| 6697 | else |
| 6698 | flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; |
| 6699 | |
| 6700 | crypt->ops->set_flags(flags, crypt->priv); |
| 6701 | |
| 6702 | break; |
| 6703 | |
| 6704 | case IW_AUTH_DROP_UNENCRYPTED:{ |
| 6705 | /* HACK: |
| 6706 | * |
| 6707 | * wpa_supplicant calls set_wpa_enabled when the driver |
| 6708 | * is loaded and unloaded, regardless of if WPA is being |
| 6709 | * used. No other calls are made which can be used to |
| 6710 | * determine if encryption will be used or not prior to |
| 6711 | * association being expected. If encryption is not being |
| 6712 | * used, drop_unencrypted is set to false, else true -- we |
| 6713 | * can use this to determine if the CAP_PRIVACY_ON bit should |
| 6714 | * be set. |
| 6715 | */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6716 | struct libipw_security sec = { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6717 | .flags = SEC_ENABLED, |
| 6718 | .enabled = param->value, |
| 6719 | }; |
| 6720 | priv->ieee->drop_unencrypted = param->value; |
| 6721 | /* We only change SEC_LEVEL for open mode. Others |
| 6722 | * are set by ipw_wpa_set_encryption. |
| 6723 | */ |
| 6724 | if (!param->value) { |
| 6725 | sec.flags |= SEC_LEVEL; |
| 6726 | sec.level = SEC_LEVEL_0; |
| 6727 | } else { |
| 6728 | sec.flags |= SEC_LEVEL; |
| 6729 | sec.level = SEC_LEVEL_1; |
| 6730 | } |
| 6731 | if (priv->ieee->set_security) |
| 6732 | priv->ieee->set_security(priv->ieee->dev, &sec); |
| 6733 | break; |
| 6734 | } |
| 6735 | |
| 6736 | case IW_AUTH_80211_AUTH_ALG: |
| 6737 | ret = ipw_wpa_set_auth_algs(priv, param->value); |
| 6738 | break; |
| 6739 | |
| 6740 | case IW_AUTH_WPA_ENABLED: |
| 6741 | ret = ipw_wpa_enable(priv, param->value); |
Zhu Yi | e3c5a64 | 2006-04-13 17:21:13 +0800 | [diff] [blame] | 6742 | ipw_disassociate(priv); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6743 | break; |
| 6744 | |
| 6745 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 6746 | ieee->ieee802_1x = param->value; |
| 6747 | break; |
| 6748 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6749 | case IW_AUTH_PRIVACY_INVOKED: |
| 6750 | ieee->privacy_invoked = param->value; |
| 6751 | break; |
| 6752 | |
| 6753 | default: |
| 6754 | return -EOPNOTSUPP; |
| 6755 | } |
| 6756 | return ret; |
| 6757 | } |
| 6758 | |
| 6759 | /* SIOCGIWAUTH */ |
| 6760 | static int ipw_wx_get_auth(struct net_device *dev, |
| 6761 | struct iw_request_info *info, |
| 6762 | union iwreq_data *wrqu, char *extra) |
| 6763 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6764 | struct ipw_priv *priv = libipw_priv(dev); |
| 6765 | struct libipw_device *ieee = priv->ieee; |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 6766 | struct lib80211_crypt_data *crypt; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6767 | struct iw_param *param = &wrqu->param; |
| 6768 | int ret = 0; |
| 6769 | |
| 6770 | switch (param->flags & IW_AUTH_INDEX) { |
| 6771 | case IW_AUTH_WPA_VERSION: |
| 6772 | case IW_AUTH_CIPHER_PAIRWISE: |
| 6773 | case IW_AUTH_CIPHER_GROUP: |
| 6774 | case IW_AUTH_KEY_MGMT: |
| 6775 | /* |
| 6776 | * wpa_supplicant will control these internally |
| 6777 | */ |
| 6778 | ret = -EOPNOTSUPP; |
| 6779 | break; |
| 6780 | |
| 6781 | case IW_AUTH_TKIP_COUNTERMEASURES: |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 6782 | crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx]; |
James Ketrenos | 991d1cc | 2005-10-13 09:26:48 +0000 | [diff] [blame] | 6783 | if (!crypt || !crypt->ops->get_flags) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6784 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6785 | |
| 6786 | param->value = (crypt->ops->get_flags(crypt->priv) & |
| 6787 | IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0; |
| 6788 | |
| 6789 | break; |
| 6790 | |
| 6791 | case IW_AUTH_DROP_UNENCRYPTED: |
| 6792 | param->value = ieee->drop_unencrypted; |
| 6793 | break; |
| 6794 | |
| 6795 | case IW_AUTH_80211_AUTH_ALG: |
| 6796 | param->value = ieee->sec.auth_mode; |
| 6797 | break; |
| 6798 | |
| 6799 | case IW_AUTH_WPA_ENABLED: |
| 6800 | param->value = ieee->wpa_enabled; |
| 6801 | break; |
| 6802 | |
| 6803 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 6804 | param->value = ieee->ieee802_1x; |
| 6805 | break; |
| 6806 | |
| 6807 | case IW_AUTH_ROAMING_CONTROL: |
| 6808 | case IW_AUTH_PRIVACY_INVOKED: |
| 6809 | param->value = ieee->privacy_invoked; |
| 6810 | break; |
| 6811 | |
| 6812 | default: |
| 6813 | return -EOPNOTSUPP; |
| 6814 | } |
| 6815 | return 0; |
| 6816 | } |
| 6817 | |
| 6818 | /* SIOCSIWENCODEEXT */ |
| 6819 | static int ipw_wx_set_encodeext(struct net_device *dev, |
| 6820 | struct iw_request_info *info, |
| 6821 | union iwreq_data *wrqu, char *extra) |
| 6822 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6823 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6824 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; |
| 6825 | |
| 6826 | if (hwcrypto) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6827 | if (ext->alg == IW_ENCODE_ALG_TKIP) { |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 6828 | /* IPW HW can't build TKIP MIC, |
| 6829 | host decryption still needed */ |
| 6830 | if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) |
| 6831 | priv->ieee->host_mc_decrypt = 1; |
| 6832 | else { |
| 6833 | priv->ieee->host_encrypt = 0; |
| 6834 | priv->ieee->host_encrypt_msdu = 1; |
| 6835 | priv->ieee->host_decrypt = 1; |
| 6836 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6837 | } else { |
| 6838 | priv->ieee->host_encrypt = 0; |
| 6839 | priv->ieee->host_encrypt_msdu = 0; |
| 6840 | priv->ieee->host_decrypt = 0; |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 6841 | priv->ieee->host_mc_decrypt = 0; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6842 | } |
| 6843 | } |
| 6844 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6845 | return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6846 | } |
| 6847 | |
| 6848 | /* SIOCGIWENCODEEXT */ |
| 6849 | static int ipw_wx_get_encodeext(struct net_device *dev, |
| 6850 | struct iw_request_info *info, |
| 6851 | union iwreq_data *wrqu, char *extra) |
| 6852 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6853 | struct ipw_priv *priv = libipw_priv(dev); |
| 6854 | return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6855 | } |
| 6856 | |
| 6857 | /* SIOCSIWMLME */ |
| 6858 | static int ipw_wx_set_mlme(struct net_device *dev, |
| 6859 | struct iw_request_info *info, |
| 6860 | union iwreq_data *wrqu, char *extra) |
| 6861 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6862 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6863 | struct iw_mlme *mlme = (struct iw_mlme *)extra; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 6864 | __le16 reason; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6865 | |
| 6866 | reason = cpu_to_le16(mlme->reason_code); |
| 6867 | |
| 6868 | switch (mlme->cmd) { |
| 6869 | case IW_MLME_DEAUTH: |
Pavel Machek | 67fd6b4 | 2006-07-11 15:34:05 +0200 | [diff] [blame] | 6870 | /* silently ignore */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6871 | break; |
| 6872 | |
| 6873 | case IW_MLME_DISASSOC: |
| 6874 | ipw_disassociate(priv); |
| 6875 | break; |
| 6876 | |
| 6877 | default: |
| 6878 | return -EOPNOTSUPP; |
| 6879 | } |
| 6880 | return 0; |
| 6881 | } |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6882 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 6883 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6884 | |
| 6885 | /* QoS */ |
| 6886 | /* |
| 6887 | * get the modulation type of the current network or |
| 6888 | * the card current mode |
| 6889 | */ |
Adrian Bunk | 53d0bcf | 2006-03-04 13:14:31 +0100 | [diff] [blame] | 6890 | static u8 ipw_qos_current_mode(struct ipw_priv * priv) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6891 | { |
| 6892 | u8 mode = 0; |
| 6893 | |
| 6894 | if (priv->status & STATUS_ASSOCIATED) { |
| 6895 | unsigned long flags; |
| 6896 | |
| 6897 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 6898 | mode = priv->assoc_network->mode; |
| 6899 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 6900 | } else { |
| 6901 | mode = priv->ieee->mode; |
| 6902 | } |
| 6903 | IPW_DEBUG_QOS("QoS network/card mode %d \n", mode); |
| 6904 | return mode; |
| 6905 | } |
| 6906 | |
| 6907 | /* |
| 6908 | * Handle management frame beacon and probe response |
| 6909 | */ |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 6910 | static int ipw_qos_handle_probe_response(struct ipw_priv *priv, |
| 6911 | int active_network, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6912 | struct libipw_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6913 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6914 | u32 size = sizeof(struct libipw_qos_parameters); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6915 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6916 | if (network->capability & WLAN_CAPABILITY_IBSS) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6917 | network->qos_data.active = network->qos_data.supported; |
| 6918 | |
| 6919 | if (network->flags & NETWORK_HAS_QOS_MASK) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6920 | if (active_network && |
| 6921 | (network->flags & NETWORK_HAS_QOS_PARAMETERS)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6922 | network->qos_data.active = network->qos_data.supported; |
| 6923 | |
| 6924 | if ((network->qos_data.active == 1) && (active_network == 1) && |
| 6925 | (network->flags & NETWORK_HAS_QOS_PARAMETERS) && |
| 6926 | (network->qos_data.old_param_count != |
| 6927 | network->qos_data.param_count)) { |
| 6928 | network->qos_data.old_param_count = |
| 6929 | network->qos_data.param_count; |
| 6930 | schedule_work(&priv->qos_activate); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6931 | IPW_DEBUG_QOS("QoS parameters change call " |
| 6932 | "qos_activate\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6933 | } |
| 6934 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6935 | if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B)) |
| 6936 | memcpy(&network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6937 | &def_parameters_CCK, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6938 | else |
| 6939 | memcpy(&network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6940 | &def_parameters_OFDM, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6941 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6942 | if ((network->qos_data.active == 1) && (active_network == 1)) { |
| 6943 | IPW_DEBUG_QOS("QoS was disabled call qos_activate \n"); |
| 6944 | schedule_work(&priv->qos_activate); |
| 6945 | } |
| 6946 | |
| 6947 | network->qos_data.active = 0; |
| 6948 | network->qos_data.supported = 0; |
| 6949 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6950 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6951 | (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) { |
| 6952 | if (memcmp(network->bssid, priv->bssid, ETH_ALEN)) |
John W. Linville | c5d3dce | 2008-09-30 17:17:26 -0400 | [diff] [blame] | 6953 | if (network->capability & WLAN_CAPABILITY_IBSS) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6954 | if ((network->ssid_len == |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6955 | priv->assoc_network->ssid_len) && |
| 6956 | !memcmp(network->ssid, |
| 6957 | priv->assoc_network->ssid, |
| 6958 | network->ssid_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6959 | queue_work(priv->workqueue, |
| 6960 | &priv->merge_networks); |
| 6961 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6962 | } |
| 6963 | |
| 6964 | return 0; |
| 6965 | } |
| 6966 | |
| 6967 | /* |
| 6968 | * This function set up the firmware to support QoS. It sends |
| 6969 | * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO |
| 6970 | */ |
| 6971 | static int ipw_qos_activate(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6972 | struct libipw_qos_data *qos_network_data) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6973 | { |
| 6974 | int err; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6975 | struct libipw_qos_parameters qos_parameters[QOS_QOS_SETS]; |
| 6976 | struct libipw_qos_parameters *active_one = NULL; |
| 6977 | u32 size = sizeof(struct libipw_qos_parameters); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6978 | u32 burst_duration; |
| 6979 | int i; |
| 6980 | u8 type; |
| 6981 | |
| 6982 | type = ipw_qos_current_mode(priv); |
| 6983 | |
| 6984 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]); |
| 6985 | memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size); |
| 6986 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]); |
| 6987 | memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size); |
| 6988 | |
| 6989 | if (qos_network_data == NULL) { |
| 6990 | if (type == IEEE_B) { |
| 6991 | IPW_DEBUG_QOS("QoS activate network mode %d\n", type); |
| 6992 | active_one = &def_parameters_CCK; |
| 6993 | } else |
| 6994 | active_one = &def_parameters_OFDM; |
| 6995 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6996 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6997 | burst_duration = ipw_qos_get_burst_duration(priv); |
| 6998 | for (i = 0; i < QOS_QUEUE_NUM; i++) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6999 | qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] = |
Al Viro | 8fffc15 | 2007-12-27 01:25:40 -0500 | [diff] [blame] | 7000 | cpu_to_le16(burst_duration); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7001 | } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7002 | if (type == IEEE_B) { |
| 7003 | IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n", |
| 7004 | type); |
| 7005 | if (priv->qos_data.qos_enable == 0) |
| 7006 | active_one = &def_parameters_CCK; |
| 7007 | else |
| 7008 | active_one = priv->qos_data.def_qos_parm_CCK; |
| 7009 | } else { |
| 7010 | if (priv->qos_data.qos_enable == 0) |
| 7011 | active_one = &def_parameters_OFDM; |
| 7012 | else |
| 7013 | active_one = priv->qos_data.def_qos_parm_OFDM; |
| 7014 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7015 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7016 | } else { |
| 7017 | unsigned long flags; |
| 7018 | int active; |
| 7019 | |
| 7020 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 7021 | active_one = &(qos_network_data->parameters); |
| 7022 | qos_network_data->old_param_count = |
| 7023 | qos_network_data->param_count; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7024 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7025 | active = qos_network_data->supported; |
| 7026 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 7027 | |
| 7028 | if (active == 0) { |
| 7029 | burst_duration = ipw_qos_get_burst_duration(priv); |
| 7030 | for (i = 0; i < QOS_QUEUE_NUM; i++) |
| 7031 | qos_parameters[QOS_PARAM_SET_ACTIVE]. |
Al Viro | 8fffc15 | 2007-12-27 01:25:40 -0500 | [diff] [blame] | 7032 | tx_op_limit[i] = cpu_to_le16(burst_duration); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7033 | } |
| 7034 | } |
| 7035 | |
| 7036 | IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7037 | err = ipw_send_qos_params_command(priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7038 | (struct libipw_qos_parameters *) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7039 | &(qos_parameters[0])); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7040 | if (err) |
| 7041 | IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n"); |
| 7042 | |
| 7043 | return err; |
| 7044 | } |
| 7045 | |
| 7046 | /* |
| 7047 | * send IPW_CMD_WME_INFO to the firmware |
| 7048 | */ |
| 7049 | static int ipw_qos_set_info_element(struct ipw_priv *priv) |
| 7050 | { |
| 7051 | int ret = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7052 | struct libipw_qos_information_element qos_info; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7053 | |
| 7054 | if (priv == NULL) |
| 7055 | return -1; |
| 7056 | |
| 7057 | qos_info.elementID = QOS_ELEMENT_ID; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7058 | qos_info.length = sizeof(struct libipw_qos_information_element) - 2; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7059 | |
| 7060 | qos_info.version = QOS_VERSION_1; |
| 7061 | qos_info.ac_info = 0; |
| 7062 | |
| 7063 | memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN); |
| 7064 | qos_info.qui_type = QOS_OUI_TYPE; |
| 7065 | qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE; |
| 7066 | |
| 7067 | ret = ipw_send_qos_info_command(priv, &qos_info); |
| 7068 | if (ret != 0) { |
| 7069 | IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n"); |
| 7070 | } |
| 7071 | return ret; |
| 7072 | } |
| 7073 | |
| 7074 | /* |
| 7075 | * Set the QoS parameter with the association request structure |
| 7076 | */ |
| 7077 | static int ipw_qos_association(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7078 | struct libipw_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7079 | { |
| 7080 | int err = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7081 | struct libipw_qos_data *qos_data = NULL; |
| 7082 | struct libipw_qos_data ibss_data = { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7083 | .supported = 1, |
| 7084 | .active = 1, |
| 7085 | }; |
| 7086 | |
| 7087 | switch (priv->ieee->iw_mode) { |
| 7088 | case IW_MODE_ADHOC: |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 7089 | BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7090 | |
| 7091 | qos_data = &ibss_data; |
| 7092 | break; |
| 7093 | |
| 7094 | case IW_MODE_INFRA: |
| 7095 | qos_data = &network->qos_data; |
| 7096 | break; |
| 7097 | |
| 7098 | default: |
| 7099 | BUG(); |
| 7100 | break; |
| 7101 | } |
| 7102 | |
| 7103 | err = ipw_qos_activate(priv, qos_data); |
| 7104 | if (err) { |
| 7105 | priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC; |
| 7106 | return err; |
| 7107 | } |
| 7108 | |
| 7109 | if (priv->qos_data.qos_enable && qos_data->supported) { |
| 7110 | IPW_DEBUG_QOS("QoS will be enabled for this association\n"); |
| 7111 | priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC; |
| 7112 | return ipw_qos_set_info_element(priv); |
| 7113 | } |
| 7114 | |
| 7115 | return 0; |
| 7116 | } |
| 7117 | |
| 7118 | /* |
Matt LaPlante | 0779bf2 | 2006-11-30 05:24:39 +0100 | [diff] [blame] | 7119 | * handling the beaconing responses. if we get different QoS setting |
| 7120 | * off the network from the associated setting, adjust the QoS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7121 | * setting |
| 7122 | */ |
| 7123 | static int ipw_qos_association_resp(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7124 | struct libipw_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7125 | { |
| 7126 | int ret = 0; |
| 7127 | unsigned long flags; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7128 | u32 size = sizeof(struct libipw_qos_parameters); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7129 | int set_qos_param = 0; |
| 7130 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7131 | if ((priv == NULL) || (network == NULL) || |
| 7132 | (priv->assoc_network == NULL)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7133 | return ret; |
| 7134 | |
| 7135 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 7136 | return ret; |
| 7137 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7138 | if ((priv->ieee->iw_mode != IW_MODE_INFRA)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7139 | return ret; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7140 | |
| 7141 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 7142 | if (network->flags & NETWORK_HAS_QOS_PARAMETERS) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7143 | memcpy(&priv->assoc_network->qos_data, &network->qos_data, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7144 | sizeof(struct libipw_qos_data)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7145 | priv->assoc_network->qos_data.active = 1; |
| 7146 | if ((network->qos_data.old_param_count != |
| 7147 | network->qos_data.param_count)) { |
| 7148 | set_qos_param = 1; |
| 7149 | network->qos_data.old_param_count = |
| 7150 | network->qos_data.param_count; |
| 7151 | } |
| 7152 | |
| 7153 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7154 | if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B)) |
| 7155 | memcpy(&priv->assoc_network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7156 | &def_parameters_CCK, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7157 | else |
| 7158 | memcpy(&priv->assoc_network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7159 | &def_parameters_OFDM, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7160 | priv->assoc_network->qos_data.active = 0; |
| 7161 | priv->assoc_network->qos_data.supported = 0; |
| 7162 | set_qos_param = 1; |
| 7163 | } |
| 7164 | |
| 7165 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 7166 | |
| 7167 | if (set_qos_param == 1) |
| 7168 | schedule_work(&priv->qos_activate); |
| 7169 | |
| 7170 | return ret; |
| 7171 | } |
| 7172 | |
| 7173 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv) |
| 7174 | { |
| 7175 | u32 ret = 0; |
| 7176 | |
| 7177 | if ((priv == NULL)) |
| 7178 | return 0; |
| 7179 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7180 | if (!(priv->ieee->modulation & LIBIPW_OFDM_MODULATION)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7181 | ret = priv->qos_data.burst_duration_CCK; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7182 | else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7183 | ret = priv->qos_data.burst_duration_OFDM; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7184 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7185 | return ret; |
| 7186 | } |
| 7187 | |
| 7188 | /* |
| 7189 | * Initialize the setting of QoS global |
| 7190 | */ |
| 7191 | static void ipw_qos_init(struct ipw_priv *priv, int enable, |
| 7192 | int burst_enable, u32 burst_duration_CCK, |
| 7193 | u32 burst_duration_OFDM) |
| 7194 | { |
| 7195 | priv->qos_data.qos_enable = enable; |
| 7196 | |
| 7197 | if (priv->qos_data.qos_enable) { |
| 7198 | priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK; |
| 7199 | priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM; |
| 7200 | IPW_DEBUG_QOS("QoS is enabled\n"); |
| 7201 | } else { |
| 7202 | priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK; |
| 7203 | priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM; |
| 7204 | IPW_DEBUG_QOS("QoS is not enabled\n"); |
| 7205 | } |
| 7206 | |
| 7207 | priv->qos_data.burst_enable = burst_enable; |
| 7208 | |
| 7209 | if (burst_enable) { |
| 7210 | priv->qos_data.burst_duration_CCK = burst_duration_CCK; |
| 7211 | priv->qos_data.burst_duration_OFDM = burst_duration_OFDM; |
| 7212 | } else { |
| 7213 | priv->qos_data.burst_duration_CCK = 0; |
| 7214 | priv->qos_data.burst_duration_OFDM = 0; |
| 7215 | } |
| 7216 | } |
| 7217 | |
| 7218 | /* |
| 7219 | * map the packet priority to the right TX Queue |
| 7220 | */ |
| 7221 | static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority) |
| 7222 | { |
| 7223 | if (priority > 7 || !priv->qos_data.qos_enable) |
| 7224 | priority = 0; |
| 7225 | |
| 7226 | return from_priority_to_tx_queue[priority] - 1; |
| 7227 | } |
| 7228 | |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7229 | static int ipw_is_qos_active(struct net_device *dev, |
| 7230 | struct sk_buff *skb) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7231 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7232 | struct ipw_priv *priv = libipw_priv(dev); |
| 7233 | struct libipw_qos_data *qos_data = NULL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7234 | int active, supported; |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7235 | u8 *daddr = skb->data + ETH_ALEN; |
| 7236 | int unicast = !is_multicast_ether_addr(daddr); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7237 | |
| 7238 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 7239 | return 0; |
| 7240 | |
| 7241 | qos_data = &priv->assoc_network->qos_data; |
| 7242 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7243 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
| 7244 | if (unicast == 0) |
| 7245 | qos_data->active = 0; |
| 7246 | else |
| 7247 | qos_data->active = qos_data->supported; |
| 7248 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7249 | active = qos_data->active; |
| 7250 | supported = qos_data->supported; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7251 | IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d " |
| 7252 | "unicast %d\n", |
| 7253 | priv->qos_data.qos_enable, active, supported, unicast); |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7254 | if (active && priv->qos_data.qos_enable) |
| 7255 | return 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7256 | |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7257 | return 0; |
| 7258 | |
| 7259 | } |
| 7260 | /* |
| 7261 | * add QoS parameter to the TX command |
| 7262 | */ |
| 7263 | static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv, |
| 7264 | u16 priority, |
| 7265 | struct tfd_data *tfd) |
| 7266 | { |
| 7267 | int tx_queue_id = 0; |
| 7268 | |
| 7269 | |
| 7270 | tx_queue_id = from_priority_to_tx_queue[priority] - 1; |
| 7271 | tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED; |
| 7272 | |
| 7273 | if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) { |
| 7274 | tfd->tx_flags &= ~DCT_FLAG_ACK_REQD; |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 7275 | tfd->tfd.tfd_26.mchdr.qos_ctrl |= cpu_to_le16(CTRL_QOS_NO_ACK); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7276 | } |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7277 | return 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7278 | } |
| 7279 | |
| 7280 | /* |
| 7281 | * background support to run QoS activate functionality |
| 7282 | */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7283 | static void ipw_bg_qos_activate(struct work_struct *work) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7284 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7285 | struct ipw_priv *priv = |
| 7286 | container_of(work, struct ipw_priv, qos_activate); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7287 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7288 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7289 | |
| 7290 | if (priv->status & STATUS_ASSOCIATED) |
| 7291 | ipw_qos_activate(priv, &(priv->assoc_network->qos_data)); |
| 7292 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7293 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7294 | } |
| 7295 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7296 | static int ipw_handle_probe_response(struct net_device *dev, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7297 | struct libipw_probe_response *resp, |
| 7298 | struct libipw_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7299 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7300 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7301 | int active_network = ((priv->status & STATUS_ASSOCIATED) && |
| 7302 | (network == priv->assoc_network)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7303 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7304 | ipw_qos_handle_probe_response(priv, active_network, network); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7305 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7306 | return 0; |
| 7307 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7308 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7309 | static int ipw_handle_beacon(struct net_device *dev, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7310 | struct libipw_beacon *resp, |
| 7311 | struct libipw_network *network) |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7312 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7313 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7314 | int active_network = ((priv->status & STATUS_ASSOCIATED) && |
| 7315 | (network == priv->assoc_network)); |
| 7316 | |
| 7317 | ipw_qos_handle_probe_response(priv, active_network, network); |
| 7318 | |
| 7319 | return 0; |
| 7320 | } |
| 7321 | |
| 7322 | static int ipw_handle_assoc_response(struct net_device *dev, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7323 | struct libipw_assoc_response *resp, |
| 7324 | struct libipw_network *network) |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7325 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7326 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7327 | ipw_qos_association_resp(priv, network); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7328 | return 0; |
| 7329 | } |
| 7330 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7331 | static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7332 | *qos_param) |
| 7333 | { |
Zhu Yi | 4e22699 | 2006-01-24 16:37:36 +0800 | [diff] [blame] | 7334 | return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS, |
| 7335 | sizeof(*qos_param) * 3, qos_param); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7336 | } |
| 7337 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7338 | static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7339 | *qos_param) |
| 7340 | { |
Zhu Yi | 4e22699 | 2006-01-24 16:37:36 +0800 | [diff] [blame] | 7341 | return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param), |
| 7342 | qos_param); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7343 | } |
| 7344 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 7345 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7346 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7347 | static int ipw_associate_network(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7348 | struct libipw_network *network, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7349 | struct ipw_supported_rates *rates, int roaming) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7350 | { |
| 7351 | int err; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 7352 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7353 | |
| 7354 | if (priv->config & CFG_FIXED_RATE) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7355 | ipw_set_fixed_rate(priv, network->mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7356 | |
| 7357 | if (!(priv->config & CFG_STATIC_ESSID)) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7358 | priv->essid_len = min(network->ssid_len, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7359 | (u8) IW_ESSID_MAX_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7360 | memcpy(priv->essid, network->ssid, priv->essid_len); |
| 7361 | } |
| 7362 | |
| 7363 | network->last_associate = jiffies; |
| 7364 | |
| 7365 | memset(&priv->assoc_request, 0, sizeof(priv->assoc_request)); |
| 7366 | priv->assoc_request.channel = network->channel; |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7367 | priv->assoc_request.auth_key = 0; |
| 7368 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7369 | if ((priv->capability & CAP_PRIVACY_ON) && |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7370 | (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7371 | priv->assoc_request.auth_type = AUTH_SHARED_KEY; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7372 | priv->assoc_request.auth_key = priv->ieee->sec.active_key; |
| 7373 | |
Zhu Yi | 1ba61e0 | 2006-02-15 13:00:55 +0800 | [diff] [blame] | 7374 | if (priv->ieee->sec.level == SEC_LEVEL_1) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7375 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7376 | |
| 7377 | } else if ((priv->capability & CAP_PRIVACY_ON) && |
| 7378 | (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP)) |
| 7379 | priv->assoc_request.auth_type = AUTH_LEAP; |
| 7380 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7381 | priv->assoc_request.auth_type = AUTH_OPEN; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7382 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7383 | if (priv->ieee->wpa_ie_len) { |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7384 | priv->assoc_request.policy_support = cpu_to_le16(0x02); /* RSN active */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7385 | ipw_set_rsn_capa(priv, priv->ieee->wpa_ie, |
| 7386 | priv->ieee->wpa_ie_len); |
| 7387 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7388 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7389 | /* |
| 7390 | * It is valid for our ieee device to support multiple modes, but |
| 7391 | * 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] | 7392 | * just one mode. |
| 7393 | */ |
| 7394 | if (network->mode & priv->ieee->mode & IEEE_A) |
| 7395 | priv->assoc_request.ieee_mode = IPW_A_MODE; |
| 7396 | else if (network->mode & priv->ieee->mode & IEEE_G) |
| 7397 | priv->assoc_request.ieee_mode = IPW_G_MODE; |
| 7398 | else if (network->mode & priv->ieee->mode & IEEE_B) |
| 7399 | priv->assoc_request.ieee_mode = IPW_B_MODE; |
| 7400 | |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7401 | priv->assoc_request.capability = cpu_to_le16(network->capability); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7402 | if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 7403 | && !(priv->config & CFG_PREAMBLE_LONG)) { |
| 7404 | priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE; |
| 7405 | } else { |
| 7406 | priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE; |
| 7407 | |
| 7408 | /* Clear the short preamble if we won't be supporting it */ |
| 7409 | priv->assoc_request.capability &= |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7410 | ~cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7411 | } |
| 7412 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7413 | /* Clear capability bits that aren't used in Ad Hoc */ |
| 7414 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 7415 | priv->assoc_request.capability &= |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7416 | ~cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7417 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7418 | IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, " |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7419 | "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] | 7420 | roaming ? "Rea" : "A", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 7421 | print_ssid(ssid, priv->essid, priv->essid_len), |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7422 | network->channel, |
| 7423 | ipw_modes[priv->assoc_request.ieee_mode], |
| 7424 | rates->num_rates, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7425 | (priv->assoc_request.preamble_length == |
| 7426 | DCT_FLAG_LONG_PREAMBLE) ? "long" : "short", |
| 7427 | network->capability & |
| 7428 | WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7429 | priv->capability & CAP_PRIVACY_ON ? "on " : "off", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7430 | priv->capability & CAP_PRIVACY_ON ? |
| 7431 | (priv->capability & CAP_SHARED_KEY ? "(shared)" : |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7432 | "(open)") : "", |
| 7433 | priv->capability & CAP_PRIVACY_ON ? " key=" : "", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7434 | priv->capability & CAP_PRIVACY_ON ? |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7435 | '1' + priv->ieee->sec.active_key : '.', |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7436 | priv->capability & CAP_PRIVACY_ON ? '.' : ' '); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7437 | |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7438 | priv->assoc_request.beacon_interval = cpu_to_le16(network->beacon_interval); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7439 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7440 | (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7441 | priv->assoc_request.assoc_type = HC_IBSS_START; |
| 7442 | priv->assoc_request.assoc_tsf_msw = 0; |
| 7443 | priv->assoc_request.assoc_tsf_lsw = 0; |
| 7444 | } else { |
| 7445 | if (unlikely(roaming)) |
| 7446 | priv->assoc_request.assoc_type = HC_REASSOCIATE; |
| 7447 | else |
| 7448 | priv->assoc_request.assoc_type = HC_ASSOCIATE; |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7449 | priv->assoc_request.assoc_tsf_msw = cpu_to_le32(network->time_stamp[1]); |
| 7450 | priv->assoc_request.assoc_tsf_lsw = cpu_to_le32(network->time_stamp[0]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7451 | } |
| 7452 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7453 | memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7454 | |
| 7455 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
| 7456 | memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN); |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7457 | priv->assoc_request.atim_window = cpu_to_le16(network->atim_window); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7458 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7459 | memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7460 | priv->assoc_request.atim_window = 0; |
| 7461 | } |
| 7462 | |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7463 | priv->assoc_request.listen_interval = cpu_to_le16(network->listen_interval); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7464 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7465 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
| 7466 | if (err) { |
| 7467 | IPW_DEBUG_HC("Attempt to send SSID command failed.\n"); |
| 7468 | return err; |
| 7469 | } |
| 7470 | |
| 7471 | rates->ieee_mode = priv->assoc_request.ieee_mode; |
| 7472 | rates->purpose = IPW_RATE_CONNECT; |
| 7473 | ipw_send_supported_rates(priv, rates); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7474 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7475 | if (priv->assoc_request.ieee_mode == IPW_G_MODE) |
| 7476 | priv->sys_config.dot11g_auto_detection = 1; |
| 7477 | else |
| 7478 | priv->sys_config.dot11g_auto_detection = 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7479 | |
| 7480 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 7481 | priv->sys_config.answer_broadcast_ssid_probe = 1; |
| 7482 | else |
| 7483 | priv->sys_config.answer_broadcast_ssid_probe = 0; |
| 7484 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7485 | err = ipw_send_system_config(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7486 | if (err) { |
| 7487 | IPW_DEBUG_HC("Attempt to send sys config command failed.\n"); |
| 7488 | return err; |
| 7489 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7490 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7491 | IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7492 | err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7493 | if (err) { |
| 7494 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); |
| 7495 | return err; |
| 7496 | } |
| 7497 | |
| 7498 | /* |
| 7499 | * If preemption is enabled, it is possible for the association |
| 7500 | * to complete before we return from ipw_send_associate. Therefore |
| 7501 | * we have to be sure and update our priviate data first. |
| 7502 | */ |
| 7503 | priv->channel = network->channel; |
| 7504 | memcpy(priv->bssid, network->bssid, ETH_ALEN); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7505 | priv->status |= STATUS_ASSOCIATING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7506 | priv->status &= ~STATUS_SECURITY_UPDATED; |
| 7507 | |
| 7508 | priv->assoc_network = network; |
| 7509 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 7510 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7511 | ipw_qos_association(priv, network); |
| 7512 | #endif |
| 7513 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7514 | err = ipw_send_associate(priv, &priv->assoc_request); |
| 7515 | if (err) { |
| 7516 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); |
| 7517 | return err; |
| 7518 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7519 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 7520 | IPW_DEBUG(IPW_DL_STATE, "associating: '%s' %pM \n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 7521 | print_ssid(ssid, priv->essid, priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 7522 | priv->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7523 | |
| 7524 | return 0; |
| 7525 | } |
| 7526 | |
| 7527 | static void ipw_roam(void *data) |
| 7528 | { |
| 7529 | struct ipw_priv *priv = data; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7530 | struct libipw_network *network = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7531 | struct ipw_network_match match = { |
| 7532 | .network = priv->assoc_network |
| 7533 | }; |
| 7534 | |
| 7535 | /* The roaming process is as follows: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7536 | * |
| 7537 | * 1. Missed beacon threshold triggers the roaming process by |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7538 | * setting the status ROAM bit and requesting a scan. |
| 7539 | * 2. When the scan completes, it schedules the ROAM work |
| 7540 | * 3. The ROAM work looks at all of the known networks for one that |
| 7541 | * is a better network than the currently associated. If none |
| 7542 | * found, the ROAM process is over (ROAM bit cleared) |
| 7543 | * 4. If a better network is found, a disassociation request is |
| 7544 | * sent. |
| 7545 | * 5. When the disassociation completes, the roam work is again |
| 7546 | * scheduled. The second time through, the driver is no longer |
| 7547 | * associated, and the newly selected network is sent an |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7548 | * association request. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7549 | * 6. At this point ,the roaming process is complete and the ROAM |
| 7550 | * status bit is cleared. |
| 7551 | */ |
| 7552 | |
| 7553 | /* If we are no longer associated, and the roaming bit is no longer |
| 7554 | * set, then we are not actively roaming, so just return */ |
| 7555 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING))) |
| 7556 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7557 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7558 | if (priv->status & STATUS_ASSOCIATED) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7559 | /* First pass through ROAM process -- look for a better |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7560 | * network */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7561 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7562 | u8 rssi = priv->assoc_network->stats.rssi; |
| 7563 | priv->assoc_network->stats.rssi = -128; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7564 | spin_lock_irqsave(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7565 | list_for_each_entry(network, &priv->ieee->network_list, list) { |
| 7566 | if (network != priv->assoc_network) |
| 7567 | ipw_best_network(priv, &match, network, 1); |
| 7568 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7569 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7570 | priv->assoc_network->stats.rssi = rssi; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7571 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7572 | if (match.network == priv->assoc_network) { |
| 7573 | IPW_DEBUG_ASSOC("No better APs in this network to " |
| 7574 | "roam to.\n"); |
| 7575 | priv->status &= ~STATUS_ROAMING; |
| 7576 | ipw_debug_config(priv); |
| 7577 | return; |
| 7578 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7579 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7580 | ipw_send_disassociate(priv, 1); |
| 7581 | priv->assoc_network = match.network; |
| 7582 | |
| 7583 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7584 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7585 | |
| 7586 | /* Second pass through ROAM process -- request association */ |
| 7587 | ipw_compatible_rates(priv, priv->assoc_network, &match.rates); |
| 7588 | ipw_associate_network(priv, priv->assoc_network, &match.rates, 1); |
| 7589 | priv->status &= ~STATUS_ROAMING; |
| 7590 | } |
| 7591 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7592 | static void ipw_bg_roam(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7593 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7594 | struct ipw_priv *priv = |
| 7595 | container_of(work, struct ipw_priv, roam); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7596 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7597 | ipw_roam(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7598 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7599 | } |
| 7600 | |
| 7601 | static int ipw_associate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7602 | { |
| 7603 | struct ipw_priv *priv = data; |
| 7604 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7605 | struct libipw_network *network = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7606 | struct ipw_network_match match = { |
| 7607 | .network = NULL |
| 7608 | }; |
| 7609 | struct ipw_supported_rates *rates; |
| 7610 | struct list_head *element; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7611 | unsigned long flags; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 7612 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7613 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7614 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
| 7615 | IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n"); |
| 7616 | return 0; |
| 7617 | } |
| 7618 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7619 | if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7620 | IPW_DEBUG_ASSOC("Not attempting association (already in " |
| 7621 | "progress)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7622 | return 0; |
| 7623 | } |
| 7624 | |
Hong Liu | e632472 | 2005-09-14 21:04:15 -0500 | [diff] [blame] | 7625 | if (priv->status & STATUS_DISASSOCIATING) { |
| 7626 | IPW_DEBUG_ASSOC("Not attempting association (in " |
| 7627 | "disassociating)\n "); |
| 7628 | queue_work(priv->workqueue, &priv->associate); |
| 7629 | return 0; |
| 7630 | } |
| 7631 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7632 | if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7633 | IPW_DEBUG_ASSOC("Not attempting association (scanning or not " |
| 7634 | "initialized)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7635 | return 0; |
| 7636 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7637 | |
| 7638 | if (!(priv->config & CFG_ASSOCIATE) && |
Alexey Fisher | 3e4127f | 2008-11-06 09:51:16 +0100 | [diff] [blame] | 7639 | !(priv->config & (CFG_STATIC_ESSID | CFG_STATIC_BSSID))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7640 | IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7641 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7642 | } |
| 7643 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7644 | /* Protect our use of the network_list */ |
| 7645 | spin_lock_irqsave(&priv->ieee->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7646 | list_for_each_entry(network, &priv->ieee->network_list, list) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7647 | ipw_best_network(priv, &match, network, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7648 | |
| 7649 | network = match.network; |
| 7650 | rates = &match.rates; |
| 7651 | |
| 7652 | if (network == NULL && |
| 7653 | priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 7654 | priv->config & CFG_ADHOC_CREATE && |
| 7655 | priv->config & CFG_STATIC_ESSID && |
Dan Williams | a6d4eae | 2008-05-29 14:38:28 -0400 | [diff] [blame] | 7656 | priv->config & CFG_STATIC_CHANNEL) { |
| 7657 | /* Use oldest network if the free list is empty */ |
| 7658 | if (list_empty(&priv->ieee->network_free_list)) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7659 | struct libipw_network *oldest = NULL; |
| 7660 | struct libipw_network *target; |
Dan Williams | a6d4eae | 2008-05-29 14:38:28 -0400 | [diff] [blame] | 7661 | |
| 7662 | list_for_each_entry(target, &priv->ieee->network_list, list) { |
| 7663 | if ((oldest == NULL) || |
| 7664 | (target->last_scanned < oldest->last_scanned)) |
| 7665 | oldest = target; |
| 7666 | } |
| 7667 | |
| 7668 | /* If there are no more slots, expire the oldest */ |
| 7669 | list_del(&oldest->list); |
| 7670 | target = oldest; |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 7671 | IPW_DEBUG_ASSOC("Expired '%s' (%pM) from " |
Dan Williams | a6d4eae | 2008-05-29 14:38:28 -0400 | [diff] [blame] | 7672 | "network list.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 7673 | print_ssid(ssid, target->ssid, |
| 7674 | target->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 7675 | target->bssid); |
Dan Williams | a6d4eae | 2008-05-29 14:38:28 -0400 | [diff] [blame] | 7676 | list_add_tail(&target->list, |
| 7677 | &priv->ieee->network_free_list); |
| 7678 | } |
| 7679 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7680 | element = priv->ieee->network_free_list.next; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7681 | network = list_entry(element, struct libipw_network, list); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7682 | ipw_adhoc_create(priv, network); |
| 7683 | rates = &priv->rates; |
| 7684 | list_del(element); |
| 7685 | list_add_tail(&network->list, &priv->ieee->network_list); |
| 7686 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7687 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7688 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7689 | /* If we reached the end of the list, then we don't have any valid |
| 7690 | * matching APs */ |
| 7691 | if (!network) { |
| 7692 | ipw_debug_config(priv); |
| 7693 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7694 | if (!(priv->status & STATUS_SCANNING)) { |
| 7695 | if (!(priv->config & CFG_SPEED_SCAN)) |
| 7696 | queue_delayed_work(priv->workqueue, |
| 7697 | &priv->request_scan, |
| 7698 | SCAN_INTERVAL); |
| 7699 | else |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7700 | queue_delayed_work(priv->workqueue, |
| 7701 | &priv->request_scan, 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7702 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7703 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7704 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7705 | } |
| 7706 | |
| 7707 | ipw_associate_network(priv, network, rates, 0); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7708 | |
| 7709 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7710 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7711 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7712 | static void ipw_bg_associate(struct work_struct *work) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7713 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7714 | struct ipw_priv *priv = |
| 7715 | container_of(work, struct ipw_priv, associate); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7716 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7717 | ipw_associate(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7718 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7719 | } |
| 7720 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7721 | static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv, |
| 7722 | struct sk_buff *skb) |
| 7723 | { |
| 7724 | struct ieee80211_hdr *hdr; |
| 7725 | u16 fc; |
| 7726 | |
| 7727 | hdr = (struct ieee80211_hdr *)skb->data; |
John W. Linville | 7211801 | 2008-09-30 21:43:03 -0400 | [diff] [blame] | 7728 | fc = le16_to_cpu(hdr->frame_control); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7729 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 7730 | return; |
| 7731 | |
| 7732 | fc &= ~IEEE80211_FCTL_PROTECTED; |
John W. Linville | 7211801 | 2008-09-30 21:43:03 -0400 | [diff] [blame] | 7733 | hdr->frame_control = cpu_to_le16(fc); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7734 | switch (priv->ieee->sec.level) { |
| 7735 | case SEC_LEVEL_3: |
| 7736 | /* Remove CCMP HDR */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7737 | memmove(skb->data + LIBIPW_3ADDR_LEN, |
| 7738 | skb->data + LIBIPW_3ADDR_LEN + 8, |
| 7739 | skb->len - LIBIPW_3ADDR_LEN - 8); |
Zhu Yi | f4ff497 | 2005-09-12 10:48:48 -0500 | [diff] [blame] | 7740 | skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7741 | break; |
| 7742 | case SEC_LEVEL_2: |
| 7743 | break; |
| 7744 | case SEC_LEVEL_1: |
| 7745 | /* Remove IV */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7746 | memmove(skb->data + LIBIPW_3ADDR_LEN, |
| 7747 | skb->data + LIBIPW_3ADDR_LEN + 4, |
| 7748 | skb->len - LIBIPW_3ADDR_LEN - 4); |
Zhu Yi | f4ff497 | 2005-09-12 10:48:48 -0500 | [diff] [blame] | 7749 | skb_trim(skb, skb->len - 8); /* IV + ICV */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7750 | break; |
| 7751 | case SEC_LEVEL_0: |
| 7752 | break; |
| 7753 | default: |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame^] | 7754 | printk(KERN_ERR "Unknown security level %d\n", |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7755 | priv->ieee->sec.level); |
| 7756 | break; |
| 7757 | } |
| 7758 | } |
| 7759 | |
| 7760 | static void ipw_handle_data_packet(struct ipw_priv *priv, |
| 7761 | struct ipw_rx_mem_buffer *rxb, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7762 | struct libipw_rx_stats *stats) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7763 | { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7764 | struct net_device *dev = priv->net_dev; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7765 | struct libipw_hdr_4addr *hdr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7766 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7767 | |
| 7768 | /* We received data from the HW, so stop the watchdog */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7769 | dev->trans_start = jiffies; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7770 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7771 | /* We only process data packets if the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7772 | * interface is open */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7773 | 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] | 7774 | skb_tailroom(rxb->skb))) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7775 | dev->stats.rx_errors++; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7776 | priv->wstats.discard.misc++; |
| 7777 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 7778 | return; |
| 7779 | } else if (unlikely(!netif_running(priv->net_dev))) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7780 | dev->stats.rx_dropped++; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7781 | priv->wstats.discard.misc++; |
| 7782 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 7783 | return; |
| 7784 | } |
| 7785 | |
| 7786 | /* Advance skb->data to the start of the actual payload */ |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 7787 | skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7788 | |
| 7789 | /* Set the size of the skb to the size of the frame */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7790 | skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7791 | |
| 7792 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); |
| 7793 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7794 | /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7795 | hdr = (struct libipw_hdr_4addr *)rxb->skb->data; |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 7796 | if (priv->ieee->iw_mode != IW_MODE_MONITOR && |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 7797 | (is_multicast_ether_addr(hdr->addr1) ? |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 7798 | !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7799 | ipw_rebuild_decrypted_skb(priv, rxb->skb); |
| 7800 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7801 | if (!libipw_rx(priv->ieee, rxb->skb, stats)) |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7802 | dev->stats.rx_errors++; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7803 | else { /* libipw_rx succeeded, so it now owns the SKB */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7804 | rxb->skb = NULL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7805 | __ipw_led_activity_on(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7806 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7807 | } |
| 7808 | |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 7809 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7810 | static void ipw_handle_data_packet_monitor(struct ipw_priv *priv, |
| 7811 | struct ipw_rx_mem_buffer *rxb, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7812 | struct libipw_rx_stats *stats) |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7813 | { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7814 | struct net_device *dev = priv->net_dev; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7815 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7816 | struct ipw_rx_frame *frame = &pkt->u.frame; |
| 7817 | |
| 7818 | /* initial pull of some data */ |
| 7819 | u16 received_channel = frame->received_channel; |
| 7820 | u8 antennaAndPhy = frame->antennaAndPhy; |
| 7821 | s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */ |
| 7822 | u16 pktrate = frame->rate; |
| 7823 | |
| 7824 | /* Magic struct that slots into the radiotap header -- no reason |
| 7825 | * to build this manually element by element, we can write it much |
| 7826 | * more efficiently than we can parse it. ORDER MATTERS HERE */ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7827 | struct ipw_rt_hdr *ipw_rt; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7828 | |
| 7829 | short len = le16_to_cpu(pkt->u.frame.length); |
| 7830 | |
| 7831 | /* We received data from the HW, so stop the watchdog */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7832 | dev->trans_start = jiffies; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7833 | |
| 7834 | /* We only process data packets if the |
| 7835 | * interface is open */ |
| 7836 | if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) > |
| 7837 | skb_tailroom(rxb->skb))) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7838 | dev->stats.rx_errors++; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7839 | priv->wstats.discard.misc++; |
| 7840 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 7841 | return; |
| 7842 | } else if (unlikely(!netif_running(priv->net_dev))) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7843 | dev->stats.rx_dropped++; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7844 | priv->wstats.discard.misc++; |
| 7845 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 7846 | return; |
| 7847 | } |
| 7848 | |
| 7849 | /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use |
| 7850 | * that now */ |
| 7851 | if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) { |
| 7852 | /* FIXME: Should alloc bigger skb instead */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7853 | dev->stats.rx_dropped++; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7854 | priv->wstats.discard.misc++; |
| 7855 | IPW_DEBUG_DROP("Dropping too large packet in monitor\n"); |
| 7856 | return; |
| 7857 | } |
| 7858 | |
| 7859 | /* copy the frame itself */ |
| 7860 | memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr), |
| 7861 | rxb->skb->data + IPW_RX_FRAME_SIZE, len); |
| 7862 | |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7863 | ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data; |
| 7864 | |
| 7865 | ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 7866 | ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 7867 | ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total header+data */ |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7868 | |
| 7869 | /* Big bitfield of all the fields we provide in radiotap */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 7870 | ipw_rt->rt_hdr.it_present = cpu_to_le32( |
| 7871 | (1 << IEEE80211_RADIOTAP_TSFT) | |
Zhu Yi | 4b1f8a9 | 2006-12-05 14:42:14 +0800 | [diff] [blame] | 7872 | (1 << IEEE80211_RADIOTAP_FLAGS) | |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7873 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 7874 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 7875 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7876 | (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7877 | (1 << IEEE80211_RADIOTAP_ANTENNA)); |
| 7878 | |
| 7879 | /* Zero the flags, we'll add to them as we go */ |
| 7880 | ipw_rt->rt_flags = 0; |
Zhu Yi | 4b1f8a9 | 2006-12-05 14:42:14 +0800 | [diff] [blame] | 7881 | ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 | |
| 7882 | frame->parent_tsf[2] << 16 | |
| 7883 | frame->parent_tsf[1] << 8 | |
| 7884 | frame->parent_tsf[0]); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7885 | |
| 7886 | /* Convert signal to DBM */ |
| 7887 | ipw_rt->rt_dbmsignal = antsignal; |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 7888 | ipw_rt->rt_dbmnoise = (s8) le16_to_cpu(frame->noise); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7889 | |
| 7890 | /* Convert the channel data and set the flags */ |
| 7891 | ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel)); |
| 7892 | if (received_channel > 14) { /* 802.11a */ |
| 7893 | ipw_rt->rt_chbitmask = |
| 7894 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); |
| 7895 | } else if (antennaAndPhy & 32) { /* 802.11b */ |
| 7896 | ipw_rt->rt_chbitmask = |
| 7897 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); |
| 7898 | } else { /* 802.11g */ |
| 7899 | ipw_rt->rt_chbitmask = |
Al Viro | 472caf8 | 2007-12-27 01:50:54 -0500 | [diff] [blame] | 7900 | cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7901 | } |
| 7902 | |
| 7903 | /* set the rate in multiples of 500k/s */ |
| 7904 | switch (pktrate) { |
| 7905 | case IPW_TX_RATE_1MB: |
| 7906 | ipw_rt->rt_rate = 2; |
| 7907 | break; |
| 7908 | case IPW_TX_RATE_2MB: |
| 7909 | ipw_rt->rt_rate = 4; |
| 7910 | break; |
| 7911 | case IPW_TX_RATE_5MB: |
| 7912 | ipw_rt->rt_rate = 10; |
| 7913 | break; |
| 7914 | case IPW_TX_RATE_6MB: |
| 7915 | ipw_rt->rt_rate = 12; |
| 7916 | break; |
| 7917 | case IPW_TX_RATE_9MB: |
| 7918 | ipw_rt->rt_rate = 18; |
| 7919 | break; |
| 7920 | case IPW_TX_RATE_11MB: |
| 7921 | ipw_rt->rt_rate = 22; |
| 7922 | break; |
| 7923 | case IPW_TX_RATE_12MB: |
| 7924 | ipw_rt->rt_rate = 24; |
| 7925 | break; |
| 7926 | case IPW_TX_RATE_18MB: |
| 7927 | ipw_rt->rt_rate = 36; |
| 7928 | break; |
| 7929 | case IPW_TX_RATE_24MB: |
| 7930 | ipw_rt->rt_rate = 48; |
| 7931 | break; |
| 7932 | case IPW_TX_RATE_36MB: |
| 7933 | ipw_rt->rt_rate = 72; |
| 7934 | break; |
| 7935 | case IPW_TX_RATE_48MB: |
| 7936 | ipw_rt->rt_rate = 96; |
| 7937 | break; |
| 7938 | case IPW_TX_RATE_54MB: |
| 7939 | ipw_rt->rt_rate = 108; |
| 7940 | break; |
| 7941 | default: |
| 7942 | ipw_rt->rt_rate = 0; |
| 7943 | break; |
| 7944 | } |
| 7945 | |
| 7946 | /* antenna number */ |
| 7947 | ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */ |
| 7948 | |
| 7949 | /* set the preamble flag if we have it */ |
| 7950 | if ((antennaAndPhy & 64)) |
| 7951 | ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; |
| 7952 | |
| 7953 | /* Set the size of the skb to the size of the frame */ |
| 7954 | skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7955 | |
| 7956 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); |
| 7957 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7958 | if (!libipw_rx(priv->ieee, rxb->skb, stats)) |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7959 | dev->stats.rx_errors++; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7960 | else { /* libipw_rx succeeded, so it now owns the SKB */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7961 | rxb->skb = NULL; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7962 | /* no LED during capture */ |
| 7963 | } |
| 7964 | } |
| 7965 | #endif |
| 7966 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7967 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7968 | #define libipw_is_probe_response(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7969 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \ |
| 7970 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP ) |
| 7971 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7972 | #define libipw_is_management(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7973 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) |
| 7974 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7975 | #define libipw_is_control(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7976 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) |
| 7977 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7978 | #define libipw_is_data(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7979 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) |
| 7980 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7981 | #define libipw_is_assoc_request(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7982 | ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ) |
| 7983 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7984 | #define libipw_is_reassoc_request(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7985 | ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ) |
| 7986 | |
| 7987 | static void ipw_handle_promiscuous_rx(struct ipw_priv *priv, |
| 7988 | struct ipw_rx_mem_buffer *rxb, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7989 | struct libipw_rx_stats *stats) |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7990 | { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7991 | struct net_device *dev = priv->prom_net_dev; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7992 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7993 | struct ipw_rx_frame *frame = &pkt->u.frame; |
| 7994 | struct ipw_rt_hdr *ipw_rt; |
| 7995 | |
| 7996 | /* First cache any information we need before we overwrite |
| 7997 | * the information provided in the skb from the hardware */ |
| 7998 | struct ieee80211_hdr *hdr; |
| 7999 | u16 channel = frame->received_channel; |
| 8000 | u8 phy_flags = frame->antennaAndPhy; |
| 8001 | s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM; |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8002 | s8 noise = (s8) le16_to_cpu(frame->noise); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8003 | u8 rate = frame->rate; |
| 8004 | short len = le16_to_cpu(pkt->u.frame.length); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8005 | struct sk_buff *skb; |
| 8006 | int hdr_only = 0; |
| 8007 | u16 filter = priv->prom_priv->filter; |
| 8008 | |
| 8009 | /* If the filter is set to not include Rx frames then return */ |
| 8010 | if (filter & IPW_PROM_NO_RX) |
| 8011 | return; |
| 8012 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8013 | /* We received data from the HW, so stop the watchdog */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8014 | dev->trans_start = jiffies; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8015 | |
| 8016 | if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8017 | dev->stats.rx_errors++; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8018 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 8019 | return; |
| 8020 | } |
| 8021 | |
| 8022 | /* We only process data packets if the interface is open */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8023 | if (unlikely(!netif_running(dev))) { |
| 8024 | dev->stats.rx_dropped++; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8025 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 8026 | return; |
| 8027 | } |
| 8028 | |
| 8029 | /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use |
| 8030 | * that now */ |
| 8031 | if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) { |
| 8032 | /* FIXME: Should alloc bigger skb instead */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8033 | dev->stats.rx_dropped++; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8034 | IPW_DEBUG_DROP("Dropping too large packet in monitor\n"); |
| 8035 | return; |
| 8036 | } |
| 8037 | |
| 8038 | hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8039 | if (libipw_is_management(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8040 | if (filter & IPW_PROM_NO_MGMT) |
| 8041 | return; |
| 8042 | if (filter & IPW_PROM_MGMT_HEADER_ONLY) |
| 8043 | hdr_only = 1; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8044 | } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8045 | if (filter & IPW_PROM_NO_CTL) |
| 8046 | return; |
| 8047 | if (filter & IPW_PROM_CTL_HEADER_ONLY) |
| 8048 | hdr_only = 1; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8049 | } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8050 | if (filter & IPW_PROM_NO_DATA) |
| 8051 | return; |
| 8052 | if (filter & IPW_PROM_DATA_HEADER_ONLY) |
| 8053 | hdr_only = 1; |
| 8054 | } |
| 8055 | |
| 8056 | /* Copy the SKB since this is for the promiscuous side */ |
| 8057 | skb = skb_copy(rxb->skb, GFP_ATOMIC); |
| 8058 | if (skb == NULL) { |
| 8059 | IPW_ERROR("skb_clone failed for promiscuous copy.\n"); |
| 8060 | return; |
| 8061 | } |
| 8062 | |
| 8063 | /* copy the frame data to write after where the radiotap header goes */ |
| 8064 | ipw_rt = (void *)skb->data; |
| 8065 | |
| 8066 | if (hdr_only) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8067 | len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control)); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8068 | |
| 8069 | memcpy(ipw_rt->payload, hdr, len); |
| 8070 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8071 | ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 8072 | ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 8073 | ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*ipw_rt)); /* total header+data */ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8074 | |
| 8075 | /* Set the size of the skb to the size of the frame */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 8076 | skb_put(skb, sizeof(*ipw_rt) + len); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8077 | |
| 8078 | /* Big bitfield of all the fields we provide in radiotap */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 8079 | ipw_rt->rt_hdr.it_present = cpu_to_le32( |
| 8080 | (1 << IEEE80211_RADIOTAP_TSFT) | |
Zhu Yi | 4b1f8a9 | 2006-12-05 14:42:14 +0800 | [diff] [blame] | 8081 | (1 << IEEE80211_RADIOTAP_FLAGS) | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8082 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 8083 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 8084 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | |
| 8085 | (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | |
| 8086 | (1 << IEEE80211_RADIOTAP_ANTENNA)); |
| 8087 | |
| 8088 | /* Zero the flags, we'll add to them as we go */ |
| 8089 | ipw_rt->rt_flags = 0; |
Zhu Yi | 4b1f8a9 | 2006-12-05 14:42:14 +0800 | [diff] [blame] | 8090 | ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 | |
| 8091 | frame->parent_tsf[2] << 16 | |
| 8092 | frame->parent_tsf[1] << 8 | |
| 8093 | frame->parent_tsf[0]); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8094 | |
| 8095 | /* Convert to DBM */ |
| 8096 | ipw_rt->rt_dbmsignal = signal; |
| 8097 | ipw_rt->rt_dbmnoise = noise; |
| 8098 | |
| 8099 | /* Convert the channel data and set the flags */ |
| 8100 | ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel)); |
| 8101 | if (channel > 14) { /* 802.11a */ |
| 8102 | ipw_rt->rt_chbitmask = |
| 8103 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); |
| 8104 | } else if (phy_flags & (1 << 5)) { /* 802.11b */ |
| 8105 | ipw_rt->rt_chbitmask = |
| 8106 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); |
| 8107 | } else { /* 802.11g */ |
| 8108 | ipw_rt->rt_chbitmask = |
Al Viro | 472caf8 | 2007-12-27 01:50:54 -0500 | [diff] [blame] | 8109 | cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8110 | } |
| 8111 | |
| 8112 | /* set the rate in multiples of 500k/s */ |
| 8113 | switch (rate) { |
| 8114 | case IPW_TX_RATE_1MB: |
| 8115 | ipw_rt->rt_rate = 2; |
| 8116 | break; |
| 8117 | case IPW_TX_RATE_2MB: |
| 8118 | ipw_rt->rt_rate = 4; |
| 8119 | break; |
| 8120 | case IPW_TX_RATE_5MB: |
| 8121 | ipw_rt->rt_rate = 10; |
| 8122 | break; |
| 8123 | case IPW_TX_RATE_6MB: |
| 8124 | ipw_rt->rt_rate = 12; |
| 8125 | break; |
| 8126 | case IPW_TX_RATE_9MB: |
| 8127 | ipw_rt->rt_rate = 18; |
| 8128 | break; |
| 8129 | case IPW_TX_RATE_11MB: |
| 8130 | ipw_rt->rt_rate = 22; |
| 8131 | break; |
| 8132 | case IPW_TX_RATE_12MB: |
| 8133 | ipw_rt->rt_rate = 24; |
| 8134 | break; |
| 8135 | case IPW_TX_RATE_18MB: |
| 8136 | ipw_rt->rt_rate = 36; |
| 8137 | break; |
| 8138 | case IPW_TX_RATE_24MB: |
| 8139 | ipw_rt->rt_rate = 48; |
| 8140 | break; |
| 8141 | case IPW_TX_RATE_36MB: |
| 8142 | ipw_rt->rt_rate = 72; |
| 8143 | break; |
| 8144 | case IPW_TX_RATE_48MB: |
| 8145 | ipw_rt->rt_rate = 96; |
| 8146 | break; |
| 8147 | case IPW_TX_RATE_54MB: |
| 8148 | ipw_rt->rt_rate = 108; |
| 8149 | break; |
| 8150 | default: |
| 8151 | ipw_rt->rt_rate = 0; |
| 8152 | break; |
| 8153 | } |
| 8154 | |
| 8155 | /* antenna number */ |
| 8156 | ipw_rt->rt_antenna = (phy_flags & 3); |
| 8157 | |
| 8158 | /* set the preamble flag if we have it */ |
| 8159 | if (phy_flags & (1 << 6)) |
| 8160 | ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; |
| 8161 | |
| 8162 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len); |
| 8163 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8164 | if (!libipw_rx(priv->prom_priv->ieee, skb, stats)) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8165 | dev->stats.rx_errors++; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8166 | dev_kfree_skb_any(skb); |
| 8167 | } |
| 8168 | } |
| 8169 | #endif |
| 8170 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 8171 | static int is_network_packet(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8172 | struct libipw_hdr_4addr *header) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8173 | { |
| 8174 | /* Filter incoming packets to determine if they are targetted toward |
| 8175 | * this network, discarding packets coming from ourselves */ |
| 8176 | switch (priv->ieee->iw_mode) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8177 | case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8178 | /* packets from our adapter are dropped (echo) */ |
| 8179 | if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN)) |
| 8180 | return 0; |
| 8181 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 8182 | /* {broad,multi}cast packets to our BSSID go through */ |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 8183 | if (is_multicast_ether_addr(header->addr1)) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8184 | return !memcmp(header->addr3, priv->bssid, ETH_ALEN); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8185 | |
| 8186 | /* packets to our adapter go through */ |
| 8187 | return !memcmp(header->addr1, priv->net_dev->dev_addr, |
| 8188 | ETH_ALEN); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8189 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 8190 | case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8191 | /* packets from our adapter are dropped (echo) */ |
| 8192 | if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN)) |
| 8193 | return 0; |
| 8194 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 8195 | /* {broad,multi}cast packets to our BSS go through */ |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 8196 | if (is_multicast_ether_addr(header->addr1)) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8197 | return !memcmp(header->addr2, priv->bssid, ETH_ALEN); |
| 8198 | |
| 8199 | /* packets to our adapter go through */ |
| 8200 | return !memcmp(header->addr1, priv->net_dev->dev_addr, |
| 8201 | ETH_ALEN); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8202 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8203 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8204 | return 1; |
| 8205 | } |
| 8206 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8207 | #define IPW_PACKET_RETRY_TIME HZ |
| 8208 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 8209 | static int is_duplicate_packet(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8210 | struct libipw_hdr_4addr *header) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8211 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8212 | u16 sc = le16_to_cpu(header->seq_ctl); |
| 8213 | u16 seq = WLAN_GET_SEQ_SEQ(sc); |
| 8214 | u16 frag = WLAN_GET_SEQ_FRAG(sc); |
| 8215 | u16 *last_seq, *last_frag; |
| 8216 | unsigned long *last_time; |
| 8217 | |
| 8218 | switch (priv->ieee->iw_mode) { |
| 8219 | case IW_MODE_ADHOC: |
| 8220 | { |
| 8221 | struct list_head *p; |
| 8222 | struct ipw_ibss_seq *entry = NULL; |
| 8223 | u8 *mac = header->addr2; |
| 8224 | int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE; |
| 8225 | |
| 8226 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
| 8227 | entry = |
| 8228 | list_entry(p, struct ipw_ibss_seq, list); |
| 8229 | if (!memcmp(entry->mac, mac, ETH_ALEN)) |
| 8230 | break; |
| 8231 | } |
| 8232 | if (p == &priv->ibss_mac_hash[index]) { |
| 8233 | entry = kmalloc(sizeof(*entry), GFP_ATOMIC); |
| 8234 | if (!entry) { |
| 8235 | IPW_ERROR |
| 8236 | ("Cannot malloc new mac entry\n"); |
| 8237 | return 0; |
| 8238 | } |
| 8239 | memcpy(entry->mac, mac, ETH_ALEN); |
| 8240 | entry->seq_num = seq; |
| 8241 | entry->frag_num = frag; |
| 8242 | entry->packet_time = jiffies; |
| 8243 | list_add(&entry->list, |
| 8244 | &priv->ibss_mac_hash[index]); |
| 8245 | return 0; |
| 8246 | } |
| 8247 | last_seq = &entry->seq_num; |
| 8248 | last_frag = &entry->frag_num; |
| 8249 | last_time = &entry->packet_time; |
| 8250 | break; |
| 8251 | } |
| 8252 | case IW_MODE_INFRA: |
| 8253 | last_seq = &priv->last_seq_num; |
| 8254 | last_frag = &priv->last_frag_num; |
| 8255 | last_time = &priv->last_packet_time; |
| 8256 | break; |
| 8257 | default: |
| 8258 | return 0; |
| 8259 | } |
| 8260 | if ((*last_seq == seq) && |
| 8261 | time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) { |
| 8262 | if (*last_frag == frag) |
| 8263 | goto drop; |
| 8264 | if (*last_frag + 1 != frag) |
| 8265 | /* out-of-order fragment */ |
| 8266 | goto drop; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8267 | } else |
| 8268 | *last_seq = seq; |
| 8269 | |
Zhu Yi | f57ce7c | 2005-07-13 12:22:15 -0500 | [diff] [blame] | 8270 | *last_frag = frag; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8271 | *last_time = jiffies; |
| 8272 | return 0; |
| 8273 | |
| 8274 | drop: |
Zhu Yi | 87b016c | 2005-08-05 17:17:35 +0800 | [diff] [blame] | 8275 | /* Comment this line now since we observed the card receives |
| 8276 | * duplicate packets but the FCTL_RETRY bit is not set in the |
| 8277 | * IBSS mode with fragmentation enabled. |
John W. Linville | 7211801 | 2008-09-30 21:43:03 -0400 | [diff] [blame] | 8278 | BUG_ON(!(le16_to_cpu(header->frame_control) & IEEE80211_FCTL_RETRY)); */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8279 | return 1; |
| 8280 | } |
| 8281 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8282 | static void ipw_handle_mgmt_packet(struct ipw_priv *priv, |
| 8283 | struct ipw_rx_mem_buffer *rxb, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8284 | struct libipw_rx_stats *stats) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8285 | { |
| 8286 | struct sk_buff *skb = rxb->skb; |
| 8287 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8288 | struct libipw_hdr_4addr *header = (struct libipw_hdr_4addr *) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8289 | (skb->data + IPW_RX_FRAME_SIZE); |
| 8290 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8291 | libipw_rx_mgt(priv->ieee, header, stats); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8292 | |
| 8293 | if (priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 8294 | ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == |
| 8295 | IEEE80211_STYPE_PROBE_RESP) || |
| 8296 | (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == |
| 8297 | IEEE80211_STYPE_BEACON))) { |
| 8298 | if (!memcmp(header->addr3, priv->bssid, ETH_ALEN)) |
| 8299 | ipw_add_station(priv, header->addr2); |
| 8300 | } |
| 8301 | |
| 8302 | if (priv->config & CFG_NET_STATS) { |
| 8303 | IPW_DEBUG_HC("sending stat packet\n"); |
| 8304 | |
| 8305 | /* Set the size of the skb to the size of the full |
| 8306 | * ipw header and 802.11 frame */ |
| 8307 | skb_put(skb, le16_to_cpu(pkt->u.frame.length) + |
| 8308 | IPW_RX_FRAME_SIZE); |
| 8309 | |
| 8310 | /* Advance past the ipw packet header to the 802.11 frame */ |
| 8311 | skb_pull(skb, IPW_RX_FRAME_SIZE); |
| 8312 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8313 | /* Push the libipw_rx_stats before the 802.11 frame */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8314 | memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats)); |
| 8315 | |
| 8316 | skb->dev = priv->ieee->dev; |
| 8317 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8318 | /* Point raw at the libipw_stats */ |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 8319 | skb_reset_mac_header(skb); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8320 | |
| 8321 | skb->pkt_type = PACKET_OTHERHOST; |
Harvey Harrison | c1b4aa3 | 2009-01-29 13:26:44 -0800 | [diff] [blame] | 8322 | skb->protocol = cpu_to_be16(ETH_P_80211_STATS); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8323 | memset(skb->cb, 0, sizeof(rxb->skb->cb)); |
| 8324 | netif_rx(skb); |
| 8325 | rxb->skb = NULL; |
| 8326 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8327 | } |
| 8328 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8329 | /* |
| 8330 | * Main entry function for recieving a packet with 80211 headers. This |
| 8331 | * should be called when ever the FW has notified us that there is a new |
| 8332 | * skb in the recieve queue. |
| 8333 | */ |
| 8334 | static void ipw_rx(struct ipw_priv *priv) |
| 8335 | { |
| 8336 | struct ipw_rx_mem_buffer *rxb; |
| 8337 | struct ipw_rx_packet *pkt; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8338 | struct libipw_hdr_4addr *header; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8339 | u32 r, w, i; |
| 8340 | u8 network_packet; |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 8341 | u8 fill_rx = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8342 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8343 | r = ipw_read32(priv, IPW_RX_READ_INDEX); |
| 8344 | w = ipw_read32(priv, IPW_RX_WRITE_INDEX); |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 8345 | i = priv->rxq->read; |
| 8346 | |
| 8347 | if (ipw_rx_queue_space (priv->rxq) > (RX_QUEUE_SIZE / 2)) |
| 8348 | fill_rx = 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8349 | |
| 8350 | while (i != r) { |
| 8351 | rxb = priv->rxq->queue[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8352 | if (unlikely(rxb == NULL)) { |
| 8353 | printk(KERN_CRIT "Queue not allocated!\n"); |
| 8354 | break; |
| 8355 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8356 | priv->rxq->queue[i] = NULL; |
| 8357 | |
| 8358 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8359 | IPW_RX_BUF_SIZE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8360 | PCI_DMA_FROMDEVICE); |
| 8361 | |
| 8362 | pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 8363 | IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n", |
| 8364 | pkt->header.message_type, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8365 | pkt->header.rx_seq_num, pkt->header.control_bits); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8366 | |
| 8367 | switch (pkt->header.message_type) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8368 | case RX_FRAME_TYPE: /* 802.11 frame */ { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8369 | struct libipw_rx_stats stats = { |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 8370 | .rssi = pkt->u.frame.rssi_dbm - |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8371 | IPW_RSSI_TO_DBM, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8372 | .signal = |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8373 | pkt->u.frame.rssi_dbm - |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 8374 | IPW_RSSI_TO_DBM + 0x100, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8375 | .noise = |
| 8376 | le16_to_cpu(pkt->u.frame.noise), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8377 | .rate = pkt->u.frame.rate, |
| 8378 | .mac_time = jiffies, |
| 8379 | .received_channel = |
| 8380 | pkt->u.frame.received_channel, |
| 8381 | .freq = |
| 8382 | (pkt->u.frame. |
| 8383 | control & (1 << 0)) ? |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8384 | LIBIPW_24GHZ_BAND : |
| 8385 | LIBIPW_52GHZ_BAND, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8386 | .len = le16_to_cpu(pkt->u.frame.length), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8387 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8388 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8389 | if (stats.rssi != 0) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8390 | stats.mask |= LIBIPW_STATMASK_RSSI; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8391 | if (stats.signal != 0) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8392 | stats.mask |= LIBIPW_STATMASK_SIGNAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8393 | if (stats.noise != 0) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8394 | stats.mask |= LIBIPW_STATMASK_NOISE; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8395 | if (stats.rate != 0) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8396 | stats.mask |= LIBIPW_STATMASK_RATE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8397 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8398 | priv->rx_packets++; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8399 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8400 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 8401 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) |
| 8402 | ipw_handle_promiscuous_rx(priv, rxb, &stats); |
| 8403 | #endif |
| 8404 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8405 | #ifdef CONFIG_IPW2200_MONITOR |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8406 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 8407 | #ifdef CONFIG_IPW2200_RADIOTAP |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8408 | |
| 8409 | ipw_handle_data_packet_monitor(priv, |
| 8410 | rxb, |
| 8411 | &stats); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8412 | #else |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8413 | ipw_handle_data_packet(priv, rxb, |
| 8414 | &stats); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8415 | #endif |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8416 | break; |
| 8417 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8418 | #endif |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8419 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8420 | header = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8421 | (struct libipw_hdr_4addr *)(rxb->skb-> |
James Ketrenos | 0dacca1 | 2005-09-21 12:23:41 -0500 | [diff] [blame] | 8422 | data + |
| 8423 | IPW_RX_FRAME_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8424 | /* TODO: Check Ad-Hoc dest/source and make sure |
| 8425 | * that we are actually parsing these packets |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8426 | * correctly -- we should probably use the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8427 | * frame control of the packet and disregard |
| 8428 | * the current iw_mode */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8429 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8430 | network_packet = |
| 8431 | is_network_packet(priv, header); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8432 | if (network_packet && priv->assoc_network) { |
| 8433 | priv->assoc_network->stats.rssi = |
| 8434 | stats.rssi; |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 8435 | priv->exp_avg_rssi = |
| 8436 | exponential_average(priv->exp_avg_rssi, |
| 8437 | stats.rssi, DEPTH_RSSI); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8438 | } |
| 8439 | |
| 8440 | IPW_DEBUG_RX("Frame: len=%u\n", |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8441 | le16_to_cpu(pkt->u.frame.length)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8442 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8443 | if (le16_to_cpu(pkt->u.frame.length) < |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8444 | libipw_get_hdrlen(le16_to_cpu( |
Zhu Yi | 9d0be03 | 2006-02-15 06:18:19 +0800 | [diff] [blame] | 8445 | header->frame_ctl))) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8446 | IPW_DEBUG_DROP |
| 8447 | ("Received packet is too small. " |
| 8448 | "Dropping.\n"); |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8449 | priv->net_dev->stats.rx_errors++; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8450 | priv->wstats.discard.misc++; |
| 8451 | break; |
| 8452 | } |
| 8453 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8454 | switch (WLAN_FC_GET_TYPE |
| 8455 | (le16_to_cpu(header->frame_ctl))) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8456 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8457 | case IEEE80211_FTYPE_MGMT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8458 | ipw_handle_mgmt_packet(priv, rxb, |
| 8459 | &stats); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8460 | break; |
| 8461 | |
| 8462 | case IEEE80211_FTYPE_CTL: |
| 8463 | break; |
| 8464 | |
| 8465 | case IEEE80211_FTYPE_DATA: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8466 | if (unlikely(!network_packet || |
| 8467 | is_duplicate_packet(priv, |
| 8468 | header))) |
| 8469 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8470 | IPW_DEBUG_DROP("Dropping: " |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 8471 | "%pM, " |
| 8472 | "%pM, " |
| 8473 | "%pM\n", |
| 8474 | header->addr1, |
| 8475 | header->addr2, |
| 8476 | header->addr3); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8477 | break; |
| 8478 | } |
| 8479 | |
| 8480 | ipw_handle_data_packet(priv, rxb, |
| 8481 | &stats); |
| 8482 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8483 | break; |
| 8484 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8485 | break; |
| 8486 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8487 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8488 | case RX_HOST_NOTIFICATION_TYPE:{ |
| 8489 | IPW_DEBUG_RX |
| 8490 | ("Notification: subtype=%02X flags=%02X size=%d\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8491 | pkt->u.notification.subtype, |
| 8492 | pkt->u.notification.flags, |
Zhu Yi | 720eeb4 | 2006-12-05 14:41:40 +0800 | [diff] [blame] | 8493 | le16_to_cpu(pkt->u.notification.size)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8494 | ipw_rx_notification(priv, &pkt->u.notification); |
| 8495 | break; |
| 8496 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8497 | |
| 8498 | default: |
| 8499 | IPW_DEBUG_RX("Bad Rx packet of type %d\n", |
| 8500 | pkt->header.message_type); |
| 8501 | break; |
| 8502 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8503 | |
| 8504 | /* For now we just don't re-use anything. We can tweak this |
| 8505 | * later to try and re-use notification packets and SKBs that |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8506 | * fail to Rx correctly */ |
| 8507 | if (rxb->skb != NULL) { |
| 8508 | dev_kfree_skb_any(rxb->skb); |
| 8509 | rxb->skb = NULL; |
| 8510 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8511 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8512 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8513 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8514 | list_add_tail(&rxb->list, &priv->rxq->rx_used); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8515 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8516 | i = (i + 1) % RX_QUEUE_SIZE; |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 8517 | |
| 8518 | /* If there are a lot of unsued frames, restock the Rx queue |
| 8519 | * so the ucode won't assert */ |
| 8520 | if (fill_rx) { |
| 8521 | priv->rxq->read = i; |
| 8522 | ipw_rx_queue_replenish(priv); |
| 8523 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8524 | } |
| 8525 | |
| 8526 | /* Backtrack one entry */ |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 8527 | priv->rxq->read = i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8528 | ipw_rx_queue_restock(priv); |
| 8529 | } |
| 8530 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8531 | #define DEFAULT_RTS_THRESHOLD 2304U |
| 8532 | #define MIN_RTS_THRESHOLD 1U |
| 8533 | #define MAX_RTS_THRESHOLD 2304U |
| 8534 | #define DEFAULT_BEACON_INTERVAL 100U |
| 8535 | #define DEFAULT_SHORT_RETRY_LIMIT 7U |
| 8536 | #define DEFAULT_LONG_RETRY_LIMIT 4U |
| 8537 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 8538 | /** |
| 8539 | * ipw_sw_reset |
| 8540 | * @option: options to control different reset behaviour |
| 8541 | * 0 = reset everything except the 'disable' module_param |
| 8542 | * 1 = reset everything and print out driver info (for probe only) |
| 8543 | * 2 = reset everything |
| 8544 | */ |
| 8545 | static int ipw_sw_reset(struct ipw_priv *priv, int option) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8546 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8547 | int band, modulation; |
| 8548 | int old_mode = priv->ieee->iw_mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8549 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8550 | /* Initialize module parameter values here */ |
| 8551 | priv->config = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8552 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8553 | /* We default to disabling the LED code as right now it causes |
| 8554 | * too many systems to lock up... */ |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8555 | if (!led_support) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8556 | priv->config |= CFG_NO_LED; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8557 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8558 | if (associate) |
| 8559 | priv->config |= CFG_ASSOCIATE; |
| 8560 | else |
| 8561 | IPW_DEBUG_INFO("Auto associate disabled.\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8562 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8563 | if (auto_create) |
| 8564 | priv->config |= CFG_ADHOC_CREATE; |
| 8565 | else |
| 8566 | IPW_DEBUG_INFO("Auto adhoc creation disabled.\n"); |
| 8567 | |
Zhu Yi | 17ed081 | 2006-01-24 16:36:31 +0800 | [diff] [blame] | 8568 | priv->config &= ~CFG_STATIC_ESSID; |
| 8569 | priv->essid_len = 0; |
| 8570 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 8571 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 8572 | if (disable && option) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8573 | priv->status |= STATUS_RF_KILL_SW; |
| 8574 | IPW_DEBUG_INFO("Radio disabled.\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8575 | } |
| 8576 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8577 | if (default_channel != 0) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8578 | priv->config |= CFG_STATIC_CHANNEL; |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8579 | priv->channel = default_channel; |
| 8580 | IPW_DEBUG_INFO("Bind to static channel %d\n", default_channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8581 | /* TODO: Validate that provided channel is in range */ |
| 8582 | } |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 8583 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8584 | ipw_qos_init(priv, qos_enable, qos_burst_enable, |
| 8585 | burst_duration_CCK, burst_duration_OFDM); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 8586 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8587 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8588 | switch (network_mode) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8589 | case 1: |
| 8590 | priv->ieee->iw_mode = IW_MODE_ADHOC; |
| 8591 | priv->net_dev->type = ARPHRD_ETHER; |
| 8592 | |
| 8593 | break; |
| 8594 | #ifdef CONFIG_IPW2200_MONITOR |
| 8595 | case 2: |
| 8596 | priv->ieee->iw_mode = IW_MODE_MONITOR; |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 8597 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8598 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 8599 | #else |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8600 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8601 | #endif |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8602 | break; |
| 8603 | #endif |
| 8604 | default: |
| 8605 | case 0: |
| 8606 | priv->net_dev->type = ARPHRD_ETHER; |
| 8607 | priv->ieee->iw_mode = IW_MODE_INFRA; |
| 8608 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8609 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8610 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8611 | if (hwcrypto) { |
| 8612 | priv->ieee->host_encrypt = 0; |
| 8613 | priv->ieee->host_encrypt_msdu = 0; |
| 8614 | priv->ieee->host_decrypt = 0; |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 8615 | priv->ieee->host_mc_decrypt = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8616 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8617 | IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8618 | |
Zhu Yi | e402c93 | 2005-08-05 17:20:40 +0800 | [diff] [blame] | 8619 | /* IPW2200/2915 is abled to do hardware fragmentation. */ |
| 8620 | priv->ieee->host_open_frag = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8621 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8622 | if ((priv->pci_dev->device == 0x4223) || |
| 8623 | (priv->pci_dev->device == 0x4224)) { |
Zhu Yi | e8c69e2 | 2006-02-17 08:25:12 +0800 | [diff] [blame] | 8624 | if (option == 1) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8625 | printk(KERN_INFO DRV_NAME |
| 8626 | ": Detected Intel PRO/Wireless 2915ABG Network " |
| 8627 | "Connection\n"); |
| 8628 | priv->ieee->abg_true = 1; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8629 | band = LIBIPW_52GHZ_BAND | LIBIPW_24GHZ_BAND; |
| 8630 | modulation = LIBIPW_OFDM_MODULATION | |
| 8631 | LIBIPW_CCK_MODULATION; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8632 | priv->adapter = IPW_2915ABG; |
| 8633 | priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8634 | } else { |
Zhu Yi | e8c69e2 | 2006-02-17 08:25:12 +0800 | [diff] [blame] | 8635 | if (option == 1) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8636 | printk(KERN_INFO DRV_NAME |
| 8637 | ": Detected Intel PRO/Wireless 2200BG Network " |
| 8638 | "Connection\n"); |
| 8639 | |
| 8640 | priv->ieee->abg_true = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8641 | band = LIBIPW_24GHZ_BAND; |
| 8642 | modulation = LIBIPW_OFDM_MODULATION | |
| 8643 | LIBIPW_CCK_MODULATION; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8644 | priv->adapter = IPW_2200BG; |
| 8645 | priv->ieee->mode = IEEE_G | IEEE_B; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8646 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8647 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8648 | priv->ieee->freq_band = band; |
| 8649 | priv->ieee->modulation = modulation; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8650 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8651 | priv->rates_mask = LIBIPW_DEFAULT_RATES_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8652 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8653 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; |
| 8654 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8655 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8656 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
| 8657 | priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT; |
| 8658 | priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8659 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8660 | /* If power management is turned on, default to AC mode */ |
| 8661 | priv->power_mode = IPW_POWER_AC; |
| 8662 | priv->tx_power = IPW_TX_POWER_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8663 | |
Zhu Yi | 0ece35b | 2005-08-05 17:26:51 +0800 | [diff] [blame] | 8664 | return old_mode == priv->ieee->iw_mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8665 | } |
| 8666 | |
| 8667 | /* |
| 8668 | * This file defines the Wireless Extension handlers. It does not |
| 8669 | * define any methods of hardware manipulation and relies on the |
| 8670 | * functions defined in ipw_main to provide the HW interaction. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8671 | * |
| 8672 | * The exception to this is the use of the ipw_get_ordinal() |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8673 | * function used to poll the hardware vs. making unecessary calls. |
| 8674 | * |
| 8675 | */ |
| 8676 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8677 | static int ipw_set_channel(struct ipw_priv *priv, u8 channel) |
| 8678 | { |
| 8679 | if (channel == 0) { |
| 8680 | IPW_DEBUG_INFO("Setting channel to ANY (0)\n"); |
| 8681 | priv->config &= ~CFG_STATIC_CHANNEL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8682 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 8683 | "parameters.\n"); |
| 8684 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8685 | return 0; |
| 8686 | } |
| 8687 | |
| 8688 | priv->config |= CFG_STATIC_CHANNEL; |
| 8689 | |
| 8690 | if (priv->channel == channel) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8691 | IPW_DEBUG_INFO("Request to set channel to current value (%d)\n", |
| 8692 | channel); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8693 | return 0; |
| 8694 | } |
| 8695 | |
| 8696 | IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel); |
| 8697 | priv->channel = channel; |
| 8698 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8699 | #ifdef CONFIG_IPW2200_MONITOR |
| 8700 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8701 | int i; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8702 | if (priv->status & STATUS_SCANNING) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8703 | IPW_DEBUG_SCAN("Scan abort triggered due to " |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8704 | "channel change.\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8705 | ipw_abort_scan(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8706 | } |
| 8707 | |
| 8708 | for (i = 1000; i && (priv->status & STATUS_SCANNING); i--) |
| 8709 | udelay(10); |
| 8710 | |
| 8711 | if (priv->status & STATUS_SCANNING) |
| 8712 | IPW_DEBUG_SCAN("Still scanning...\n"); |
| 8713 | else |
| 8714 | IPW_DEBUG_SCAN("Took %dms to abort current scan\n", |
| 8715 | 1000 - i); |
| 8716 | |
| 8717 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8718 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8719 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 8720 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8721 | /* Network configuration changed -- force [re]association */ |
| 8722 | IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n"); |
| 8723 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8724 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8725 | |
| 8726 | return 0; |
| 8727 | } |
| 8728 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8729 | static int ipw_wx_set_freq(struct net_device *dev, |
| 8730 | struct iw_request_info *info, |
| 8731 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8732 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8733 | struct ipw_priv *priv = libipw_priv(dev); |
| 8734 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8735 | struct iw_freq *fwrq = &wrqu->freq; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8736 | int ret = 0, i; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8737 | u8 channel, flags; |
| 8738 | int band; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8739 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8740 | if (fwrq->m == 0) { |
| 8741 | IPW_DEBUG_WX("SET Freq/Channel -> any\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8742 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8743 | ret = ipw_set_channel(priv, 0); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8744 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8745 | return ret; |
| 8746 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8747 | /* if setting by freq convert to channel */ |
| 8748 | if (fwrq->e == 1) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8749 | channel = libipw_freq_to_channel(priv->ieee, fwrq->m); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8750 | if (channel == 0) |
| 8751 | return -EINVAL; |
| 8752 | } else |
| 8753 | channel = fwrq->m; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8754 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8755 | if (!(band = libipw_is_valid_channel(priv->ieee, channel))) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8756 | return -EINVAL; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8757 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8758 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8759 | i = libipw_channel_to_index(priv->ieee, channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8760 | if (i == -1) |
| 8761 | return -EINVAL; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8762 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8763 | flags = (band == LIBIPW_24GHZ_BAND) ? |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8764 | geo->bg[i].flags : geo->a[i].flags; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8765 | if (flags & LIBIPW_CH_PASSIVE_ONLY) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8766 | IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n"); |
| 8767 | return -EINVAL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8768 | } |
| 8769 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8770 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8771 | IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8772 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8773 | ret = ipw_set_channel(priv, channel); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8774 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8775 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8776 | } |
| 8777 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8778 | static int ipw_wx_get_freq(struct net_device *dev, |
| 8779 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8780 | union iwreq_data *wrqu, char *extra) |
| 8781 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8782 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8783 | |
| 8784 | wrqu->freq.e = 0; |
| 8785 | |
| 8786 | /* If we are associated, trying to associate, or have a statically |
| 8787 | * configured CHANNEL then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8788 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8789 | if (priv->config & CFG_STATIC_CHANNEL || |
Zhu Yi | c580f67 | 2006-08-21 11:37:01 +0800 | [diff] [blame] | 8790 | priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) { |
| 8791 | int i; |
| 8792 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8793 | i = libipw_channel_to_index(priv->ieee, priv->channel); |
Zhu Yi | c580f67 | 2006-08-21 11:37:01 +0800 | [diff] [blame] | 8794 | BUG_ON(i == -1); |
| 8795 | wrqu->freq.e = 1; |
| 8796 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8797 | switch (libipw_is_valid_channel(priv->ieee, priv->channel)) { |
| 8798 | case LIBIPW_52GHZ_BAND: |
Zhu Yi | c580f67 | 2006-08-21 11:37:01 +0800 | [diff] [blame] | 8799 | wrqu->freq.m = priv->ieee->geo.a[i].freq * 100000; |
| 8800 | break; |
| 8801 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8802 | case LIBIPW_24GHZ_BAND: |
Zhu Yi | c580f67 | 2006-08-21 11:37:01 +0800 | [diff] [blame] | 8803 | wrqu->freq.m = priv->ieee->geo.bg[i].freq * 100000; |
| 8804 | break; |
| 8805 | |
| 8806 | default: |
| 8807 | BUG(); |
| 8808 | } |
| 8809 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8810 | wrqu->freq.m = 0; |
| 8811 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8812 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8813 | IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel); |
| 8814 | return 0; |
| 8815 | } |
| 8816 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8817 | static int ipw_wx_set_mode(struct net_device *dev, |
| 8818 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8819 | union iwreq_data *wrqu, char *extra) |
| 8820 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8821 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8822 | int err = 0; |
| 8823 | |
| 8824 | IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode); |
| 8825 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8826 | switch (wrqu->mode) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8827 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8828 | case IW_MODE_MONITOR: |
| 8829 | #endif |
| 8830 | case IW_MODE_ADHOC: |
| 8831 | case IW_MODE_INFRA: |
| 8832 | break; |
| 8833 | case IW_MODE_AUTO: |
| 8834 | wrqu->mode = IW_MODE_INFRA; |
| 8835 | break; |
| 8836 | default: |
| 8837 | return -EINVAL; |
| 8838 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8839 | if (wrqu->mode == priv->ieee->iw_mode) |
| 8840 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8841 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8842 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8843 | |
| 8844 | ipw_sw_reset(priv, 0); |
| 8845 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8846 | #ifdef CONFIG_IPW2200_MONITOR |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8847 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8848 | priv->net_dev->type = ARPHRD_ETHER; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8849 | |
| 8850 | if (wrqu->mode == IW_MODE_MONITOR) |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 8851 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8852 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 8853 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8854 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8855 | #endif |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8856 | #endif /* CONFIG_IPW2200_MONITOR */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8857 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8858 | /* Free the existing firmware and reset the fw_loaded |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 8859 | * flag so ipw_load() will bring in the new firmware */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8860 | free_firmware(); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8861 | |
| 8862 | priv->ieee->iw_mode = wrqu->mode; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8863 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8864 | queue_work(priv->workqueue, &priv->adapter_restart); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8865 | mutex_unlock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8866 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8867 | } |
| 8868 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8869 | static int ipw_wx_get_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8870 | struct iw_request_info *info, |
| 8871 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8872 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8873 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8874 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8875 | wrqu->mode = priv->ieee->iw_mode; |
| 8876 | IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode); |
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 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8881 | /* Values are in microsecond */ |
| 8882 | static const s32 timeout_duration[] = { |
| 8883 | 350000, |
| 8884 | 250000, |
| 8885 | 75000, |
| 8886 | 37000, |
| 8887 | 25000, |
| 8888 | }; |
| 8889 | |
| 8890 | static const s32 period_duration[] = { |
| 8891 | 400000, |
| 8892 | 700000, |
| 8893 | 1000000, |
| 8894 | 1000000, |
| 8895 | 1000000 |
| 8896 | }; |
| 8897 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8898 | static int ipw_wx_get_range(struct net_device *dev, |
| 8899 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8900 | union iwreq_data *wrqu, char *extra) |
| 8901 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8902 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8903 | struct iw_range *range = (struct iw_range *)extra; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8904 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8905 | int i = 0, j; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8906 | |
| 8907 | wrqu->data.length = sizeof(*range); |
| 8908 | memset(range, 0, sizeof(*range)); |
| 8909 | |
| 8910 | /* 54Mbs == ~27 Mb/s real (802.11g) */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8911 | range->throughput = 27 * 1000 * 1000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8912 | |
| 8913 | range->max_qual.qual = 100; |
| 8914 | /* TODO: Find real max RSSI and stick here */ |
| 8915 | range->max_qual.level = 0; |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 8916 | range->max_qual.noise = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8917 | range->max_qual.updated = 7; /* Updated all three */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8918 | |
| 8919 | range->avg_qual.qual = 70; |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame^] | 8920 | /* TODO: Find real 'good' to 'bad' threshold value for RSSI */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8921 | range->avg_qual.level = 0; /* FIXME to real average level */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8922 | range->avg_qual.noise = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8923 | range->avg_qual.updated = 7; /* Updated all three */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8924 | mutex_lock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8925 | range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8926 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8927 | for (i = 0; i < range->num_bitrates; i++) |
| 8928 | range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) * |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8929 | 500000; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8930 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8931 | range->max_rts = DEFAULT_RTS_THRESHOLD; |
| 8932 | range->min_frag = MIN_FRAG_THRESHOLD; |
| 8933 | range->max_frag = MAX_FRAG_THRESHOLD; |
| 8934 | |
| 8935 | range->encoding_size[0] = 5; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8936 | range->encoding_size[1] = 13; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8937 | range->num_encoding_sizes = 2; |
| 8938 | range->max_encoding_tokens = WEP_KEYS; |
| 8939 | |
| 8940 | /* Set the Wireless Extension versions */ |
| 8941 | range->we_version_compiled = WIRELESS_EXT; |
Dan Williams | f1b5086 | 2006-01-30 13:58:56 -0500 | [diff] [blame] | 8942 | range->we_version_source = 18; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8943 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8944 | i = 0; |
| 8945 | if (priv->ieee->mode & (IEEE_B | IEEE_G)) { |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8946 | for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) { |
| 8947 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8948 | (geo->bg[j].flags & LIBIPW_CH_PASSIVE_ONLY)) |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8949 | continue; |
| 8950 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8951 | range->freq[i].i = geo->bg[j].channel; |
| 8952 | range->freq[i].m = geo->bg[j].freq * 100000; |
| 8953 | range->freq[i].e = 1; |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8954 | i++; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8955 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8956 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8957 | |
| 8958 | if (priv->ieee->mode & IEEE_A) { |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8959 | for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) { |
| 8960 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8961 | (geo->a[j].flags & LIBIPW_CH_PASSIVE_ONLY)) |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8962 | continue; |
| 8963 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8964 | range->freq[i].i = geo->a[j].channel; |
| 8965 | range->freq[i].m = geo->a[j].freq * 100000; |
| 8966 | range->freq[i].e = 1; |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8967 | i++; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8968 | } |
| 8969 | } |
| 8970 | |
| 8971 | range->num_channels = i; |
| 8972 | range->num_frequency = i; |
| 8973 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8974 | mutex_unlock(&priv->mutex); |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 8975 | |
| 8976 | /* Event capability (kernel + driver) */ |
| 8977 | range->event_capa[0] = (IW_EVENT_CAPA_K_0 | |
| 8978 | IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) | |
Zhu Yi | 07f02e4 | 2006-04-13 17:19:25 +0800 | [diff] [blame] | 8979 | IW_EVENT_CAPA_MASK(SIOCGIWAP) | |
| 8980 | IW_EVENT_CAPA_MASK(SIOCGIWSCAN)); |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 8981 | range->event_capa[1] = IW_EVENT_CAPA_K_1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8982 | |
Dan Williams | f1b5086 | 2006-01-30 13:58:56 -0500 | [diff] [blame] | 8983 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | |
| 8984 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; |
| 8985 | |
Dan Williams | 374fdfb | 2007-12-12 10:25:07 -0500 | [diff] [blame] | 8986 | range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE; |
| 8987 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8988 | IPW_DEBUG_WX("GET Range\n"); |
| 8989 | return 0; |
| 8990 | } |
| 8991 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8992 | static int ipw_wx_set_wap(struct net_device *dev, |
| 8993 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8994 | union iwreq_data *wrqu, char *extra) |
| 8995 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8996 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8997 | |
| 8998 | static const unsigned char any[] = { |
| 8999 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff |
| 9000 | }; |
| 9001 | static const unsigned char off[] = { |
| 9002 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 9003 | }; |
| 9004 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9005 | if (wrqu->ap_addr.sa_family != ARPHRD_ETHER) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9006 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9007 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9008 | if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) || |
| 9009 | !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) { |
| 9010 | /* we disable mandatory BSSID association */ |
| 9011 | IPW_DEBUG_WX("Setting AP BSSID to ANY\n"); |
| 9012 | priv->config &= ~CFG_STATIC_BSSID; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9013 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 9014 | "parameters.\n"); |
| 9015 | ipw_associate(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9016 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9017 | return 0; |
| 9018 | } |
| 9019 | |
| 9020 | priv->config |= CFG_STATIC_BSSID; |
| 9021 | if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) { |
| 9022 | IPW_DEBUG_WX("BSSID set to current BSSID.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9023 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9024 | return 0; |
| 9025 | } |
| 9026 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 9027 | IPW_DEBUG_WX("Setting mandatory BSSID to %pM\n", |
| 9028 | wrqu->ap_addr.sa_data); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9029 | |
| 9030 | memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN); |
| 9031 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9032 | /* Network configuration changed -- force [re]association */ |
| 9033 | IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n"); |
| 9034 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9035 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9036 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9037 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9038 | return 0; |
| 9039 | } |
| 9040 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9041 | static int ipw_wx_get_wap(struct net_device *dev, |
| 9042 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9043 | union iwreq_data *wrqu, char *extra) |
| 9044 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9045 | struct ipw_priv *priv = libipw_priv(dev); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 9046 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9047 | /* If we are associated, trying to associate, or have a statically |
| 9048 | * configured BSSID then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9049 | mutex_lock(&priv->mutex); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9050 | if (priv->config & CFG_STATIC_BSSID || |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9051 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
| 9052 | wrqu->ap_addr.sa_family = ARPHRD_ETHER; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9053 | memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9054 | } else |
| 9055 | memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN); |
| 9056 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 9057 | IPW_DEBUG_WX("Getting WAP BSSID: %pM\n", |
| 9058 | wrqu->ap_addr.sa_data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9059 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9060 | return 0; |
| 9061 | } |
| 9062 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9063 | static int ipw_wx_set_essid(struct net_device *dev, |
| 9064 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9065 | union iwreq_data *wrqu, char *extra) |
| 9066 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9067 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | ab644b0 | 2006-08-21 11:37:13 +0800 | [diff] [blame] | 9068 | int length; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 9069 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9070 | |
Zhu Yi | ab644b0 | 2006-08-21 11:37:13 +0800 | [diff] [blame] | 9071 | mutex_lock(&priv->mutex); |
| 9072 | |
| 9073 | if (!wrqu->essid.flags) |
| 9074 | { |
| 9075 | IPW_DEBUG_WX("Setting ESSID to ANY\n"); |
| 9076 | ipw_disassociate(priv); |
| 9077 | priv->config &= ~CFG_STATIC_ESSID; |
| 9078 | ipw_associate(priv); |
| 9079 | mutex_unlock(&priv->mutex); |
| 9080 | return 0; |
| 9081 | } |
| 9082 | |
Zhu Yi | a9f0d42 | 2006-08-21 11:37:26 +0800 | [diff] [blame] | 9083 | length = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9084 | |
| 9085 | priv->config |= CFG_STATIC_ESSID; |
| 9086 | |
Zhu Yi | a9f0d42 | 2006-08-21 11:37:26 +0800 | [diff] [blame] | 9087 | if (priv->essid_len == length && !memcmp(priv->essid, extra, length) |
| 9088 | && (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9089 | IPW_DEBUG_WX("ESSID set to current ESSID.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9090 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9091 | return 0; |
| 9092 | } |
| 9093 | |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 9094 | IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", |
| 9095 | print_ssid(ssid, extra, length), length); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9096 | |
| 9097 | priv->essid_len = length; |
Zhu Yi | a9f0d42 | 2006-08-21 11:37:26 +0800 | [diff] [blame] | 9098 | memcpy(priv->essid, extra, priv->essid_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9099 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9100 | /* Network configuration changed -- force [re]association */ |
| 9101 | IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n"); |
| 9102 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9103 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9104 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9105 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9106 | return 0; |
| 9107 | } |
| 9108 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9109 | static int ipw_wx_get_essid(struct net_device *dev, |
| 9110 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9111 | union iwreq_data *wrqu, char *extra) |
| 9112 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9113 | struct ipw_priv *priv = libipw_priv(dev); |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 9114 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9115 | |
| 9116 | /* If we are associated, trying to associate, or have a statically |
| 9117 | * configured ESSID then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9118 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9119 | if (priv->config & CFG_STATIC_ESSID || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9120 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
| 9121 | IPW_DEBUG_WX("Getting essid: '%s'\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 9122 | print_ssid(ssid, priv->essid, priv->essid_len)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9123 | memcpy(extra, priv->essid, priv->essid_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9124 | wrqu->essid.length = priv->essid_len; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9125 | wrqu->essid.flags = 1; /* active */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9126 | } else { |
| 9127 | IPW_DEBUG_WX("Getting essid: ANY\n"); |
| 9128 | wrqu->essid.length = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9129 | wrqu->essid.flags = 0; /* active */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9130 | } |
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 | return 0; |
| 9133 | } |
| 9134 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9135 | static int ipw_wx_set_nick(struct net_device *dev, |
| 9136 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9137 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9138 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9139 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9140 | |
| 9141 | IPW_DEBUG_WX("Setting nick to '%s'\n", extra); |
| 9142 | if (wrqu->data.length > IW_ESSID_MAX_SIZE) |
| 9143 | return -E2BIG; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9144 | mutex_lock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9145 | wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9146 | memset(priv->nick, 0, sizeof(priv->nick)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9147 | memcpy(priv->nick, extra, wrqu->data.length); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9148 | IPW_DEBUG_TRACE("<<\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9149 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9150 | return 0; |
| 9151 | |
| 9152 | } |
| 9153 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9154 | static int ipw_wx_get_nick(struct net_device *dev, |
| 9155 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9156 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9157 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9158 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9159 | IPW_DEBUG_WX("Getting nick\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9160 | mutex_lock(&priv->mutex); |
Jean Tourrilhes | 919ee6d | 2006-08-29 18:01:40 -0700 | [diff] [blame] | 9161 | wrqu->data.length = strlen(priv->nick); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9162 | memcpy(extra, priv->nick, wrqu->data.length); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9163 | wrqu->data.flags = 1; /* active */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9164 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9165 | return 0; |
| 9166 | } |
| 9167 | |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame] | 9168 | static int ipw_wx_set_sens(struct net_device *dev, |
| 9169 | struct iw_request_info *info, |
| 9170 | union iwreq_data *wrqu, char *extra) |
| 9171 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9172 | struct ipw_priv *priv = libipw_priv(dev); |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame] | 9173 | int err = 0; |
| 9174 | |
| 9175 | IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value); |
| 9176 | IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value); |
| 9177 | mutex_lock(&priv->mutex); |
| 9178 | |
| 9179 | if (wrqu->sens.fixed == 0) |
| 9180 | { |
| 9181 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; |
| 9182 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; |
| 9183 | goto out; |
| 9184 | } |
| 9185 | if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) || |
| 9186 | (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) { |
| 9187 | err = -EINVAL; |
| 9188 | goto out; |
| 9189 | } |
| 9190 | |
| 9191 | priv->roaming_threshold = wrqu->sens.value; |
| 9192 | priv->disassociate_threshold = 3*wrqu->sens.value; |
| 9193 | out: |
| 9194 | mutex_unlock(&priv->mutex); |
| 9195 | return err; |
| 9196 | } |
| 9197 | |
| 9198 | static int ipw_wx_get_sens(struct net_device *dev, |
| 9199 | struct iw_request_info *info, |
| 9200 | union iwreq_data *wrqu, char *extra) |
| 9201 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9202 | struct ipw_priv *priv = libipw_priv(dev); |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame] | 9203 | mutex_lock(&priv->mutex); |
| 9204 | wrqu->sens.fixed = 1; |
| 9205 | wrqu->sens.value = priv->roaming_threshold; |
| 9206 | mutex_unlock(&priv->mutex); |
| 9207 | |
| 9208 | IPW_DEBUG_WX("GET roaming threshold -> %s %d \n", |
| 9209 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); |
| 9210 | |
| 9211 | return 0; |
| 9212 | } |
| 9213 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9214 | static int ipw_wx_set_rate(struct net_device *dev, |
| 9215 | struct iw_request_info *info, |
| 9216 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9217 | { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9218 | /* TODO: We should use semaphores or locks for access to priv */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9219 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9220 | u32 target_rate = wrqu->bitrate.value; |
| 9221 | u32 fixed, mask; |
| 9222 | |
| 9223 | /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */ |
| 9224 | /* value = X, fixed = 1 means only rate X */ |
| 9225 | /* value = X, fixed = 0 means all rates lower equal X */ |
| 9226 | |
| 9227 | if (target_rate == -1) { |
| 9228 | fixed = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9229 | mask = LIBIPW_DEFAULT_RATES_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9230 | /* Now we should reassociate */ |
| 9231 | goto apply; |
| 9232 | } |
| 9233 | |
| 9234 | mask = 0; |
| 9235 | fixed = wrqu->bitrate.fixed; |
| 9236 | |
| 9237 | if (target_rate == 1000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9238 | mask |= LIBIPW_CCK_RATE_1MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9239 | if (target_rate == 1000000) |
| 9240 | goto apply; |
| 9241 | |
| 9242 | if (target_rate == 2000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9243 | mask |= LIBIPW_CCK_RATE_2MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9244 | if (target_rate == 2000000) |
| 9245 | goto apply; |
| 9246 | |
| 9247 | if (target_rate == 5500000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9248 | mask |= LIBIPW_CCK_RATE_5MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9249 | if (target_rate == 5500000) |
| 9250 | goto apply; |
| 9251 | |
| 9252 | if (target_rate == 6000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9253 | mask |= LIBIPW_OFDM_RATE_6MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9254 | if (target_rate == 6000000) |
| 9255 | goto apply; |
| 9256 | |
| 9257 | if (target_rate == 9000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9258 | mask |= LIBIPW_OFDM_RATE_9MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9259 | if (target_rate == 9000000) |
| 9260 | goto apply; |
| 9261 | |
| 9262 | if (target_rate == 11000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9263 | mask |= LIBIPW_CCK_RATE_11MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9264 | if (target_rate == 11000000) |
| 9265 | goto apply; |
| 9266 | |
| 9267 | if (target_rate == 12000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9268 | mask |= LIBIPW_OFDM_RATE_12MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9269 | if (target_rate == 12000000) |
| 9270 | goto apply; |
| 9271 | |
| 9272 | if (target_rate == 18000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9273 | mask |= LIBIPW_OFDM_RATE_18MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9274 | if (target_rate == 18000000) |
| 9275 | goto apply; |
| 9276 | |
| 9277 | if (target_rate == 24000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9278 | mask |= LIBIPW_OFDM_RATE_24MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9279 | if (target_rate == 24000000) |
| 9280 | goto apply; |
| 9281 | |
| 9282 | if (target_rate == 36000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9283 | mask |= LIBIPW_OFDM_RATE_36MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9284 | if (target_rate == 36000000) |
| 9285 | goto apply; |
| 9286 | |
| 9287 | if (target_rate == 48000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9288 | mask |= LIBIPW_OFDM_RATE_48MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9289 | if (target_rate == 48000000) |
| 9290 | goto apply; |
| 9291 | |
| 9292 | if (target_rate == 54000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9293 | mask |= LIBIPW_OFDM_RATE_54MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9294 | if (target_rate == 54000000) |
| 9295 | goto apply; |
| 9296 | |
| 9297 | IPW_DEBUG_WX("invalid rate specified, returning error\n"); |
| 9298 | return -EINVAL; |
| 9299 | |
| 9300 | apply: |
| 9301 | IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n", |
| 9302 | mask, fixed ? "fixed" : "sub-rates"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9303 | mutex_lock(&priv->mutex); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9304 | if (mask == LIBIPW_DEFAULT_RATES_MASK) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9305 | priv->config &= ~CFG_FIXED_RATE; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9306 | ipw_set_fixed_rate(priv, priv->ieee->mode); |
| 9307 | } else |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9308 | priv->config |= CFG_FIXED_RATE; |
| 9309 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9310 | if (priv->rates_mask == mask) { |
| 9311 | IPW_DEBUG_WX("Mask set to current mask.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9312 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9313 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9314 | } |
| 9315 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9316 | priv->rates_mask = mask; |
| 9317 | |
| 9318 | /* Network configuration changed -- force [re]association */ |
| 9319 | IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n"); |
| 9320 | if (!ipw_disassociate(priv)) |
| 9321 | ipw_associate(priv); |
| 9322 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9323 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9324 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9325 | } |
| 9326 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9327 | static int ipw_wx_get_rate(struct net_device *dev, |
| 9328 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9329 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9330 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9331 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9332 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9333 | wrqu->bitrate.value = priv->last_rate; |
Zhu Yi | 455936c | 2006-04-13 17:20:05 +0800 | [diff] [blame] | 9334 | wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9335 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9336 | IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value); |
| 9337 | return 0; |
| 9338 | } |
| 9339 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9340 | static int ipw_wx_set_rts(struct net_device *dev, |
| 9341 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9342 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9343 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9344 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9345 | mutex_lock(&priv->mutex); |
Zhu Yi | ea8862d | 2007-01-11 17:32:54 +0800 | [diff] [blame] | 9346 | if (wrqu->rts.disabled || !wrqu->rts.fixed) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9347 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
| 9348 | else { |
| 9349 | if (wrqu->rts.value < MIN_RTS_THRESHOLD || |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9350 | wrqu->rts.value > MAX_RTS_THRESHOLD) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9351 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9352 | return -EINVAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9353 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9354 | priv->rts_threshold = wrqu->rts.value; |
| 9355 | } |
| 9356 | |
| 9357 | ipw_send_rts_threshold(priv, priv->rts_threshold); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9358 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9359 | IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold); |
| 9360 | return 0; |
| 9361 | } |
| 9362 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9363 | static int ipw_wx_get_rts(struct net_device *dev, |
| 9364 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9365 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9366 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9367 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9368 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9369 | wrqu->rts.value = priv->rts_threshold; |
| 9370 | wrqu->rts.fixed = 0; /* no auto select */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9371 | wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9372 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9373 | IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value); |
| 9374 | return 0; |
| 9375 | } |
| 9376 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9377 | static int ipw_wx_set_txpow(struct net_device *dev, |
| 9378 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9379 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9380 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9381 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9382 | int err = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9383 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9384 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9385 | if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9386 | err = -EINPROGRESS; |
| 9387 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9388 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9389 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9390 | if (!wrqu->power.fixed) |
| 9391 | wrqu->power.value = IPW_TX_POWER_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9392 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9393 | if (wrqu->power.flags != IW_TXPOW_DBM) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9394 | err = -EINVAL; |
| 9395 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9396 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9397 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9398 | if ((wrqu->power.value > IPW_TX_POWER_MAX) || |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9399 | (wrqu->power.value < IPW_TX_POWER_MIN)) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9400 | err = -EINVAL; |
| 9401 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9402 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9403 | |
| 9404 | priv->tx_power = wrqu->power.value; |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9405 | err = ipw_set_tx_power(priv); |
| 9406 | out: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9407 | mutex_unlock(&priv->mutex); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9408 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9409 | } |
| 9410 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9411 | static int ipw_wx_get_txpow(struct net_device *dev, |
| 9412 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9413 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9414 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9415 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9416 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9417 | wrqu->power.value = priv->tx_power; |
| 9418 | wrqu->power.fixed = 1; |
| 9419 | wrqu->power.flags = IW_TXPOW_DBM; |
| 9420 | wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9421 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9422 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9423 | IPW_DEBUG_WX("GET TX Power -> %s %d \n", |
Zhu Yi | 22501c8 | 2005-08-11 10:49:17 +0800 | [diff] [blame] | 9424 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9425 | |
| 9426 | return 0; |
| 9427 | } |
| 9428 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9429 | static int ipw_wx_set_frag(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9430 | struct iw_request_info *info, |
| 9431 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9432 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9433 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9434 | mutex_lock(&priv->mutex); |
Zhu Yi | ea8862d | 2007-01-11 17:32:54 +0800 | [diff] [blame] | 9435 | if (wrqu->frag.disabled || !wrqu->frag.fixed) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9436 | priv->ieee->fts = DEFAULT_FTS; |
| 9437 | else { |
| 9438 | if (wrqu->frag.value < MIN_FRAG_THRESHOLD || |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9439 | wrqu->frag.value > MAX_FRAG_THRESHOLD) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9440 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9441 | return -EINVAL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9442 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9443 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9444 | priv->ieee->fts = wrqu->frag.value & ~0x1; |
| 9445 | } |
| 9446 | |
| 9447 | ipw_send_frag_threshold(priv, wrqu->frag.value); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9448 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9449 | IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value); |
| 9450 | return 0; |
| 9451 | } |
| 9452 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9453 | static int ipw_wx_get_frag(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9454 | struct iw_request_info *info, |
| 9455 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9456 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9457 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9458 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9459 | wrqu->frag.value = priv->ieee->fts; |
| 9460 | wrqu->frag.fixed = 0; /* no auto select */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9461 | wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9462 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9463 | IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value); |
| 9464 | |
| 9465 | return 0; |
| 9466 | } |
| 9467 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9468 | static int ipw_wx_set_retry(struct net_device *dev, |
| 9469 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9470 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9471 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9472 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9473 | |
| 9474 | if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled) |
| 9475 | return -EINVAL; |
| 9476 | |
| 9477 | if (!(wrqu->retry.flags & IW_RETRY_LIMIT)) |
| 9478 | return 0; |
| 9479 | |
Zhu Yi | d5f7ac2 | 2006-08-21 11:38:17 +0800 | [diff] [blame] | 9480 | if (wrqu->retry.value < 0 || wrqu->retry.value >= 255) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9481 | return -EINVAL; |
| 9482 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9483 | mutex_lock(&priv->mutex); |
Jean Tourrilhes | 919ee6d | 2006-08-29 18:01:40 -0700 | [diff] [blame] | 9484 | if (wrqu->retry.flags & IW_RETRY_SHORT) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9485 | priv->short_retry_limit = (u8) wrqu->retry.value; |
Jean Tourrilhes | 919ee6d | 2006-08-29 18:01:40 -0700 | [diff] [blame] | 9486 | else if (wrqu->retry.flags & IW_RETRY_LONG) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9487 | priv->long_retry_limit = (u8) wrqu->retry.value; |
| 9488 | else { |
| 9489 | priv->short_retry_limit = (u8) wrqu->retry.value; |
| 9490 | priv->long_retry_limit = (u8) wrqu->retry.value; |
| 9491 | } |
| 9492 | |
| 9493 | ipw_send_retry_limit(priv, priv->short_retry_limit, |
| 9494 | priv->long_retry_limit); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9495 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9496 | IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n", |
| 9497 | priv->short_retry_limit, priv->long_retry_limit); |
| 9498 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9499 | } |
| 9500 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9501 | static int ipw_wx_get_retry(struct net_device *dev, |
| 9502 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9503 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9504 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9505 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9506 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9507 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9508 | wrqu->retry.disabled = 0; |
| 9509 | |
| 9510 | if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9511 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9512 | return -EINVAL; |
| 9513 | } |
| 9514 | |
Jean Tourrilhes | 919ee6d | 2006-08-29 18:01:40 -0700 | [diff] [blame] | 9515 | if (wrqu->retry.flags & IW_RETRY_LONG) { |
| 9516 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9517 | wrqu->retry.value = priv->long_retry_limit; |
Jean Tourrilhes | 919ee6d | 2006-08-29 18:01:40 -0700 | [diff] [blame] | 9518 | } else if (wrqu->retry.flags & IW_RETRY_SHORT) { |
| 9519 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9520 | wrqu->retry.value = priv->short_retry_limit; |
| 9521 | } else { |
| 9522 | wrqu->retry.flags = IW_RETRY_LIMIT; |
| 9523 | wrqu->retry.value = priv->short_retry_limit; |
| 9524 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9525 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9526 | |
| 9527 | IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value); |
| 9528 | |
| 9529 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9530 | } |
| 9531 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9532 | static int ipw_wx_set_scan(struct net_device *dev, |
| 9533 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9534 | union iwreq_data *wrqu, char *extra) |
| 9535 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9536 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 9537 | struct iw_scan_req *req = (struct iw_scan_req *)extra; |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9538 | struct delayed_work *work = NULL; |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 9539 | |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 9540 | mutex_lock(&priv->mutex); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9541 | |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 9542 | priv->user_requested_scan = 1; |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 9543 | |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 9544 | if (wrqu->data.length == sizeof(struct iw_scan_req)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9545 | if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9546 | int len = min((int)req->essid_len, |
| 9547 | (int)sizeof(priv->direct_scan_ssid)); |
| 9548 | memcpy(priv->direct_scan_ssid, req->essid, len); |
| 9549 | priv->direct_scan_ssid_len = len; |
| 9550 | work = &priv->request_direct_scan; |
| 9551 | } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) { |
| 9552 | work = &priv->request_passive_scan; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9553 | } |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9554 | } else { |
| 9555 | /* Normal active broadcast scan */ |
| 9556 | work = &priv->request_scan; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9557 | } |
James Ketrenos | 8935f39 | 2005-10-05 15:59:08 -0500 | [diff] [blame] | 9558 | |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9559 | mutex_unlock(&priv->mutex); |
| 9560 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9561 | IPW_DEBUG_WX("Start scan\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9562 | |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9563 | queue_delayed_work(priv->workqueue, work, 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9564 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9565 | return 0; |
| 9566 | } |
| 9567 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9568 | static int ipw_wx_get_scan(struct net_device *dev, |
| 9569 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9570 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9571 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9572 | struct ipw_priv *priv = libipw_priv(dev); |
| 9573 | return libipw_wx_get_scan(priv->ieee, info, wrqu, extra); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9574 | } |
| 9575 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9576 | static int ipw_wx_set_encode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9577 | struct iw_request_info *info, |
| 9578 | union iwreq_data *wrqu, char *key) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9579 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9580 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9581 | int ret; |
Hong Liu | caeff81 | 2005-08-05 17:25:50 +0800 | [diff] [blame] | 9582 | u32 cap = priv->capability; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9583 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9584 | mutex_lock(&priv->mutex); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9585 | ret = libipw_wx_set_encode(priv->ieee, info, wrqu, key); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9586 | |
Hong Liu | caeff81 | 2005-08-05 17:25:50 +0800 | [diff] [blame] | 9587 | /* In IBSS mode, we need to notify the firmware to update |
| 9588 | * the beacon info after we changed the capability. */ |
| 9589 | if (cap != priv->capability && |
| 9590 | priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 9591 | priv->status & STATUS_ASSOCIATED) |
| 9592 | ipw_disassociate(priv); |
| 9593 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9594 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9595 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9596 | } |
| 9597 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9598 | static int ipw_wx_get_encode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9599 | struct iw_request_info *info, |
| 9600 | union iwreq_data *wrqu, char *key) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9601 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9602 | struct ipw_priv *priv = libipw_priv(dev); |
| 9603 | return libipw_wx_get_encode(priv->ieee, info, wrqu, key); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9604 | } |
| 9605 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9606 | static int ipw_wx_set_power(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9607 | struct iw_request_info *info, |
| 9608 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9609 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9610 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9611 | int err; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9612 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9613 | if (wrqu->power.disabled) { |
| 9614 | priv->power_mode = IPW_POWER_LEVEL(priv->power_mode); |
| 9615 | err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM); |
| 9616 | if (err) { |
| 9617 | IPW_DEBUG_WX("failed setting power mode.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9618 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9619 | return err; |
| 9620 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9621 | IPW_DEBUG_WX("SET Power Management Mode -> off\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9622 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9623 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9624 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9625 | |
| 9626 | switch (wrqu->power.flags & IW_POWER_MODE) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9627 | case IW_POWER_ON: /* If not specified */ |
| 9628 | case IW_POWER_MODE: /* If set all mask */ |
Jean Delvare | c03983a | 2007-10-19 23:22:55 +0200 | [diff] [blame] | 9629 | case IW_POWER_ALL_R: /* If explicitly state all */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9630 | break; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9631 | default: /* Otherwise we don't support it */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9632 | IPW_DEBUG_WX("SET PM Mode: %X not supported.\n", |
| 9633 | wrqu->power.flags); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9634 | mutex_unlock(&priv->mutex); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9635 | return -EOPNOTSUPP; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9636 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9637 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9638 | /* If the user hasn't specified a power management mode yet, default |
| 9639 | * to BATTERY */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9640 | if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9641 | priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9642 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9643 | priv->power_mode = IPW_POWER_ENABLED | priv->power_mode; |
Zhu Yi | 4e157f0 | 2007-07-12 16:09:32 +0800 | [diff] [blame] | 9644 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9645 | err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode)); |
| 9646 | if (err) { |
| 9647 | IPW_DEBUG_WX("failed setting power mode.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9648 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9649 | return err; |
| 9650 | } |
| 9651 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9652 | 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] | 9653 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9654 | return 0; |
| 9655 | } |
| 9656 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9657 | static int ipw_wx_get_power(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9658 | struct iw_request_info *info, |
| 9659 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9660 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9661 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9662 | mutex_lock(&priv->mutex); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9663 | if (!(priv->power_mode & IPW_POWER_ENABLED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9664 | wrqu->power.disabled = 1; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9665 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9666 | wrqu->power.disabled = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9667 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9668 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9669 | IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9670 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9671 | return 0; |
| 9672 | } |
| 9673 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9674 | static int ipw_wx_set_powermode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9675 | struct iw_request_info *info, |
| 9676 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9677 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9678 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9679 | int mode = *(int *)extra; |
| 9680 | int err; |
Zhu Yi | 4e157f0 | 2007-07-12 16:09:32 +0800 | [diff] [blame] | 9681 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9682 | mutex_lock(&priv->mutex); |
Zhu Yi | 4e157f0 | 2007-07-12 16:09:32 +0800 | [diff] [blame] | 9683 | if ((mode < 1) || (mode > IPW_POWER_LIMIT)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9684 | mode = IPW_POWER_AC; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9685 | |
Zhu Yi | 4e157f0 | 2007-07-12 16:09:32 +0800 | [diff] [blame] | 9686 | if (IPW_POWER_LEVEL(priv->power_mode) != mode) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9687 | err = ipw_send_power_mode(priv, mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9688 | if (err) { |
| 9689 | IPW_DEBUG_WX("failed setting power mode.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9690 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9691 | return err; |
| 9692 | } |
Zhu Yi | 4e157f0 | 2007-07-12 16:09:32 +0800 | [diff] [blame] | 9693 | priv->power_mode = IPW_POWER_ENABLED | mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9694 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9695 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9696 | return 0; |
| 9697 | } |
| 9698 | |
| 9699 | #define MAX_WX_STRING 80 |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9700 | static int ipw_wx_get_powermode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9701 | struct iw_request_info *info, |
| 9702 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9703 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9704 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9705 | int level = IPW_POWER_LEVEL(priv->power_mode); |
| 9706 | char *p = extra; |
| 9707 | |
| 9708 | p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level); |
| 9709 | |
| 9710 | switch (level) { |
| 9711 | case IPW_POWER_AC: |
| 9712 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)"); |
| 9713 | break; |
| 9714 | case IPW_POWER_BATTERY: |
| 9715 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)"); |
| 9716 | break; |
| 9717 | default: |
| 9718 | p += snprintf(p, MAX_WX_STRING - (p - extra), |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9719 | "(Timeout %dms, Period %dms)", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9720 | timeout_duration[level - 1] / 1000, |
| 9721 | period_duration[level - 1] / 1000); |
| 9722 | } |
| 9723 | |
| 9724 | if (!(priv->power_mode & IPW_POWER_ENABLED)) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9725 | p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9726 | |
| 9727 | wrqu->data.length = p - extra + 1; |
| 9728 | |
| 9729 | return 0; |
| 9730 | } |
| 9731 | |
| 9732 | static int ipw_wx_set_wireless_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9733 | struct iw_request_info *info, |
| 9734 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9735 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9736 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9737 | int mode = *(int *)extra; |
| 9738 | u8 band = 0, modulation = 0; |
| 9739 | |
| 9740 | if (mode == 0 || mode & ~IEEE_MODE_MASK) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9741 | IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9742 | return -EINVAL; |
| 9743 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9744 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9745 | if (priv->adapter == IPW_2915ABG) { |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9746 | priv->ieee->abg_true = 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9747 | if (mode & IEEE_A) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9748 | band |= LIBIPW_52GHZ_BAND; |
| 9749 | modulation |= LIBIPW_OFDM_MODULATION; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9750 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9751 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9752 | } else { |
| 9753 | if (mode & IEEE_A) { |
| 9754 | IPW_WARNING("Attempt to set 2200BG into " |
| 9755 | "802.11a mode\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9756 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9757 | return -EINVAL; |
| 9758 | } |
| 9759 | |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9760 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9761 | } |
| 9762 | |
| 9763 | if (mode & IEEE_B) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9764 | band |= LIBIPW_24GHZ_BAND; |
| 9765 | modulation |= LIBIPW_CCK_MODULATION; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9766 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9767 | priv->ieee->abg_true = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9768 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9769 | if (mode & IEEE_G) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9770 | band |= LIBIPW_24GHZ_BAND; |
| 9771 | modulation |= LIBIPW_OFDM_MODULATION; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9772 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9773 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9774 | |
| 9775 | priv->ieee->mode = mode; |
| 9776 | priv->ieee->freq_band = band; |
| 9777 | priv->ieee->modulation = modulation; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9778 | init_supported_rates(priv, &priv->rates); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9779 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9780 | /* Network configuration changed -- force [re]association */ |
| 9781 | IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n"); |
| 9782 | if (!ipw_disassociate(priv)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9783 | ipw_send_supported_rates(priv, &priv->rates); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9784 | ipw_associate(priv); |
| 9785 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9786 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9787 | /* Update the band LEDs */ |
| 9788 | ipw_led_band_on(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9789 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9790 | IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9791 | mode & IEEE_A ? 'a' : '.', |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9792 | mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.'); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9793 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9794 | return 0; |
| 9795 | } |
| 9796 | |
| 9797 | static int ipw_wx_get_wireless_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9798 | struct iw_request_info *info, |
| 9799 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9800 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9801 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9802 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9803 | switch (priv->ieee->mode) { |
| 9804 | case IEEE_A: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9805 | strncpy(extra, "802.11a (1)", MAX_WX_STRING); |
| 9806 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9807 | case IEEE_B: |
| 9808 | strncpy(extra, "802.11b (2)", MAX_WX_STRING); |
| 9809 | break; |
| 9810 | case IEEE_A | IEEE_B: |
| 9811 | strncpy(extra, "802.11ab (3)", MAX_WX_STRING); |
| 9812 | break; |
| 9813 | case IEEE_G: |
| 9814 | strncpy(extra, "802.11g (4)", MAX_WX_STRING); |
| 9815 | break; |
| 9816 | case IEEE_A | IEEE_G: |
| 9817 | strncpy(extra, "802.11ag (5)", MAX_WX_STRING); |
| 9818 | break; |
| 9819 | case IEEE_B | IEEE_G: |
| 9820 | strncpy(extra, "802.11bg (6)", MAX_WX_STRING); |
| 9821 | break; |
| 9822 | case IEEE_A | IEEE_B | IEEE_G: |
| 9823 | strncpy(extra, "802.11abg (7)", MAX_WX_STRING); |
| 9824 | break; |
| 9825 | default: |
| 9826 | strncpy(extra, "unknown", MAX_WX_STRING); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9827 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9828 | } |
| 9829 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9830 | IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra); |
| 9831 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9832 | wrqu->data.length = strlen(extra) + 1; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9833 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9834 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9835 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9836 | } |
| 9837 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9838 | static int ipw_wx_set_preamble(struct net_device *dev, |
| 9839 | struct iw_request_info *info, |
| 9840 | union iwreq_data *wrqu, char *extra) |
| 9841 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9842 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9843 | int mode = *(int *)extra; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9844 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9845 | /* Switching from SHORT -> LONG requires a disassociation */ |
| 9846 | if (mode == 1) { |
| 9847 | if (!(priv->config & CFG_PREAMBLE_LONG)) { |
| 9848 | priv->config |= CFG_PREAMBLE_LONG; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9849 | |
| 9850 | /* Network configuration changed -- force [re]association */ |
| 9851 | IPW_DEBUG_ASSOC |
| 9852 | ("[re]association triggered due to preamble change.\n"); |
| 9853 | if (!ipw_disassociate(priv)) |
| 9854 | ipw_associate(priv); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9855 | } |
| 9856 | goto done; |
| 9857 | } |
| 9858 | |
| 9859 | if (mode == 0) { |
| 9860 | priv->config &= ~CFG_PREAMBLE_LONG; |
| 9861 | goto done; |
| 9862 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9863 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9864 | return -EINVAL; |
| 9865 | |
| 9866 | done: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9867 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9868 | return 0; |
| 9869 | } |
| 9870 | |
| 9871 | static int ipw_wx_get_preamble(struct net_device *dev, |
| 9872 | struct iw_request_info *info, |
| 9873 | union iwreq_data *wrqu, char *extra) |
| 9874 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9875 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9876 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9877 | if (priv->config & CFG_PREAMBLE_LONG) |
| 9878 | snprintf(wrqu->name, IFNAMSIZ, "long (1)"); |
| 9879 | else |
| 9880 | snprintf(wrqu->name, IFNAMSIZ, "auto (0)"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9881 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9882 | return 0; |
| 9883 | } |
| 9884 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9885 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9886 | static int ipw_wx_set_monitor(struct net_device *dev, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9887 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9888 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9889 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9890 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9891 | int *parms = (int *)extra; |
| 9892 | int enable = (parms[0] > 0); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9893 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9894 | IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9895 | if (enable) { |
| 9896 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 9897 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 9898 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 9899 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9900 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 9901 | #endif |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9902 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9903 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9904 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9905 | ipw_set_channel(priv, parms[1]); |
| 9906 | } else { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9907 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9908 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9909 | return 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9910 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9911 | priv->net_dev->type = ARPHRD_ETHER; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9912 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9913 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9914 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9915 | return 0; |
| 9916 | } |
| 9917 | |
Pavel Machek | 67fd6b4 | 2006-07-11 15:34:05 +0200 | [diff] [blame] | 9918 | #endif /* CONFIG_IPW2200_MONITOR */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9919 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9920 | static int ipw_wx_reset(struct net_device *dev, |
| 9921 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9922 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9923 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9924 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9925 | IPW_DEBUG_WX("RESET\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9926 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9927 | return 0; |
| 9928 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9929 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9930 | static int ipw_wx_sw_reset(struct net_device *dev, |
| 9931 | struct iw_request_info *info, |
| 9932 | union iwreq_data *wrqu, char *extra) |
| 9933 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9934 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9935 | union iwreq_data wrqu_sec = { |
| 9936 | .encoding = { |
| 9937 | .flags = IW_ENCODE_DISABLED, |
| 9938 | }, |
| 9939 | }; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9940 | int ret; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9941 | |
| 9942 | IPW_DEBUG_WX("SW_RESET\n"); |
| 9943 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9944 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9945 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 9946 | ret = ipw_sw_reset(priv, 2); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9947 | if (!ret) { |
| 9948 | free_firmware(); |
| 9949 | ipw_adapter_restart(priv); |
| 9950 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9951 | |
| 9952 | /* The SW reset bit might have been toggled on by the 'disable' |
| 9953 | * module parameter, so take appropriate action */ |
| 9954 | ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW); |
| 9955 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9956 | mutex_unlock(&priv->mutex); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9957 | libipw_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9958 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9959 | |
| 9960 | if (!(priv->status & STATUS_RF_KILL_MASK)) { |
| 9961 | /* Configuration likely changed -- force [re]association */ |
| 9962 | IPW_DEBUG_ASSOC("[re]association triggered due to sw " |
| 9963 | "reset.\n"); |
| 9964 | if (!ipw_disassociate(priv)) |
| 9965 | ipw_associate(priv); |
| 9966 | } |
| 9967 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9968 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9969 | |
| 9970 | return 0; |
| 9971 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9972 | |
| 9973 | /* Rebase the WE IOCTLs to zero for the handler array */ |
| 9974 | #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT] |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9975 | static iw_handler ipw_wx_handlers[] = { |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 9976 | IW_IOCTL(SIOCGIWNAME) = (iw_handler) cfg80211_wext_giwname, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9977 | IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq, |
| 9978 | IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq, |
| 9979 | IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode, |
| 9980 | IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode, |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame] | 9981 | IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens, |
| 9982 | IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9983 | IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range, |
| 9984 | IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap, |
| 9985 | IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap, |
| 9986 | IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan, |
| 9987 | IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan, |
| 9988 | IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid, |
| 9989 | IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid, |
| 9990 | IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick, |
| 9991 | IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick, |
| 9992 | IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate, |
| 9993 | IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate, |
| 9994 | IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts, |
| 9995 | IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts, |
| 9996 | IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag, |
| 9997 | IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag, |
| 9998 | IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow, |
| 9999 | IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow, |
| 10000 | IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry, |
| 10001 | IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry, |
| 10002 | IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode, |
| 10003 | IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode, |
| 10004 | IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power, |
| 10005 | IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10006 | IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy, |
| 10007 | IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy, |
| 10008 | IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy, |
| 10009 | IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy, |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10010 | IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie, |
| 10011 | IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie, |
| 10012 | IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme, |
| 10013 | IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth, |
| 10014 | IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth, |
| 10015 | IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext, |
| 10016 | IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10017 | }; |
| 10018 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10019 | enum { |
| 10020 | IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV, |
| 10021 | IPW_PRIV_GET_POWER, |
| 10022 | IPW_PRIV_SET_MODE, |
| 10023 | IPW_PRIV_GET_MODE, |
| 10024 | IPW_PRIV_SET_PREAMBLE, |
| 10025 | IPW_PRIV_GET_PREAMBLE, |
| 10026 | IPW_PRIV_RESET, |
| 10027 | IPW_PRIV_SW_RESET, |
| 10028 | #ifdef CONFIG_IPW2200_MONITOR |
| 10029 | IPW_PRIV_SET_MONITOR, |
| 10030 | #endif |
| 10031 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10032 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10033 | static struct iw_priv_args ipw_priv_args[] = { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10034 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10035 | .cmd = IPW_PRIV_SET_POWER, |
| 10036 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 10037 | .name = "set_power"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10038 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10039 | .cmd = IPW_PRIV_GET_POWER, |
| 10040 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, |
| 10041 | .name = "get_power"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10042 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10043 | .cmd = IPW_PRIV_SET_MODE, |
| 10044 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 10045 | .name = "set_mode"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10046 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10047 | .cmd = IPW_PRIV_GET_MODE, |
| 10048 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, |
| 10049 | .name = "get_mode"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10050 | { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10051 | .cmd = IPW_PRIV_SET_PREAMBLE, |
| 10052 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 10053 | .name = "set_preamble"}, |
| 10054 | { |
| 10055 | .cmd = IPW_PRIV_GET_PREAMBLE, |
| 10056 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, |
| 10057 | .name = "get_preamble"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10058 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10059 | IPW_PRIV_RESET, |
| 10060 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"}, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10061 | { |
| 10062 | IPW_PRIV_SW_RESET, |
| 10063 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"}, |
| 10064 | #ifdef CONFIG_IPW2200_MONITOR |
| 10065 | { |
| 10066 | IPW_PRIV_SET_MONITOR, |
| 10067 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"}, |
| 10068 | #endif /* CONFIG_IPW2200_MONITOR */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10069 | }; |
| 10070 | |
| 10071 | static iw_handler ipw_priv_handler[] = { |
| 10072 | ipw_wx_set_powermode, |
| 10073 | ipw_wx_get_powermode, |
| 10074 | ipw_wx_set_wireless_mode, |
| 10075 | ipw_wx_get_wireless_mode, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10076 | ipw_wx_set_preamble, |
| 10077 | ipw_wx_get_preamble, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10078 | ipw_wx_reset, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10079 | ipw_wx_sw_reset, |
| 10080 | #ifdef CONFIG_IPW2200_MONITOR |
| 10081 | ipw_wx_set_monitor, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10082 | #endif |
| 10083 | }; |
| 10084 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10085 | static struct iw_handler_def ipw_wx_handler_def = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10086 | .standard = ipw_wx_handlers, |
| 10087 | .num_standard = ARRAY_SIZE(ipw_wx_handlers), |
| 10088 | .num_private = ARRAY_SIZE(ipw_priv_handler), |
| 10089 | .num_private_args = ARRAY_SIZE(ipw_priv_args), |
| 10090 | .private = ipw_priv_handler, |
| 10091 | .private_args = ipw_priv_args, |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 10092 | .get_wireless_stats = ipw_get_wireless_stats, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10093 | }; |
| 10094 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10095 | /* |
| 10096 | * Get wireless statistics. |
| 10097 | * Called by /proc/net/wireless |
| 10098 | * Also called by SIOCGIWSTATS |
| 10099 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10100 | static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10101 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10102 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10103 | struct iw_statistics *wstats; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10104 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10105 | wstats = &priv->wstats; |
| 10106 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10107 | /* if hw is disabled, then ipw_get_ordinal() can't be called. |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10108 | * netdev->get_wireless_stats seems to be called before fw is |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10109 | * initialized. STATUS_ASSOCIATED will only be set if the hw is up |
| 10110 | * and associated; if not associcated, the values are all meaningless |
| 10111 | * anyway, so set them all to NULL and INVALID */ |
| 10112 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 10113 | wstats->miss.beacon = 0; |
| 10114 | wstats->discard.retries = 0; |
| 10115 | wstats->qual.qual = 0; |
| 10116 | wstats->qual.level = 0; |
| 10117 | wstats->qual.noise = 0; |
| 10118 | wstats->qual.updated = 7; |
| 10119 | wstats->qual.updated |= IW_QUAL_NOISE_INVALID | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10120 | IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10121 | return wstats; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10122 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10123 | |
| 10124 | wstats->qual.qual = priv->quality; |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 10125 | wstats->qual.level = priv->exp_avg_rssi; |
| 10126 | wstats->qual.noise = priv->exp_avg_noise; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10127 | wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 10128 | IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10129 | |
| 10130 | wstats->miss.beacon = average_value(&priv->average_missed_beacons); |
| 10131 | wstats->discard.retries = priv->last_tx_failures; |
| 10132 | wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10133 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10134 | /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len)) |
| 10135 | goto fail_get_ordinal; |
| 10136 | wstats->discard.retries += tx_retry; */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10137 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10138 | return wstats; |
| 10139 | } |
| 10140 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10141 | /* net device stuff */ |
| 10142 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 10143 | static void init_sys_config(struct ipw_sys_config *sys_config) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10144 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10145 | memset(sys_config, 0, sizeof(struct ipw_sys_config)); |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10146 | sys_config->bt_coexistence = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10147 | sys_config->answer_broadcast_ssid_probe = 0; |
| 10148 | sys_config->accept_all_data_frames = 0; |
| 10149 | sys_config->accept_non_directed_frames = 1; |
| 10150 | sys_config->exclude_unicast_unencrypted = 0; |
| 10151 | sys_config->disable_unicast_decryption = 1; |
| 10152 | sys_config->exclude_multicast_unencrypted = 0; |
| 10153 | sys_config->disable_multicast_decryption = 1; |
Zhu Yi | d2b83e1 | 2006-04-13 17:19:36 +0800 | [diff] [blame] | 10154 | if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B) |
| 10155 | antenna = CFG_SYS_ANTENNA_BOTH; |
| 10156 | sys_config->antenna_diversity = antenna; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10157 | 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] | 10158 | sys_config->dot11g_auto_detection = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10159 | sys_config->enable_cts_to_self = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10160 | sys_config->bt_coexist_collision_thr = 0; |
Pavel Machek | 67fd6b4 | 2006-07-11 15:34:05 +0200 | [diff] [blame] | 10161 | 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] | 10162 | sys_config->silence_threshold = 0x1e; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10163 | } |
| 10164 | |
| 10165 | static int ipw_net_open(struct net_device *dev) |
| 10166 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10167 | IPW_DEBUG_INFO("dev->open\n"); |
David S. Miller | 521c4d9 | 2008-07-22 18:32:47 -0700 | [diff] [blame] | 10168 | netif_start_queue(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10169 | return 0; |
| 10170 | } |
| 10171 | |
| 10172 | static int ipw_net_stop(struct net_device *dev) |
| 10173 | { |
| 10174 | IPW_DEBUG_INFO("dev->close\n"); |
| 10175 | netif_stop_queue(dev); |
| 10176 | return 0; |
| 10177 | } |
| 10178 | |
| 10179 | /* |
| 10180 | todo: |
| 10181 | |
| 10182 | modify to send one tfd per fragment instead of using chunking. otherwise |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10183 | we need to heavily modify the libipw_skb_to_txb. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10184 | */ |
| 10185 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10186 | static int ipw_tx_skb(struct ipw_priv *priv, struct libipw_txb *txb, |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10187 | int pri) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10188 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10189 | struct libipw_hdr_3addrqos *hdr = (struct libipw_hdr_3addrqos *) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10190 | txb->fragments[0]->data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10191 | int i = 0; |
| 10192 | struct tfd_frame *tfd; |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10193 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10194 | int tx_id = ipw_get_tx_queue_number(priv, pri); |
| 10195 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; |
| 10196 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10197 | struct clx2_tx_queue *txq = &priv->txq[0]; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10198 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10199 | struct clx2_queue *q = &txq->q; |
| 10200 | u8 id, hdr_len, unicast; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10201 | int fc; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10202 | |
Zhu Yi | b8ddafd | 2008-11-27 13:42:20 +0800 | [diff] [blame] | 10203 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 10204 | goto drop; |
| 10205 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10206 | hdr_len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10207 | switch (priv->ieee->iw_mode) { |
| 10208 | case IW_MODE_ADHOC: |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 10209 | unicast = !is_multicast_ether_addr(hdr->addr1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10210 | id = ipw_find_station(priv, hdr->addr1); |
| 10211 | if (id == IPW_INVALID_STATION) { |
| 10212 | id = ipw_add_station(priv, hdr->addr1); |
| 10213 | if (id == IPW_INVALID_STATION) { |
| 10214 | IPW_WARNING("Attempt to send data to " |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 10215 | "invalid cell: %pM\n", |
| 10216 | hdr->addr1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10217 | goto drop; |
| 10218 | } |
| 10219 | } |
| 10220 | break; |
| 10221 | |
| 10222 | case IW_MODE_INFRA: |
| 10223 | default: |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 10224 | unicast = !is_multicast_ether_addr(hdr->addr3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10225 | id = 0; |
| 10226 | break; |
| 10227 | } |
| 10228 | |
| 10229 | tfd = &txq->bd[q->first_empty]; |
| 10230 | txq->txb[q->first_empty] = txb; |
| 10231 | memset(tfd, 0, sizeof(*tfd)); |
| 10232 | tfd->u.data.station_number = id; |
| 10233 | |
| 10234 | tfd->control_flags.message_type = TX_FRAME_TYPE; |
| 10235 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; |
| 10236 | |
| 10237 | tfd->u.data.cmd_id = DINO_CMD_TX; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10238 | tfd->u.data.len = cpu_to_le16(txb->payload_size); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10239 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10240 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10241 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10242 | else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10243 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10244 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10245 | if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE) |
| 10246 | tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10247 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10248 | fc = le16_to_cpu(hdr->frame_ctl); |
| 10249 | hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10250 | |
| 10251 | memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len); |
| 10252 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10253 | if (likely(unicast)) |
| 10254 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; |
| 10255 | |
| 10256 | if (txb->encrypted && !priv->ieee->host_encrypt) { |
| 10257 | switch (priv->ieee->sec.level) { |
| 10258 | case SEC_LEVEL_3: |
| 10259 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 10260 | cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10261 | /* XXX: ACK flag must be set for CCMP even if it |
| 10262 | * is a multicast/broadcast packet, because CCMP |
| 10263 | * group communication encrypted by GTK is |
| 10264 | * actually done by the AP. */ |
| 10265 | if (!unicast) |
| 10266 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; |
| 10267 | |
| 10268 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; |
| 10269 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM; |
| 10270 | tfd->u.data.key_index = 0; |
| 10271 | tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE; |
| 10272 | break; |
| 10273 | case SEC_LEVEL_2: |
| 10274 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 10275 | cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10276 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; |
| 10277 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP; |
| 10278 | tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE; |
| 10279 | break; |
| 10280 | case SEC_LEVEL_1: |
| 10281 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 10282 | cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 10283 | tfd->u.data.key_index = priv->ieee->crypt_info.tx_keyidx; |
| 10284 | if (priv->ieee->sec.key_sizes[priv->ieee->crypt_info.tx_keyidx] <= |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10285 | 40) |
| 10286 | tfd->u.data.key_index |= DCT_WEP_KEY_64Bit; |
| 10287 | else |
| 10288 | tfd->u.data.key_index |= DCT_WEP_KEY_128Bit; |
| 10289 | break; |
| 10290 | case SEC_LEVEL_0: |
| 10291 | break; |
| 10292 | default: |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame^] | 10293 | printk(KERN_ERR "Unknown security level %d\n", |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10294 | priv->ieee->sec.level); |
| 10295 | break; |
| 10296 | } |
| 10297 | } else |
| 10298 | /* No hardware encryption */ |
| 10299 | tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP; |
| 10300 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10301 | #ifdef CONFIG_IPW2200_QOS |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 10302 | if (fc & IEEE80211_STYPE_QOS_DATA) |
| 10303 | ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data)); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10304 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10305 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10306 | /* payload */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10307 | tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2), |
| 10308 | txb->nr_frags)); |
| 10309 | IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n", |
| 10310 | txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks)); |
| 10311 | for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) { |
| 10312 | IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n", |
| 10313 | i, le32_to_cpu(tfd->u.data.num_chunks), |
| 10314 | txb->fragments[i]->len - hdr_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10315 | 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] | 10316 | i, tfd->u.data.num_chunks, |
| 10317 | txb->fragments[i]->len - hdr_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10318 | printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10319 | txb->fragments[i]->len - hdr_len); |
| 10320 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10321 | tfd->u.data.chunk_ptr[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10322 | cpu_to_le32(pci_map_single |
| 10323 | (priv->pci_dev, |
| 10324 | txb->fragments[i]->data + hdr_len, |
| 10325 | txb->fragments[i]->len - hdr_len, |
| 10326 | PCI_DMA_TODEVICE)); |
| 10327 | tfd->u.data.chunk_len[i] = |
| 10328 | cpu_to_le16(txb->fragments[i]->len - hdr_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10329 | } |
| 10330 | |
| 10331 | if (i != txb->nr_frags) { |
| 10332 | struct sk_buff *skb; |
| 10333 | u16 remaining_bytes = 0; |
| 10334 | int j; |
| 10335 | |
| 10336 | for (j = i; j < txb->nr_frags; j++) |
| 10337 | remaining_bytes += txb->fragments[j]->len - hdr_len; |
| 10338 | |
| 10339 | printk(KERN_INFO "Trying to reallocate for %d bytes\n", |
| 10340 | remaining_bytes); |
| 10341 | skb = alloc_skb(remaining_bytes, GFP_ATOMIC); |
| 10342 | if (skb != NULL) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10343 | tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10344 | for (j = i; j < txb->nr_frags; j++) { |
| 10345 | int size = txb->fragments[j]->len - hdr_len; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10346 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10347 | printk(KERN_INFO "Adding frag %d %d...\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10348 | j, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10349 | memcpy(skb_put(skb, size), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10350 | txb->fragments[j]->data + hdr_len, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10351 | } |
| 10352 | dev_kfree_skb_any(txb->fragments[i]); |
| 10353 | txb->fragments[i] = skb; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10354 | tfd->u.data.chunk_ptr[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10355 | cpu_to_le32(pci_map_single |
| 10356 | (priv->pci_dev, skb->data, |
Al Viro | 4958730 | 2007-12-27 01:57:47 -0500 | [diff] [blame] | 10357 | remaining_bytes, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10358 | PCI_DMA_TODEVICE)); |
| 10359 | |
Marcin Slusarz | 5c05863 | 2008-02-13 00:06:12 +0100 | [diff] [blame] | 10360 | le32_add_cpu(&tfd->u.data.num_chunks, 1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10361 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10362 | } |
| 10363 | |
| 10364 | /* kick DMA */ |
| 10365 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); |
| 10366 | ipw_write32(priv, q->reg_w, q->first_empty); |
| 10367 | |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 10368 | if (ipw_tx_queue_space(q) < q->high_mark) |
James Ketrenos | f697014 | 2006-02-14 09:10:51 +0800 | [diff] [blame] | 10369 | netif_stop_queue(priv->net_dev); |
| 10370 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10371 | return NETDEV_TX_OK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10372 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10373 | drop: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10374 | IPW_DEBUG_DROP("Silently dropping Tx packet.\n"); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10375 | libipw_txb_free(txb); |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10376 | return NETDEV_TX_OK; |
| 10377 | } |
| 10378 | |
| 10379 | static int ipw_net_is_queue_full(struct net_device *dev, int pri) |
| 10380 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10381 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10382 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10383 | int tx_id = ipw_get_tx_queue_number(priv, pri); |
| 10384 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; |
| 10385 | #else |
| 10386 | struct clx2_tx_queue *txq = &priv->txq[0]; |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10387 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10388 | |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 10389 | if (ipw_tx_queue_space(&txq->q) < txq->q.high_mark) |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10390 | return 1; |
| 10391 | |
| 10392 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10393 | } |
| 10394 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10395 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 10396 | static void ipw_handle_promiscuous_tx(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10397 | struct libipw_txb *txb) |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10398 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10399 | struct libipw_rx_stats dummystats; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10400 | struct ieee80211_hdr *hdr; |
| 10401 | u8 n; |
| 10402 | u16 filter = priv->prom_priv->filter; |
| 10403 | int hdr_only = 0; |
| 10404 | |
| 10405 | if (filter & IPW_PROM_NO_TX) |
| 10406 | return; |
| 10407 | |
| 10408 | memset(&dummystats, 0, sizeof(dummystats)); |
| 10409 | |
| 10410 | /* Filtering of fragment chains is done agains the first fragment */ |
| 10411 | hdr = (void *)txb->fragments[0]->data; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10412 | if (libipw_is_management(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10413 | if (filter & IPW_PROM_NO_MGMT) |
| 10414 | return; |
| 10415 | if (filter & IPW_PROM_MGMT_HEADER_ONLY) |
| 10416 | hdr_only = 1; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10417 | } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10418 | if (filter & IPW_PROM_NO_CTL) |
| 10419 | return; |
| 10420 | if (filter & IPW_PROM_CTL_HEADER_ONLY) |
| 10421 | hdr_only = 1; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10422 | } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10423 | if (filter & IPW_PROM_NO_DATA) |
| 10424 | return; |
| 10425 | if (filter & IPW_PROM_DATA_HEADER_ONLY) |
| 10426 | hdr_only = 1; |
| 10427 | } |
| 10428 | |
| 10429 | for(n=0; n<txb->nr_frags; ++n) { |
| 10430 | struct sk_buff *src = txb->fragments[n]; |
| 10431 | struct sk_buff *dst; |
| 10432 | struct ieee80211_radiotap_header *rt_hdr; |
| 10433 | int len; |
| 10434 | |
| 10435 | if (hdr_only) { |
| 10436 | hdr = (void *)src->data; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10437 | len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control)); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10438 | } else |
| 10439 | len = src->len; |
| 10440 | |
Johannes Berg | 007e5dd | 2008-11-27 23:13:38 +0100 | [diff] [blame] | 10441 | dst = alloc_skb(len + sizeof(*rt_hdr), GFP_ATOMIC); |
| 10442 | if (!dst) |
| 10443 | continue; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10444 | |
| 10445 | rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr)); |
| 10446 | |
| 10447 | rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION; |
| 10448 | rt_hdr->it_pad = 0; |
| 10449 | rt_hdr->it_present = 0; /* after all, it's just an idea */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 10450 | rt_hdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_CHANNEL); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10451 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 10452 | *(__le16*)skb_put(dst, sizeof(u16)) = cpu_to_le16( |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10453 | ieee80211chan2mhz(priv->channel)); |
| 10454 | if (priv->channel > 14) /* 802.11a */ |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 10455 | *(__le16*)skb_put(dst, sizeof(u16)) = |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10456 | cpu_to_le16(IEEE80211_CHAN_OFDM | |
| 10457 | IEEE80211_CHAN_5GHZ); |
| 10458 | else if (priv->ieee->mode == IEEE_B) /* 802.11b */ |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 10459 | *(__le16*)skb_put(dst, sizeof(u16)) = |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10460 | cpu_to_le16(IEEE80211_CHAN_CCK | |
| 10461 | IEEE80211_CHAN_2GHZ); |
| 10462 | else /* 802.11g */ |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 10463 | *(__le16*)skb_put(dst, sizeof(u16)) = |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10464 | cpu_to_le16(IEEE80211_CHAN_OFDM | |
| 10465 | IEEE80211_CHAN_2GHZ); |
| 10466 | |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 10467 | rt_hdr->it_len = cpu_to_le16(dst->len); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10468 | |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 10469 | skb_copy_from_linear_data(src, skb_put(dst, len), len); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10470 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10471 | if (!libipw_rx(priv->prom_priv->ieee, dst, &dummystats)) |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10472 | dev_kfree_skb_any(dst); |
| 10473 | } |
| 10474 | } |
| 10475 | #endif |
| 10476 | |
Stephen Hemminger | d0cf9c0 | 2009-08-31 19:50:57 +0000 | [diff] [blame] | 10477 | static netdev_tx_t ipw_net_hard_start_xmit(struct libipw_txb *txb, |
| 10478 | struct net_device *dev, int pri) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10479 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10480 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10481 | unsigned long flags; |
Stephen Hemminger | d0cf9c0 | 2009-08-31 19:50:57 +0000 | [diff] [blame] | 10482 | netdev_tx_t ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10483 | |
| 10484 | IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10485 | spin_lock_irqsave(&priv->lock, flags); |
| 10486 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10487 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 10488 | if (rtap_iface && netif_running(priv->prom_net_dev)) |
| 10489 | ipw_handle_promiscuous_tx(priv, txb); |
| 10490 | #endif |
| 10491 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10492 | ret = ipw_tx_skb(priv, txb, pri); |
| 10493 | if (ret == NETDEV_TX_OK) |
| 10494 | __ipw_led_activity_on(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10495 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10496 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10497 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10498 | } |
| 10499 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10500 | static void ipw_net_set_multicast_list(struct net_device *dev) |
| 10501 | { |
| 10502 | |
| 10503 | } |
| 10504 | |
| 10505 | static int ipw_net_set_mac_address(struct net_device *dev, void *p) |
| 10506 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10507 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10508 | struct sockaddr *addr = p; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 10509 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10510 | if (!is_valid_ether_addr(addr->sa_data)) |
| 10511 | return -EADDRNOTAVAIL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10512 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10513 | priv->config |= CFG_CUSTOM_MAC; |
| 10514 | memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 10515 | printk(KERN_INFO "%s: Setting MAC to %pM\n", |
| 10516 | priv->net_dev->name, priv->mac_addr); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10517 | queue_work(priv->workqueue, &priv->adapter_restart); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10518 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10519 | return 0; |
| 10520 | } |
| 10521 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10522 | static void ipw_ethtool_get_drvinfo(struct net_device *dev, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10523 | struct ethtool_drvinfo *info) |
| 10524 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10525 | struct ipw_priv *p = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10526 | char vers[64]; |
| 10527 | char date[32]; |
| 10528 | u32 len; |
| 10529 | |
| 10530 | strcpy(info->driver, DRV_NAME); |
| 10531 | strcpy(info->version, DRV_VERSION); |
| 10532 | |
| 10533 | len = sizeof(vers); |
| 10534 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len); |
| 10535 | len = sizeof(date); |
| 10536 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len); |
| 10537 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10538 | snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10539 | vers, date); |
| 10540 | strcpy(info->bus_info, pci_name(p->pci_dev)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10541 | info->eedump_len = IPW_EEPROM_IMAGE_SIZE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10542 | } |
| 10543 | |
| 10544 | static u32 ipw_ethtool_get_link(struct net_device *dev) |
| 10545 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10546 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10547 | return (priv->status & STATUS_ASSOCIATED) != 0; |
| 10548 | } |
| 10549 | |
| 10550 | static int ipw_ethtool_get_eeprom_len(struct net_device *dev) |
| 10551 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10552 | return IPW_EEPROM_IMAGE_SIZE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10553 | } |
| 10554 | |
| 10555 | static int ipw_ethtool_get_eeprom(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10556 | struct ethtool_eeprom *eeprom, u8 * bytes) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10557 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10558 | struct ipw_priv *p = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10559 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10560 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10561 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10562 | mutex_lock(&p->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10563 | memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10564 | mutex_unlock(&p->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10565 | return 0; |
| 10566 | } |
| 10567 | |
| 10568 | static int ipw_ethtool_set_eeprom(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10569 | struct ethtool_eeprom *eeprom, u8 * bytes) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10570 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10571 | struct ipw_priv *p = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10572 | int i; |
| 10573 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10574 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10575 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10576 | mutex_lock(&p->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10577 | memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len); |
Adrian Bunk | 71e585f | 2006-03-11 04:42:58 +0100 | [diff] [blame] | 10578 | for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) |
| 10579 | ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10580 | mutex_unlock(&p->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10581 | return 0; |
| 10582 | } |
| 10583 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 10584 | static const struct ethtool_ops ipw_ethtool_ops = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10585 | .get_link = ipw_ethtool_get_link, |
| 10586 | .get_drvinfo = ipw_ethtool_get_drvinfo, |
| 10587 | .get_eeprom_len = ipw_ethtool_get_eeprom_len, |
| 10588 | .get_eeprom = ipw_ethtool_get_eeprom, |
| 10589 | .set_eeprom = ipw_ethtool_set_eeprom, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10590 | }; |
| 10591 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 10592 | static irqreturn_t ipw_isr(int irq, void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10593 | { |
| 10594 | struct ipw_priv *priv = data; |
| 10595 | u32 inta, inta_mask; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10596 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10597 | if (!priv) |
| 10598 | return IRQ_NONE; |
| 10599 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 10600 | spin_lock(&priv->irq_lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10601 | |
| 10602 | if (!(priv->status & STATUS_INT_ENABLED)) { |
Zhu Yi | d00d012 | 2007-07-12 16:09:40 +0800 | [diff] [blame] | 10603 | /* IRQ is disabled */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10604 | goto none; |
| 10605 | } |
| 10606 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10607 | inta = ipw_read32(priv, IPW_INTA_RW); |
| 10608 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10609 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10610 | if (inta == 0xFFFFFFFF) { |
| 10611 | /* Hardware disappeared */ |
| 10612 | IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n"); |
| 10613 | goto none; |
| 10614 | } |
| 10615 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10616 | if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10617 | /* Shared interrupt */ |
| 10618 | goto none; |
| 10619 | } |
| 10620 | |
| 10621 | /* tell the device to stop sending interrupts */ |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 10622 | __ipw_disable_interrupts(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10623 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10624 | /* ack current interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10625 | inta &= (IPW_INTA_MASK_ALL & inta_mask); |
| 10626 | ipw_write32(priv, IPW_INTA_RW, inta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10627 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10628 | /* Cache INTA value for our tasklet */ |
| 10629 | priv->isr_inta = inta; |
| 10630 | |
| 10631 | tasklet_schedule(&priv->irq_tasklet); |
| 10632 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 10633 | spin_unlock(&priv->irq_lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10634 | |
| 10635 | return IRQ_HANDLED; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10636 | none: |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 10637 | spin_unlock(&priv->irq_lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10638 | return IRQ_NONE; |
| 10639 | } |
| 10640 | |
| 10641 | static void ipw_rf_kill(void *adapter) |
| 10642 | { |
| 10643 | struct ipw_priv *priv = adapter; |
| 10644 | unsigned long flags; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10645 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10646 | spin_lock_irqsave(&priv->lock, flags); |
| 10647 | |
| 10648 | if (rf_kill_active(priv)) { |
| 10649 | IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n"); |
| 10650 | if (priv->workqueue) |
| 10651 | queue_delayed_work(priv->workqueue, |
| 10652 | &priv->rf_kill, 2 * HZ); |
| 10653 | goto exit_unlock; |
| 10654 | } |
| 10655 | |
| 10656 | /* RF Kill is now disabled, so bring the device back up */ |
| 10657 | |
| 10658 | if (!(priv->status & STATUS_RF_KILL_MASK)) { |
| 10659 | IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting " |
| 10660 | "device\n"); |
| 10661 | |
| 10662 | /* we can not do an adapter restart while inside an irq lock */ |
| 10663 | queue_work(priv->workqueue, &priv->adapter_restart); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10664 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10665 | IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still " |
| 10666 | "enabled\n"); |
| 10667 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10668 | exit_unlock: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10669 | spin_unlock_irqrestore(&priv->lock, flags); |
| 10670 | } |
| 10671 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10672 | static void ipw_bg_rf_kill(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10673 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10674 | struct ipw_priv *priv = |
| 10675 | container_of(work, struct ipw_priv, rf_kill.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10676 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10677 | ipw_rf_kill(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10678 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10679 | } |
| 10680 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 10681 | static void ipw_link_up(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10682 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10683 | priv->last_seq_num = -1; |
| 10684 | priv->last_frag_num = -1; |
| 10685 | priv->last_packet_time = 0; |
| 10686 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10687 | netif_carrier_on(priv->net_dev); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10688 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10689 | cancel_delayed_work(&priv->request_scan); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 10690 | cancel_delayed_work(&priv->request_direct_scan); |
| 10691 | cancel_delayed_work(&priv->request_passive_scan); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 10692 | cancel_delayed_work(&priv->scan_event); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10693 | ipw_reset_stats(priv); |
| 10694 | /* Ensure the rate is updated immediately */ |
| 10695 | priv->last_rate = ipw_get_current_rate(priv); |
| 10696 | ipw_gather_stats(priv); |
| 10697 | ipw_led_link_up(priv); |
| 10698 | notify_wx_assoc_event(priv); |
| 10699 | |
| 10700 | if (priv->config & CFG_BACKGROUND_SCAN) |
| 10701 | queue_delayed_work(priv->workqueue, &priv->request_scan, HZ); |
| 10702 | } |
| 10703 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10704 | static void ipw_bg_link_up(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10705 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10706 | struct ipw_priv *priv = |
| 10707 | container_of(work, struct ipw_priv, link_up); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10708 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10709 | ipw_link_up(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10710 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10711 | } |
| 10712 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 10713 | static void ipw_link_down(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10714 | { |
| 10715 | ipw_led_link_down(priv); |
| 10716 | netif_carrier_off(priv->net_dev); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10717 | notify_wx_assoc_event(priv); |
| 10718 | |
| 10719 | /* Cancel any queued work ... */ |
| 10720 | cancel_delayed_work(&priv->request_scan); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 10721 | cancel_delayed_work(&priv->request_direct_scan); |
| 10722 | cancel_delayed_work(&priv->request_passive_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10723 | cancel_delayed_work(&priv->adhoc_check); |
| 10724 | cancel_delayed_work(&priv->gather_stats); |
| 10725 | |
| 10726 | ipw_reset_stats(priv); |
| 10727 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10728 | if (!(priv->status & STATUS_EXIT_PENDING)) { |
| 10729 | /* Queue up another scan... */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10730 | queue_delayed_work(priv->workqueue, &priv->request_scan, 0); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 10731 | } else |
| 10732 | cancel_delayed_work(&priv->scan_event); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10733 | } |
| 10734 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10735 | static void ipw_bg_link_down(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10736 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10737 | struct ipw_priv *priv = |
| 10738 | container_of(work, struct ipw_priv, link_down); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10739 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10740 | ipw_link_down(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10741 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10742 | } |
| 10743 | |
Adrian Bunk | 2ef19e6 | 2007-12-11 23:20:22 +0100 | [diff] [blame] | 10744 | static int __devinit ipw_setup_deferred_work(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10745 | { |
| 10746 | int ret = 0; |
| 10747 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10748 | priv->workqueue = create_workqueue(DRV_NAME); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10749 | init_waitqueue_head(&priv->wait_command_queue); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10750 | init_waitqueue_head(&priv->wait_state); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10751 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10752 | INIT_DELAYED_WORK(&priv->adhoc_check, ipw_bg_adhoc_check); |
| 10753 | INIT_WORK(&priv->associate, ipw_bg_associate); |
| 10754 | INIT_WORK(&priv->disassociate, ipw_bg_disassociate); |
| 10755 | INIT_WORK(&priv->system_config, ipw_system_config); |
| 10756 | INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish); |
| 10757 | INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart); |
| 10758 | INIT_DELAYED_WORK(&priv->rf_kill, ipw_bg_rf_kill); |
| 10759 | INIT_WORK(&priv->up, ipw_bg_up); |
| 10760 | INIT_WORK(&priv->down, ipw_bg_down); |
| 10761 | INIT_DELAYED_WORK(&priv->request_scan, ipw_request_scan); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 10762 | INIT_DELAYED_WORK(&priv->request_direct_scan, ipw_request_direct_scan); |
| 10763 | INIT_DELAYED_WORK(&priv->request_passive_scan, ipw_request_passive_scan); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 10764 | INIT_DELAYED_WORK(&priv->scan_event, ipw_scan_event); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10765 | INIT_DELAYED_WORK(&priv->gather_stats, ipw_bg_gather_stats); |
| 10766 | INIT_WORK(&priv->abort_scan, ipw_bg_abort_scan); |
| 10767 | INIT_WORK(&priv->roam, ipw_bg_roam); |
| 10768 | INIT_DELAYED_WORK(&priv->scan_check, ipw_bg_scan_check); |
| 10769 | INIT_WORK(&priv->link_up, ipw_bg_link_up); |
| 10770 | INIT_WORK(&priv->link_down, ipw_bg_link_down); |
| 10771 | INIT_DELAYED_WORK(&priv->led_link_on, ipw_bg_led_link_on); |
| 10772 | INIT_DELAYED_WORK(&priv->led_link_off, ipw_bg_led_link_off); |
| 10773 | INIT_DELAYED_WORK(&priv->led_act_off, ipw_bg_led_activity_off); |
| 10774 | INIT_WORK(&priv->merge_networks, ipw_merge_adhoc_network); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10775 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10776 | #ifdef CONFIG_IPW2200_QOS |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10777 | INIT_WORK(&priv->qos_activate, ipw_bg_qos_activate); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10778 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10779 | |
| 10780 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
| 10781 | ipw_irq_tasklet, (unsigned long)priv); |
| 10782 | |
| 10783 | return ret; |
| 10784 | } |
| 10785 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10786 | static void shim__set_security(struct net_device *dev, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10787 | struct libipw_security *sec) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10788 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10789 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10790 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10791 | for (i = 0; i < 4; i++) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10792 | if (sec->flags & (1 << i)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10793 | priv->ieee->sec.encode_alg[i] = sec->encode_alg[i]; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10794 | priv->ieee->sec.key_sizes[i] = sec->key_sizes[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10795 | if (sec->key_sizes[i] == 0) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10796 | priv->ieee->sec.flags &= ~(1 << i); |
| 10797 | else { |
| 10798 | memcpy(priv->ieee->sec.keys[i], sec->keys[i], |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10799 | sec->key_sizes[i]); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10800 | priv->ieee->sec.flags |= (1 << i); |
| 10801 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10802 | priv->status |= STATUS_SECURITY_UPDATED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10803 | } else if (sec->level != SEC_LEVEL_1) |
| 10804 | priv->ieee->sec.flags &= ~(1 << i); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10805 | } |
| 10806 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10807 | if (sec->flags & SEC_ACTIVE_KEY) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10808 | if (sec->active_key <= 3) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10809 | priv->ieee->sec.active_key = sec->active_key; |
| 10810 | priv->ieee->sec.flags |= SEC_ACTIVE_KEY; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10811 | } else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10812 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10813 | priv->status |= STATUS_SECURITY_UPDATED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10814 | } else |
| 10815 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10816 | |
| 10817 | if ((sec->flags & SEC_AUTH_MODE) && |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10818 | (priv->ieee->sec.auth_mode != sec->auth_mode)) { |
| 10819 | priv->ieee->sec.auth_mode = sec->auth_mode; |
| 10820 | priv->ieee->sec.flags |= SEC_AUTH_MODE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10821 | if (sec->auth_mode == WLAN_AUTH_SHARED_KEY) |
| 10822 | priv->capability |= CAP_SHARED_KEY; |
| 10823 | else |
| 10824 | priv->capability &= ~CAP_SHARED_KEY; |
| 10825 | priv->status |= STATUS_SECURITY_UPDATED; |
| 10826 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10827 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10828 | if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) { |
| 10829 | priv->ieee->sec.flags |= SEC_ENABLED; |
| 10830 | priv->ieee->sec.enabled = sec->enabled; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10831 | priv->status |= STATUS_SECURITY_UPDATED; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10832 | if (sec->enabled) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10833 | priv->capability |= CAP_PRIVACY_ON; |
| 10834 | else |
| 10835 | priv->capability &= ~CAP_PRIVACY_ON; |
| 10836 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10837 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10838 | if (sec->flags & SEC_ENCRYPT) |
| 10839 | priv->ieee->sec.encrypt = sec->encrypt; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10840 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10841 | if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) { |
| 10842 | priv->ieee->sec.level = sec->level; |
| 10843 | priv->ieee->sec.flags |= SEC_LEVEL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10844 | priv->status |= STATUS_SECURITY_UPDATED; |
| 10845 | } |
| 10846 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 10847 | if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT)) |
| 10848 | ipw_set_hwcrypto_keys(priv); |
| 10849 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10850 | /* To match current functionality of ipw2100 (which works well w/ |
| 10851 | * various supplicants, we don't force a disassociate if the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10852 | * privacy capability changes ... */ |
| 10853 | #if 0 |
| 10854 | if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) && |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10855 | (((priv->assoc_request.capability & |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 10856 | cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && !sec->enabled) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10857 | (!(priv->assoc_request.capability & |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 10858 | cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && sec->enabled))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10859 | IPW_DEBUG_ASSOC("Disassociating due to capability " |
| 10860 | "change.\n"); |
| 10861 | ipw_disassociate(priv); |
| 10862 | } |
| 10863 | #endif |
| 10864 | } |
| 10865 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10866 | static int init_supported_rates(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10867 | struct ipw_supported_rates *rates) |
| 10868 | { |
| 10869 | /* TODO: Mask out rates based on priv->rates_mask */ |
| 10870 | |
| 10871 | memset(rates, 0, sizeof(*rates)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10872 | /* configure supported rates */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10873 | switch (priv->ieee->freq_band) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10874 | case LIBIPW_52GHZ_BAND: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10875 | rates->ieee_mode = IPW_A_MODE; |
| 10876 | rates->purpose = IPW_RATE_CAPABILITIES; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10877 | ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION, |
| 10878 | LIBIPW_OFDM_DEFAULT_RATES_MASK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10879 | break; |
| 10880 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10881 | default: /* Mixed or 2.4Ghz */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10882 | rates->ieee_mode = IPW_G_MODE; |
| 10883 | rates->purpose = IPW_RATE_CAPABILITIES; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10884 | ipw_add_cck_scan_rates(rates, LIBIPW_CCK_MODULATION, |
| 10885 | LIBIPW_CCK_DEFAULT_RATES_MASK); |
| 10886 | if (priv->ieee->modulation & LIBIPW_OFDM_MODULATION) { |
| 10887 | ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION, |
| 10888 | LIBIPW_OFDM_DEFAULT_RATES_MASK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10889 | } |
| 10890 | break; |
| 10891 | } |
| 10892 | |
| 10893 | return 0; |
| 10894 | } |
| 10895 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10896 | static int ipw_config(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10897 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10898 | /* This is only called from ipw_up, which resets/reloads the firmware |
| 10899 | so, we don't need to first disable the card before we configure |
| 10900 | it */ |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 10901 | if (ipw_set_tx_power(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10902 | goto error; |
| 10903 | |
| 10904 | /* initialize adapter address */ |
| 10905 | if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr)) |
| 10906 | goto error; |
| 10907 | |
| 10908 | /* set basic system config settings */ |
| 10909 | init_sys_config(&priv->sys_config); |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10910 | |
| 10911 | /* Support Bluetooth if we have BT h/w on board, and user wants to. |
| 10912 | * Does not support BT priority yet (don't abort or defer our Tx) */ |
| 10913 | if (bt_coexist) { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10914 | unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY]; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10915 | |
| 10916 | if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG) |
| 10917 | priv->sys_config.bt_coexistence |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10918 | |= CFG_BT_COEXISTENCE_SIGNAL_CHNL; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10919 | if (bt_caps & EEPROM_SKU_CAP_BT_OOB) |
| 10920 | priv->sys_config.bt_coexistence |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10921 | |= CFG_BT_COEXISTENCE_OOB; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10922 | } |
| 10923 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10924 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 10925 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) { |
| 10926 | priv->sys_config.accept_all_data_frames = 1; |
| 10927 | priv->sys_config.accept_non_directed_frames = 1; |
| 10928 | priv->sys_config.accept_all_mgmt_bcpr = 1; |
| 10929 | priv->sys_config.accept_all_mgmt_frames = 1; |
| 10930 | } |
| 10931 | #endif |
| 10932 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10933 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 10934 | priv->sys_config.answer_broadcast_ssid_probe = 1; |
| 10935 | else |
| 10936 | priv->sys_config.answer_broadcast_ssid_probe = 0; |
| 10937 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10938 | if (ipw_send_system_config(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10939 | goto error; |
| 10940 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10941 | init_supported_rates(priv, &priv->rates); |
| 10942 | if (ipw_send_supported_rates(priv, &priv->rates)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10943 | goto error; |
| 10944 | |
| 10945 | /* Set request-to-send threshold */ |
| 10946 | if (priv->rts_threshold) { |
| 10947 | if (ipw_send_rts_threshold(priv, priv->rts_threshold)) |
| 10948 | goto error; |
| 10949 | } |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10950 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10951 | IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n"); |
| 10952 | ipw_qos_activate(priv, NULL); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10953 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10954 | |
| 10955 | if (ipw_set_random_seed(priv)) |
| 10956 | goto error; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10957 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10958 | /* final state transition to the RUN state */ |
| 10959 | if (ipw_send_host_complete(priv)) |
| 10960 | goto error; |
| 10961 | |
James Ketrenos | e666619 | 2005-08-12 09:17:04 -0500 | [diff] [blame] | 10962 | priv->status |= STATUS_INIT; |
| 10963 | |
| 10964 | ipw_led_init(priv); |
| 10965 | ipw_led_radio_on(priv); |
| 10966 | priv->notif_missed_beacons = 0; |
| 10967 | |
| 10968 | /* Set hardware WEP key if it is configured. */ |
| 10969 | if ((priv->capability & CAP_PRIVACY_ON) && |
| 10970 | (priv->ieee->sec.level == SEC_LEVEL_1) && |
| 10971 | !(priv->ieee->host_encrypt || priv->ieee->host_decrypt)) |
| 10972 | ipw_set_hwcrypto_keys(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10973 | |
| 10974 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10975 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10976 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10977 | return -EIO; |
| 10978 | } |
| 10979 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10980 | /* |
| 10981 | * NOTE: |
| 10982 | * |
| 10983 | * These tables have been tested in conjunction with the |
| 10984 | * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters. |
| 10985 | * |
| 10986 | * Altering this values, using it on other hardware, or in geographies |
| 10987 | * not intended for resale of the above mentioned Intel adapters has |
| 10988 | * not been tested. |
| 10989 | * |
Henrik Brix Andersen | 48a8477 | 2006-02-14 09:09:52 +0800 | [diff] [blame] | 10990 | * Remember to update the table in README.ipw2200 when changing this |
| 10991 | * table. |
| 10992 | * |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10993 | */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10994 | static const struct libipw_geo ipw_geos[] = { |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10995 | { /* Restricted */ |
| 10996 | "---", |
| 10997 | .bg_channels = 11, |
| 10998 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10999 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11000 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11001 | {2457, 10}, {2462, 11}}, |
| 11002 | }, |
| 11003 | |
| 11004 | { /* Custom US/Canada */ |
| 11005 | "ZZF", |
| 11006 | .bg_channels = 11, |
| 11007 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11008 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11009 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11010 | {2457, 10}, {2462, 11}}, |
| 11011 | .a_channels = 8, |
| 11012 | .a = {{5180, 36}, |
| 11013 | {5200, 40}, |
| 11014 | {5220, 44}, |
| 11015 | {5240, 48}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11016 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11017 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11018 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11019 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11020 | }, |
| 11021 | |
| 11022 | { /* Rest of World */ |
| 11023 | "ZZD", |
| 11024 | .bg_channels = 13, |
| 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}}, |
| 11030 | }, |
| 11031 | |
| 11032 | { /* Custom USA & Europe & High */ |
| 11033 | "ZZA", |
| 11034 | .bg_channels = 11, |
| 11035 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11036 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11037 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11038 | {2457, 10}, {2462, 11}}, |
| 11039 | .a_channels = 13, |
| 11040 | .a = {{5180, 36}, |
| 11041 | {5200, 40}, |
| 11042 | {5220, 44}, |
| 11043 | {5240, 48}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11044 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11045 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11046 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11047 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11048 | {5745, 149}, |
| 11049 | {5765, 153}, |
| 11050 | {5785, 157}, |
| 11051 | {5805, 161}, |
| 11052 | {5825, 165}}, |
| 11053 | }, |
| 11054 | |
| 11055 | { /* Custom NA & Europe */ |
| 11056 | "ZZB", |
| 11057 | .bg_channels = 11, |
| 11058 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11059 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11060 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11061 | {2457, 10}, {2462, 11}}, |
| 11062 | .a_channels = 13, |
| 11063 | .a = {{5180, 36}, |
| 11064 | {5200, 40}, |
| 11065 | {5220, 44}, |
| 11066 | {5240, 48}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11067 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11068 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11069 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11070 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, |
| 11071 | {5745, 149, LIBIPW_CH_PASSIVE_ONLY}, |
| 11072 | {5765, 153, LIBIPW_CH_PASSIVE_ONLY}, |
| 11073 | {5785, 157, LIBIPW_CH_PASSIVE_ONLY}, |
| 11074 | {5805, 161, LIBIPW_CH_PASSIVE_ONLY}, |
| 11075 | {5825, 165, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11076 | }, |
| 11077 | |
| 11078 | { /* Custom Japan */ |
| 11079 | "ZZC", |
| 11080 | .bg_channels = 11, |
| 11081 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11082 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11083 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11084 | {2457, 10}, {2462, 11}}, |
| 11085 | .a_channels = 4, |
| 11086 | .a = {{5170, 34}, {5190, 38}, |
| 11087 | {5210, 42}, {5230, 46}}, |
| 11088 | }, |
| 11089 | |
| 11090 | { /* Custom */ |
| 11091 | "ZZM", |
| 11092 | .bg_channels = 11, |
| 11093 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11094 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11095 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11096 | {2457, 10}, {2462, 11}}, |
| 11097 | }, |
| 11098 | |
| 11099 | { /* Europe */ |
| 11100 | "ZZE", |
| 11101 | .bg_channels = 13, |
| 11102 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11103 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11104 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11105 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 11106 | {2472, 13}}, |
| 11107 | .a_channels = 19, |
| 11108 | .a = {{5180, 36}, |
| 11109 | {5200, 40}, |
| 11110 | {5220, 44}, |
| 11111 | {5240, 48}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11112 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11113 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11114 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11115 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, |
| 11116 | {5500, 100, LIBIPW_CH_PASSIVE_ONLY}, |
| 11117 | {5520, 104, LIBIPW_CH_PASSIVE_ONLY}, |
| 11118 | {5540, 108, LIBIPW_CH_PASSIVE_ONLY}, |
| 11119 | {5560, 112, LIBIPW_CH_PASSIVE_ONLY}, |
| 11120 | {5580, 116, LIBIPW_CH_PASSIVE_ONLY}, |
| 11121 | {5600, 120, LIBIPW_CH_PASSIVE_ONLY}, |
| 11122 | {5620, 124, LIBIPW_CH_PASSIVE_ONLY}, |
| 11123 | {5640, 128, LIBIPW_CH_PASSIVE_ONLY}, |
| 11124 | {5660, 132, LIBIPW_CH_PASSIVE_ONLY}, |
| 11125 | {5680, 136, LIBIPW_CH_PASSIVE_ONLY}, |
| 11126 | {5700, 140, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11127 | }, |
| 11128 | |
| 11129 | { /* Custom Japan */ |
| 11130 | "ZZJ", |
| 11131 | .bg_channels = 14, |
| 11132 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11133 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11134 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11135 | {2457, 10}, {2462, 11}, {2467, 12}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11136 | {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11137 | .a_channels = 4, |
| 11138 | .a = {{5170, 34}, {5190, 38}, |
| 11139 | {5210, 42}, {5230, 46}}, |
| 11140 | }, |
| 11141 | |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 11142 | { /* Rest of World */ |
| 11143 | "ZZR", |
| 11144 | .bg_channels = 14, |
| 11145 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11146 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11147 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11148 | {2457, 10}, {2462, 11}, {2467, 12}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11149 | {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY | |
| 11150 | LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 11151 | }, |
| 11152 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11153 | { /* High Band */ |
| 11154 | "ZZH", |
| 11155 | .bg_channels = 13, |
| 11156 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11157 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11158 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11159 | {2457, 10}, {2462, 11}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11160 | {2467, 12, LIBIPW_CH_PASSIVE_ONLY}, |
| 11161 | {2472, 13, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11162 | .a_channels = 4, |
| 11163 | .a = {{5745, 149}, {5765, 153}, |
| 11164 | {5785, 157}, {5805, 161}}, |
| 11165 | }, |
| 11166 | |
| 11167 | { /* Custom Europe */ |
| 11168 | "ZZG", |
| 11169 | .bg_channels = 13, |
| 11170 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11171 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11172 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11173 | {2457, 10}, {2462, 11}, |
| 11174 | {2467, 12}, {2472, 13}}, |
| 11175 | .a_channels = 4, |
| 11176 | .a = {{5180, 36}, {5200, 40}, |
| 11177 | {5220, 44}, {5240, 48}}, |
| 11178 | }, |
| 11179 | |
| 11180 | { /* Europe */ |
| 11181 | "ZZK", |
| 11182 | .bg_channels = 13, |
| 11183 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11184 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11185 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11186 | {2457, 10}, {2462, 11}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11187 | {2467, 12, LIBIPW_CH_PASSIVE_ONLY}, |
| 11188 | {2472, 13, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11189 | .a_channels = 24, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11190 | .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY}, |
| 11191 | {5200, 40, LIBIPW_CH_PASSIVE_ONLY}, |
| 11192 | {5220, 44, LIBIPW_CH_PASSIVE_ONLY}, |
| 11193 | {5240, 48, LIBIPW_CH_PASSIVE_ONLY}, |
| 11194 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11195 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11196 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11197 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, |
| 11198 | {5500, 100, LIBIPW_CH_PASSIVE_ONLY}, |
| 11199 | {5520, 104, LIBIPW_CH_PASSIVE_ONLY}, |
| 11200 | {5540, 108, LIBIPW_CH_PASSIVE_ONLY}, |
| 11201 | {5560, 112, LIBIPW_CH_PASSIVE_ONLY}, |
| 11202 | {5580, 116, LIBIPW_CH_PASSIVE_ONLY}, |
| 11203 | {5600, 120, LIBIPW_CH_PASSIVE_ONLY}, |
| 11204 | {5620, 124, LIBIPW_CH_PASSIVE_ONLY}, |
| 11205 | {5640, 128, LIBIPW_CH_PASSIVE_ONLY}, |
| 11206 | {5660, 132, LIBIPW_CH_PASSIVE_ONLY}, |
| 11207 | {5680, 136, LIBIPW_CH_PASSIVE_ONLY}, |
| 11208 | {5700, 140, LIBIPW_CH_PASSIVE_ONLY}, |
| 11209 | {5745, 149, LIBIPW_CH_PASSIVE_ONLY}, |
| 11210 | {5765, 153, LIBIPW_CH_PASSIVE_ONLY}, |
| 11211 | {5785, 157, LIBIPW_CH_PASSIVE_ONLY}, |
| 11212 | {5805, 161, LIBIPW_CH_PASSIVE_ONLY}, |
| 11213 | {5825, 165, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11214 | }, |
| 11215 | |
| 11216 | { /* Europe */ |
| 11217 | "ZZL", |
| 11218 | .bg_channels = 11, |
| 11219 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11220 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11221 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11222 | {2457, 10}, {2462, 11}}, |
| 11223 | .a_channels = 13, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11224 | .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY}, |
| 11225 | {5200, 40, LIBIPW_CH_PASSIVE_ONLY}, |
| 11226 | {5220, 44, LIBIPW_CH_PASSIVE_ONLY}, |
| 11227 | {5240, 48, LIBIPW_CH_PASSIVE_ONLY}, |
| 11228 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11229 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11230 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11231 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, |
| 11232 | {5745, 149, LIBIPW_CH_PASSIVE_ONLY}, |
| 11233 | {5765, 153, LIBIPW_CH_PASSIVE_ONLY}, |
| 11234 | {5785, 157, LIBIPW_CH_PASSIVE_ONLY}, |
| 11235 | {5805, 161, LIBIPW_CH_PASSIVE_ONLY}, |
| 11236 | {5825, 165, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11237 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11238 | }; |
| 11239 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11240 | #define MAX_HW_RESTARTS 5 |
| 11241 | static int ipw_up(struct ipw_priv *priv) |
| 11242 | { |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11243 | int rc, i, j; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11244 | |
Dan Williams | c3d72b9 | 2009-02-11 13:26:06 -0500 | [diff] [blame] | 11245 | /* Age scan list entries found before suspend */ |
| 11246 | if (priv->suspend_time) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11247 | libipw_networks_age(priv->ieee, priv->suspend_time); |
Dan Williams | c3d72b9 | 2009-02-11 13:26:06 -0500 | [diff] [blame] | 11248 | priv->suspend_time = 0; |
| 11249 | } |
| 11250 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11251 | if (priv->status & STATUS_EXIT_PENDING) |
| 11252 | return -EIO; |
| 11253 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11254 | if (cmdlog && !priv->cmdlog) { |
Yan Burman | e6e3f12 | 2006-12-02 13:38:14 +0200 | [diff] [blame] | 11255 | priv->cmdlog = kcalloc(cmdlog, sizeof(*priv->cmdlog), |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11256 | GFP_KERNEL); |
| 11257 | if (priv->cmdlog == NULL) { |
| 11258 | IPW_ERROR("Error allocating %d command log entries.\n", |
| 11259 | cmdlog); |
Zhu Yi | d0b526b | 2006-04-13 17:19:50 +0800 | [diff] [blame] | 11260 | return -ENOMEM; |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11261 | } else { |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11262 | priv->cmdlog_len = cmdlog; |
| 11263 | } |
| 11264 | } |
| 11265 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11266 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11267 | /* Load the microcode, firmware, and eeprom. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11268 | * Also start the clocks. */ |
| 11269 | rc = ipw_load(priv); |
| 11270 | if (rc) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 11271 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11272 | return rc; |
| 11273 | } |
| 11274 | |
| 11275 | ipw_init_ordinals(priv); |
| 11276 | if (!(priv->config & CFG_CUSTOM_MAC)) |
| 11277 | eeprom_parse_mac(priv, priv->mac_addr); |
| 11278 | memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN); |
| 11279 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11280 | for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) { |
| 11281 | if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE], |
| 11282 | ipw_geos[j].name, 3)) |
| 11283 | break; |
| 11284 | } |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 11285 | if (j == ARRAY_SIZE(ipw_geos)) { |
| 11286 | IPW_WARNING("SKU [%c%c%c] not recognized.\n", |
| 11287 | priv->eeprom[EEPROM_COUNTRY_CODE + 0], |
| 11288 | priv->eeprom[EEPROM_COUNTRY_CODE + 1], |
| 11289 | priv->eeprom[EEPROM_COUNTRY_CODE + 2]); |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11290 | j = 0; |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 11291 | } |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11292 | if (libipw_set_geo(priv->ieee, &ipw_geos[j])) { |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11293 | IPW_WARNING("Could not set geography."); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11294 | return 0; |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11295 | } |
| 11296 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11297 | if (priv->status & STATUS_RF_KILL_SW) { |
| 11298 | IPW_WARNING("Radio disabled by module parameter.\n"); |
| 11299 | return 0; |
| 11300 | } else if (rf_kill_active(priv)) { |
| 11301 | IPW_WARNING("Radio Frequency Kill Switch is On:\n" |
| 11302 | "Kill switch must be turned off for " |
| 11303 | "wireless networking to work.\n"); |
| 11304 | queue_delayed_work(priv->workqueue, &priv->rf_kill, |
| 11305 | 2 * HZ); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11306 | return 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11307 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11308 | |
| 11309 | rc = ipw_config(priv); |
| 11310 | if (!rc) { |
| 11311 | IPW_DEBUG_INFO("Configured device on count %i\n", i); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11312 | |
James Ketrenos | e666619 | 2005-08-12 09:17:04 -0500 | [diff] [blame] | 11313 | /* If configure to try and auto-associate, kick |
| 11314 | * off a scan. */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11315 | queue_delayed_work(priv->workqueue, |
| 11316 | &priv->request_scan, 0); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11317 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11318 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11319 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11320 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11321 | IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11322 | IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n", |
| 11323 | i, MAX_HW_RESTARTS); |
| 11324 | |
| 11325 | /* We had an error bringing up the hardware, so take it |
| 11326 | * all the way back down so we can try again */ |
| 11327 | ipw_down(priv); |
| 11328 | } |
| 11329 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11330 | /* tried to restart and config the device for as long as our |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11331 | * patience could withstand */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11332 | IPW_ERROR("Unable to initialize device after %d attempts.\n", i); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11333 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11334 | return -EIO; |
| 11335 | } |
| 11336 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11337 | static void ipw_bg_up(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11338 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11339 | struct ipw_priv *priv = |
| 11340 | container_of(work, struct ipw_priv, up); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11341 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11342 | ipw_up(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11343 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11344 | } |
| 11345 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11346 | static void ipw_deinit(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11347 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11348 | int i; |
| 11349 | |
| 11350 | if (priv->status & STATUS_SCANNING) { |
| 11351 | IPW_DEBUG_INFO("Aborting scan during shutdown.\n"); |
| 11352 | ipw_abort_scan(priv); |
| 11353 | } |
| 11354 | |
| 11355 | if (priv->status & STATUS_ASSOCIATED) { |
| 11356 | IPW_DEBUG_INFO("Disassociating during shutdown.\n"); |
| 11357 | ipw_disassociate(priv); |
| 11358 | } |
| 11359 | |
| 11360 | ipw_led_shutdown(priv); |
| 11361 | |
| 11362 | /* Wait up to 1s for status to change to not scanning and not |
| 11363 | * associated (disassociation can take a while for a ful 802.11 |
| 11364 | * exchange */ |
| 11365 | for (i = 1000; i && (priv->status & |
| 11366 | (STATUS_DISASSOCIATING | |
| 11367 | STATUS_ASSOCIATED | STATUS_SCANNING)); i--) |
| 11368 | udelay(10); |
| 11369 | |
| 11370 | if (priv->status & (STATUS_DISASSOCIATING | |
| 11371 | STATUS_ASSOCIATED | STATUS_SCANNING)) |
| 11372 | IPW_DEBUG_INFO("Still associated or scanning...\n"); |
| 11373 | else |
| 11374 | IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i); |
| 11375 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11376 | /* Attempt to disable the card */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11377 | ipw_send_card_disable(priv, 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11378 | |
| 11379 | priv->status &= ~STATUS_INIT; |
| 11380 | } |
| 11381 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11382 | static void ipw_down(struct ipw_priv *priv) |
| 11383 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11384 | int exit_pending = priv->status & STATUS_EXIT_PENDING; |
| 11385 | |
| 11386 | priv->status |= STATUS_EXIT_PENDING; |
| 11387 | |
| 11388 | if (ipw_is_init(priv)) |
| 11389 | ipw_deinit(priv); |
| 11390 | |
| 11391 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 11392 | * exiting the module */ |
| 11393 | if (!exit_pending) |
| 11394 | priv->status &= ~STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11395 | |
| 11396 | /* tell the device to stop sending interrupts */ |
| 11397 | ipw_disable_interrupts(priv); |
| 11398 | |
| 11399 | /* Clear all bits but the RF Kill */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11400 | priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11401 | netif_carrier_off(priv->net_dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11402 | |
| 11403 | ipw_stop_nic(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11404 | |
| 11405 | ipw_led_radio_off(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11406 | } |
| 11407 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11408 | static void ipw_bg_down(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11409 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11410 | struct ipw_priv *priv = |
| 11411 | container_of(work, struct ipw_priv, down); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11412 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11413 | ipw_down(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11414 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11415 | } |
| 11416 | |
| 11417 | /* Called by register_netdev() */ |
| 11418 | static int ipw_net_init(struct net_device *dev) |
| 11419 | { |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11420 | int i, rc = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11421 | struct ipw_priv *priv = libipw_priv(dev); |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11422 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
| 11423 | struct wireless_dev *wdev = &priv->ieee->wdev; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11424 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11425 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11426 | if (ipw_up(priv)) { |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11427 | rc = -EIO; |
| 11428 | goto out; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11429 | } |
| 11430 | |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11431 | memcpy(wdev->wiphy->perm_addr, priv->mac_addr, ETH_ALEN); |
| 11432 | |
| 11433 | /* fill-out priv->ieee->bg_band */ |
| 11434 | if (geo->bg_channels) { |
| 11435 | struct ieee80211_supported_band *bg_band = &priv->ieee->bg_band; |
| 11436 | |
| 11437 | bg_band->band = IEEE80211_BAND_2GHZ; |
| 11438 | bg_band->n_channels = geo->bg_channels; |
| 11439 | bg_band->channels = |
| 11440 | kzalloc(geo->bg_channels * |
| 11441 | sizeof(struct ieee80211_channel), GFP_KERNEL); |
| 11442 | /* translate geo->bg to bg_band.channels */ |
| 11443 | for (i = 0; i < geo->bg_channels; i++) { |
| 11444 | bg_band->channels[i].band = IEEE80211_BAND_2GHZ; |
| 11445 | bg_band->channels[i].center_freq = geo->bg[i].freq; |
| 11446 | bg_band->channels[i].hw_value = geo->bg[i].channel; |
| 11447 | bg_band->channels[i].max_power = geo->bg[i].max_power; |
| 11448 | if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) |
| 11449 | bg_band->channels[i].flags |= |
| 11450 | IEEE80211_CHAN_PASSIVE_SCAN; |
| 11451 | if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS) |
| 11452 | bg_band->channels[i].flags |= |
| 11453 | IEEE80211_CHAN_NO_IBSS; |
| 11454 | if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT) |
| 11455 | bg_band->channels[i].flags |= |
| 11456 | IEEE80211_CHAN_RADAR; |
| 11457 | /* No equivalent for LIBIPW_CH_80211H_RULES, |
| 11458 | LIBIPW_CH_UNIFORM_SPREADING, or |
| 11459 | LIBIPW_CH_B_ONLY... */ |
| 11460 | } |
| 11461 | /* point at bitrate info */ |
| 11462 | bg_band->bitrates = ipw2200_bg_rates; |
| 11463 | bg_band->n_bitrates = ipw2200_num_bg_rates; |
| 11464 | |
| 11465 | wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = bg_band; |
| 11466 | } |
| 11467 | |
| 11468 | /* fill-out priv->ieee->a_band */ |
| 11469 | if (geo->a_channels) { |
| 11470 | struct ieee80211_supported_band *a_band = &priv->ieee->a_band; |
| 11471 | |
| 11472 | a_band->band = IEEE80211_BAND_5GHZ; |
| 11473 | a_band->n_channels = geo->a_channels; |
| 11474 | a_band->channels = |
| 11475 | kzalloc(geo->a_channels * |
| 11476 | sizeof(struct ieee80211_channel), GFP_KERNEL); |
| 11477 | /* translate geo->bg to a_band.channels */ |
| 11478 | for (i = 0; i < geo->a_channels; i++) { |
| 11479 | a_band->channels[i].band = IEEE80211_BAND_2GHZ; |
| 11480 | a_band->channels[i].center_freq = geo->a[i].freq; |
| 11481 | a_band->channels[i].hw_value = geo->a[i].channel; |
| 11482 | a_band->channels[i].max_power = geo->a[i].max_power; |
| 11483 | if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) |
| 11484 | a_band->channels[i].flags |= |
| 11485 | IEEE80211_CHAN_PASSIVE_SCAN; |
| 11486 | if (geo->a[i].flags & LIBIPW_CH_NO_IBSS) |
| 11487 | a_band->channels[i].flags |= |
| 11488 | IEEE80211_CHAN_NO_IBSS; |
| 11489 | if (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT) |
| 11490 | a_band->channels[i].flags |= |
| 11491 | IEEE80211_CHAN_RADAR; |
| 11492 | /* No equivalent for LIBIPW_CH_80211H_RULES, |
| 11493 | LIBIPW_CH_UNIFORM_SPREADING, or |
| 11494 | LIBIPW_CH_B_ONLY... */ |
| 11495 | } |
| 11496 | /* point at bitrate info */ |
| 11497 | a_band->bitrates = ipw2200_a_rates; |
| 11498 | a_band->n_bitrates = ipw2200_num_a_rates; |
| 11499 | |
| 11500 | wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = a_band; |
| 11501 | } |
| 11502 | |
| 11503 | set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev); |
| 11504 | |
| 11505 | /* With that information in place, we can now register the wiphy... */ |
| 11506 | if (wiphy_register(wdev->wiphy)) { |
| 11507 | rc = -EIO; |
| 11508 | goto out; |
| 11509 | } |
| 11510 | |
| 11511 | out: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11512 | mutex_unlock(&priv->mutex); |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11513 | return rc; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11514 | } |
| 11515 | |
| 11516 | /* PCI driver stuff */ |
| 11517 | static struct pci_device_id card_ids[] = { |
| 11518 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0}, |
| 11519 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0}, |
| 11520 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0}, |
| 11521 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0}, |
| 11522 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0}, |
| 11523 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0}, |
| 11524 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0}, |
| 11525 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0}, |
| 11526 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0}, |
| 11527 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0}, |
| 11528 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0}, |
| 11529 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0}, |
| 11530 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0}, |
| 11531 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0}, |
| 11532 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0}, |
| 11533 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0}, |
| 11534 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0}, |
Joe Perches | 8ab0ea7 | 2009-06-24 22:13:27 -0700 | [diff] [blame] | 11535 | {PCI_VDEVICE(INTEL, 0x104f), 0}, |
| 11536 | {PCI_VDEVICE(INTEL, 0x4220), 0}, /* BG */ |
| 11537 | {PCI_VDEVICE(INTEL, 0x4221), 0}, /* BG */ |
| 11538 | {PCI_VDEVICE(INTEL, 0x4223), 0}, /* ABG */ |
| 11539 | {PCI_VDEVICE(INTEL, 0x4224), 0}, /* ABG */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11540 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11541 | /* required last entry */ |
| 11542 | {0,} |
| 11543 | }; |
| 11544 | |
| 11545 | MODULE_DEVICE_TABLE(pci, card_ids); |
| 11546 | |
| 11547 | static struct attribute *ipw_sysfs_entries[] = { |
| 11548 | &dev_attr_rf_kill.attr, |
| 11549 | &dev_attr_direct_dword.attr, |
| 11550 | &dev_attr_indirect_byte.attr, |
| 11551 | &dev_attr_indirect_dword.attr, |
| 11552 | &dev_attr_mem_gpio_reg.attr, |
| 11553 | &dev_attr_command_event_reg.attr, |
| 11554 | &dev_attr_nic_type.attr, |
| 11555 | &dev_attr_status.attr, |
| 11556 | &dev_attr_cfg.attr, |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 11557 | &dev_attr_error.attr, |
| 11558 | &dev_attr_event_log.attr, |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11559 | &dev_attr_cmd_log.attr, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11560 | &dev_attr_eeprom_delay.attr, |
| 11561 | &dev_attr_ucode_version.attr, |
| 11562 | &dev_attr_rtc.attr, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11563 | &dev_attr_scan_age.attr, |
| 11564 | &dev_attr_led.attr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11565 | &dev_attr_speed_scan.attr, |
| 11566 | &dev_attr_net_stats.attr, |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 11567 | &dev_attr_channels.attr, |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11568 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11569 | &dev_attr_rtap_iface.attr, |
| 11570 | &dev_attr_rtap_filter.attr, |
| 11571 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11572 | NULL |
| 11573 | }; |
| 11574 | |
| 11575 | static struct attribute_group ipw_attribute_group = { |
| 11576 | .name = NULL, /* put in device directory */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11577 | .attrs = ipw_sysfs_entries, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11578 | }; |
| 11579 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11580 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11581 | static int ipw_prom_open(struct net_device *dev) |
| 11582 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11583 | struct ipw_prom_priv *prom_priv = libipw_priv(dev); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11584 | struct ipw_priv *priv = prom_priv->priv; |
| 11585 | |
| 11586 | IPW_DEBUG_INFO("prom dev->open\n"); |
| 11587 | netif_carrier_off(dev); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11588 | |
| 11589 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
| 11590 | priv->sys_config.accept_all_data_frames = 1; |
| 11591 | priv->sys_config.accept_non_directed_frames = 1; |
| 11592 | priv->sys_config.accept_all_mgmt_bcpr = 1; |
| 11593 | priv->sys_config.accept_all_mgmt_frames = 1; |
| 11594 | |
| 11595 | ipw_send_system_config(priv); |
| 11596 | } |
| 11597 | |
| 11598 | return 0; |
| 11599 | } |
| 11600 | |
| 11601 | static int ipw_prom_stop(struct net_device *dev) |
| 11602 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11603 | struct ipw_prom_priv *prom_priv = libipw_priv(dev); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11604 | struct ipw_priv *priv = prom_priv->priv; |
| 11605 | |
| 11606 | IPW_DEBUG_INFO("prom dev->stop\n"); |
| 11607 | |
| 11608 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
| 11609 | priv->sys_config.accept_all_data_frames = 0; |
| 11610 | priv->sys_config.accept_non_directed_frames = 0; |
| 11611 | priv->sys_config.accept_all_mgmt_bcpr = 0; |
| 11612 | priv->sys_config.accept_all_mgmt_frames = 0; |
| 11613 | |
| 11614 | ipw_send_system_config(priv); |
| 11615 | } |
| 11616 | |
| 11617 | return 0; |
| 11618 | } |
| 11619 | |
Stephen Hemminger | d0cf9c0 | 2009-08-31 19:50:57 +0000 | [diff] [blame] | 11620 | static netdev_tx_t ipw_prom_hard_start_xmit(struct sk_buff *skb, |
| 11621 | struct net_device *dev) |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11622 | { |
| 11623 | IPW_DEBUG_INFO("prom dev->xmit\n"); |
Patrick McHardy | 4153e77 | 2009-06-12 04:08:02 +0000 | [diff] [blame] | 11624 | dev_kfree_skb(skb); |
| 11625 | return NETDEV_TX_OK; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11626 | } |
| 11627 | |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11628 | static const struct net_device_ops ipw_prom_netdev_ops = { |
| 11629 | .ndo_open = ipw_prom_open, |
| 11630 | .ndo_stop = ipw_prom_stop, |
| 11631 | .ndo_start_xmit = ipw_prom_hard_start_xmit, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11632 | .ndo_change_mtu = libipw_change_mtu, |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11633 | .ndo_set_mac_address = eth_mac_addr, |
| 11634 | .ndo_validate_addr = eth_validate_addr, |
| 11635 | }; |
| 11636 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11637 | static int ipw_prom_alloc(struct ipw_priv *priv) |
| 11638 | { |
| 11639 | int rc = 0; |
| 11640 | |
| 11641 | if (priv->prom_net_dev) |
| 11642 | return -EPERM; |
| 11643 | |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11644 | priv->prom_net_dev = alloc_ieee80211(sizeof(struct ipw_prom_priv), 1); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11645 | if (priv->prom_net_dev == NULL) |
| 11646 | return -ENOMEM; |
| 11647 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11648 | priv->prom_priv = libipw_priv(priv->prom_net_dev); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11649 | priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev); |
| 11650 | priv->prom_priv->priv = priv; |
| 11651 | |
| 11652 | strcpy(priv->prom_net_dev->name, "rtap%d"); |
Daniel Drake | 3f2eeac | 2008-04-02 20:33:54 +0100 | [diff] [blame] | 11653 | memcpy(priv->prom_net_dev->dev_addr, priv->mac_addr, ETH_ALEN); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11654 | |
| 11655 | priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11656 | priv->prom_net_dev->netdev_ops = &ipw_prom_netdev_ops; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11657 | |
| 11658 | priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR; |
Masakazu Mokuno | 229ce3a | 2008-05-14 14:16:50 +0900 | [diff] [blame] | 11659 | SET_NETDEV_DEV(priv->prom_net_dev, &priv->pci_dev->dev); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11660 | |
| 11661 | rc = register_netdev(priv->prom_net_dev); |
| 11662 | if (rc) { |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11663 | free_ieee80211(priv->prom_net_dev, 1); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11664 | priv->prom_net_dev = NULL; |
| 11665 | return rc; |
| 11666 | } |
| 11667 | |
| 11668 | return 0; |
| 11669 | } |
| 11670 | |
| 11671 | static void ipw_prom_free(struct ipw_priv *priv) |
| 11672 | { |
| 11673 | if (!priv->prom_net_dev) |
| 11674 | return; |
| 11675 | |
| 11676 | unregister_netdev(priv->prom_net_dev); |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11677 | free_ieee80211(priv->prom_net_dev, 1); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11678 | |
| 11679 | priv->prom_net_dev = NULL; |
| 11680 | } |
| 11681 | |
| 11682 | #endif |
| 11683 | |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11684 | static const struct net_device_ops ipw_netdev_ops = { |
| 11685 | .ndo_init = ipw_net_init, |
| 11686 | .ndo_open = ipw_net_open, |
| 11687 | .ndo_stop = ipw_net_stop, |
| 11688 | .ndo_set_multicast_list = ipw_net_set_multicast_list, |
| 11689 | .ndo_set_mac_address = ipw_net_set_mac_address, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11690 | .ndo_start_xmit = libipw_xmit, |
| 11691 | .ndo_change_mtu = libipw_change_mtu, |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11692 | .ndo_validate_addr = eth_validate_addr, |
| 11693 | }; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11694 | |
Adrian Bunk | 2ef19e6 | 2007-12-11 23:20:22 +0100 | [diff] [blame] | 11695 | static int __devinit ipw_pci_probe(struct pci_dev *pdev, |
| 11696 | const struct pci_device_id *ent) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11697 | { |
| 11698 | int err = 0; |
| 11699 | struct net_device *net_dev; |
| 11700 | void __iomem *base; |
| 11701 | u32 length, val; |
| 11702 | struct ipw_priv *priv; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11703 | int i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11704 | |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11705 | net_dev = alloc_ieee80211(sizeof(struct ipw_priv), 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11706 | if (net_dev == NULL) { |
| 11707 | err = -ENOMEM; |
| 11708 | goto out; |
| 11709 | } |
| 11710 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11711 | priv = libipw_priv(net_dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11712 | priv->ieee = netdev_priv(net_dev); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11713 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11714 | priv->net_dev = net_dev; |
| 11715 | priv->pci_dev = pdev; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11716 | ipw_debug_level = debug; |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 11717 | spin_lock_init(&priv->irq_lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11718 | spin_lock_init(&priv->lock); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11719 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) |
| 11720 | INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11721 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11722 | mutex_init(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11723 | if (pci_enable_device(pdev)) { |
| 11724 | err = -ENODEV; |
| 11725 | goto out_free_ieee80211; |
| 11726 | } |
| 11727 | |
| 11728 | pci_set_master(pdev); |
| 11729 | |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 11730 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11731 | if (!err) |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 11732 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11733 | if (err) { |
| 11734 | printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n"); |
| 11735 | goto out_pci_disable_device; |
| 11736 | } |
| 11737 | |
| 11738 | pci_set_drvdata(pdev, priv); |
| 11739 | |
| 11740 | err = pci_request_regions(pdev, DRV_NAME); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11741 | if (err) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11742 | goto out_pci_disable_device; |
| 11743 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11744 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11745 | * PCI Tx retries from interfering with C3 CPU state */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11746 | pci_read_config_dword(pdev, 0x40, &val); |
| 11747 | if ((val & 0x0000ff00) != 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11748 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11749 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11750 | length = pci_resource_len(pdev, 0); |
| 11751 | priv->hw_len = length; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11752 | |
Arjan van de Ven | 275f165 | 2008-10-20 21:42:39 -0700 | [diff] [blame] | 11753 | base = pci_ioremap_bar(pdev, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11754 | if (!base) { |
| 11755 | err = -ENODEV; |
| 11756 | goto out_pci_release_regions; |
| 11757 | } |
| 11758 | |
| 11759 | priv->hw_base = base; |
| 11760 | IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length); |
| 11761 | IPW_DEBUG_INFO("pci_resource_base = %p\n", base); |
| 11762 | |
| 11763 | err = ipw_setup_deferred_work(priv); |
| 11764 | if (err) { |
| 11765 | IPW_ERROR("Unable to setup deferred work\n"); |
| 11766 | goto out_iounmap; |
| 11767 | } |
| 11768 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11769 | ipw_sw_reset(priv, 1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11770 | |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 11771 | err = request_irq(pdev->irq, ipw_isr, IRQF_SHARED, DRV_NAME, priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11772 | if (err) { |
| 11773 | IPW_ERROR("Error allocating IRQ %d\n", pdev->irq); |
| 11774 | goto out_destroy_workqueue; |
| 11775 | } |
| 11776 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11777 | SET_NETDEV_DEV(net_dev, &pdev->dev); |
| 11778 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11779 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11780 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11781 | priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit; |
| 11782 | priv->ieee->set_security = shim__set_security; |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 11783 | priv->ieee->is_queue_full = ipw_net_is_queue_full; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11784 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 11785 | #ifdef CONFIG_IPW2200_QOS |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 11786 | priv->ieee->is_qos_active = ipw_is_qos_active; |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 11787 | priv->ieee->handle_probe_response = ipw_handle_beacon; |
| 11788 | priv->ieee->handle_beacon = ipw_handle_probe_response; |
| 11789 | priv->ieee->handle_assoc_response = ipw_handle_assoc_response; |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 11790 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11791 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11792 | priv->ieee->perfect_rssi = -20; |
| 11793 | priv->ieee->worst_rssi = -85; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11794 | |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11795 | net_dev->netdev_ops = &ipw_netdev_ops; |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 11796 | priv->wireless_data.spy_data = &priv->ieee->spy_data; |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 11797 | net_dev->wireless_data = &priv->wireless_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11798 | net_dev->wireless_handlers = &ipw_wx_handler_def; |
| 11799 | net_dev->ethtool_ops = &ipw_ethtool_ops; |
| 11800 | net_dev->irq = pdev->irq; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11801 | net_dev->base_addr = (unsigned long)priv->hw_base; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11802 | net_dev->mem_start = pci_resource_start(pdev, 0); |
| 11803 | net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1; |
| 11804 | |
| 11805 | err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group); |
| 11806 | if (err) { |
| 11807 | IPW_ERROR("failed to create sysfs device attributes\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11808 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11809 | goto out_release_irq; |
| 11810 | } |
| 11811 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11812 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11813 | err = register_netdev(net_dev); |
| 11814 | if (err) { |
| 11815 | IPW_ERROR("failed to register network device\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11816 | goto out_remove_sysfs; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11817 | } |
Henrik Brix Andersen | 48a8477 | 2006-02-14 09:09:52 +0800 | [diff] [blame] | 11818 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11819 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11820 | if (rtap_iface) { |
| 11821 | err = ipw_prom_alloc(priv); |
| 11822 | if (err) { |
| 11823 | IPW_ERROR("Failed to register promiscuous network " |
| 11824 | "device (error %d).\n", err); |
Zhu Yi | e6c5fc5 | 2009-10-15 14:50:28 +0800 | [diff] [blame] | 11825 | unregister_ieee80211(priv->ieee); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11826 | unregister_netdev(priv->net_dev); |
| 11827 | goto out_remove_sysfs; |
| 11828 | } |
| 11829 | } |
| 11830 | #endif |
| 11831 | |
Henrik Brix Andersen | 48a8477 | 2006-02-14 09:09:52 +0800 | [diff] [blame] | 11832 | printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg " |
| 11833 | "channels, %d 802.11a channels)\n", |
| 11834 | priv->ieee->geo.name, priv->ieee->geo.bg_channels, |
| 11835 | priv->ieee->geo.a_channels); |
| 11836 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11837 | return 0; |
| 11838 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11839 | out_remove_sysfs: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11840 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11841 | out_release_irq: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11842 | free_irq(pdev->irq, priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11843 | out_destroy_workqueue: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11844 | destroy_workqueue(priv->workqueue); |
| 11845 | priv->workqueue = NULL; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11846 | out_iounmap: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11847 | iounmap(priv->hw_base); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11848 | out_pci_release_regions: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11849 | pci_release_regions(pdev); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11850 | out_pci_disable_device: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11851 | pci_disable_device(pdev); |
| 11852 | pci_set_drvdata(pdev, NULL); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11853 | out_free_ieee80211: |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11854 | free_ieee80211(priv->net_dev, 0); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11855 | out: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11856 | return err; |
| 11857 | } |
| 11858 | |
Adrian Bunk | 2ef19e6 | 2007-12-11 23:20:22 +0100 | [diff] [blame] | 11859 | static void __devexit ipw_pci_remove(struct pci_dev *pdev) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11860 | { |
| 11861 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11862 | struct list_head *p, *q; |
| 11863 | int i; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11864 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11865 | if (!priv) |
| 11866 | return; |
| 11867 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11868 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11869 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11870 | priv->status |= STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11871 | ipw_down(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11872 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
| 11873 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11874 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11875 | |
Zhu Yi | e6c5fc5 | 2009-10-15 14:50:28 +0800 | [diff] [blame] | 11876 | unregister_ieee80211(priv->ieee); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11877 | unregister_netdev(priv->net_dev); |
| 11878 | |
| 11879 | if (priv->rxq) { |
| 11880 | ipw_rx_queue_free(priv, priv->rxq); |
| 11881 | priv->rxq = NULL; |
| 11882 | } |
| 11883 | ipw_tx_queue_free(priv); |
| 11884 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11885 | if (priv->cmdlog) { |
| 11886 | kfree(priv->cmdlog); |
| 11887 | priv->cmdlog = NULL; |
| 11888 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11889 | /* ipw_down will ensure that there is no more pending work |
| 11890 | * in the workqueue's, so we can safely remove them now. */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11891 | cancel_delayed_work(&priv->adhoc_check); |
| 11892 | cancel_delayed_work(&priv->gather_stats); |
| 11893 | cancel_delayed_work(&priv->request_scan); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 11894 | cancel_delayed_work(&priv->request_direct_scan); |
| 11895 | cancel_delayed_work(&priv->request_passive_scan); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 11896 | cancel_delayed_work(&priv->scan_event); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11897 | cancel_delayed_work(&priv->rf_kill); |
| 11898 | cancel_delayed_work(&priv->scan_check); |
| 11899 | destroy_workqueue(priv->workqueue); |
| 11900 | priv->workqueue = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11901 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11902 | /* Free MAC hash list for ADHOC */ |
| 11903 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) { |
| 11904 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11905 | list_del(p); |
Zhu Yi | 489f445 | 2006-01-24 16:37:41 +0800 | [diff] [blame] | 11906 | kfree(list_entry(p, struct ipw_ibss_seq, list)); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11907 | } |
| 11908 | } |
| 11909 | |
Jesper Juhl | 8f76078 | 2006-06-27 02:55:06 -0700 | [diff] [blame] | 11910 | kfree(priv->error); |
| 11911 | priv->error = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11912 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11913 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11914 | ipw_prom_free(priv); |
| 11915 | #endif |
| 11916 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11917 | free_irq(pdev->irq, priv); |
| 11918 | iounmap(priv->hw_base); |
| 11919 | pci_release_regions(pdev); |
| 11920 | pci_disable_device(pdev); |
| 11921 | pci_set_drvdata(pdev, NULL); |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11922 | free_ieee80211(priv->net_dev, 0); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11923 | free_firmware(); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11924 | } |
| 11925 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11926 | #ifdef CONFIG_PM |
Pavel Machek | 583a4e8 | 2005-09-03 15:56:58 -0700 | [diff] [blame] | 11927 | 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] | 11928 | { |
| 11929 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 11930 | struct net_device *dev = priv->net_dev; |
| 11931 | |
| 11932 | printk(KERN_INFO "%s: Going into suspend...\n", dev->name); |
| 11933 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11934 | /* Take down the device; powers it off, etc. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11935 | ipw_down(priv); |
| 11936 | |
| 11937 | /* Remove the PRESENT state of the device */ |
| 11938 | netif_device_detach(dev); |
| 11939 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11940 | pci_save_state(pdev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11941 | pci_disable_device(pdev); |
Pavel Machek | 583a4e8 | 2005-09-03 15:56:58 -0700 | [diff] [blame] | 11942 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11943 | |
Dan Williams | c3d72b9 | 2009-02-11 13:26:06 -0500 | [diff] [blame] | 11944 | priv->suspend_at = get_seconds(); |
| 11945 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11946 | return 0; |
| 11947 | } |
| 11948 | |
| 11949 | static int ipw_pci_resume(struct pci_dev *pdev) |
| 11950 | { |
| 11951 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 11952 | struct net_device *dev = priv->net_dev; |
John W. Linville | 02e0e5e | 2006-11-07 20:53:48 -0500 | [diff] [blame] | 11953 | int err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11954 | u32 val; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11955 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11956 | printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name); |
| 11957 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 11958 | pci_set_power_state(pdev, PCI_D0); |
John W. Linville | 02e0e5e | 2006-11-07 20:53:48 -0500 | [diff] [blame] | 11959 | err = pci_enable_device(pdev); |
| 11960 | if (err) { |
| 11961 | printk(KERN_ERR "%s: pci_enable_device failed on resume\n", |
| 11962 | dev->name); |
| 11963 | return err; |
| 11964 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11965 | pci_restore_state(pdev); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 11966 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11967 | /* |
| 11968 | * Suspend/Resume resets the PCI configuration space, so we have to |
| 11969 | * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries |
| 11970 | * from interfering with C3 CPU state. pci_restore_state won't help |
| 11971 | * here since it only restores the first 64 bytes pci config header. |
| 11972 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11973 | pci_read_config_dword(pdev, 0x40, &val); |
| 11974 | if ((val & 0x0000ff00) != 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11975 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
| 11976 | |
| 11977 | /* Set the device back into the PRESENT state; this will also wake |
| 11978 | * the queue of needed */ |
| 11979 | netif_device_attach(dev); |
| 11980 | |
Dan Williams | c3d72b9 | 2009-02-11 13:26:06 -0500 | [diff] [blame] | 11981 | priv->suspend_time = get_seconds() - priv->suspend_at; |
| 11982 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11983 | /* Bring the device back up */ |
| 11984 | queue_work(priv->workqueue, &priv->up); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11985 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11986 | return 0; |
| 11987 | } |
| 11988 | #endif |
| 11989 | |
Zhu Yi | c8c22c9 | 2006-08-21 11:38:39 +0800 | [diff] [blame] | 11990 | static void ipw_pci_shutdown(struct pci_dev *pdev) |
| 11991 | { |
| 11992 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 11993 | |
| 11994 | /* Take down the device; powers it off, etc. */ |
| 11995 | ipw_down(priv); |
| 11996 | |
| 11997 | pci_disable_device(pdev); |
| 11998 | } |
| 11999 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12000 | /* driver initialization stuff */ |
| 12001 | static struct pci_driver ipw_driver = { |
| 12002 | .name = DRV_NAME, |
| 12003 | .id_table = card_ids, |
| 12004 | .probe = ipw_pci_probe, |
| 12005 | .remove = __devexit_p(ipw_pci_remove), |
| 12006 | #ifdef CONFIG_PM |
| 12007 | .suspend = ipw_pci_suspend, |
| 12008 | .resume = ipw_pci_resume, |
| 12009 | #endif |
Zhu Yi | c8c22c9 | 2006-08-21 11:38:39 +0800 | [diff] [blame] | 12010 | .shutdown = ipw_pci_shutdown, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12011 | }; |
| 12012 | |
| 12013 | static int __init ipw_init(void) |
| 12014 | { |
| 12015 | int ret; |
| 12016 | |
| 12017 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 12018 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
| 12019 | |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 12020 | ret = pci_register_driver(&ipw_driver); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12021 | if (ret) { |
| 12022 | IPW_ERROR("Unable to initialize PCI module\n"); |
| 12023 | return ret; |
| 12024 | } |
| 12025 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 12026 | ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12027 | if (ret) { |
| 12028 | IPW_ERROR("Unable to create driver sysfs file\n"); |
| 12029 | pci_unregister_driver(&ipw_driver); |
| 12030 | return ret; |
| 12031 | } |
| 12032 | |
| 12033 | return ret; |
| 12034 | } |
| 12035 | |
| 12036 | static void __exit ipw_exit(void) |
| 12037 | { |
| 12038 | driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level); |
| 12039 | pci_unregister_driver(&ipw_driver); |
| 12040 | } |
| 12041 | |
| 12042 | module_param(disable, int, 0444); |
| 12043 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
| 12044 | |
| 12045 | module_param(associate, int, 0444); |
Tim Gardner | 5c7f9b7 | 2008-10-14 10:38:03 -0600 | [diff] [blame] | 12046 | MODULE_PARM_DESC(associate, "auto associate when scanning (default off)"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12047 | |
| 12048 | module_param(auto_create, int, 0444); |
| 12049 | MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)"); |
| 12050 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 12051 | module_param_named(led, led_support, int, 0444); |
Niels de Vos | 61a2d07 | 2008-07-31 00:07:23 -0700 | [diff] [blame] | 12052 | MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 12053 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12054 | module_param(debug, int, 0444); |
| 12055 | MODULE_PARM_DESC(debug, "debug output mask"); |
| 12056 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 12057 | module_param_named(channel, default_channel, int, 0444); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 12058 | MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12059 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 12060 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 12061 | module_param(rtap_iface, int, 0444); |
| 12062 | MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)"); |
| 12063 | #endif |
| 12064 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 12065 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 12066 | module_param(qos_enable, int, 0444); |
| 12067 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12068 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 12069 | module_param(qos_burst_enable, int, 0444); |
| 12070 | MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode"); |
| 12071 | |
| 12072 | module_param(qos_no_ack_mask, int, 0444); |
| 12073 | MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack"); |
| 12074 | |
| 12075 | module_param(burst_duration_CCK, int, 0444); |
| 12076 | MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value"); |
| 12077 | |
| 12078 | module_param(burst_duration_OFDM, int, 0444); |
| 12079 | MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value"); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 12080 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 12081 | |
| 12082 | #ifdef CONFIG_IPW2200_MONITOR |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 12083 | module_param_named(mode, network_mode, int, 0444); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12084 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)"); |
| 12085 | #else |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 12086 | module_param_named(mode, network_mode, int, 0444); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12087 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)"); |
| 12088 | #endif |
| 12089 | |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 12090 | module_param(bt_coexist, int, 0444); |
| 12091 | MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)"); |
| 12092 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 12093 | module_param(hwcrypto, int, 0444); |
Zhu Yi | bde37d0 | 2006-01-24 16:38:08 +0800 | [diff] [blame] | 12094 | MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 12095 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 12096 | module_param(cmdlog, int, 0444); |
| 12097 | MODULE_PARM_DESC(cmdlog, |
| 12098 | "allocate a ring buffer for logging firmware commands"); |
| 12099 | |
Zhu Yi | 4bfdb91 | 2006-01-24 16:37:16 +0800 | [diff] [blame] | 12100 | module_param(roaming, int, 0444); |
| 12101 | MODULE_PARM_DESC(roaming, "enable roaming support (default on)"); |
| 12102 | |
Zhu Yi | d2b83e1 | 2006-04-13 17:19:36 +0800 | [diff] [blame] | 12103 | module_param(antenna, int, 0444); |
| 12104 | MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)"); |
| 12105 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12106 | module_exit(ipw_exit); |
| 12107 | module_init(ipw_init); |